Browse Source

fix:更新看课记录定时任务

caoliqin 1 month ago
parent
commit
4142391467

+ 15 - 2
fs-service-system/src/main/java/com/fs/course/service/impl/FsCourseWatchLogServiceImpl.java

@@ -858,7 +858,8 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
     public void scheduleUpdateDurationToDatabase() {
         log.info("WXH5-开始更新会员看课时长,检查完课>>>>>>");
         //读取所有的key
-        Collection<String> keys = redisCache.keys("h5wxuser:watch:duration::*");
+        Collection<String> keys = redisCache.keys("h5wxuser:watch:duration:*");
+
         //读取看课配置
         String json = configService.selectConfigByKey("course.config");
         CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
@@ -884,7 +885,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
             watchLog.setDuration(duration);
 
             //取对应视频的时长
-            Long videoDuration = getVideoDuration(videoId);
+            Long videoDuration = getFsUserVideoDuration(videoId);
             if (videoDuration != null && videoDuration != 0) {
                 //判断是否完课
                 long percentage = (duration * 100 / videoDuration);
@@ -904,6 +905,18 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
         batchUpdateFsUserCourseWatchLog(logs,100);
     }
 
+    public Long getFsUserVideoDuration(Long videoId){
+        //将视频时长也存到redis
+        String videoRedisKey = "h5wxuser:video:duration:" + videoId;
+        Long videoDuration = redisCache.getCacheObject(videoRedisKey);
+        if (videoDuration==null){
+            FsUserCourseVideo video = courseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
+            videoDuration=video.getDuration();
+            redisCache.setCacheObject(videoRedisKey,video.getDuration().toString());
+        }
+        return videoDuration;
+    }
+
     @Override
     public void checkFsUserWatchStatus() {
         log.info("WXH5-开始更新会员看课中断记录>>>>>");