Просмотр исходного кода

fix 优化每月订单导出数据、数据统计查询

zoujiajian 3 лет назад
Родитель
Сommit
3accec4815

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GoodsDonMapper.java

@@ -2,6 +2,7 @@ package com.cyksj.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.GoodsDon;
+import com.cyksj.model.views.GoodsDonSkuView;
 import org.apache.ibatis.annotations.Select;
 
 import java.math.BigDecimal;
@@ -22,4 +23,8 @@ public interface GoodsDonMapper extends BaseMapper<GoodsDon> {
 	@Select("select distinct g.id,g.title from order_don o inner join (select user_id from user_distribute_shared where shared_id = #{cpsUserId}) us on us.user_id = o.user_id and o.is_fixed_distribute is true and o.relation_id != 0 and o.status not in ('close','noPayment')" +
 			" inner join goods_don g on o.goods_id = g.id order by g.id")
 	List<GoodsDon> getDistributeGoodsDetail(Long cpsUserId);
+
+	@Select("select sku.id as skuId,sku.goods_id,sku.spec_val,g.title as goodsTitle from goods_don_sku sku inner join goods_don g on g.id = sku.goods_id" +
+			" where g.deleted is true and type = #{type}")
+	List<GoodsDonSkuView> selectGoodsDonSkuByGoodsType(Integer type);
 }

+ 6 - 2
netflix-dao/src/main/java/com/cyksj/mapper/OrderDonMapper.java

@@ -12,7 +12,7 @@ import org.apache.ibatis.annotations.Param;
 import java.math.BigDecimal;
 import java.util.Date;
 import java.util.List;
