|
|
@@ -3,14 +3,17 @@ package com.fs.course.service.impl;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.company.domain.Company;
|
|
|
import com.fs.company.mapper.CompanyMapper;
|
|
|
+import com.fs.company.param.CompanyStatisticsParam;
|
|
|
+import com.fs.company.vo.CompanyRedPacketStatisticsVO;
|
|
|
+import com.fs.course.domain.FsCourseWatchLog;
|
|
|
import com.fs.course.domain.FsUserCoursePeriod;
|
|
|
import com.fs.course.domain.FsUserWatchStatistics;
|
|
|
-import com.fs.course.mapper.FsUserCoursePeriodMapper;
|
|
|
-import com.fs.course.mapper.FsUserWatchStatisticsMapper;
|
|
|
+import com.fs.course.mapper.*;
|
|
|
import com.fs.course.service.IFsUserWatchStatisticsService;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.ibatis.session.ExecutorType;
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
@@ -24,6 +27,7 @@ import java.math.RoundingMode;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.ZonedDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -46,6 +50,15 @@ public class FsUserWatchStatisticsServiceImpl extends ServiceImpl<FsUserWatchSta
|
|
|
|
|
|
private final CompanyMapper companyMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsCourseRedPacketLogMapper fsCourseRedPacketLogMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCompanyUserMapper fsUserCompanyUserMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCourseWatchLogMapper fsCourseWatchLogMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询会员看课统计-按营期统计
|
|
|
*
|
|
|
@@ -208,6 +221,8 @@ public class FsUserWatchStatisticsServiceImpl extends ServiceImpl<FsUserWatchSta
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void batchInsert(List<FsUserWatchStatistics> list) {
|
|
|
// 分批次处理,一次提交500条
|
|
|
List<List<FsUserWatchStatistics>> batches = Lists.partition(list, 500);
|
|
|
@@ -222,4 +237,110 @@ public class FsUserWatchStatisticsServiceImpl extends ServiceImpl<FsUserWatchSta
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Description: 看课统计 按销售统计用户 新增用户 完课 红包
|
|
|
+ * @Param:
|
|
|
+ * @Return:
|
|
|
+ * @Author xgb
|
|
|
+ * @Date 2026/3/26 14:16
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CompanyRedPacketStatisticsVO> selectRedPacketStatisticsBySales(CompanyStatisticsParam param) {
|
|
|
+ // 异步查询
|
|
|
+ // 用户数
|
|
|
+ CompletableFuture<List<CompanyRedPacketStatisticsVO>> userFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ return fsUserCompanyUserMapper.selectSalesUserCount(param);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 新注册用户
|
|
|
+ CompletableFuture<List<CompanyRedPacketStatisticsVO>> newUserFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ return fsUserCompanyUserMapper.selectSalesNewUserCount(param);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 看课记录数
|
|
|
+ CompletableFuture<List<CompanyRedPacketStatisticsVO>> watchLogFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ return fsCourseWatchLogMapper.selectCourseFinishCount(param);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 红包记录
|
|
|
+ CompletableFuture<List<CompanyRedPacketStatisticsVO>> redPacketFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
+ return fsCourseRedPacketLogMapper.selectCourseFinishCount(param);
|
|
|
+ });
|
|
|
+
|
|
|
+ CompletableFuture.allOf(userFuture, newUserFuture, watchLogFuture, redPacketFuture).join();
|
|
|
+
|
|
|
+
|
|
|
+ // 获取各个查询结果
|
|
|
+ List<CompanyRedPacketStatisticsVO> userList = userFuture.join();
|
|
|
+ List<CompanyRedPacketStatisticsVO> newUserList = newUserFuture.join();
|
|
|
+ List<CompanyRedPacketStatisticsVO> watchLogList = watchLogFuture.join();
|
|
|
+ List<CompanyRedPacketStatisticsVO> redPacketList = redPacketFuture.join();
|
|
|
+
|
|
|
+ // 按销售 ID(company_user_id)分组,合并数据
|
|
|
+ Map<Long, CompanyRedPacketStatisticsVO> statisticsMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 1. 先处理用户数(作为基础数据)
|
|
|
+ if (userList != null && !userList.isEmpty()) {
|
|
|
+ for (CompanyRedPacketStatisticsVO vo : userList) {
|
|
|
+ Long key = vo.getCompanyUserId();
|
|
|
+ CompanyRedPacketStatisticsVO statisticsVO = new CompanyRedPacketStatisticsVO();
|
|
|
+ statisticsVO.setCompanyUserId(vo.getCompanyUserId());
|
|
|
+ statisticsVO.setUserName(vo.getUserName());
|
|
|
+ statisticsVO.setUserCount(vo.getUserCount() != null ? vo.getUserCount() : 0);
|
|
|
+ statisticsVO.setNewUserCount(0);
|
|
|
+ statisticsVO.setFinishCount(0);
|
|
|
+ statisticsVO.setRedPacketAmount(new BigDecimal(0));
|
|
|
+ statisticsMap.put(key, statisticsVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 合并新增用户数
|
|
|
+ if (newUserList != null && !newUserList.isEmpty()) {
|
|
|
+ for (CompanyRedPacketStatisticsVO vo : newUserList) {
|
|
|
+ Long key = vo.getCompanyUserId();
|
|
|
+ CompanyRedPacketStatisticsVO statisticsVO = statisticsMap.get(key);
|
|
|
+ if (statisticsVO != null) {
|
|
|
+ statisticsVO.setNewUserCount(vo.getNewUserCount() != null ? vo.getNewUserCount() : 0);
|
|
|
+ } else {
|
|
|
+ // 如果该销售不在用户数列表中,创建新记录
|
|
|
+ statisticsVO = new CompanyRedPacketStatisticsVO();
|
|
|
+ statisticsVO.setCompanyUserId(vo.getCompanyUserId());
|
|
|
+ statisticsVO.setUserName(vo.getUserName());
|
|
|
+ statisticsVO.setUserCount(0);
|
|
|
+ statisticsVO.setNewUserCount(vo.getNewUserCount() != null ? vo.getNewUserCount() : 0);
|
|
|
+ statisticsVO.setFinishCount(0);
|
|
|
+ statisticsVO.setRedPacketAmount(new BigDecimal(0));
|
|
|
+ statisticsMap.put(key, statisticsVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 合并完课数
|
|
|
+ if (watchLogList != null && !watchLogList.isEmpty()) {
|
|
|
+ for (CompanyRedPacketStatisticsVO vo : watchLogList) {
|
|
|
+ Long key = vo.getCompanyUserId();
|
|
|
+ CompanyRedPacketStatisticsVO statisticsVO = statisticsMap.get(key);
|
|
|
+ if (statisticsVO != null) {
|
|
|
+ statisticsVO.setFinishCount(vo.getFinishCount() != null ? vo.getFinishCount() : 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 合并红包金额
|
|
|
+ if (redPacketList != null && !redPacketList.isEmpty()) {
|
|
|
+ for (CompanyRedPacketStatisticsVO vo : redPacketList) {
|
|
|
+ Long key = vo.getCompanyUserId();
|
|
|
+ CompanyRedPacketStatisticsVO statisticsVO = statisticsMap.get(key);
|
|
|
+ if (statisticsVO != null) {
|
|
|
+ statisticsVO.setRedPacketAmount(vo.getRedPacketAmount() != null ? vo.getRedPacketAmount() : new BigDecimal(0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为列表返回
|
|
|
+ return new ArrayList<>(statisticsMap.values());
|
|
|
+ }
|
|
|
+
|
|
|
}
|