Forráskód Böngészése

Merge branch 'statistics_balance'

zoujiajian 2 éve
szülő
commit
df8852ec99

+ 6 - 0
netflix-common/src/main/java/com/cyksj/common/constant/Constant.java

@@ -26,6 +26,12 @@ public interface Constant {
 	 */
 	List<Integer> realGoodsType = List.of(2, 3);
 
+	/**
+	 * 平台类型
+	 * 1、虚拟、2实物、3潮玩好物
+	 */
+	List<Integer> goodsType = List.of(1, 2, 3);
+
 	/**
 	 * 默认头像
 	 */

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

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.OrderDon;
 import com.cyksj.model.entity.RealGoodsInterestUser;
 import com.cyksj.model.excel.ExcelOrderDonInfo;
+import com.cyksj.model.views.BackgroundDataView;
 import com.cyksj.model.views.BrokenLineObjView;
 import com.cyksj.model.views.ChannelPopularizeView;
 import com.cyksj.model.views.ChannelStatisticsView;
@@ -47,4 +48,8 @@ public interface OrderDonMapper extends BaseMapper<OrderDon> {
 	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);
+
+	BackgroundDataView getBackgroundDataView(@Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("noOrderStatus") List<String> noOrderStatus);
+
+	BigDecimal statisticsUsedBalance(@Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("noOrderAllStatus") List<String> noOrderAllStatus);
 }

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/mapper/UserMapper.java

@@ -50,4 +50,7 @@ public interface UserMapper extends BaseMapper<User> {
 
     @Select("select id from user where show_id = #{showId} limit 1")
     Long getUserIdByShowId(String showId);
+
+    @Select("select cast(ifnull(sum(balance),0)/100 as decimal(11,2)) from user")
+	BigDecimal statisticsRemainBalance();
 }

+ 10 - 0
netflix-dao/src/main/java/com/cyksj/model/views/BackgroundDataView.java

@@ -183,4 +183,14 @@ public class BackgroundDataView {
 	 */
 	private Integer waitingSendRealOrder;
 
+	/**
+	 * 已使用余额
+	 */
+	private BigDecimal usedBalance;
+
+	/**
+	 * 剩余余额
+	 */
+	private BigDecimal remainBalance;
+
 }

+ 32 - 1
netflix-dao/src/main/resources/mapper/OrderDonMapper.xml

@@ -176,7 +176,7 @@
 
     <select id="getOrderDetailByGoodsType" resultType="java.util.Map">
         select count(id) as orderNum,
-               ifnull(sum(money),0) as money
+        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=")">
@@ -189,4 +189,35 @@
             and created_time &lt; #{endDate}
         </if>
     </select>
+
+    <select id="getBackgroundDataView" resultType="com.cyksj.model.views.BackgroundDataView">
+        select count(distinct user_id) as totalNumOfUser,
+        count(id) as totalNumOfOrder,
+        cast(ifnull(sum(money),0)/100 as decimal(11,2)) as totalOrderAmount,
+        count(if(status = 'refund',1,NULL)) as totalNumOfRefundOrder,
+        cast(sum(if(status = 'refund',ifnull(refund_money,0),0)) as decimal(11,2)) as totalRefundAmount
+        from `order_don` where 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>
+
+    <select id="statisticsUsedBalance" resultType="java.math.BigDecimal">
+        select cast(ifnull(sum(balance),0)/100 as decimal(11,2)) from order_don where status not in
+        <foreach collection="noOrderAllStatus" 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>

+ 3 - 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) throws InterruptedException;
+	Result<BackgroundDataView> getStatisticsByCondition(Integer type, 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);
 
@@ -41,4 +41,6 @@ public interface StatisticsDataService {
 	 * 每月业务数据导出
 	 */
 	List<ExcelSheetAndData> exportMonthlyData(Long startTime, Long endTime);
+
+	Result<BackgroundDataView> getStatisticsHeader(Long startTime, Long endTime);
 }

