|
|
@@ -36,7 +36,10 @@ import com.fs.his.dto.AppUserCompanyDTO;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.service.IFsUserService;
|
|
|
import com.fs.his.utils.ConfigUtil;
|
|
|
+import com.fs.his.utils.PhoneUtil;
|
|
|
import com.fs.his.vo.AppCourseReportVO;
|
|
|
+import com.fs.his.vo.AppWatchLogReportVO;
|
|
|
+import com.fs.his.vo.WatchLogReportVO;
|
|
|
import com.fs.qw.Bean.MsgBean;
|
|
|
import com.fs.qw.cache.IQwExternalContactCacheService;
|
|
|
import com.fs.qw.cache.IQwUserCacheService;
|
|
|
@@ -1829,6 +1832,162 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
|
|
|
|
|
|
return allCompanies;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AppWatchLogReportVO> selectUserAppWatchLogReportVO(FsCourseWatchLogStatisticsListParam param) {
|
|
|
+ if (StringUtils.isNotEmpty(param.getUserPhone())) {
|
|
|
+ //加密手机号
|
|
|
+ param.setUserPhone(PhoneUtil.encryptPhone(param.getUserPhone()));
|
|
|
+ }
|
|
|
+ // 时间转字符串
|
|
|
+ if (param.getSTime() != null && param.getETime() != null) {
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ param.setStartDate(simpleDateFormat.format(param.getSTime()));
|
|
|
+ param.setEndDate(simpleDateFormat.format(param.getETime()));
|
|
|
+ }
|
|
|
+ // 获取基础数据
|
|
|
+ List<AppWatchLogReportVO> baseData = fsCourseWatchLogMapper.selectAppUserBaseData(param);
|
|
|
+ if (CollectionUtils.isEmpty(baseData)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 获取统计数据和组装结果
|
|
|
+ return assembleAppStatisticsData(baseData, param);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装APP统计数据
|
|
|
+ */
|
|
|
+ private List<AppWatchLogReportVO> assembleAppStatisticsData(List<AppWatchLogReportVO> baseData, FsCourseWatchLogStatisticsListParam param) {
|
|
|
+ // 准备查询条件
|
|
|
+ List<Long> periods = baseData.stream().map(AppWatchLogReportVO::getPeriodId).collect(Collectors.toList());
|
|
|
+ List<Long> logIds = baseData.stream().map(AppWatchLogReportVO::getLogId).collect(Collectors.toList());
|
|
|
+ List<Long> userIds = baseData.stream().map(AppWatchLogReportVO::getUserId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 批量查询统计数据
|
|
|
+ // 营期数据
|
|
|
+ Map<Long, WatchLogReportVO> perMap = convertCampPeriodToMap(fsCourseWatchLogMapper.selectCampPeriodByPeriod(periods));
|
|
|
+
|
|
|
+ // 红包数据
|
|
|
+ Map<Long, WatchLogReportVO> redPacketMap = convertRedPacketToMap(
|
|
|
+ fsCourseWatchLogMapper.selectRedPacketStats(logIds)
|
|
|
+ );
|
|
|
+
|
|
|
+// // 订单数据
|
|
|
+// Map<Long, WatchLogReportVO> orderMap = convertOrderToMap(
|
|
|
+// fsCourseWatchLogMapper.selectOrderStats(userIds, param)
|
|
|
+// );
|
|
|
+
|
|
|
+ // 答题数据
|
|
|
+ Map<Long, WatchLogReportVO> answerMap = convertAnswerToMap(
|
|
|
+ fsCourseWatchLogMapper.selectAnswerStats(logIds)
|
|
|
+ );
|
|
|
+
|
|
|
+ // 学习时长数据(来自fs_user_course_study_log表)- 使用字符串时间
|
|
|
+// Map<String, AppWatchLogReportVO> studyDurationMap = fsUserCourseStudyLogMapper.selectStudyDurationByUserIds(userIds, param.getStartDate(), param.getEndDate())
|
|
|
+// .stream()
|
|
|
+// .collect(Collectors.toMap(
|
|
|
+// item -> item.getUserId() + "_" + item.getVideoId(),
|
|
|
+// Function.identity()
|
|
|
+// ));
|
|
|
+
|
|
|
+ // 组装数据
|
|
|
+ for (AppWatchLogReportVO item : baseData) {
|
|
|
+ // 营期数据
|
|
|
+ WatchLogReportVO watchStats = perMap.getOrDefault(item.getPeriodId(), null);
|
|
|
+ if (watchStats != null) {
|
|
|
+ item.setPeriodName(watchStats.getPeriodName());
|
|
|
+ item.setTrainingCampName(watchStats.getTrainingCampName());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 红包数据
|
|
|
+ WatchLogReportVO redPacketStats = redPacketMap.getOrDefault(item.getLogId(), null);
|
|
|
+ if (redPacketStats != null) {
|
|
|
+ item.setRedPacketAmount(redPacketStats.getRedPacketAmount());
|
|
|
+ }
|
|
|
+
|
|
|
+// // 订单数据
|
|
|
+// WatchLogReportVO order = orderMap.getOrDefault(item.getUserId(), null);
|
|
|
+// if (order != null) {
|
|
|
+// item.setHistoryOrderCount(order.getHistoryOrderCount());
|
|
|
+// }
|
|
|
+
|
|
|
+ // 答题数据
|
|
|
+ WatchLogReportVO answer = answerMap.getOrDefault(item.getLogId(), null);
|
|
|
+ if (answer != null) {
|
|
|
+ item.setAnswerStatus(answer.getAnswerStatus());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 学习时长数据
|
|
|
+// AppWatchLogReportVO studyDuration = studyDurationMap.get(item.getUserId() + "_" + item.getVideoId());
|
|
|
+// if (studyDuration != null && studyDuration.getPublicCourseDuration() != null) {
|
|
|
+// // 将秒转换为时分秒格式
|
|
|
+// item.setPublicCourseDuration(formatDuration(Long.valueOf(studyDuration.getPublicCourseDuration())));
|
|
|
+// }
|
|
|
+ }
|
|
|
+ return baseData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 红包数据转Map
|
|
|
+ */
|
|
|
+ public Map<Long, WatchLogReportVO> convertRedPacketToMap(List<WatchLogReportVO> list) {
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ return list.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ WatchLogReportVO::getLogId,
|
|
|
+ Function.identity(),
|
|
|
+ (existing, replacement) -> existing // 当出现重复键时,保留第一个值
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 营期数据转Map
|
|
|
+ */
|
|
|
+ public Map<Long, WatchLogReportVO> convertCampPeriodToMap(List<WatchLogReportVO> list) {
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ return list.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ WatchLogReportVO::getPeriodId,
|
|
|
+ Function.identity(),
|
|
|
+ (existing, replacement) -> existing // 当出现重复键时,保留第一个值
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单数据转Map
|
|
|
+ */
|
|
|
+ public Map<Long, WatchLogReportVO> convertOrderToMap(List<WatchLogReportVO> list) {
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ return list.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ WatchLogReportVO::getUserId,
|
|
|
+ Function.identity(),
|
|
|
+ (existing, replacement) -> existing // 当出现重复键时,保留第一个值
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 答题数据转Map
|
|
|
+ */
|
|
|
+ public Map<Long, WatchLogReportVO> convertAnswerToMap(List<WatchLogReportVO> list) {
|
|
|
+ if (list == null || list.isEmpty()) {
|
|
|
+ return new HashMap<>();
|
|
|
+ }
|
|
|
+ return list.stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ WatchLogReportVO::getLogId,
|
|
|
+ Function.identity(),
|
|
|
+ (existing, replacement) -> existing // 当出现重复键时,保留第一个值
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* app 看课率((看课中人次+完课人次)/ 私域课总人次)
|
|
|
* @param watchingCount 私域看课中人次
|