Переглянути джерело

isAddKf 添加项目校验、看课数校验

Long 5 днів тому
батько
коміт
5d2e1ff5aa

+ 5 - 0
fs-service-system/src/main/java/com/fs/course/mapper/FsUserCourseMapper.java

@@ -233,4 +233,9 @@ public interface FsUserCourseMapper
             "order by course_id asc" +
             "</script> ")
     List<FsCourseListBySidebarVO> getFsCourseListBySidebar(@Param("data") FsCourseListBySidebarParam param);
+
+    /**
+     * 查询当天用户-项目看课记录条数
+     */
+    Integer selectTodayCourseWatchLogCountByUserIdAndProjectId(@Param("userId") Long userId, @Param("projectId") Long projectId);
 }

+ 11 - 1
fs-service-system/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -1,6 +1,5 @@
 package com.fs.course.service.impl;
 
-import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
@@ -1246,6 +1245,17 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
             courseProject = fsUserCourse.getProject();
         }
 
+        // 项目校验
+        if (Objects.isNull(courseProject) || !courseProject.equals(param.getProjectId())) {
+            return ResponseResult.fail(504, "课程项目不匹配");
+        }
+
+        // 项目看课数限制
+        Integer logCount = fsUserCourseMapper.selectTodayCourseWatchLogCountByUserIdAndProjectId(param.getUserId(), param.getProjectId());
+        if (Objects.isNull(watchCourseVideo) && logCount > 0) {
+            return ResponseResult.fail(504, "超过项目看课数量限制");
+        }
+
         //添加判断:该用户是否已经存在此课程的看课记录,并且看课记录的销售id不是传入的销售id
         if(watchCourseVideo != null){
             if(!watchCourseVideo.getCompanyUserId().equals(param.getCompanyUserId())) {

+ 9 - 0
fs-service-system/src/main/resources/mapper/course/FsUserCourseMapper.xml

@@ -334,4 +334,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             and user_id = #{userId}
         </if>
     </select>
+
+    <select id="selectTodayCourseWatchLogCountByUserIdAndProjectId" resultType="java.lang.Integer">
+        select count(distinct cwl.video_id)
+        from fs_course_watch_log cwl
+        inner join fs_user_course_video ucv on ucv.video_id = cwl.video_id
+        inner join fs_user_course uc on uc.course_id = ucv.course_id
+        where cwl.user_id = #{userId} and uc.project = #{projectId}
+        and cwl.create_time between curdate() and date_add(curdate(), interval 1 day)
+    </select>
 </mapper>