Bladeren bron

Merge branch 'stat_data_func'

# Conflicts:
#	netflix-dao/src/main/java/com/cyksj/mapper/OrderDonMapper.java
#	netflix-dao/src/main/resources/mapper/OrderDonMapper.xml
zoujiajian 2 jaren geleden
bovenliggende
commit
e51c1b71ad

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

@@ -58,4 +58,10 @@ public interface OrderDonMapper extends BaseMapper<OrderDon> {
 	Integer selectCountActiveCodeOrderByAcId(Long acId);
 
 	Map<String, Object> selectActiveCodeOrderDetail(@Param("acId") Long acId, @Param("startTime") String startTime, @Param("endTime") String endTime);
+
+	BigDecimal getOriRenewOrderMoney(@Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	BigDecimal getTotalMoney(@Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	BigDecimal getClearRenewOrderMoney(@Param("startDate") String startDate, @Param("endDate") String endDate);
 }

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

@@ -1,6 +1,7 @@
 package com.cyksj.mapper.manage.statistics;
 
 import cn.hutool.core.date.DateTime;
+import com.cyksj.model.dto.NatureOrderDataDto;
 import com.cyksj.model.excel.statistics.ExcelAppleOneData;
 import org.apache.ibatis.annotations.Param;
 
@@ -68,4 +69,6 @@ public interface StatisticsExportMapper{
 	Integer getAppleOnePayMonthTypeOrderThisMonth(@Param("skuId") Long skuId, @Param("startDate") String startDate, @Param("endDate") String endDate);
 
 	Map<String, BigDecimal> getTransferData(@Param("startDate") String startDate, @Param("endDate") String endDate);
+
+	List<NatureOrderDataDto> getGroupsOrderData(@Param("startDate") String startDate, @Param("endDate") String endDate);
 }

+ 20 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/NatureOrderDataDto.java

@@ -0,0 +1,20 @@
+package com.cyksj.model.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: NatureOrderDataDto
+ * 创建者: JavaZou
+ * 创建时间:2023/10/18 11:03
+ */
+@Getter
+@Setter
+public class NatureOrderDataDto {
+	private Integer type;
+
+	private BigDecimal money;
+}

+ 74 - 0
netflix-dao/src/main/java/com/cyksj/model/views/GroupsDataStatisticsView.java

@@ -0,0 +1,74 @@
+package com.cyksj.model.views;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.math.BigDecimal;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: GroupsDataStatisticsView
+ * 创建者: JavaZou
+ * 创建时间:2023/10/17 16:40
+ */
+@Getter
+@Setter
+public class GroupsDataStatisticsView {
+	/**
+	 * 自然渠道销售金额
+	 */
+	private BigDecimal natureMoney;
+
+	/**
+	 * 渠道销售金额
+	 */
+
+	private BigDecimal channelMoney;
+
+	/**
+	 * 个人销售金额
+	 */
+	private BigDecimal personalMoney;
+
+	/**
+	 * 自然渠道流媒体销售金额
+	 */
+	private BigDecimal natureStreamingMoney;
+
+
+	/**
+	 * 自然渠道流Ai销售金额
+	 */
+	private BigDecimal natureAiOrderMoney;
+
+
+	/**
+	 * 自然渠道流设备销售金额
+	 */
+	private BigDecimal natureEpOrderMoney;
+
+	/**
+	 * 渠道+个人流媒体销售金额
+	 */
+	private BigDecimal groupsStreamingMoney;
+
+	/**
+	 * 渠道+个人 Ai销售金额
+	 */
+	private BigDecimal groupsAiOrderMoney;
+
+	/**
+	 * 渠道+个人 设备销售金额
+	 */
+	private BigDecimal groupsEpOrderMoney;
+
+	/**
+	 * 续费金额
+	 */
+	private BigDecimal renewOrderMoney;
+
+	/**
+	 * 非续费金额
+	 */
+	private BigDecimal newBuyOrderMoney;
+}

+ 39 - 0
netflix-dao/src/main/resources/mapper/OrderDonMapper.xml

@@ -255,4 +255,43 @@
             and o.created_time &lt; #{endTime}
         </if>
     </select>
+
+
+    <select id="getOriRenewOrderMoney" resultType="java.math.BigDecimal">
+        select cast(ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as decimal(10,2)) from order_don
+        where status not in ('close','noPayment')
+        <if test="startDate != null">
+            and created_time >= #{startDate}
+        </if>
+        <if test="endDate != null">
+            and created_time &lt; #{endDate}
+        </if>
+        and order_type = 2
+    </select>
+
+    <select id="getTotalMoney" resultType="java.math.BigDecimal">
+        select cast(ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as decimal(10,2)) from order_don
+        where 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="getClearRenewOrderMoney" resultType="java.math.BigDecimal">
+        select cast(ifnull((sum(o.money) - ifnull(sum(o.refund_money),0))/100,0) as decimal(10,2)) from
+        user_ticket_cleared_record utr inner join order_don o
+        on o.user_id = utr.user_id and o.goods_id = utr.goods_id and utr.source = 'self'
+        where order_type = 1 and o.created_time > utr.start_time and o.status not in ('close', 'noPayment')
+        <if test="startDate != null">
+            and utr.created_time >= #{startDate}
+            and o.created_time >= #{startDate}
+        </if>
+        <if test="endDate != null">
+            and utr.created_time &lt; #{endDate}
+            and o.created_time &lt; #{endDate}
+        </if>
+    </select>
 </mapper>

+ 29 - 2
netflix-dao/src/main/resources/mapper/StatisticsExportMapper.xml

@@ -378,7 +378,12 @@
                 us.id is not null
             </otherwise>
         </choose>
-        and o.created_time >= #{startDate} and o.created_time &lt; #{endDate}
+        <if test="startDate != null">
+            and o.created_time >= #{startDate}
+        </if>
+        <if test="endDate != null">
+            and o.created_time &lt; #{endDate}
+        </if>
         and status not in ('close', 'noPayment')
         and goods_id in (select id from goods_don
         <where>
@@ -386,7 +391,7 @@
                 `type` = #{goodsType}
             </if>
             <if test="category!=null">
-                category = #{category}
+                and id in (select goods_id from goods_don_category_relate where category = #{category})
             </if>
         </where>
         )
@@ -453,4 +458,26 @@
           and created_time &lt; #{endDate}
           and verify_status = 'success'
     </select>
+
+    <select id="getGroupsOrderData" resultType="com.cyksj.model.dto.NatureOrderDataDto">
+        select type,
+        ifnull((sum(money) - ifnull(sum(refund_money),0))/100,0) as money from (select money,
+        refund_money,
+        (case
+        when us.id is null then 1
+        when us.id is not null and ud.id is null then 2
+        when ud.id is not null then 3
+        else 1
+        end) as `type`
+        from `order_don` o
+        left join `user_distribute_shared` us on us.user_id = o.user_Id
+        left join `user_distribute` ud on ud.user_id = us.shared_id
+        where status not in ('close', 'noPayment')
+        <if test="startDate != null">
+            and o.created_time >= #{startDate}
+        </if>
+        <if test="endDate != null">
+            and o.created_time &lt; #{endDate}
+        </if>) s group by `type`
+    </select>
 </mapper>

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

@@ -6,6 +6,7 @@ import com.cyksj.model.excel.ExcelAccountData;
 import com.cyksj.model.excel.ExcelSheetAndData;
 import com.cyksj.model.views.BackgroundDataView;
 import com.cyksj.model.views.ExpiredAccountDataView;
+import com.cyksj.model.views.GroupsDataStatisticsView;
 
 import java.util.Date;
 import java.util.List;
@@ -45,4 +46,6 @@ public interface StatisticsDataService {
 	Result<BackgroundDataView> getStatisticsHeader(Long startTime, Long endTime);
 
 	void yhShopDistribute(BackgroundDataView backgroundDataView, Date startDate, Date endDate);
+
+	GroupsDataStatisticsView getGroupsData(Long startTime, Long endTime, Integer type) throws Exception;
 }

+ 115 - 4
netflix-service/src/main/java/com/cyksj/service/mange/statistics/impl/StatisticsDataServiceImpl.java

@@ -12,6 +12,7 @@ import com.cyksj.enums.GatewayResponse;
 import com.cyksj.mapper.*;
 import com.cyksj.mapper.manage.statistics.*;
 import com.cyksj.mapper.shop.YhShopMapper;
+import com.cyksj.model.dto.NatureOrderDataDto;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.excel.ExcelAccountData;
 import com.cyksj.model.excel.ExcelMonthOrderData;
@@ -23,10 +24,7 @@ import com.cyksj.model.excel.statistics.ExcelRegisterAccountData;
 import com.cyksj.model.excel.statistics.ExcelStreamingAccountData;
 import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.manage.views.OrderDonView;
-import com.cyksj.model.views.BackgroundDataView;
-import com.cyksj.model.views.DistributeOrdersView;
-import com.cyksj.model.views.ExpiredAccountDataView;
-import com.cyksj.model.views.GoodsDonSkuView;
+import com.cyksj.model.views.*;
 import com.cyksj.service.mange.CmsAccountService;
 import com.cyksj.service.mange.statistics.StatisticsDataDayService;
 import com.cyksj.service.mange.statistics.StatisticsDataService;
@@ -401,6 +399,119 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		}
 	}
 
+	@Override
+	public GroupsDataStatisticsView getGroupsData(Long startTime, Long endTime, Integer type) throws Exception {
+		GroupsDataStatisticsView groupsDataStatisticsView = new GroupsDataStatisticsView();
+		String startDate = null;
+		String endDate = null;
+		if (startTime != null) {
+			startDate = DateTime.of(startTime).toString();
+		}
+		if (endTime != null) {
+			endDate = DateTime.of(endTime).toString();
+		}
+		if (startDate == null) {
+			startDate = DateUtil.beginOfMonth(DateTime.now()).toString();
+		}
+		switch (type) {
+			case 1:
+				getNatureOrderData(groupsDataStatisticsView, startDate, endDate);
+				break;
+			case 2:
+				getCategoryOrderData(groupsDataStatisticsView, startDate, endDate);
+				break;
+			case 3:
+				getGroupsOrderCategoryData(groupsDataStatisticsView, startDate, endDate);
+				break;
+			case 4:
+				getRenewOrderData(groupsDataStatisticsView, startDate, endDate);
+				break;
+			default:
+				getSynthesisData(groupsDataStatisticsView, startDate, endDate);
+		}
+		return groupsDataStatisticsView;
+	}
+
+	public void getNatureOrderData(GroupsDataStatisticsView groupsDataStatisticsView, String startDate, String endDate) {
+		List<NatureOrderDataDto> orderDataList = statisticsExportMapper.getGroupsOrderData(startDate, endDate);
+		orderDataList.forEach(data -> {
+			BigDecimal money = data.getMoney();
+			if (data.getType() == 1) {
+				groupsDataStatisticsView.setNatureMoney(money);
+				return;
+			}
+			if (data.getType() == 2) {
+				groupsDataStatisticsView.setPersonalMoney(money);
+				return;
+			}
+			if (data.getType() == 3) {
+				groupsDataStatisticsView.setChannelMoney(money);
+			}
+		});
+		if (groupsDataStatisticsView.getNatureMoney() == null) {
+			groupsDataStatisticsView.setNatureMoney(BigDecimal.ZERO);
+		}
+		if (groupsDataStatisticsView.getPersonalMoney() == null) {
+			groupsDataStatisticsView.setPersonalMoney(BigDecimal.ZERO);
+		}
+		if (groupsDataStatisticsView.getChannelMoney() == null) {
+			groupsDataStatisticsView.setChannelMoney(BigDecimal.ZERO);
+		}
+	}
+
+	public void getCategoryOrderData(GroupsDataStatisticsView groupsDataStatisticsView, String startDate, String endDate) {
+		BigDecimal natureStreamingMoney = Optional.ofNullable(statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(1, null, 2l, startDate, endDate)).orElse(BigDecimal.ZERO);
+		// AI销售金额
+		BigDecimal natureAiOrderMoney = Optional.ofNullable(statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(1, null, 1l, startDate, endDate)).orElse(BigDecimal.ZERO);
+		//设备销售金额
+		BigDecimal natureEpOrderMoney = Optional.ofNullable(statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(1, 2, null, startDate, endDate)).orElse(BigDecimal.ZERO);
+		groupsDataStatisticsView.setNatureStreamingMoney(natureStreamingMoney);
+		groupsDataStatisticsView.setNatureAiOrderMoney(natureAiOrderMoney);
+		groupsDataStatisticsView.setNatureEpOrderMoney(natureEpOrderMoney);
+	}
+
+	public void getGroupsOrderCategoryData(GroupsDataStatisticsView groupsDataStatisticsView, String startDate, String endDate) {
+		//渠道商+个人分销
+		//流媒体
+		BigDecimal groupsStreamingMoney = Optional.ofNullable(statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(2, null, 2l, startDate, endDate)).orElse(BigDecimal.ZERO);
+		// AI销售金额
+		BigDecimal groupsAiOrderMoney = Optional.ofNullable(statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(2, null, 1l, startDate, endDate)).orElse(BigDecimal.ZERO);
+		//设备销售金额
+		BigDecimal groupsEpOrderMoney = Optional.ofNullable(statisticsExportMapper.getMonthGoodsTypeAmountOfOrderByType(2, 2, null, startDate, endDate)).orElse(BigDecimal.ZERO);
+		groupsDataStatisticsView.setGroupsStreamingMoney(groupsStreamingMoney);
+		groupsDataStatisticsView.setGroupsAiOrderMoney(groupsAiOrderMoney);
+		groupsDataStatisticsView.setGroupsEpOrderMoney(groupsEpOrderMoney);
+	}
+
+	public void getRenewOrderData(GroupsDataStatisticsView groupsDataStatisticsView, String startDate, String endDate) {
+		BigDecimal oriRenewOrderMoney = Optional.ofNullable(orderDonMapper.getOriRenewOrderMoney(startDate, endDate)).orElse(BigDecimal.ZERO);
+		BigDecimal clearRenewOrderMoney = Optional.ofNullable(orderDonMapper.getClearRenewOrderMoney(startDate, endDate)).orElse(BigDecimal.ZERO);
+		groupsDataStatisticsView.setRenewOrderMoney(oriRenewOrderMoney.add(clearRenewOrderMoney));
+		BigDecimal totalMoney = Optional.ofNullable(orderDonMapper.getTotalMoney(startDate, endDate)).orElse(BigDecimal.ZERO);
+		groupsDataStatisticsView.setNewBuyOrderMoney(totalMoney.subtract(groupsDataStatisticsView.getRenewOrderMoney()));
+	}
+
+	public void getSynthesisData(GroupsDataStatisticsView groupsDataStatisticsView, String startDate, String endDate) throws Exception {
+		CountDownLatch latch = new CountDownLatch(2);
+		TASK_POOL.execute(() -> {
+			try {
+				getNatureOrderData(groupsDataStatisticsView, startDate, endDate);
+				getCategoryOrderData(groupsDataStatisticsView, startDate, endDate);
+			} finally {
+				latch.countDown();
+			}
+		});
+		TASK_POOL.execute(() -> {
+			try {
+				getGroupsOrderCategoryData(groupsDataStatisticsView, startDate, endDate);
+				getRenewOrderData(groupsDataStatisticsView, startDate, endDate);
+			} finally {
+				latch.countDown();
+			}
+		});
+		latch.await();
+	}
+
 	private void exportBusinessMonthlyData(List<ExcelSheetAndData> excelSheetDataList, Long startTime, Long endTime) {
 		//月付、季付、年付
 		Long nf_goodsId = 1l;

+ 10 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/statistics/StatisticsDataController.java

@@ -132,6 +132,16 @@ public class StatisticsDataController {
 		EasyExcelUtils.createExcelStreamMutilByEasyExcel(response, excelSheetDataList, String.format("%s月业务数据", DateUtil.month(DateTime.of(startTime)) + 1), ExcelTypeEnum.XLSX, null);
 	}
 
+	/**
+	 * 综合数据统计
+	 * type 1销售数据 2自然渠道分类数据 3 渠道商+个人 分类数据 4 续费/非续费数据
+	 */
+	@GetMapping("/get/groupsData")
+	public Result<GroupsDataStatisticsView> getGroupsData(Long startTime, Long endTime, @RequestParam(defaultValue = "0") Integer type) throws Exception {
+		GroupsDataStatisticsView groupsDataStatisticsView = statisticsDataService.getGroupsData(startTime, endTime, type);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(groupsDataStatisticsView);
+	}
+
 	/**
 	 * 有效子账号数列表
 	 */