-import java.util.Optional;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -42,5 +42,9 @@ public interface OrderDonMapper extends BaseMapper<OrderDon> {
 
 	ChannelPopularizeView countPopularizeOrderDetail(@Param("popularizeId") Long popularizeId, @Param("startTime") String startTime, @Param("endTime") String endTime);
 
-	Optional<BigDecimal> selectThisMonthMoney(@Param("skuIds") Set<Long> skuIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+	BigDecimal selectThisMonthAppleOneMoney(@Param("skuIds") Set<Long> skuIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	BigDecimal selectThisMonthDistributeOrderMoney(@Param("skuIds") Set<Long> skuIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	Map<String, Object> getOrderDetailByGoodsType(@Param("type") Integer type, @Param("noOrderStatus") List<String> noOrderStatus, @Param("startDate") Date startDate, @Param("endDate") Date endDate);
 }

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/statistics/StatisticsExportMapper.java

@@ -1,10 +1,12 @@
 package com.cyksj.mapper.manage.statistics;
 
 import cn.hutool.core.date.DateTime;
+import com.cyksj.model.excel.statistics.ExcelAppleOneData;
 import org.apache.ibatis.annotations.Param;
 
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Set;
 
 /*
  *项目名: netflix
@@ -59,4 +61,8 @@ public interface StatisticsExportMapper{
 	BigDecimal getMonthGoodsTypeAmountOfOrderByType(@Param("type") Integer type, @Param("goodsType") Integer goodsType, @Param("category") Integer category, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
 	Integer getMonthUserSourceNumOrderByType(@Param("type") Integer type, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	ExcelAppleOneData getAppleOneDataThisMonth(@Param("skuIds") Set<Long> skuIds, @Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	Integer getAppleOnePayMonthTypeOrderThisMonth(@Param("skuId") Long skuId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 }

+ 8 - 0
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelSheetAndData.java

@@ -22,4 +22,12 @@ public class ExcelSheetAndData {
     private List<?> data;
 
     private Class<?> clazz;
+
+    private Integer sort;
+
+    public ExcelSheetAndData(String sheetName, List<?> data, Class<?> clazz) {
+        this.sheetName = sheetName;
+        this.data = data;
+        this.clazz = clazz;
+    }
 }

+ 27 - 2
netflix-dao/src/main/resources/mapper/OrderDonMapper.xml

@@ -157,11 +157,36 @@
         s2
     </select>
 
-    <select id="selectThisMonthMoney" resultType="java.math.BigDecimal">
-        select sum(money) - ifnull(sum(refund_money),0) from `order_don` where sku_id in
+    <select id="selectThisMonthAppleOneMoney" resultType="java.math.BigDecimal">
+        select cast(ifnull((sum(money),0) - ifnull(sum(refund_money),0))/100 as decimal(10,2)) from `order_don` where sku_id in
         <foreach collection="skuIds" item="item" open="(" separator="," close=")">
             #{item}
         </foreach>
         and status not in ('close','noPayment') and created_time between #{startDate} and #{endDate}
     </select>
+
+    <select id="selectThisMonthDistributeOrderMoney" resultType="java.math.BigDecimal">
+        select cast((ifnull(sum(money),0) - ifnull(sum(refund_money),0))/100 as decimal(10,2)) from `order_don` where sku_id in
+        <foreach collection="skuIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and status not in ('close','noPayment') and is_distribute = 1
+        and created_time between #{startDate} and #{endDate}
+    </select>
+
+    <select id="getOrderDetailByGoodsType" resultType="java.util.Map">
+        select count(id) as orderNum,
+               ifnull(sum(money),0) as money
+        from order_don where goods_id in (select id from `goods_don` where type = #{type})
+        and status not in
+        <foreach collection="noOrderStatus" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        <if test="startDate != null">
+            and created_time >= #{startDate}
+        </if>
+        <if test="endDate != null">
+            and created_time &lt; #{endDate}
+        </if>
+    </select>
 </mapper>

+ 33 - 0
netflix-dao/src/main/resources/mapper/StatisticsExportMapper.xml

@@ -396,4 +396,37 @@
         ) s left join order_don o on o.user_id = s.id where o.status not in ('close', 'noPayment','refund')
         and o.created_time >= #{startDate} and o.created_time &lt; #{endDate}
     </select>
+
+    <select id="getAppleOneDataThisMonth" resultType="com.cyksj.model.excel.statistics.ExcelAppleOneData">
+        select count(distinct if(status = 'refund',NUll,user_id)) as numOfUser,
+        count(if(status = 'refund',NULL,id)) as numOfOrder,
+        cast((ifnull(sum(money),0)-ifnull(sum(refund_money),0))/100 as decimal(10,2)) as money,
+        count(if(type = 'EX_CODE' and status != 'refund',id,NULL)) as numOfExCodeOrder,
+        count(if(is_distribute = 1 and status != 'refund',id,NULL)) as disOrder,
+        cast((sum(if(is_distribute = 1,money,0))-ifnull(sum(if(is_distribute = 1,refund_money,0)),0))/100 as
+        decimal(10,2)) as disMoney
+        from `order_don`
+        where sku_id in
+        <foreach collection="skuIds" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+        and status not in ('close','noPayment')
+        <if test="startDate != null">
+            and created_time >= #{startDate}
+        </if>
+        <if test="endDate != null">
+            and created_time &lt; #{endDate}
+        </if>
+    </select>
+
+    <select id="getAppleOnePayMonthTypeOrderThisMonth" resultType="java.lang.Integer">
+        select count(*) from `order_don` where sku_id = #{skuId}
+        and status not in ('close','noPayment','refund')
+        <if test="startDate != null">
+            and created_time >= #{startDate}
+        </if>
+        <if test="endDate != null">
+            and created_time &lt; #{endDate}
+        </if>
+    </select>
 </mapper>

+ 5 - 2
netflix-dao/src/main/resources/mapper/StatisticsUserDataMapper.xml

@@ -6,7 +6,10 @@
             resultType="com.cyksj.model.excel.statistics.ExcelStreamingAccountData">
         select count(distinct if(status = 'refund',NUll,user_id)) as numOfUser,
                count(if(status = 'refund',NULL,id)) as numOfOrder,
-               ifnull((sum(money)-ifnull(sum(refund_money),0))/100,0) as money
+               cast((ifnull(sum(money),0)-ifnull(sum(refund_money),0))/100 as decimal(10,2)) as money,
+               count(if(type = 'EX_CODE' and status != 'refund',id,NULL)) as numOfExCodeOrder,
+               count(if(is_distribute = 1 and status != 'refund',id,NULL)) as disOrder,
+               cast((sum(if(is_distribute = 1,money,0))-ifnull(sum(if(is_distribute = 1,refund_money,0)),0))/100 as decimal(10,2)) as disMoney
         from `order_don`
         where sku_id in (select id from `goods_don_sku` where goods_id = #{goodsId})
         and status not in ('close','noPayment')
@@ -42,7 +45,7 @@
     <select id="getExportGoodsDonDataBySkuId" resultType="com.cyksj.model.excel.statistics.ExcelRealGoodsData">
         select count(distinct if(status = 'refund',NULL,user_id)) as numOfUser,
                count(if(status = 'refund',NULL,id)) as numOfOrder,
-               ifnull((sum(money) - ifnull(sum(refund_money),0)) / 100, 0) as money
+               cast((ifnull(sum(money),0) - ifnull(sum(refund_money),0)) / 100 as decimal(10,2)) as money
         from `order_don`
         where sku_id = #{skuId}
           and status not in ('close', 'noPayment')

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/statistics/StatisticsDataService.java

@@ -17,7 +17,7 @@ import java.util.List;
  *创建时间:2022/10/17 14:43
  */
 public interface StatisticsDataService {
-	Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime);
+	Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) throws InterruptedException;
 
 	IPage<ExpiredAccountDataView> getExpiredAccountView(Boolean isCorpWx, String customerService, Long goodsId, Long skuId, String account, Boolean renewStatus, Boolean handleStatus, String cnAccount, String usAccount, Integer uid, Long startTime, Long endTime, Long start, Long limit);
 

+ 3 - 1
netflix-service/src/main/java/com/cyksj/service/mange/statistics/impl/StatisticsDataDayServiceImpl.java

@@ -243,7 +243,9 @@ public class StatisticsDataDayServiceImpl implements StatisticsDataDayService {
 	 * 统计实物数据
 	 */
 	public List<RealGoodsData> statisticsRealGoodsData(Date yesZeroDate, Date thisZeroDate, Boolean today) {
-		List<GoodsDon> goodsDons = goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getType, Constant.realGoodsType.get(0)));
+		List<GoodsDon> goodsDons = goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class)
+				.eq(GoodsDon::getType, Constant.realGoodsType.get(0))
+				.eq(GoodsDon::getDeleted, 1));
 		List<RealGoodsData> realGoodsDataList = new ArrayList<>();
 		if (!goodsDons.isEmpty()) {
 			goodsDons.forEach(goods -> {

+ 132 - 112
netflix-service/src/main/java/com/cyksj/service/mange/statistics/impl/StatisticsDataServiceImpl.java

@@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.constant.Constant;
+import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.mapper.*;
@@ -36,6 +37,7 @@ import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
+import java.util.concurrent.CountDownLatch;
 import java.util.stream.Collectors;
 
 /*
@@ -78,8 +80,10 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 
 	private final StatisticsExportMapper statisticsExportMapper;
 
+	private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
+
 	@Override
-	public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) {
+	public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) throws InterruptedException {
 		BackgroundDataView backgroundDataView = new BackgroundDataView();
 		Date startDate = null;
 		Date endDate = null;
@@ -89,18 +93,34 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		if (endTime != null) {
 			endDate = DateUtil.date(endTime);
 		}
+		CountDownLatch countDownLatch = new CountDownLatch(2);
+		final Date f_st = startDate;
+		final Date f_et = endDate;
 		//头部数据
-		headerData(backgroundDataView, startDate, endDate);
-		//流媒体账号
-		getStreamingAccountDataView(backgroundDataView, startDate, endDate);
-		//appleOne
-		getAppleOneDataView(backgroundDataView, startDate, endDate);
-		//实物数据
-		getRealGoodsData(backgroundDataView, startDate, endDate);
-		//注册账号数据
-		getRegisterAccountData(backgroundDataView, startDate, endDate);
-		//潮玩好物数据
-		getFashionGoodsData(backgroundDataView, startDate, endDate);
+		TASK_POOL.execute(() -> {
+			try {
+				headerData(backgroundDataView, f_st, f_et);
+			} finally {
+				countDownLatch.countDown();
+			}
+		});
+		TASK_POOL.execute(() -> {
+			try {
+				//流媒体账号
+				getStreamingAccountDataView(backgroundDataView, f_st, f_et);
+				//appleOne
+				getAppleOneDataView(backgroundDataView, f_st, f_et);
+				//实物数据
+				getRealGoodsData(backgroundDataView, f_st, f_et);
+				//注册账号数据
+				getRegisterAccountData(backgroundDataView, f_st, f_et);
+				//潮玩好物数据
+				getFashionGoodsData(backgroundDataView, f_st, f_et);
+			} finally {
+				countDownLatch.countDown();
+			}
+		});
+		countDownLatch.await();
 		return GatewayResponse.SUCCESS.newBuilder().toResult(backgroundDataView);
 	}
 
@@ -282,22 +302,63 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		if (endTime != null) {
 			endDate = DateTime.of(endTime).toString();
 		}
+		final String f_st = startDate;
+		final String f_et = endDate;
+		CountDownLatch countDownLatch = new CountDownLatch(3);
 		//业务订单数
-		exportBusinessMonthlyData(excelSheetDataList, startTime, endTime);
+		TASK_POOL.execute(() -> {
+			try {
+				exportBusinessMonthlyData(excelSheetDataList, startTime, endTime);
+			} finally {
+				countDownLatch.countDown();
+			}
+		});
 		//分销类型订单数据
-		exportDistributeMonthlyData(excelSheetDataList, startDate, endDate);
-
+		TASK_POOL.execute(() -> {
+			try {
+				exportDistributeMonthlyData(excelSheetDataList, f_st, f_et);
+			} finally {
+				countDownLatch.countDown();
+			}
+		});
 		//所有平台类型的订单数据
-		exportAllTypeData(excelSheetDataList, startDate, endDate);
+		TASK_POOL.execute(() -> {
+			try {
+				exportAllTypeData(excelSheetDataList, f_st, f_et);
+			} finally {
+				countDownLatch.countDown();
+			}
+		});
+		try {
+			countDownLatch.await();
+		} catch (InterruptedException e) {
+		}
 		return excelSheetDataList;
 	}
 
 	public void exportAllTypeData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
+		CountDownLatch latch = new CountDownLatch(2);
+		TASK_POOL.execute(() -> {
+			try {
+				exportStreamingAccountData(excelSheetDataList, startDate, endDate);
+			} finally {
+				latch.countDown();
+			}
+		});
+		TASK_POOL.execute(() -> {
+			try {
+				exportRealGoodsData(excelSheetDataList, startDate, endDate);
+			} finally {
+				latch.countDown();
+			}
+		});
 		exportAppleOneData(excelSheetDataList, startDate, endDate);
-		exportStreamingAccountData(excelSheetDataList, startDate, endDate);
-		exportRealGoodsData(excelSheetDataList, startDate, endDate);
 		exportFashionData(excelSheetDataList, startDate, endDate);
 		exportRegisterData(excelSheetDataList, startDate, endDate);
+		try {
+			latch.await();
+		} catch (InterruptedException e) {
+		}
 	}
 
 	private void exportBusinessMonthlyData(List<ExcelSheetAndData> excelSheetDataList, Long startTime, Long endTime) {
@@ -404,7 +465,7 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 //				.setMonthPrivateStreamingNumOfUser(monthPrivateStreamingNumOfUser)
 //				.setMonthPrivateAiNumOfUser(monthPrivateAiNumOfUser)
 //				.setMonthPrivateEqNumOfUser(monthPrivateEqNumOfUser);
-		excelSheetDataList.add(new ExcelSheetAndData("每月订单业务数据", List.of(excelMonthOrderData), ExcelMonthOrderData.class));
+		excelSheetDataList.add(new ExcelSheetAndData("每月订单业务数据", List.of(excelMonthOrderData), ExcelMonthOrderData.class, 1));
 	}
 
 	private void exportDistributeMonthlyData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
@@ -469,7 +530,7 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		excelMonthlyDistributeOrderData.setChannelUserSourceNum(channelUserSourceNum);
 		excelMonthlyDistributeOrderData.setChannelUserSourceOrderNum(channelUserSourceOrderNum);
 		excelMonthlyDistributeOrderData.setChannelUserSourceOrderRate(channelUserSourceOrderRate);
-		excelSheetDataList.add(new ExcelSheetAndData("每月用户分销数据", List.of(excelMonthlyDistributeOrderData), ExcelMonthlyDistributeOrderData.class));
+		excelSheetDataList.add(new ExcelSheetAndData("每月用户分销数据", List.of(excelMonthlyDistributeOrderData), ExcelMonthlyDistributeOrderData.class, 2));
 	}
 
 	private void exportRegisterData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
@@ -491,76 +552,70 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		if (registerAccountData.isEmpty()) {
 			return;
 		}
-		excelSheetDataList.add(new ExcelSheetAndData("注册账号数据", registerAccountData, ExcelRegisterAccountData.class));
+		excelSheetDataList.add(new ExcelSheetAndData("注册账号数据", registerAccountData, ExcelRegisterAccountData.class, 7));
 	}
 
 	private void exportFashionData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
-		List<Long> goodsIds = goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getType, Constant.realGoodsType.get(1))).stream().map(GoodsDon::getId).collect(Collectors.toList());
+		List<GoodsDonSkuView> goodsDonSkuViews = goodsDonMapper.selectGoodsDonSkuByGoodsType(Constant.realGoodsType.get(1));
 		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);
-				}
-			});
+		goodsDonSkuViews.forEach(goodsDonSkuView -> {
+			Long skuId = goodsDonSkuView.getSkuId();
+			String goodsTitle = goodsDonSkuView.getGoodsTitle();
+			String specVal = goodsDonSkuView.getSpecVal();
+			//订单数据
+			ExcelRealGoodsData exportData = statisticsUserDataMapper.getExportGoodsDonDataBySkuId(skuId, startDate, endDate);
+			if (exportData == null || exportData.getNumOfOrder() == 0) {
+				return;
+			}
+			exportData.setName(goodsTitle);
+			exportData.setSpecVal(specVal);
+
+			fashionData.add(exportData);
 		});
 		if (fashionData.isEmpty()) {
 			return;
 		}
-		excelSheetDataList.add(new ExcelSheetAndData("潮玩好物", fashionData, ExcelRealGoodsData.class));
+		excelSheetDataList.add(new ExcelSheetAndData("潮玩好物", fashionData, ExcelRealGoodsData.class, 6));
 	}
 
 	private void exportRealGoodsData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
-		List<Long> goodsIds = goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getType, Constant.realGoodsType.get(0))).stream().map(GoodsDon::getId).collect(Collectors.toList());
+		List<GoodsDonSkuView> goodsDonSkuViews = goodsDonMapper.selectGoodsDonSkuByGoodsType(Constant.realGoodsType.get(0));
 		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);
-				}
-			});
+		goodsDonSkuViews.forEach(goodsDonSkuView -> {
+			Long skuId = goodsDonSkuView.getSkuId();
+			String goodsTitle = goodsDonSkuView.getGoodsTitle();
+			String specVal = goodsDonSkuView.getSpecVal();
+			//订单数据
+			ExcelRealGoodsData exportData = statisticsUserDataMapper.getExportGoodsDonDataBySkuId(skuId, startDate, endDate);
+			if (exportData == null || exportData.getNumOfOrder() == 0) {
+				return;
+			}
+			exportData.setName(goodsTitle);
+			exportData.setSpecVal(specVal);
+
+			realGoodsData.add(exportData);
 		});
 		if (realGoodsData.isEmpty()) {
 			return;
 		}
-		excelSheetDataList.add(new ExcelSheetAndData("硬件设备数据", realGoodsData, ExcelRealGoodsData.class));
+		excelSheetDataList.add(new ExcelSheetAndData("硬件设备数据", realGoodsData, ExcelRealGoodsData.class, 5));
 	}
 
 	private void exportStreamingAccountData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
-		List<Account> accounts = accountService.getNoAppleOneAccount(2l);
-		Map<Long, List<Account>> accountMaps = accounts.stream().collect(Collectors.groupingBy(Account::getGoodsId));
+		Long appleOneGoodsId = 2l;
+		List<GoodsDon> goodsDons = goodsDonMapper.selectList(Wrappers.lambdaQuery(GoodsDon.class)
+				.ne(GoodsDon::getId, appleOneGoodsId)
+				.eq(GoodsDon::getType, 1)
+				.eq(GoodsDon::getDeleted, 1));
 		List<ExcelStreamingAccountData> streamingAccountData = new ArrayList<>();
-		accountMaps.forEach((goodsId, accountList) -> {
+		goodsDons.forEach((goods) -> {
+			Long goodsId = goods.getId();
 			//订单数据
 			ExcelStreamingAccountData exportData = statisticsUserDataMapper.getExportStreamingAccountData(goodsId, null, null, startDate, endDate);
 			if (exportData == null || exportData.getNumOfUser() == 0) {
 				return;
 			}
-			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.setName(goods.getTitle());
 			//月、季、年
 			exportData.setMonth(statisticsUserDataMapper.getTypeData(goodsId, Constant.payType.get(0), startDate, endDate));
 			exportData.setSeason(statisticsUserDataMapper.getTypeData(goodsId, Constant.payType.get(1), startDate, endDate));
@@ -570,59 +625,32 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		if (streamingAccountData.isEmpty()) {
 			return;
 		}
-		excelSheetDataList.add(new ExcelSheetAndData("流媒体账号数据", streamingAccountData, ExcelStreamingAccountData.class));
+		excelSheetDataList.add(new ExcelSheetAndData("流媒体账号数据", streamingAccountData, ExcelStreamingAccountData.class, 4));
 	}
 
 	private void exportAppleOneData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
 		Map<String, List<GoodsDonSku>> appleOneMap = statistics.getAppleOneMap();
 		List<ExcelAppleOneData> appleData = new ArrayList<>();
 		appleOneMap.forEach((areaName, goodsDonSkuList) -> {
-			ExcelAppleOneData appleDataExcel = new ExcelAppleOneData();
-			appleDataExcel.setArea(areaName);
 			Set<Long> skuIds = goodsDonSkuList.stream().map(GoodsDonSku::getId).collect(Collectors.toSet());
-			List<OrderDon> orderDons = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class).in(OrderDon::getSkuId, skuIds)
-					.notIn(OrderDon::getStatus, Constant.noOrderAllStatus)
-					.ge(ObjectUtil.isNotNull(startDate), OrderDon::getCreatedTime, startDate)
-					.lt(ObjectUtil.isNotNull(endDate), OrderDon::getCreatedTime, 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.noOrderAllStatus)
-					.ge(ObjectUtil.isNotNull(startDate), OrderDon::getCreatedTime, startDate)
-					.lt(ObjectUtil.isNotNull(endDate), OrderDon::getCreatedTime, endDate));
-			if (orderDons.isEmpty()) {
+			ExcelAppleOneData appleDataExcel = statisticsExportMapper.getAppleOneDataThisMonth(skuIds, startDate, endDate);
+			if (appleDataExcel == null || appleDataExcel.getNumOfOrder() == 0) {
 				return;
 			}
-			appleDataExcel.setNumOfExCodeOrder(exCodeOrders.size());
-			//金额
-			Optional<BigDecimal> money = orderDonMapper.selectThisMonthMoney(skuIds, startDate, endDate);
-			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.noOrderAllStatus)
-					.ge(ObjectUtil.isNotNull(startDate), OrderDon::getCreatedTime, startDate)
-					.lt(ObjectUtil.isNotNull(endDate), OrderDon::getCreatedTime, 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));
+			appleDataExcel.setArea(areaName);
+
 			Integer monthOrder = 0;
 			Integer searOrder = 0;
 			Integer yearOrder = 0;
 			for (GoodsDonSku sku : goodsDonSkuList) {
 				Long skuId = sku.getId();
 				if (StrUtil.isNotBlank(sku.getSpecVal())) {
-					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))) {
-						monthOrder += dons.size();
+						monthOrder += statisticsExportMapper.getAppleOnePayMonthTypeOrderThisMonth(skuId, startDate, endDate);
 					} else if (sku.getSpecVal().contains(Constant.payType.get(1))) {
-						searOrder += dons.size();
+						searOrder += statisticsExportMapper.getAppleOnePayMonthTypeOrderThisMonth(skuId, startDate, endDate);
 					} else if (!sku.getSpecVal().contains(Constant.payType.get(0)) && sku.getSpecVal().contains(Constant.payType.get(2))) {
-						yearOrder += dons.size();
+						yearOrder += statisticsExportMapper.getAppleOnePayMonthTypeOrderThisMonth(skuId, startDate, endDate);
 					}
 				}
 			}
@@ -634,7 +662,7 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		if (appleData.isEmpty()) {
 			return;
 		}
-		excelSheetDataList.add(new ExcelSheetAndData("Apple One数据", appleData, ExcelAppleOneData.class));
+		excelSheetDataList.add(new ExcelSheetAndData("Apple One数据", appleData, ExcelAppleOneData.class, 3));
 	}
 
 
@@ -825,17 +853,9 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 	}
 
 	public void setGoodsMoneyAndOrder(Integer type, Date startDate, Date endDate, BackgroundDataView backgroundDataView) {
-		List<OrderDonStatisticsView> orderDonStatisticsView = Optional.ofNullable(beanSearcher.searchAll(OrderDonStatisticsView.class,
-				MapUtils.builder().field(OrderDonStatisticsView::getGoodsType, type)
-						.field(OrderDonStatisticsView::getStatus, Constant.noOrderStatus).op(Operator.NotIn)
-						.field(OrderDonStatisticsView::getCreateTime, startDate, endDate).op(Operator.Between)
-						.build())).orElse(new ArrayList<>());
-		Optional<BigDecimal> orderMoneyReduce = orderDonStatisticsView.stream().map(OrderDonStatisticsView::getMoney).reduce(BigDecimal::add);
-		int totalOrder = orderDonStatisticsView.size();
-
-		BigDecimal orderMoney = orderMoneyReduce.isPresent() ? orderMoneyReduce.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO;
-		backgroundDataView.setFashionNumOfOrder(totalOrder);
-		backgroundDataView.setFashionAccountOfOrder(orderMoney);
+		Map<String, Object> map = orderDonMapper.getOrderDetailByGoodsType(type, Constant.noOrderStatus, startDate, endDate);
+		Integer totalOrder = Integer.parseInt(map.get("orderNum").toString());
+		BigDecimal orderMoney = BigDecimal.valueOf(Long.parseLong(map.get("money").toString())).divide(BigDecimal.valueOf(100));
 		if (type == 1) {
 			backgroundDataView.setVirtualNumOfOrder(totalOrder);
 			backgroundDataView.setVirtualAccountOfOrder(orderMoney);

+ 3 - 5
netflix-web/src/main/java/com/cyksj/web/controller/manage/statistics/StatisticsDataController.java

@@ -48,10 +48,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /*
@@ -95,7 +92,7 @@ public class StatisticsDataController {
 	 */
 	@GetMapping
 	@SaCheckPermission("statics:view")
-	public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) {
+	public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) throws InterruptedException {
 		return statisticsDataService.getStatisticsByCondition(startTime, endTime);
 	}
 
@@ -115,6 +112,7 @@ public class StatisticsDataController {
 	@GetMapping("/export/monthly/data")
 	public void exportMonthlyData(Long startTime, Long endTime, HttpServletResponse response) {
 		List<ExcelSheetAndData> excelSheetDataList = statisticsDataService.exportMonthlyData(startTime, endTime);
+		excelSheetDataList = excelSheetDataList.stream().sorted(Comparator.comparing(ExcelSheetAndData::getSort)).collect(Collectors.toList());
 		EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, excelSheetDataList, String.format("%s月订单数据", DateUtil.month(DateTime.of(startTime)) + 1), ExcelTypeEnum.XLSX, null);
 	}