|
@@ -0,0 +1,251 @@
|
|
|
+package com.ym.mec.web.controller.open;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alipay.api.domain.BizActionComsumedAmountDTO;
|
|
|
+import com.microsvc.toolkit.common.response.template.R;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
|
|
|
+import com.ym.mec.biz.dal.entity.Organization;
|
|
|
+import com.ym.mec.biz.dal.entity.SysConfig;
|
|
|
+import com.ym.mec.biz.dal.enums.GroupType;
|
|
|
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.wrapper.Double11StaticWrapper;
|
|
|
+import com.ym.mec.biz.service.OrganizationService;
|
|
|
+import com.ym.mec.biz.service.SysConfigService;
|
|
|
+import com.ym.mec.common.controller.BaseController;
|
|
|
+import com.ym.mec.common.page.PageInfo;
|
|
|
+import com.ym.mec.util.collection.MapUtil;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.ParsePosition;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author 袁亮
|
|
|
+ * @apiNote 2023双11销售统计
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@RequestMapping("${app-config.url.web:}/open/double11Statics")
|
|
|
+@Api(tags = "2023双11统计")
|
|
|
+public class OpenDouble11StaticsController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderDao studentPaymentOrderDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrganizationService organizationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value = "2023双11销售统计", notes = "2023双11销售统计")
|
|
|
+ @PostMapping("/saleStatics")
|
|
|
+ public R<Double11StaticWrapper.SaleStatics> saleStatics() {
|
|
|
+ Double11StaticWrapper.SaleStaticsQuery query = new Double11StaticWrapper.SaleStaticsQuery();
|
|
|
+
|
|
|
+ SysConfig config = sysConfigService.findByParamName("2023_double_eleven_active_config");
|
|
|
+ Double11StaticWrapper.SaleStaticConfigParam configParam =
|
|
|
+ JSON.parseObject(config.getParanValue(), Double11StaticWrapper.SaleStaticConfigParam.class);
|
|
|
+
|
|
|
+ Double11StaticWrapper.SaleStatics result = new Double11StaticWrapper.SaleStatics();
|
|
|
+ // 1V1
|
|
|
+ query.setSaleStaticsType(1);
|
|
|
+ setQueryParam(query, configParam);
|
|
|
+ Double11StaticWrapper.SaleAmountAndUser s1v1 = studentPaymentOrderDao.saleStatics(query);
|
|
|
+ result.setTotalSale1V1(s1v1.getSaleAmount());
|
|
|
+ result.setTotalUser1V1PurchaseNumber(s1v1.getUserPurchaseNumber());
|
|
|
+
|
|
|
+ // 1v12
|
|
|
+ query.setSaleStaticsType(2);
|
|
|
+ setQueryParam(query, configParam);
|
|
|
+ Double11StaticWrapper.SaleAmountAndUser s1v2 = studentPaymentOrderDao.saleStatics(query);
|
|
|
+ result.setTotalSale1V2(s1v2.getSaleAmount());
|
|
|
+ result.setTotalUser1V2PurchaseNumber(s1v2.getUserPurchaseNumber());
|
|
|
+
|
|
|
+ // 乐理直播
|
|
|
+ query.setSaleStaticsType(3);
|
|
|
+ setQueryParam(query, configParam);
|
|
|
+ Double11StaticWrapper.SaleAmountAndUser theory = studentPaymentOrderDao.saleStatics(query);
|
|
|
+ result.setTotalSaleTheory(theory.getSaleAmount());
|
|
|
+ result.setTotalUserTheoryPurchaseNumber(theory.getUserPurchaseNumber());
|
|
|
+
|
|
|
+ // 云教练
|
|
|
+ query.setSaleStaticsType(4);
|
|
|
+ setQueryParam(query, configParam);
|
|
|
+ Double11StaticWrapper.SaleAmountAndUser cloudTeacher = studentPaymentOrderDao.saleStatics(query);
|
|
|
+ result.setTotalSaleCloudTeacher(cloudTeacher.getSaleAmount());
|
|
|
+ result.setTotalUserCloudTeacherPurchaseNumber(cloudTeacher.getUserPurchaseNumber());
|
|
|
+
|
|
|
+ // 乐器
|
|
|
+ query.setSaleStaticsType(5);
|
|
|
+ setQueryParam(query, configParam);
|
|
|
+ Double11StaticWrapper.SaleAmountAndUser good = studentPaymentOrderDao.musicalSaleStatics(query);
|
|
|
+ result.setTotalSaleMusical(good.getSaleAmount());
|
|
|
+ result.setTotalUserMusicalPurchaseNumber(good.getUserPurchaseNumber());
|
|
|
+
|
|
|
+ // 保价卡
|
|
|
+ query.setSaleStaticsType(6);
|
|
|
+ setQueryParam(query, configParam);
|
|
|
+ Double11StaticWrapper.SaleAmountAndUser sporadic = studentPaymentOrderDao.saleStatics(query);
|
|
|
+ result.setTotalSaleMaintenance(sporadic.getSaleAmount());
|
|
|
+ result.setTotalUserMaintenancePurchaseNumber(sporadic.getUserPurchaseNumber());
|
|
|
+
|
|
|
+ BigDecimal totalAmount = result.getTotalSale1V1()
|
|
|
+ .add(result.getTotalSale1V2())
|
|
|
+ .add(result.getTotalSaleMaintenance())
|
|
|
+ .add(result.getTotalSaleMusical())
|
|
|
+ .add(result.getTotalSaleTheory())
|
|
|
+ .add(result.getTotalSaleCloudTeacher());
|
|
|
+ result.setTotalSaleAmount(totalAmount);
|
|
|
+ return R.from(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "2023双11销售统计详情", notes = "2023双11销售统计详情")
|
|
|
+ @GetMapping("/saleStaticsDetail")
|
|
|
+ public R<List<Double11StaticWrapper.SaleAmountAndUser>> saleStaticsDetail(Double11StaticWrapper.SaleStaticsQuery query) {
|
|
|
+
|
|
|
+
|
|
|
+ SysConfig config = sysConfigService.findByParamName("2023_double_eleven_active_config");
|
|
|
+ Double11StaticWrapper.SaleStaticConfigParam configParam =
|
|
|
+ JSON.parseObject(config.getParanValue(), Double11StaticWrapper.SaleStaticConfigParam.class);
|
|
|
+ setQueryParam(query, configParam);
|
|
|
+
|
|
|
+
|
|
|
+ List<Organization> allOrgans = organizationService.findAllOrgans(query.getTenantId());
|
|
|
+ Map<Integer, String> orgIdNameMap = allOrgans.stream()
|
|
|
+ .collect(Collectors.toMap(Organization::getId, Organization::getName));
|
|
|
+ List<Double11StaticWrapper.SaleAmountAndUser> result = studentPaymentOrderDao.saleStaticsByOrgId(query);
|
|
|
+ result.forEach(next -> next.setOrganName(orgIdNameMap.getOrDefault(next.getOrganId(), "")));
|
|
|
+
|
|
|
+ String orderBy = Optional.ofNullable(query.getOrderBy()).orElse("saleAmount");
|
|
|
+ int asc = Optional.ofNullable(query.getAsc()).orElse(0);
|
|
|
+ if ("saleAmount".equals(orderBy)) {
|
|
|
+ result.sort((o1, o2) -> {
|
|
|
+ if (0 == asc) {
|
|
|
+ return o1.getSaleAmount().compareTo(o2.getSaleAmount());
|
|
|
+ } else {
|
|
|
+ return o2.getSaleAmount().compareTo(o1.getSaleAmount());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if ("userCount".equals(orderBy)) {
|
|
|
+ result.sort((o1, o2) -> {
|
|
|
+ if (0 == asc) {
|
|
|
+ return o1.getUserPurchaseNumber().compareTo(o2.getUserPurchaseNumber());
|
|
|
+ } else {
|
|
|
+ return o2.getUserPurchaseNumber().compareTo(o1.getUserPurchaseNumber());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ Double11StaticWrapper.SaleAmountAndUser total = new Double11StaticWrapper.SaleAmountAndUser();
|
|
|
+ total.setOrganName("总部");
|
|
|
+ double acAmount = result.stream().map(Double11StaticWrapper.SaleAmountAndUser::getActualAmount)
|
|
|
+ .mapToDouble(BigDecimal::doubleValue).sum();
|
|
|
+ total.setActualAmount(new BigDecimal(acAmount));
|
|
|
+ double baAmount = result.stream().map(Double11StaticWrapper.SaleAmountAndUser::getBalancePaymentAmount)
|
|
|
+ .mapToDouble(BigDecimal::doubleValue).sum();
|
|
|
+ total.setBalancePaymentAmount(new BigDecimal(baAmount));
|
|
|
+ int totalUser = result.stream().map(Double11StaticWrapper.SaleAmountAndUser::getUserPurchaseNumber)
|
|
|
+ .mapToInt(Integer::intValue).sum();
|
|
|
+ total.setUserPurchaseNumber(totalUser);
|
|
|
+
|
|
|
+ result.add(0, total);
|
|
|
+ return R.from(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "2023双11销售统计详情", notes = "2023双11销售统计详情")
|
|
|
+ @GetMapping("/queryStudentPaymentOrder")
|
|
|
+ public R<PageInfo<Double11StaticWrapper.SaleStaticsStudent>> queryStudentPaymentOrder(Double11StaticWrapper.SaleStaticsStudentQuery query) {
|
|
|
+ Double11StaticWrapper.SaleStaticsQuery temp = new Double11StaticWrapper.SaleStaticsQuery();
|
|
|
+ SysConfig config = sysConfigService.findByParamName("2023_double_eleven_active_config");
|
|
|
+ Double11StaticWrapper.SaleStaticConfigParam configParam =
|
|
|
+ JSON.parseObject(config.getParanValue(), Double11StaticWrapper.SaleStaticConfigParam.class);
|
|
|
+ setQueryParam(temp, configParam);
|
|
|
+ Map<String, Object> tempMap = new HashMap<>();
|
|
|
+ MapUtil.populateMap(tempMap, temp);
|
|
|
+
|
|
|
+ query.setOrderBy("t.pay_time_");
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ MapUtil.populateMap(params, query);
|
|
|
+ params.putAll(tempMap);
|
|
|
+ PageInfo<Double11StaticWrapper.SaleStaticsStudent> pageInfo = new PageInfo<>(query.getPage(), query.getRows());
|
|
|
+ List<Double11StaticWrapper.SaleStaticsStudent> dataList = new ArrayList<>();
|
|
|
+ Integer count = studentPaymentOrderDao.queryPaymentStudentCount(params);
|
|
|
+ if (count > 0) {
|
|
|
+ pageInfo.setTotal(count);
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
+ dataList = studentPaymentOrderDao.queryPaymentStudentByPage(params);
|
|
|
+ }
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
+ return R.from(pageInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setQueryParam(Double11StaticWrapper.SaleStaticsQuery query,
|
|
|
+ Double11StaticWrapper.SaleStaticConfigParam configParam) {
|
|
|
+
|
|
|
+ Integer saleStaticsType = query.getSaleStaticsType();
|
|
|
+ query.setGroupType(null);
|
|
|
+ query.setType(null);
|
|
|
+ query.setActivityId(null);
|
|
|
+ query.setGoodId(null);
|
|
|
+ query.setMusicGroupId(null);
|
|
|
+ query.setTenantId(Optional.ofNullable(configParam.getTenantId()).orElse(1));
|
|
|
+
|
|
|
+ if (saleStaticsType == 1) {
|
|
|
+ // 1V1
|
|
|
+ query.setGroupType(GroupType.VIP);
|
|
|
+ query.setType(OrderTypeEnum.SMALL_CLASS_TO_BUY);
|
|
|
+ query.setActivityId(configParam.getV1());
|
|
|
+ } else if (saleStaticsType == 2) {
|
|
|
+ // 乐理
|
|
|
+ query.setGroupType(GroupType.LIVE);
|
|
|
+ query.setType(OrderTypeEnum.LIVE_BUY);
|
|
|
+ query.setActivityId(configParam.getV2());
|
|
|
+ } else if (saleStaticsType == 3) {
|
|
|
+ // 乐理
|
|
|
+ query.setGroupType(GroupType.LIVE);
|
|
|
+ query.setType(OrderTypeEnum.LIVE_BUY);
|
|
|
+ query.setActivityId(configParam.getTheoryLive());
|
|
|
+ } else if (saleStaticsType == 4) {
|
|
|
+ // 云教练
|
|
|
+ query.setGroupType(GroupType.MEMBER);
|
|
|
+ query.setType(OrderTypeEnum.MEMBER);
|
|
|
+ query.setActivityId(configParam.getCloudTeacher());
|
|
|
+ } else if (saleStaticsType == 5) {
|
|
|
+ // 乐器销售
|
|
|
+ Map<String, Long> musical = configParam.getMusical();
|
|
|
+ if (musical != null) {
|
|
|
+ Collection<String> values = musical.values().stream().map(String::valueOf).collect(Collectors.toList());
|
|
|
+ query.setGoodId(String.join(",", values));
|
|
|
+ }
|
|
|
+ query.setStartPayTime(Optional.ofNullable(configParam.getStartPayTime()).orElse(new SimpleDateFormat(
|
|
|
+ "yyyy-MM-dd HH:mm:ss").parse("2023-11-11 00:00:00", new ParsePosition(0))));
|
|
|
+ query.setEndPayTime(Optional.ofNullable(configParam.getEndPayTime()).orElse(new SimpleDateFormat(
|
|
|
+ "yyyy-MM-dd HH:mm:ss").parse("2023-11-11 23:59:59", new ParsePosition(0))));
|
|
|
+ } else if (saleStaticsType == 6) {
|
|
|
+ // 保价卡销售
|
|
|
+ query.setGroupType(GroupType.SPORADIC);
|
|
|
+ query.setType(OrderTypeEnum.SPORADIC);
|
|
|
+ query.setMusicGroupId(configParam.getSporadic());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|