瀏覽代碼

新增累计观看天数和连续观看天数

yfh 6 天之前
父節點
當前提交
c1bac6dd46

+ 1 - 0
fs-company-app/src/main/java/com/fs/app/controller/FsUserCourseVideoController.java

@@ -130,6 +130,7 @@ public class FsUserCourseVideoController extends AppBaseController {
 
         PageHelper.startPage(pageNum, pageSize);
         List<FsUserCourseParticipationRecordVO> record = fsUserCourseService.getParticipationRecordByMap(params);
+        System.out.println("所有数据:"+record);
         return ResponseResult.ok(new PageInfo<>(record));
     }
 

+ 22 - 0
fs-service-system/src/main/java/com/fs/course/mapper/FsCourseWatchLogMapper.java

@@ -386,4 +386,26 @@ public interface FsCourseWatchLogMapper extends BaseMapper<FsCourseWatchLog> {
             ") dd ON ds.report_date = dd.log_date\n" +
             "ORDER BY ds.report_date ASC")
     List<WatchLogDTO> selectFsCourseWatchLog30DayByExtId(@Param("extId") Long extId);
+
+    @Select("select count(*) from fs_course_watch_log where user_id =#{userId} and project =#{projectId} ")
+    Long selectByWatchLjDay(@Param("userId") Long userId,@Param("projectId")  Long projectId);
+    @Select("SELECT IFNULL(MAX(streak), 0) AS current_consecutive_days\n" +
+            "FROM (\n" +
+            "    SELECT \n" +
+            "        watch_date,\n" +
+            "        @streak := IF(\n" +
+            "            DATEDIFF(@prev_date, watch_date) = 1, \n" +
+            "            @streak + 1, \n" +
+            "            1\n" +
+            "        ) AS streak,\n" +
+            "        @prev_date := watch_date\n" +
+            "    FROM (\n" +
+            "        SELECT DISTINCT DATE(create_time) AS watch_date\n" +
+            "        FROM fs_course_watch_log\n" +
+            "        WHERE user_id = #{userId} AND project = #{projectId}\n" +
+            "        ORDER BY watch_date DESC\n" +
+            "    ) AS dates,\n" +
+            "    (SELECT @streak := 0, @prev_date := NULL) AS vars\n" +
+            ") AS streak_data;")
+    Long selectByWatchlxDay(@Param("userId") Long userId,@Param("projectId")  Long projectId);
 }

+ 4 - 1
fs-service-system/src/main/java/com/fs/course/service/impl/FsUserCourseServiceImpl.java

@@ -429,11 +429,14 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
 
             // 观看时长
             recordVO.setWatchTime((BigDecimal) sumMap.getOrDefault("watchTime", BigDecimal.ZERO));
-
             //累计观看天数
             Long ljDay = fsCourseWatchLogMapper.selectByWatchLjDay(recordVO.getUserId(),recordVO.getProjectId());
+            System.out.println("进入了统计累计观看天数:"+ljDay+"天");
+            recordVO.setWatchLjCount(ljDay);
             //连续观看天数
             Long lxDay = fsCourseWatchLogMapper.selectByWatchlxDay(recordVO.getUserId(),recordVO.getProjectId());
+            System.out.println("进入了连续观看天数:"+lxDay+"天");
+            recordVO.setWatchLxCount(lxDay);
             // 领取状态
             Long count = fsCourseAnswerLogsMapper.selectRedStatus(recordVO.getUserId(), recordVO.getVideoId());
             if (Objects.nonNull(count) && count > 0) {

+ 10 - 0
fs-service-system/src/main/java/com/fs/course/vo/FsUserCourseParticipationRecordVO.java

@@ -52,6 +52,16 @@ public class FsUserCourseParticipationRecordVO {
      * 完播次数
      */
     private Long finishCount;
+
+    /**
+     * 累计观看天数
+     */
+    private Long watchLjCount;
+
+    /**
+     * 连续观看天数
+     */
+    private Long watchLxCount;
     /**
      * 累计时长
      */