|
|
@@ -8,15 +8,15 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
-import com.cyksj.mapper.GoodsDonMapper;
|
|
|
-import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
-import com.cyksj.mapper.GroupsMapper;
|
|
|
-import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
+import com.cyksj.mapper.*;
|
|
|
import com.cyksj.mapper.manage.statistics.AppleOneDataMapper;
|
|
|
import com.cyksj.mapper.manage.statistics.RealGoodsDataMapper;
|
|
|
+import com.cyksj.mapper.manage.statistics.StatisticsUserDataMapper;
|
|
|
import com.cyksj.mapper.manage.statistics.StreamingAccountDataMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.excel.ExcelAccountData;
|
|
|
+import com.cyksj.model.excel.ExcelSheetAndData;
|
|
|
+import com.cyksj.model.excel.statistics.*;
|
|
|
import com.cyksj.model.manage.views.GroupsRelationView;
|
|
|
import com.cyksj.model.manage.views.OrderDonView;
|
|
|
import com.cyksj.model.views.*;
|
|
|
@@ -68,6 +68,10 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
|
|
|
private final GroupsMapper groupsMapper;
|
|
|
|
|
|
+ private final OrderDonMapper orderDonMapper;
|
|
|
+
|
|
|
+ private final StatisticsUserDataMapper statisticsUserDataMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) {
|
|
|
BackgroundDataView backgroundDataView = new BackgroundDataView();
|
|
|
@@ -228,6 +232,191 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("处理状态变更成功");
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<ExcelSheetAndData> exportStatisticsDataByType(Integer type, Long startTime, Long endTime) {
|
|
|
+ String startDate = null;
|
|
|
+ String endDate = null;
|
|
|
+ if (type==null) type = 0;
|
|
|
+ if (startTime != null) {
|
|
|
+ startDate = DateTime.of(startTime).toString();
|
|
|
+ }
|
|
|
+ if (endTime != null) {
|
|
|
+ endDate = DateTime.of(endTime).toString();
|
|
|
+ }
|
|
|
+ List<ExcelSheetAndData> excelSheetDataList = new ArrayList<>();
|
|
|
+ switch (type) {
|
|
|
+ case 1:
|
|
|
+ exportAppleOneData(excelSheetDataList, startDate, endDate);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ exportStreamingAccountData(excelSheetDataList, startDate, endDate);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ exportRealGoodsData(excelSheetDataList, startDate, endDate);
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ exportFashionData(excelSheetDataList, startDate, endDate);
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ exportRegisterData(excelSheetDataList, startDate, endDate);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ exportAppleOneData(excelSheetDataList, startDate, endDate);
|
|
|
+ exportStreamingAccountData(excelSheetDataList, startDate, endDate);
|
|
|
+ exportRealGoodsData(excelSheetDataList, startDate, endDate);
|
|
|
+ exportFashionData(excelSheetDataList, startDate, endDate);
|
|
|
+ exportRegisterData(excelSheetDataList, startDate, endDate);
|
|
|
+ }
|
|
|
+ return excelSheetDataList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void exportRegisterData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
|
|
|
+ List<ExcelRegisterAccountData> registerAccountData = new ArrayList<>();
|
|
|
+ Constant.registerAccount.forEach(platform -> {
|
|
|
+ List<RegisterOrderDon> registerOrderDons = statisticsUserDataMapper.getPlatformHasPaymentOrders(platform, startDate, endDate);
|
|
|
+ if (registerOrderDons.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ExcelRegisterAccountData registerDataExcel = new ExcelRegisterAccountData();
|
|
|
+ registerDataExcel.setPlatform(platform);
|
|
|
+ registerDataExcel.setNumOfOrder(registerOrderDons.size());
|
|
|
+ Set<Long> userSet = registerOrderDons.stream().map(RegisterOrderDon::getUserId).collect(Collectors.toSet());
|
|
|
+ registerDataExcel.setNumOfUser(userSet.size());
|
|
|
+ Optional<BigDecimal> reduce = registerOrderDons.stream().map(RegisterOrderDon::getMoney).reduce(BigDecimal::add);
|
|
|
+ registerDataExcel.setMoney(reduce.isPresent() ? reduce.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO);
|
|
|
+ registerAccountData.add(registerDataExcel);
|
|
|
+ });
|
|
|
+ if (registerAccountData.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ excelSheetDataList.add(new ExcelSheetAndData("注册账号数据", registerAccountData, ExcelRegisterAccountData.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void exportFashionData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
|
|
|
+ List<Long> goodsIds = statisticsUserDataMapper.getAllFashionGoods(startDate, endDate);
|
|
|
+ List<ExcelRealGoodsData> fashionData = new ArrayList<>();
|
|
|
+ goodsIds.forEach(goodsId->{
|
|
|
+ //查找所有规格
|
|
|
+ List<Long> skuIds = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, goodsId)).stream().map(GoodsDonSku::getId).collect(Collectors.toList());
|
|
|
+ skuIds.forEach(skuId -> {
|
|
|
+ //订单数据
|
|
|
+ ExcelRealGoodsData exportData = statisticsUserDataMapper.getExportGoodsDonDataBySkuId(skuId, startDate, endDate);
|
|
|
+ if (exportData == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ exportData.setName(goodsDonMapper.selectById(goodsId).getTitle());
|
|
|
+ exportData.setSpecVal(goodsDonSkuMapper.selectById(skuId).getSpecVal());
|
|
|
+ if (exportData.getNumOfOrder() != 0) {
|
|
|
+ fashionData.add(exportData);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (fashionData.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ excelSheetDataList.add(new ExcelSheetAndData("潮玩好物", fashionData, ExcelRealGoodsData.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void exportRealGoodsData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
|
|
|
+ List<Long> goodsIds = statisticsUserDataMapper.getAllRealGoods(startDate, endDate);
|
|
|
+ List<ExcelRealGoodsData> realGoodsData = new ArrayList<>();
|
|
|
+ goodsIds.forEach(goodsId -> {
|
|
|
+ //查找所有规格
|
|
|
+ List<Long> skuIds = goodsDonSkuMapper.selectList(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, goodsId)).stream().map(GoodsDonSku::getId).collect(Collectors.toList());
|
|
|
+ skuIds.forEach(skuId -> {
|
|
|
+ //订单数据
|
|
|
+ ExcelRealGoodsData exportData = statisticsUserDataMapper.getExportGoodsDonDataBySkuId(skuId, startDate, endDate);
|
|
|
+ if (exportData == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ exportData.setName(goodsDonMapper.selectById(goodsId).getTitle());
|
|
|
+ exportData.setSpecVal(goodsDonSkuMapper.selectById(skuId).getSpecVal());
|
|
|
+ if (exportData.getNumOfOrder() != 0) {
|
|
|
+ realGoodsData.add(exportData);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ if (realGoodsData.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ excelSheetDataList.add(new ExcelSheetAndData("硬件设备数据", realGoodsData, ExcelRealGoodsData.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void exportStreamingAccountData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
|
|
|
+ List<Long> goodsIds = statisticsUserDataMapper.getAllStreaming(startDate, endDate);
|
|
|
+ List<ExcelStreamingAccountData> streamingAccountData = new ArrayList<>();
|
|
|
+ goodsIds.forEach(goodsId -> {
|
|
|
+ //订单数据
|
|
|
+ ExcelStreamingAccountData exportData = statisticsUserDataMapper.getExportStreamingAccountData(goodsId, null, null, startDate, endDate);
|
|
|
+ exportData.setName(goodsDonMapper.selectById(goodsId).getTitle());
|
|
|
+ //兑换单数
|
|
|
+ exportData.setNumOfExCodeOrder(statisticsUserDataMapper.getExportStreamingAccountData(goodsId, null, true, startDate, endDate).getNumOfOrder());
|
|
|
+ //分销记录
|
|
|
+ ExcelStreamingAccountData distributeData = statisticsUserDataMapper.getExportStreamingAccountData(goodsId, true, null, startDate, endDate);
|
|
|
+ exportData.setDisOrder(distributeData.getNumOfOrder());
|
|
|
+ exportData.setDisMoney(distributeData.getMoney() != null ? distributeData.getMoney() : BigDecimal.ZERO);
|
|
|
+ //月、季、年
|
|
|
+ exportData.setMonth(statisticsUserDataMapper.getTypeData(goodsId, Constant.payType.get(0), startDate, endDate));
|
|
|
+ exportData.setSeason(statisticsUserDataMapper.getTypeData(goodsId, Constant.payType.get(1), startDate, endDate));
|
|
|
+ exportData.setYear(statisticsUserDataMapper.getTypeData(goodsId, Constant.payType.get(2), startDate, endDate));
|
|
|
+ streamingAccountData.add(exportData);
|
|
|
+ });
|
|
|
+ if (streamingAccountData.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ excelSheetDataList.add(new ExcelSheetAndData("流媒体账号数据", streamingAccountData, ExcelStreamingAccountData.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private void exportAppleOneData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
|
|
|
+ Map<String, List<GoodsDonSku>> appleOneMap = statistics.getAppleOneMap();
|
|
|
+ List<ExcelAppleOneData> appleData = new ArrayList<>();
|
|
|
+ appleOneMap.forEach((k,v)->{
|
|
|
+ ExcelAppleOneData appleDataExcel = new ExcelAppleOneData();
|
|
|
+ appleDataExcel.setArea(k);
|
|
|
+ Set<Long> skuIds = v.stream().map(GoodsDonSku::getId).collect(Collectors.toSet());
|
|
|
+ List<OrderDon> orderDons = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class).in(OrderDon::getSkuId, skuIds).notIn(OrderDon::getStatus, Constant.noOrderStatus).between(OrderDon::getCreatedTime, startDate, endDate));
|
|
|
+ appleDataExcel.setNumOfOrder(orderDons.size());
|
|
|
+ Set<Long> userSet = Optional.ofNullable(orderDons.stream().map(OrderDon::getUserId).collect(Collectors.toSet())).orElse(new HashSet<>());
|
|
|
+ appleDataExcel.setNumOfUser(userSet.size());
|
|
|
+ List<OrderDon> exCodeOrders = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getType, OrderDon.Type.EX_CODE)
|
|
|
+ .in(OrderDon::getSkuId, skuIds)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderStatus).between(OrderDon::getCreatedTime, startDate, endDate));
|
|
|
+ if (orderDons.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ appleDataExcel.setNumOfExCodeOrder(exCodeOrders.size());
|
|
|
+ Optional<BigDecimal> money = orderDons.stream().map(OrderDon::getMoney).reduce(BigDecimal::add);
|
|
|
+ appleDataExcel.setMoney(money.isPresent() ? money.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO);
|
|
|
+ List<OrderDon> distributeOrders = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getIsDistribute, true)
|
|
|
+ .in(OrderDon::getSkuId, skuIds)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderStatus).between(OrderDon::getCreatedTime, startDate, endDate));
|
|
|
+ appleDataExcel.setDisOrder(distributeOrders.size());
|
|
|
+ Optional<BigDecimal> distributeMoney = distributeOrders.stream().map(OrderDon::getMoney).reduce(BigDecimal::add);
|
|
|
+ appleDataExcel.setDisMoney(distributeMoney.isPresent() ? distributeMoney.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO);
|
|
|
+ Map<Long, List<OrderDon>> skuMaps = orderDons.stream().collect(Collectors.groupingBy(OrderDon::getSkuId));
|
|
|
+ v.forEach(sku -> {
|
|
|
+ Long skuId = sku.getId();
|
|
|
+ List<OrderDon> dons = Optional.ofNullable(skuMaps.get(skuId)).orElse(new ArrayList<>());
|
|
|
+ if (sku.getSpecVal().contains(Constant.payType.get(0)) && !sku.getSpecVal().contains(Constant.payType.get(2))) {
|
|
|
+ appleDataExcel.setMonth(dons.size());
|
|
|
+ } else if (sku.getSpecVal().contains(Constant.payType.get(1))) {
|
|
|
+ appleDataExcel.setSeason(dons.size());
|
|
|
+ } else if (!sku.getSpecVal().contains(Constant.payType.get(0)) && sku.getSpecVal().contains(Constant.payType.get(2))) {
|
|
|
+ appleDataExcel.setYear(dons.size());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ appleData.add(appleDataExcel);
|
|
|
+ });
|
|
|
+ if (appleData.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ excelSheetDataList.add(new ExcelSheetAndData("Apple One数据", appleData, ExcelAppleOneData.class));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void getAppleOneDataView(BackgroundDataView backgroundDataView, Date startDate, Date endDate) {
|
|
|
List<AppleOneData> appleOneData = appleOneDataMapper.statisticsAppleOneData(startDate, endDate);
|
|
|
if (DateUtil.beginOfDay(DateTime.now()).equals(startDate) && DateUtil.beginOfDay(DateUtil.offsetDay(DateTime.now(), 1)).equals(endDate)) {
|