+ 65 - 52
netflix-service/src/main/java/com/cyksj/service/mange/statistics/impl/StatisticsDataServiceImpl.java

@@ -2,7 +2,6 @@ package com.cyksj.service.mange.statistics.impl;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -23,7 +22,10 @@ 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.*;
+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.service.mange.CmsAccountService;
 import com.cyksj.service.mange.statistics.StatisticsDataDayService;
 import com.cyksj.service.mange.statistics.StatisticsDataService;
@@ -74,6 +76,8 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 
 	private final OrderDonMapper orderDonMapper;
 
+	private final UserMapper userMapper;
+
 	private final StatisticsUserDataMapper statisticsUserDataMapper;
 
 	private final StatisticsFashionGoodsDataMapper statisticsFashionGoodsDataMapper;
@@ -83,7 +87,7 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 	private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
 
 	@Override
-	public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) throws InterruptedException {
+	public Result<BackgroundDataView> getStatisticsByCondition(Integer type, Long startTime, Long endTime) {
 		BackgroundDataView backgroundDataView = new BackgroundDataView();
 		Date startDate = null;
 		Date endDate = null;
@@ -93,34 +97,37 @@ 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;
-		//头部数据
-		TASK_POOL.execute(() -> {
-			try {
-				headerData(backgroundDataView, f_st, f_et);
-			} finally {
-				countDownLatch.countDown();
-			}
-		});
-		TASK_POOL.execute(() -> {
-			try {
+		switch (type) {
+			case 1:
 				//流媒体账号
-				getStreamingAccountDataView(backgroundDataView, f_st, f_et);
+				getStreamingAccountDataView(backgroundDataView, startDate, endDate);
 				//appleOne
-				getAppleOneDataView(backgroundDataView, f_st, f_et);
+				getAppleOneDataView(backgroundDataView, startDate, endDate);
+				break;
+			case 2:
 				//实物数据
-				getRealGoodsData(backgroundDataView, f_st, f_et);
+				getRealGoodsData(backgroundDataView, startDate, endDate);
+				break;
+			case 3:
 				//注册账号数据
-				getRegisterAccountData(backgroundDataView, f_st, f_et);
+				getRegisterAccountData(backgroundDataView, startDate, endDate);
+				break;
+			case 4:
 				//潮玩好物数据
-				getFashionGoodsData(backgroundDataView, f_st, f_et);
-			} finally {
-				countDownLatch.countDown();
-			}
-		});
-		countDownLatch.await();
+				getFashionGoodsData(backgroundDataView, startDate, endDate);
+				break;
+			default:
+				//流媒体账号
+				getStreamingAccountDataView(backgroundDataView, startDate, endDate);
+				//appleOne
+				getAppleOneDataView(backgroundDataView, startDate, endDate);
+				//实物数据
+				getRealGoodsData(backgroundDataView, startDate, endDate);
+				//注册账号数据
+				getRegisterAccountData(backgroundDataView, startDate, endDate);
+				//潮玩好物数据
+				getFashionGoodsData(backgroundDataView, startDate, endDate);
+		}
 		return GatewayResponse.SUCCESS.newBuilder().toResult(backgroundDataView);
 	}
 
@@ -328,6 +335,20 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		return excelSheetDataList;
 	}
 
