|
|
@@ -3,22 +3,27 @@ package com.fs.company.service.impl;
|
|
|
import cn.hutool.core.date.StopWatch;
|
|
|
import com.fs.common.enums.DimensionEnum;
|
|
|
import com.fs.company.domain.CompanyDeptUserInfo;
|
|
|
-import com.fs.company.domain.ComprehensiveDailyStats;
|
|
|
-import com.fs.company.dto.CompanyDeptUserInfoDTO;
|
|
|
+import com.fs.company.domain.CourseWatchLogData;
|
|
|
+import com.fs.company.domain.CourseWatchLogStatistics;
|
|
|
+import com.fs.company.mapper.CourseWatchLogStatisticsMapper;
|
|
|
import com.fs.company.mapper.StatisticManageMapper;
|
|
|
import com.fs.company.service.IStatisticManageService;
|
|
|
+import com.fs.statis.dto.ComprehensiveStatisticsDTO;
|
|
|
import com.fs.statis.param.ComprehensiveStatisticsParam;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
- * @description:
|
|
|
+ * @description: sql的代码以及整合了大部门,这里很多代码都可以整合按照不同的维度进行
|
|
|
* @author: Guos
|
|
|
* @time: 2025/10/30 上午9:21
|
|
|
*/
|
|
|
@@ -29,6 +34,9 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
@Resource
|
|
|
private StatisticManageMapper statisticManageMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private CourseWatchLogStatisticsMapper courseWatchLogStatisticsMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 统计
|
|
|
* 按照部门分组情况
|
|
|
@@ -38,145 +46,407 @@ public class StatisticManageServiceImpl implements IStatisticManageService {
|
|
|
public Object statisticMain(ComprehensiveStatisticsParam param) {
|
|
|
if(param.getDimension() == DimensionEnum.COMPANY.getValue()){
|
|
|
Assert.notNull(param.getId(), "按公司展示查询条件不能为空!");
|
|
|
- return getStatisticNumByCompanyId(param.getStartTime(), param.getEndTime(), param.getId());
|
|
|
+ return getStatisticNumByCompanyId(param);
|
|
|
}
|
|
|
if(param.getDimension() == DimensionEnum.DEPARTMENT.getValue()){
|
|
|
Assert.notNull(param.getId(), "按部门展示查询条件不能为空!");
|
|
|
- return getStatisticNumByDeptId(param.getStartTime(), param.getEndTime(), param.getId());
|
|
|
+ return getStatisticNumByDeptId(param);
|
|
|
}
|
|
|
if (param.getDimension() == DimensionEnum.PERSONAL.getValue()){
|
|
|
Assert.notNull(param.getId(), "按个人展示查询条件不能为空!");
|
|
|
- return getStatisticNumByPersonal(DimensionEnum.PERSONAL.getValue(), param.getStartTime(), param.getEndTime(), param.getId());
|
|
|
+ return getStatisticNumByPersonal(param);
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取搜索公司信息
|
|
|
+ * 获取个人统计数据
|
|
|
*/
|
|
|
- @Override
|
|
|
- public List<CompanyDeptUserInfo> getSearchCompanyInfo(){
|
|
|
- return statisticManageMapper.getCompanyInfo();
|
|
|
+ public List getStatisticNumByDeptId(ComprehensiveStatisticsParam param){
|
|
|
+ //先获取部门下的用户的信息
|
|
|
+ Long id = param.getId();
|
|
|
+ List<CompanyDeptUserInfo> searchUserInfo = statisticManageMapper.getSearchUserInfo(id);
|
|
|
+ List result = Lists.newArrayList();
|
|
|
+ List<Date> dates = generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
+ for (Date date : dates){
|
|
|
+ param.setStartTime(date);
|
|
|
+ param.setEndTime(date);
|
|
|
+ for (CompanyDeptUserInfo companyDeptUserInfo : searchUserInfo) {
|
|
|
+ String deptName = companyDeptUserInfo.getDeptName();
|
|
|
+ String companyName = companyDeptUserInfo.getCompanyName();
|
|
|
+ Long deptId = companyDeptUserInfo.getDeptId();
|
|
|
+ Long companyId = companyDeptUserInfo.getCompanyId();
|
|
|
+ param.setUserId(companyDeptUserInfo.getUserId());
|
|
|
+ ComprehensiveStatisticsDTO statisticDataByDeptId =
|
|
|
+ statisticManageMapper.getStatisticDataByDeptId(param);
|
|
|
+ if(ObjectUtils.isEmpty(statisticDataByDeptId)){
|
|
|
+ statisticDataByDeptId = new ComprehensiveStatisticsDTO();
|
|
|
+ statisticDataByDeptId.setAnswerNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setSendCount(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ statisticDataByDeptId.setCompanyUserName(companyDeptUserInfo.getNickName());
|
|
|
+ statisticDataByDeptId.setCompanyUserId(companyDeptUserInfo.getUserId());
|
|
|
+ statisticDataByDeptId.setDeptName(deptName);
|
|
|
+ statisticDataByDeptId.setDeptId(deptId.intValue());
|
|
|
+ statisticDataByDeptId.setCompanyName(companyName);
|
|
|
+ statisticDataByDeptId.setCompanyId(companyId);
|
|
|
+ statisticDataByDeptId.setStatisticsTime(date);
|
|
|
+ result.add(statisticDataByDeptId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据公司id获取部门下拉搜索信息
|
|
|
- * @param id
|
|
|
+ * 获取个人统计数据
|
|
|
*/
|
|
|
- @Override
|
|
|
- public List<CompanyDeptUserInfo> getSearchDeptInfo(Long id){
|
|
|
- return statisticManageMapper.getSearchDeptInfo(id);
|
|
|
+ public List getStatisticNumByPersonal(ComprehensiveStatisticsParam param){
|
|
|
+ //先获取用户的信息
|
|
|
+ Long id = param.getId();
|
|
|
+ CompanyDeptUserInfo userInfoByUserId = statisticManageMapper.getUserInfoByUserId(id);
|
|
|
+ List result = Lists.newArrayList();
|
|
|
+ List<Date> dates = generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
+ for (Date date : dates){
|
|
|
+ param.setStartTime(date);
|
|
|
+ param.setEndTime(date);
|
|
|
+ param.setDeptId(userInfoByUserId.getDeptId());
|
|
|
+ param.setUserId(id);
|
|
|
+ ComprehensiveStatisticsDTO statisticDataByDeptId = statisticManageMapper.getStatisticDataByDeptId(param);
|
|
|
+ if(ObjectUtils.isEmpty(statisticDataByDeptId)){
|
|
|
+ statisticDataByDeptId = new ComprehensiveStatisticsDTO();
|
|
|
+ statisticDataByDeptId.setAnswerNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setSendCount(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ statisticDataByDeptId.setDeptName(userInfoByUserId.getDeptName());
|
|
|
+ statisticDataByDeptId.setCompanyUserName(userInfoByUserId.getNickName());
|
|
|
+ statisticDataByDeptId.setCompanyUserId(userInfoByUserId.getUserId());
|
|
|
+ statisticDataByDeptId.setDeptName(userInfoByUserId.getDeptName());
|
|
|
+ statisticDataByDeptId.setDeptId(userInfoByUserId.getDeptId().intValue());
|
|
|
+ statisticDataByDeptId.setCompanyName(userInfoByUserId.getCompanyName());
|
|
|
+ statisticDataByDeptId.setCompanyId(userInfoByUserId.getCompanyId());
|
|
|
+ statisticDataByDeptId.setStatisticsTime(date);
|
|
|
+ result.add(statisticDataByDeptId);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据部门id获取用户下拉信息
|
|
|
- * @param id
|
|
|
+ * 根据公司获取统计数据
|
|
|
*/
|
|
|
- @Override
|
|
|
- public List<CompanyDeptUserInfo> getSearchUserInfo(Long id){
|
|
|
- return statisticManageMapper.getSearchUserInfo(id);
|
|
|
+ public List getStatisticNumByCompanyId(ComprehensiveStatisticsParam param){
|
|
|
+ //先从公司拿到公司和部门的信息
|
|
|
+ List<CompanyDeptUserInfo> searchDeptInfo = getSearchDeptInfo(param.getId());
|
|
|
+ List result = Lists.newArrayList();
|
|
|
+
|
|
|
+ List<Date> dates = generateDateList(param.getStartTime(), param.getEndTime());
|
|
|
+ for (Date date : dates){
|
|
|
+ param.setStartTime(date);
|
|
|
+ param.setEndTime(date);
|
|
|
+ for (CompanyDeptUserInfo companyDeptUserInfo : searchDeptInfo) {
|
|
|
+ String deptName = companyDeptUserInfo.getDeptName();
|
|
|
+ String companyName = companyDeptUserInfo.getCompanyName();
|
|
|
+ Long deptId = companyDeptUserInfo.getDeptId();
|
|
|
+ Long companyId = companyDeptUserInfo.getCompanyId();
|
|
|
+ param.setDeptId(deptId);
|
|
|
+ ComprehensiveStatisticsDTO statisticDataByDeptId =
|
|
|
+ statisticManageMapper.getStatisticDataByDeptId(param);
|
|
|
+ if(ObjectUtils.isEmpty(statisticDataByDeptId)){
|
|
|
+ statisticDataByDeptId = new ComprehensiveStatisticsDTO();
|
|
|
+ statisticDataByDeptId.setAnswerNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setSendCount(BigDecimal.ZERO.intValue());
|
|
|
+ statisticDataByDeptId.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ statisticDataByDeptId.setDeptName(deptName);
|
|
|
+ statisticDataByDeptId.setDeptId(deptId.intValue());
|
|
|
+ statisticDataByDeptId.setCompanyName(companyName);
|
|
|
+ statisticDataByDeptId.setCompanyId(companyId);
|
|
|
+ statisticDataByDeptId.setStatisticsTime(date);
|
|
|
+ result.add(statisticDataByDeptId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取个人统计数据
|
|
|
- * @param dimension 维度
|
|
|
+ * 生成开始时间到结束时间之间的每日时间数组
|
|
|
* @param startTime 开始时间
|
|
|
* @param endTime 结束时间
|
|
|
- * @param userIds 用户id
|
|
|
- * @return
|
|
|
+ * @return 时间数组列表
|
|
|
*/
|
|
|
- public List<ComprehensiveDailyStats> getStatisticNumByPersonal(Integer dimension, Date startTime, Date endTime, Long... userIds) {
|
|
|
- return statisticManageMapper.getStatisticNumByPersonal(dimension, startTime, endTime, userIds);
|
|
|
+ public List<Date> generateDateList(Date startTime, Date endTime) {
|
|
|
+ List<Date> dateList = new ArrayList<>();
|
|
|
+ if (startTime == null || endTime == null) {
|
|
|
+ return dateList;
|
|
|
+ }
|
|
|
+
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(startTime);
|
|
|
+
|
|
|
+ // 设置时间为当天00:00:00,确保按天计算
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+
|
|
|
+ Date currentDate = calendar.getTime();
|
|
|
+ Date finalEndTime = getStartOfDay(endTime);
|
|
|
+
|
|
|
+ while (!currentDate.after(finalEndTime)) {
|
|
|
+ dateList.add(currentDate);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
+ currentDate = calendar.getTime();
|
|
|
+ }
|
|
|
+
|
|
|
+ return dateList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取部门统计数据
|
|
|
- * @param startTime 开始时间
|
|
|
- * @param endTime 结束时间
|
|
|
- * @param deptId 用户id
|
|
|
- * @return
|
|
|
+ * 获取指定日期的开始时间(00:00:00)
|
|
|
+ * @param date 指定日期
|
|
|
+ * @return 当天开始时间
|
|
|
*/
|
|
|
- public List<ComprehensiveDailyStats> getStatisticNumByDeptId(Date startTime, Date endTime, Long... deptId) {
|
|
|
- return statisticManageMapper.getStatisticNumByDeptId(startTime, endTime, deptId);
|
|
|
+ private Date getStartOfDay(Date date) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(date);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ return calendar.getTime();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取部门统计数据
|
|
|
- * @param startTime 开始时间
|
|
|
- * @param endTime 结束时间
|
|
|
- * @param deptId 用户id
|
|
|
- * @return
|
|
|
+ * 获取搜索公司信息
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CompanyDeptUserInfo> getSearchCompanyInfo(){
|
|
|
+ return statisticManageMapper.getCompanyInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据公司id获取部门下拉搜索信息
|
|
|
+ * @param id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CompanyDeptUserInfo> getSearchDeptInfo(Long id){
|
|
|
+ return statisticManageMapper.getSearchDeptInfo(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据部门id获取用户下拉信息
|
|
|
+ * @param id
|
|
|
*/
|
|
|
- public List<ComprehensiveDailyStats> getStatisticNumByCompanyId(Date startTime, Date endTime, Long... deptId) {
|
|
|
- return statisticManageMapper.getStatisticNumByCompanyId(startTime, endTime, deptId);
|
|
|
+ @Override
|
|
|
+ public List<CompanyDeptUserInfo> getSearchUserInfo(Long id){
|
|
|
+ return statisticManageMapper.getSearchUserInfo(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 执行定时任务
|
|
|
+ * 执行定时任务3.0
|
|
|
+ * 公司,部门,人,【课程,项目,视频id】,【发送,看视频】,【答题,完课,红包领取,红包金额】
|
|
|
* 还需要考虑在统计部门数据时,部门下面没有用户,某个时候这个部门下面又加入新的用户了,这个时候就会出现数据偏差
|
|
|
*/
|
|
|
@Override
|
|
|
- public void executeTask() {
|
|
|
+ public void executeTask(Date dateTime) {
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
stopWatch.start("gs-执行数据统计任务");
|
|
|
List<CompanyDeptUserInfo> companyDeptdUserList = statisticManageMapper.getCompanyAndDeptAndDeptUserList(null);
|
|
|
log.info("统计人数列表:{}", companyDeptdUserList.size());
|
|
|
+ if(null == dateTime){
|
|
|
+ dateTime = new Date();
|
|
|
+ }
|
|
|
+ Date finalDateTime = dateTime;
|
|
|
companyDeptdUserList.forEach(companyDeptUserInfo -> {
|
|
|
- CompanyDeptUserInfoDTO statisticNum = new CompanyDeptUserInfoDTO();
|
|
|
- boolean empty = null == companyDeptUserInfo.getUserId(); //用户id为空返回true
|
|
|
- if(!empty){
|
|
|
- statisticNum = statisticManageMapper.getStatisticNum(companyDeptUserInfo.getUserId());
|
|
|
- }
|
|
|
- ComprehensiveDailyStats comprehensiveDailyStats = component(companyDeptUserInfo, statisticNum);
|
|
|
- ComprehensiveDailyStats selectResult = null;
|
|
|
- if(!empty){
|
|
|
- //用户id不为空,我们就用用户id去查询这个日期是否有数据
|
|
|
- selectResult = statisticManageMapper.selectByUserAndDate(comprehensiveDailyStats.getUserId(), comprehensiveDailyStats.getStatisticsTime());
|
|
|
- }else{
|
|
|
- //如果用户id为空,说明部门下面没有人(没人情况下,部门id只会在当天的日期中存在一条),先按照部门去查询后删除(或者直接按照id更新就可以了)
|
|
|
- selectResult = statisticManageMapper.selectByDeptAndDate(companyDeptUserInfo.getDeptId(), comprehensiveDailyStats.getStatisticsTime());
|
|
|
- }
|
|
|
- if(!ObjectUtils.isEmpty(selectResult)){
|
|
|
- comprehensiveDailyStats.setId(selectResult.getId());
|
|
|
- statisticManageMapper.updateById(comprehensiveDailyStats);
|
|
|
+ Long userId = companyDeptUserInfo.getUserId();
|
|
|
+ courseWatchLogStatisticsMapper.deleteByStatisticsTimeAndDeptId(userId, companyDeptUserInfo.getDeptId(), finalDateTime);
|
|
|
+ //第一步通过人去查询【课程,项目,视频id】,【发送,看视频状态】
|
|
|
+ List<CourseWatchLogData> courseWatchLogData = statisticManageMapper.getCourseWatchLogData(userId, finalDateTime);
|
|
|
+ CourseWatchLogStatistics courseWatchLogStatistics = component(companyDeptUserInfo, finalDateTime);
|
|
|
+ if(CollectionUtils.isEmpty(courseWatchLogData)){
|
|
|
+ //如果为空,那么这个人其他数据都是0直接放入数据库
|
|
|
+ //TODO 需要判断当天是否有数据了,如果有数据,就需要更新(为空就刷新一下更新时间就可以了)
|
|
|
+ courseWatchLogStatisticsMapper.insert(courseWatchLogStatistics);
|
|
|
+ log.info("companyUserId:{}, 统计时间:{},无数据!", userId, finalDateTime);
|
|
|
}else{
|
|
|
- statisticManageMapper.insert(comprehensiveDailyStats);
|
|
|
+ //先按照project分组,这里过滤了为空的项目,有的数据project字段就是空的,这个统计时候去处理就麻烦了
|
|
|
+ Map<String, List<CourseWatchLogData>> projectIdCollect = courseWatchLogData.stream().filter(c -> c.getProject() != null)
|
|
|
+ .collect(Collectors.groupingBy(CourseWatchLogData::getProject));
|
|
|
+ for (Map.Entry<String, List<CourseWatchLogData>> entry : projectIdCollect.entrySet()) {
|
|
|
+ String projectId = entry.getKey();
|
|
|
+ List<CourseWatchLogData> courseWatchLogDataList = entry.getValue();
|
|
|
+ //有时候这个字段是空的
|
|
|
+ courseWatchLogStatistics.setProjectId(Long.parseLong(projectId));
|
|
|
+ int size = courseWatchLogDataList.size();
|
|
|
+ if (size == 1) {
|
|
|
+ CourseWatchLogData detail = courseWatchLogDataList.get(0);
|
|
|
+ courseWatchLogStatistics.setCourseId(detail.getCourseId());
|
|
|
+ courseWatchLogStatistics.setVideoId(detail.getVideoId());
|
|
|
+ courseWatchLogStatistics.setLogType(detail.getLogType());
|
|
|
+ courseWatchLogStatistics.setSendCount(1);
|
|
|
+ courseWatchLogStatisticsMapper.insert(courseWatchLogStatistics);
|
|
|
+ }else{
|
|
|
+ //按照courseId分组
|
|
|
+ Map<Long, List<CourseWatchLogData>> courseIdCollect = courseWatchLogDataList.stream()
|
|
|
+ .collect(Collectors.groupingBy(CourseWatchLogData::getCourseId));
|
|
|
+ for (Map.Entry<Long, List<CourseWatchLogData>> courseEntry : courseIdCollect.entrySet()) {
|
|
|
+ Long courseId = courseEntry.getKey();
|
|
|
+ List<CourseWatchLogData> byCourseIdList = courseEntry.getValue();
|
|
|
+ courseWatchLogStatistics.setCourseId(courseId);
|
|
|
+ int byCourseIdListSize = byCourseIdList.size();
|
|
|
+ if(byCourseIdListSize == 1){
|
|
|
+ CourseWatchLogData detail = courseWatchLogDataList.get(0);
|
|
|
+ courseWatchLogStatistics.setVideoId(detail.getVideoId());
|
|
|
+ courseWatchLogStatistics.setLogType(detail.getLogType());
|
|
|
+ courseWatchLogStatistics.setSendCount(1);
|
|
|
+ courseWatchLogStatisticsMapper.insert(courseWatchLogStatistics);
|
|
|
+ }else{
|
|
|
+ //按照VideoId分组
|
|
|
+ Map<Long, List<CourseWatchLogData>> videoIdCollect = byCourseIdList.stream()
|
|
|
+ .collect(Collectors.groupingBy(CourseWatchLogData::getVideoId));
|
|
|
+ for (Map.Entry<Long, List<CourseWatchLogData>> videoIdEntry : videoIdCollect.entrySet()) {
|
|
|
+ Long videoId = videoIdEntry.getKey();
|
|
|
+ List<CourseWatchLogData> byVideoIdList = videoIdEntry.getValue();
|
|
|
+ courseWatchLogStatistics.setVideoId(videoId);
|
|
|
+ int byVideoIdListSize = byVideoIdList.size();
|
|
|
+ if(byVideoIdListSize == 1){
|
|
|
+ CourseWatchLogData detail = courseWatchLogDataList.get(0);
|
|
|
+ courseWatchLogStatistics.setLogType(detail.getLogType());
|
|
|
+ courseWatchLogStatistics.setSendCount(1);
|
|
|
+ courseWatchLogStatisticsMapper.insert(courseWatchLogStatistics);
|
|
|
+ }else{
|
|
|
+ // 直接统计按照不同的logType进行数量统计
|
|
|
+ Map<Integer, List<CourseWatchLogData>> logTypeCollect = byVideoIdList.stream()
|
|
|
+ .collect(Collectors.groupingBy(CourseWatchLogData::getLogType));
|
|
|
+ for (Map.Entry<Integer, List<CourseWatchLogData>> logTypeEntry : logTypeCollect.entrySet()) {
|
|
|
+ Integer logType = logTypeEntry.getKey();
|
|
|
+ List<CourseWatchLogData> logTypeList = logTypeEntry.getValue();
|
|
|
+ courseWatchLogStatistics.setLogType(logType);
|
|
|
+ courseWatchLogStatistics.setSendCount(logTypeList.size());
|
|
|
+ courseWatchLogStatisticsMapper.insert(courseWatchLogStatistics);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("companyUserId:{}, 统计时间:{},有数据,数据条数:{}!", userId, finalDateTime, courseWatchLogData.size());
|
|
|
}
|
|
|
});
|
|
|
stopWatch.stop();
|
|
|
+ stopWatch.start("反查数据更新红包等信息");
|
|
|
+ //上面代码其实都是差不多,为了方便之后优化代码,保持整个逻辑清晰,先将整个数据保存后,再反查数据将答题数量、红包领取数量,以及金额统计更新
|
|
|
+ updateCourseRedPacket(finalDateTime);
|
|
|
+ stopWatch.stop();
|
|
|
log.info("gs-执行数据统计任务完成,耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
}
|
|
|
|
|
|
- private ComprehensiveDailyStats component(CompanyDeptUserInfo source, CompanyDeptUserInfoDTO statisticNum){
|
|
|
- ComprehensiveDailyStats target = new ComprehensiveDailyStats();
|
|
|
- target.setCompanyId(source.getCompanyId());
|
|
|
- target.setCompanyName(source.getCompanyName());
|
|
|
- target.setDeptId(source.getDeptId());
|
|
|
- target.setDeptName(source.getDeptName());
|
|
|
- target.setStatisticsTime(new Date());
|
|
|
- target.setCreateTime(new Date());
|
|
|
- target.setUpdateTime(new Date());
|
|
|
- if(null != source.getUserId()){
|
|
|
- target.setUserId(source.getUserId());
|
|
|
- target.setUserName(source.getUserName());
|
|
|
- target.setNickName(source.getNickName());
|
|
|
- target.setAnswerNum(statisticNum.getAnswerNum());
|
|
|
- target.setCompleteNum(statisticNum.getCompleteNum());
|
|
|
- target.setLineNum(statisticNum.getLineNum());
|
|
|
- target.setActiveNum(statisticNum.getActiveNum());
|
|
|
- target.setRedPacketNum(statisticNum.getRedPacketNum());
|
|
|
- target.setRedPacketAmount(new BigDecimal(0.00));
|
|
|
- }else{
|
|
|
- target.setAnswerNum(0);
|
|
|
- target.setCompleteNum(0);
|
|
|
- target.setLineNum(0);
|
|
|
- target.setActiveNum(0);
|
|
|
- target.setRedPacketNum(0);
|
|
|
- target.setRedPacketAmount(new BigDecimal(0.00));
|
|
|
+ /**
|
|
|
+ * 通过反查数据来更新红包信息
|
|
|
+ */
|
|
|
+ public void updateCourseRedPacket(Date dateTime){
|
|
|
+ List<CourseWatchLogStatistics> needUpdateData = courseWatchLogStatisticsMapper.getNeedUpdateData(dateTime);
|
|
|
+ for(CourseWatchLogStatistics courseWatchLogStatistics:needUpdateData){
|
|
|
+ CourseWatchLogData answerAndRedPacketData = statisticManageMapper.getAnswerAndRedPacketData(courseWatchLogStatistics.getCompanyUserId(),
|
|
|
+ courseWatchLogStatistics.getVideoId(), dateTime);
|
|
|
+ courseWatchLogStatistics.setAnswerNum(answerAndRedPacketData.getAnswerNum());
|
|
|
+ courseWatchLogStatistics.setRedPacketNum(answerAndRedPacketData.getRedPacketNum());
|
|
|
+ courseWatchLogStatistics.setRedPacketAmount(answerAndRedPacketData.getRedPacketAmount());
|
|
|
+ courseWatchLogStatisticsMapper.updateByPrimaryKey(courseWatchLogStatistics);
|
|
|
}
|
|
|
- return target;
|
|
|
}
|
|
|
|
|
|
+ //返回一个所有数据都是空的对象
|
|
|
+ public CourseWatchLogStatistics component(CompanyDeptUserInfo companyDeptUserInfo, Date dateTime){
|
|
|
+ CourseWatchLogStatistics build = new CourseWatchLogStatistics();
|
|
|
+ build.setCompanyId(companyDeptUserInfo.getCompanyId());
|
|
|
+ build.setCompanyUserId(companyDeptUserInfo.getUserId());
|
|
|
+ build.setDeptId(companyDeptUserInfo.getDeptId().intValue());
|
|
|
+ build.setStatisticsTime(dateTime);
|
|
|
+ build.setLogType(null);
|
|
|
+ build.setSendCount(null);
|
|
|
+ build.setProjectId(null);
|
|
|
+ build.setVideoId(null);
|
|
|
+ build.setCourseId(null);
|
|
|
+ build.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
+ build.setAnswerNum(BigDecimal.ZERO.intValue());
|
|
|
+ build.setRedPacketNum(BigDecimal.ZERO.intValue());
|
|
|
+ build.setCreateTime(new Date());
|
|
|
+ build.setUpdateTime(new Date());
|
|
|
+ return build;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// /**
|
|
|
+// * 执行定时任务
|
|
|
+// * 还需要考虑在统计部门数据时,部门下面没有用户,某个时候这个部门下面又加入新的用户了,这个时候就会出现数据偏差
|
|
|
+// */
|
|
|
+// @Override
|
|
|
+// public void executeTask() {
|
|
|
+// StopWatch stopWatch = new StopWatch();
|
|
|
+// stopWatch.start("gs-执行数据统计任务");
|
|
|
+// List<CompanyDeptUserInfo> companyDeptdUserList = statisticManageMapper.getCompanyAndDeptAndDeptUserList(null);
|
|
|
+// log.info("统计人数列表:{}", companyDeptdUserList.size());
|
|
|
+// companyDeptdUserList.forEach(companyDeptUserInfo -> {
|
|
|
+// CompanyDeptUserInfoDTO statisticNum = new CompanyDeptUserInfoDTO();
|
|
|
+// boolean empty = null == companyDeptUserInfo.getUserId(); //用户id为空返回true
|
|
|
+// if(!empty){
|
|
|
+// statisticNum = statisticManageMapper.getStatisticNum(companyDeptUserInfo.getUserId());
|
|
|
+// }
|
|
|
+// ComprehensiveDailyStats comprehensiveDailyStats = component(companyDeptUserInfo, statisticNum);
|
|
|
+// ComprehensiveDailyStats selectResult = null;
|
|
|
+// if(!empty){
|
|
|
+// //用户id不为空,我们就用用户id去查询这个日期是否有数据
|
|
|
+// selectResult = statisticManageMapper.selectByUserAndDate(comprehensiveDailyStats.getUserId(), comprehensiveDailyStats.getStatisticsTime());
|
|
|
+// }else{
|
|
|
+// //如果用户id为空,说明部门下面没有人(没人情况下,部门id只会在当天的日期中存在一条),先按照部门去查询后删除(或者直接按照id更新就可以了)
|
|
|
+// selectResult = statisticManageMapper.selectByDeptAndDate(companyDeptUserInfo.getDeptId(), comprehensiveDailyStats.getStatisticsTime());
|
|
|
+// }
|
|
|
+// if(!ObjectUtils.isEmpty(selectResult)){
|
|
|
+// comprehensiveDailyStats.setId(selectResult.getId());
|
|
|
+// statisticManageMapper.updateById(comprehensiveDailyStats);
|
|
|
+// }else{
|
|
|
+// statisticManageMapper.insert(comprehensiveDailyStats);
|
|
|
+// }
|
|
|
+// });
|
|
|
+// stopWatch.stop();
|
|
|
+// log.info("gs-执行数据统计任务完成,耗时:{}", stopWatch.getTotalTimeSeconds());
|
|
|
+// }
|
|
|
+//
|
|
|
+// private ComprehensiveDailyStats component(CompanyDeptUserInfo source, CompanyDeptUserInfoDTO statisticNum){
|
|
|
+// ComprehensiveDailyStats target = new ComprehensiveDailyStats();
|
|
|
+// target.setCompanyId(source.getCompanyId());
|
|
|
+// target.setCompanyName(source.getCompanyName());
|
|
|
+// target.setDeptId(source.getDeptId());
|
|
|
+// target.setDeptName(source.getDeptName());
|
|
|
+// target.setStatisticsTime(new Date());
|
|
|
+// target.setCreateTime(new Date());
|
|
|
+// target.setUpdateTime(new Date());
|
|
|
+// if(null != source.getUserId()){
|
|
|
+// target.setUserId(source.getUserId());
|
|
|
+// target.setUserName(source.getUserName());
|
|
|
+// target.setNickName(source.getNickName());
|
|
|
+// target.setAnswerNum(statisticNum.getAnswerNum());
|
|
|
+// target.setCompleteNum(statisticNum.getCompleteNum());
|
|
|
+// target.setLineNum(statisticNum.getLineNum());
|
|
|
+// target.setActiveNum(statisticNum.getActiveNum());
|
|
|
+// target.setRedPacketNum(statisticNum.getRedPacketNum());
|
|
|
+// target.setRedPacketAmount(new BigDecimal(0.00));
|
|
|
+// }else{
|
|
|
+// target.setAnswerNum(0);
|
|
|
+// target.setCompleteNum(0);
|
|
|
+// target.setLineNum(0);
|
|
|
+// target.setActiveNum(0);
|
|
|
+// target.setRedPacketNum(0);
|
|
|
+// target.setRedPacketAmount(new BigDecimal(0.00));
|
|
|
+// }
|
|
|
+// return target;
|
|
|
+// }
|
|
|
|
|
|
}
|
|
|
|