|
@@ -1,19 +1,17 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fs.course.domain.FsUserCoursePeriodDays;
|
|
|
import com.fs.course.mapper.FsUserCoursePeriodDaysMapper;
|
|
|
-import com.fs.course.vo.FsPeriodCountVO;
|
|
|
-import com.fs.course.vo.newfs.FsCourseAnalysisCountVO;
|
|
|
import com.fs.store.mapper.FsUserMapper;
|
|
|
-import com.fs.store.param.h5.CourseAnalysisParam;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.ibatis.session.ExecutorType;
|
|
|
+import org.apache.ibatis.session.SqlSession;
|
|
|
+import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -21,7 +19,6 @@ import com.fs.course.mapper.FsUserWatchCourseStatisticsMapper;
|
|
|
import com.fs.course.domain.FsUserWatchCourseStatistics;
|
|
|
import com.fs.course.service.IFsUserWatchCourseStatisticsService;
|
|
|
|
|
|
-import static org.apache.coyote.http11.Constants.a;
|
|
|
|
|
|
/**
|
|
|
* 会员看课统计-按课程统计Service业务层处理
|
|
@@ -37,6 +34,9 @@ public class FsUserWatchCourseStatisticsServiceImpl extends ServiceImpl<FsUserWa
|
|
|
|
|
|
private FsUserMapper fsUserMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SqlSessionFactory sqlSessionFactory;
|
|
|
+
|
|
|
/**
|
|
|
* 查询会员看课统计-按课程统计
|
|
|
*
|
|
@@ -115,60 +115,78 @@ public class FsUserWatchCourseStatisticsServiceImpl extends ServiceImpl<FsUserWa
|
|
|
// 查询课程相关数据
|
|
|
List<FsUserWatchCourseStatistics> fsUserWatchCourseStatistics = fsUserCoursePeriodDaysMapper.selectDaysCountList();
|
|
|
|
|
|
- //2、查询统计数据
|
|
|
+ // 查询统计数据
|
|
|
List<FsUserWatchCourseStatistics> watchLog = fsUserMapper.selectWatchLogCount();
|
|
|
List<FsUserWatchCourseStatistics> redPacketLog = fsUserMapper.selectRedPacketLogCount();
|
|
|
List<FsUserWatchCourseStatistics> answerLog = fsUserMapper.selectAnswerLogCount();
|
|
|
-// List<FsCourseAnalysisCountVO> courseCountList = fsUserMapper.courseAnalysisWatchLog(courseAnalysisParam);
|
|
|
-// List<FsCourseAnalysisCountVO> redPacketCountList = fsUserMapper.courseAnalysisRedPacketCount(courseAnalysisParam);
|
|
|
-// List<FsCourseAnalysisCountVO> answerCountList = fsUserMapper.courseAnalysisAnswerCount(courseAnalysisParam);
|
|
|
-
|
|
|
- //3、转化为自定义键的map
|
|
|
-// Map<Long, FsCourseAnalysisCountVO> courseMap = courseCountList.stream()
|
|
|
-// .collect(Collectors.toMap(
|
|
|
-// FsCourseAnalysisCountVO::getVideoId,
|
|
|
-// Function.identity()
|
|
|
-// ));
|
|
|
-// Map<Long, FsCourseAnalysisCountVO> redPacketMap = redPacketCountList.stream()
|
|
|
-// .collect(Collectors.toMap(
|
|
|
-// FsCourseAnalysisCountVO::getVideoId,
|
|
|
-// Function.identity()
|
|
|
-// ));
|
|
|
-// Map<Long, FsCourseAnalysisCountVO> answerMap = answerCountList.stream()
|
|
|
-// .collect(Collectors.toMap(
|
|
|
-// FsCourseAnalysisCountVO::getVideoId,
|
|
|
-// Function.identity()
|
|
|
-// ));
|
|
|
+ List<FsUserWatchCourseStatistics> userTotal = fsUserMapper.selectFsUserDetail();
|
|
|
+
|
|
|
+ // 转化为自定义键的map
|
|
|
Map<String, FsUserWatchCourseStatistics> watchLogMap = watchLog.stream().collect(Collectors.toMap(k -> String.format("%s-%s-%s", k.getPeriodId(), k.getVideoId(), k.getCompanyUserId()), v -> v));
|
|
|
Map<String, FsUserWatchCourseStatistics> redPacketLogMap = redPacketLog.stream().collect(Collectors.toMap(k -> String.format("%s-%s-%s", k.getPeriodId(), k.getVideoId(), k.getCompanyUserId()), v -> v));
|
|
|
Map<String, FsUserWatchCourseStatistics> answerLogMap = answerLog.stream().collect(Collectors.toMap(k -> String.format("%s-%s-%s", k.getPeriodId(), k.getVideoId(), k.getCompanyUserId()), v -> v));
|
|
|
+ Map<Long, FsUserWatchCourseStatistics> userTotalMap = userTotal.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ FsUserWatchCourseStatistics::getCompanyUserId,
|
|
|
+ Function.identity()
|
|
|
+ ));
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// //4、处理数据
|
|
|
-// return videoList.stream().map(v -> {
|
|
|
-// FsPeriodCountVO allVO = new FsPeriodCountVO();
|
|
|
-// BeanUtils.copyProperties(v, allVO);
|
|
|
-// allVO.setTitle(v.getVideoName());
|
|
|
-//
|
|
|
-// FsCourseAnalysisCountVO countVO = getCourseAnalysisCountVO(v, courseMap, redPacketMap, answerMap);
|
|
|
-// allVO.setCountDetailsVO(countVO);
|
|
|
-// return allVO;
|
|
|
-// }).collect(Collectors.toList());
|
|
|
+ // 处理数据
|
|
|
+ List<FsUserWatchCourseStatistics> list = new ArrayList<>();
|
|
|
for (FsUserWatchCourseStatistics data : fsUserWatchCourseStatistics) {
|
|
|
FsUserWatchCourseStatistics vo = new FsUserWatchCourseStatistics();
|
|
|
String key = String.format("%s-%s-%s", data.getPeriodId(), data.getVideoId(), data.getCompanyUserId());
|
|
|
FsUserWatchCourseStatistics watchLogData = watchLogMap.get(key);
|
|
|
FsUserWatchCourseStatistics redPacketLogData = redPacketLogMap.get(key);
|
|
|
FsUserWatchCourseStatistics answerLogData = answerLogMap.get(key);
|
|
|
-// BeanUtils.copyProperties();
|
|
|
+ FsUserWatchCourseStatistics userTotalData = userTotalMap.get(data.getCompanyUserId());
|
|
|
+ BeanUtils.copyProperties(data, vo);
|
|
|
+ if(userTotalData != null){
|
|
|
+ vo.setUserNum(userTotalData.getUserNum());
|
|
|
+ vo.setNewUserNum(userTotalData.getNewUserNum());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(watchLogData != null) {
|
|
|
+ vo.setWatchNum(watchLogData.getWatchNum());
|
|
|
+ vo.setCompleteWatchNum(watchLogData.getCompleteWatchNum());
|
|
|
+ vo.setCompleteWatchRate(watchLogData.getCompleteWatchRate());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(redPacketLogData != null) {
|
|
|
+ vo.setRedPacketNum(redPacketLogData.getRedPacketNum());
|
|
|
+ vo.setRedPacketAmount(redPacketLogData.getRedPacketAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(answerLogData != null) {
|
|
|
+ vo.setAnswerNum(answerLogData.getAnswerNum());
|
|
|
+ vo.setAnswerRightNum(answerLogData.getAnswerRightNum());
|
|
|
+ vo.setAnswerRightRate(answerLogData.getAnswerRightRate());
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setCreateTime(new Date());
|
|
|
+ vo.setUpdateTime(new Date());
|
|
|
+ list.add(vo);
|
|
|
}
|
|
|
|
|
|
+ //2、分批次插入数据
|
|
|
+ this.batchInsert(list);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- private String buildKey(Long periodId, Long videoId, Long companyUserId) {
|
|
|
- return periodId + "|" + videoId + "|" + companyUserId; // 使用特殊字符分隔,确保唯一性
|
|
|
+ private void batchInsert(List<FsUserWatchCourseStatistics> list) {
|
|
|
+ // 分批次处理,一次提交500条
|
|
|
+ List<List<FsUserWatchCourseStatistics>> batches = Lists.partition(list, 500);
|
|
|
+ batches.forEach(batch -> {
|
|
|
+ SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
|
|
+ try {
|
|
|
+ FsUserWatchCourseStatisticsMapper mapper = sqlSession.getMapper(FsUserWatchCourseStatisticsMapper.class);
|
|
|
+ batch.forEach(mapper::insertFsUserWatchCourseStatisticsTask);
|
|
|
+ sqlSession.commit();
|
|
|
+ } finally {
|
|
|
+ sqlSession.close();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
+
|
|
|
}
|