+	@Override
+	public Result<BackgroundDataView> getStatisticsHeader(Long startTime, Long endTime) {
+		Date startDate = null;
+		Date endDate = null;
+		if (startTime != null) {
+			startDate = DateUtil.date(startTime);
+		}
+		if (endTime != null) {
+			endDate = DateUtil.date(endTime);
+		}
+		BackgroundDataView backgroundDataView = getHeaderData(startDate, endDate);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(backgroundDataView);
+	}
+
 	public void exportAllTypeData(List<ExcelSheetAndData> excelSheetDataList, String startDate, String endDate) {
 		CountDownLatch latch = new CountDownLatch(2);
 		TASK_POOL.execute(() -> {
@@ -681,6 +702,7 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 	}
 
 	private void getStreamingAccountDataView(BackgroundDataView backgroundDataView, Date startDate, Date endDate) {
+		//当天
 		if (DateUtil.beginOfDay(DateTime.now()).equals(startDate) && (DateUtil.beginOfDay(DateUtil.offsetDay(DateTime.now(), 1)).equals(endDate) || DateUtil.endOfDay(DateTime.now()).equals(endDate))) {
 			List<StreamingAccountData> streamingAccountData = statistics.statisticsStreamingAccountData(startDate, endDate, true);
 			List<StreamingAccountData> collect = streamingAccountData.stream().filter(data -> {
@@ -721,13 +743,10 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		} else {
 			List<RealGoodsData> realGoodsData = realGoodsDataMapper.statisticsRealGoodsData(startDate, endDate);
 			Optional.ofNullable(realGoodsData).ifPresent(list -> list.forEach(data -> {
-				GoodsDon goodsDon = goodsDonMapper.selectOne(Wrappers.lambdaQuery(GoodsDon.class).eq(GoodsDon::getId, data.getGoodsId()).last("limit 1"));
-				if (goodsDon != null) {
-					data.setGoodsTitle(goodsDon.getTitle());
-				}
-				GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getId, data.getSkuId()).last("limit 1"));
-				if (goodsDonSku != null) {
-					data.setSpecVal(goodsDonSku.getSpecVal());
+				GoodsDonSkuView goodsDonSkuView = beanSearcher.searchFirst(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, data.getSkuId()).build());
+				if (goodsDonSkuView != null) {
+					data.setGoodsTitle(goodsDonSkuView.getGoodsTitle());
+					data.setSpecVal(goodsDonSkuView.getSpecVal());
 				}
 				data.setRefundMoney(getRefundMoney(null, data.getSkuId(), startDate, endDate));
 				data.setNumOfRefundOrder(getNumOfRefundOrder(null, data.getSkuId(), startDate, endDate));
@@ -736,37 +755,31 @@ public class StatisticsDataServiceImpl implements StatisticsDataService {
 		}
 	}
 
-	private void headerData(BackgroundDataView backgroundDataView, Date startDate, Date endDate) {
-		//总订单数
-		List<OrderDon> orderDons = Optional.ofNullable(orderDonService.list(Wrappers.lambdaQuery(OrderDon.class).notIn(OrderDon::getStatus, Constant.noOrderStatus).ge(ObjectUtil.isNotNull(startDate), OrderDon::getCreatedTime, startDate).lt(ObjectUtil.isNotNull(endDate), OrderDon::getCreatedTime, endDate))).orElse(new ArrayList<>());
-		backgroundDataView.setTotalNumOfOrder(orderDons.size());
-		//总下单用户数
-		backgroundDataView.setTotalNumOfUser(orderDons.stream().map(OrderDon::getUserId).collect(Collectors.toSet()).size());
-		Optional<BigDecimal> totalMoney = orderDons.stream().map(OrderDon::getMoney).reduce(BigDecimal::add);
-		//总订单金额
-		backgroundDataView.setTotalOrderAmount(totalMoney.isPresent() ? totalMoney.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO);
-		//退款列表
-		List<OrderDon> refundOrders = Optional.ofNullable(orderDonService.list(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getStatus, OrderDon.Status.refund).ge(ObjectUtil.isNotNull(startDate), OrderDon::getCreatedTime, startDate).lt(ObjectUtil.isNotNull(endDate), OrderDon::getCreatedTime, endDate).select(OrderDon::getId, OrderDon::getRefundMoney))).orElse(new ArrayList<>());
-		backgroundDataView.setTotalNumOfRefundOrder(refundOrders.size());
-		//退款金额
-		Optional<BigDecimal> totalRefundAmount = refundOrders.stream().map(OrderDon::getRefundMoney).reduce(BigDecimal::add);
-		backgroundDataView.setTotalRefundAmount(totalRefundAmount.isPresent() ? totalRefundAmount.get().divide(BigDecimal.valueOf(100)) : BigDecimal.ZERO);
+	private BackgroundDataView getHeaderData(Date startDate, Date endDate) {
+		BackgroundDataView backgroundDataView = orderDonMapper.getBackgroundDataView(startDate, endDate, Constant.noOrderStatus);
 		//近5天将要到期的主账号总数
 		DateTime now = DateTime.now();
 		DateTime zero = DateUtil.beginOfDay(now);
 		DateTime fiveDays = DateUtil.offsetDay(zero, 5);
 		//5天后将到期的主账号
-		List<Account> willExpireAccounts = Optional.ofNullable(accountService.list(Wrappers.lambdaQuery(Account.class).between(Account::getExpiryTime, zero, fiveDays))).orElse(new ArrayList<>());
-		backgroundDataView.setTotalNumOfWillExpireAccount(willExpireAccounts.size());
+		Integer willExpireAccounts = accountService.count(Wrappers.lambdaQuery(Account.class).between(Account::getExpiryTime, zero, fiveDays));
+		backgroundDataView.setTotalNumOfWillExpireAccount(willExpireAccounts);
 		//已到期主账号
-		List<Account> expiredAccounts = Optional.ofNullable(accountService.list(Wrappers.lambdaQuery(Account.class).le(Account::getExpiryTime, now))).orElse(new ArrayList<>());
-		backgroundDataView.setTotalExpiredAccountNum(expiredAccounts.size());
+		Integer expiredAccounts = accountService.count(Wrappers.lambdaQuery(Account.class).le(Account::getExpiryTime, now));
+		backgroundDataView.setTotalExpiredAccountNum(expiredAccounts);
 		//虚物
 		setGoodsMoneyAndOrder(1, startDate, endDate, backgroundDataView);
 		//实物
 		setGoodsMoneyAndOrder(2, startDate, endDate, backgroundDataView);
 		//潮玩
 		setGoodsMoneyAndOrder(3, startDate, endDate, backgroundDataView);
+		//已使用余额
+		BigDecimal usedBalance = orderDonMapper.statisticsUsedBalance(startDate, endDate, Constant.noOrderAllStatus);
+		backgroundDataView.setUsedBalance(usedBalance);
+		//剩余余额
+		BigDecimal remainBalance = userMapper.statisticsRemainBalance();
+		backgroundDataView.setRemainBalance(remainBalance);
+		return backgroundDataView;
 	}
 
 	/**

+ 13 - 4
netflix-web/src/main/java/com/cyksj/web/controller/manage/statistics/StatisticsDataController.java

@@ -88,12 +88,21 @@ public class StatisticsDataController {
 	private final OrderDonMapper orderDonMapper;
 
 	/**
-	 * 查询统计数据
+	 * 查询头部统计数据
 	 */
-	@GetMapping
+	@GetMapping("/get/header")
+	public Result<BackgroundDataView> getStatisticsHeader(Long startTime, Long endTime) throws InterruptedException {
+		return statisticsDataService.getStatisticsHeader(startTime, endTime);
+	}
+
+	/**
+	 * 查询平台统计数据
+	 * type 1、流媒体,2、实物,3、潮玩,4、注册账号
+	 */
+	@GetMapping("/get/goods")
 	@SaCheckPermission("statics:view")
-	public Result<BackgroundDataView> getStatisticsByCondition(Long startTime, Long endTime) throws InterruptedException {
-		return statisticsDataService.getStatisticsByCondition(startTime, endTime);
+	public Result<BackgroundDataView> getStatisticsByCondition(@RequestParam(defaultValue = "0") Integer type, Long startTime, Long endTime) throws InterruptedException {
+		return statisticsDataService.getStatisticsByCondition(type, startTime, endTime);
 	}
 
 	/**