Jelajahi Sumber

代码提交

yjwang 5 jam lalu
induk
melakukan
e5f60f693c

+ 8 - 0
fs-qw-task/src/main/java/com/fs/app/controller/CommonController.java

@@ -148,6 +148,9 @@ public class CommonController {
     @Autowired
     private IFsUserWxService userWxService;
 
+    @Autowired
+    private IFsCourseWatchLogService courseWatchLogService;
+
     /**
      * 获取跳转微信小程序的链接地址
      */
@@ -429,4 +432,9 @@ public class CommonController {
         return userWxService.getWxQueryLinkInfo(appId,link);
     }
 
+    @GetMapping("/wank")
+    public void scheduleBatchUpdateToDatabase(){
+        courseWatchLogService.scheduleUpdateDurationToDatabaseText();
+    }
+
 }

+ 2 - 0
fs-service/src/main/java/com/fs/course/service/IFsCourseWatchLogService.java

@@ -139,4 +139,6 @@ public interface IFsCourseWatchLogService extends IService<FsCourseWatchLog> {
      * 看课统计
      * */
     List<FsCourseWatchLogStatisticsListVO> selectQwFsCourseWatchLogStatisticsListVO(QwSidebarStatsParam param);
+
+    void scheduleUpdateDurationToDatabaseText();
 }

+ 61 - 0
fs-service/src/main/java/com/fs/course/service/impl/FsCourseWatchLogServiceImpl.java

@@ -1242,5 +1242,66 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
         return fsCourseWatchLogMapper.selectQwFsCourseWatchLogStatisticsListVO(param);
     }
 
+    @Override
+    public void scheduleUpdateDurationToDatabaseText() {
+        log.info("WXH5-开始更新会员看课时长,检查完课-------------------------------->");
+        //读取所有的key
+        Collection<String> keys = redisCache.keys("h5wxuser:watch:duration:682578:8178:*");
+        log.info("WXH5aaaaaaaaaaaaaaa----------------->{}", keys);
+        //读取看课配置
+        String json = configService.selectConfigByKey("course.config");
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+
+        List<FsCourseWatchLog> logs = new ArrayList<>();
+        for (String key : keys) {
+            //取key中数据
+            String[] parts = key.split(":");
+            Long userId = Long.parseLong(parts[3]);
+            Long videoId = Long.parseLong(parts[4]);
+            Long companyUserId = Long.parseLong(parts[5]);
+            String durationStr = redisCache.getCacheObject(key);
+            log.info("WXH5获取时长-aaaaaaaaaa---------------->{}", durationStr);
+            if(durationStr==null){
+                log.error("key中数据为null:{}",key);
+                continue;  // 如果 Redis 中没有记录,跳过
+            }
+            Long duration = Long.valueOf(durationStr);
 
+            FsCourseWatchLog watchLog = new FsCourseWatchLog();
+            watchLog.setVideoId(videoId);
+            watchLog.setUserId(userId);
+            watchLog.setCompanyUserId(companyUserId);
+            watchLog.setDuration(duration);
+
+            //取对应视频的时长
+            Long videoDuration = 0L;
+            try {
+                videoDuration = getFsUserVideoDuration(videoId);
+                log.info("WXH5获取时长-aaaaaaaaaa视频时长---------------->{}", videoDuration);
+            }catch (Exception e){
+                log.info("WXH5获取时长-aaaaaaaaaa---------------->{}", "视频时长识别错误");
+                log.error("视频时长识别错误:{}", key);
+                continue;
+            }
+            if (videoDuration != null && videoDuration != 0) {
+                log.info("WXH5获取时长-aaaaaaaaaa-视频时长不为空---------------->{}", videoDuration);
+                //判断是否完课
+                long percentage = (duration * 100 / videoDuration);
+                log.info("WXH5获取时长-aaaaaaaaaa-判断百分比---------------->{}", percentage);
+                if (percentage >= config.getAnswerRate()) {
+                    log.info("WXH5获取时长-aaaaaaaaaa-完课---------------->{}", percentage);
+                    watchLog.setLogType(2); // 设置状态为“已完成”checkFsUserWatchStatus
+                    watchLog.setFinishTime(new Date());
+                    String heartbeatKey ="h5wxuser:watch:heartbeat:" + userId+ ":" + videoId + ":" + companyUserId;
+                    // 完课删除心跳记录
+                    redisCache.deleteObject(heartbeatKey);
+                    // 完课删除看课时长记录
+                    redisCache.deleteObject(key);
+                }
+            }
+            //集合中增加
+            logs.add(watchLog);
+        }
+        batchUpdateFsUserCourseWatchLog(logs,100);
+    }
 }