Browse Source

fix(course):优化课程问题库批量更新逻辑并增强自由模式检查

- 重构 FsCourseQuestionBankMapper.xml 批量更新语句,提高执行效率和可读性
- 在 FsUserCourseVideoServiceImpl 中增加对自由模式的详细日志记录-
xw 3 ngày trước cách đây
mục cha
commit
f3fe47eda2

+ 29 - 3
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -1884,12 +1884,21 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
         if (!isUserCoursePeriodValid(param)) {
             return ResponseResult.fail(504, "请观看最新的课程项目");
         }
-        // 项目看课数限制
-        if(!"福本源".equals(signProjectName) && !"宽益堂".equals(signProjectName) && !CloudHostUtils.hasCloudHostName("弘德堂")) {
+        
+        // 检查是否为自由模式
+        FsUserCoursePeriod period = fsUserCoursePeriodMapper.selectFsUserCoursePeriodById(param.getPeriodId());
+        boolean isFreeMode = period != null && period.getFreeMode() != null && period.getFreeMode() == 1;
+        
+        // 项目看课数限制(自由模式下跳过此限制)
+        if(!isFreeMode && !"福本源".equals(signProjectName) && !"宽益堂".equals(signProjectName) && !CloudHostUtils.hasCloudHostName("弘德堂")) {
             Integer logCount = fsUserCourseMapper.selectTodayCourseWatchLogCountByUserIdAndProjectId(param.getUserId(), courseProject);
             if (Objects.isNull(watchCourseVideo) && logCount > 0) {
+                log.info("【自由模式检查】固定模式下超过项目看课数量限制,periodId={}, userId={}, logCount={}", 
+                        param.getPeriodId(), param.getUserId(), logCount);
                 return ResponseResult.fail(504, "超过项目看课数量限制");
             }
+        } else if(isFreeMode) {
+            log.info("【自由模式检查】✅ 自由模式,跳过项目看课数量限制检查,periodId={}", param.getPeriodId());
         }
 
         //添加判断:该用户是否已经存在此课程的看课记录,并且看课记录的销售id不是传入的销售id
@@ -1947,16 +1956,33 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
      * @return 如果当前时间在有效范围内且状态为1,返回true,否则返回false
      */
     public boolean isUserCoursePeriodValid(FsUserCourseAddCompanyUserParam param) {
+        log.info("【自由模式检查】开始验证课程权限,参数:periodId={}, videoId={}, courseId={}, companyUserId={}", 
+                param.getPeriodId(), param.getVideoId(), param.getCourseId(), param.getCompanyUserId());
+        
         // 查询课程周期信息
         FsUserCoursePeriodDays periodDays = getPeriodDaysInfo(param);
+        log.info("【自由模式检查】课程周期信息:periodDays={}, status={}, startTime={}, endTime={}", 
+                periodDays != null ? periodDays.getId() : null,
+                periodDays != null ? periodDays.getStatus() : null,
+                periodDays != null ? periodDays.getStartDateTime() : null,
+                periodDays != null ? periodDays.getEndDateTime() : null);
 
         // 检查是否开启自由模式
         FsUserCoursePeriod period = fsUserCoursePeriodMapper.selectFsUserCoursePeriodById(param.getPeriodId());
+        log.info("【自由模式检查】营期信息:periodId={}, periodName={}, freeMode={}, period对象={}", 
+                param.getPeriodId(),
+                period != null ? period.getPeriodName() : "NULL",
+                period != null ? period.getFreeMode() : "NULL",
+                period != null ? "存在" : "不存在");
+        
         if (period != null && period.getFreeMode() != null && period.getFreeMode() == 1) {
             // 自由模式:不检查时间和状态,直接返回有效
-            log.info("自由模式营期,跳过时间和状态检查,periodId={}", param.getPeriodId());
+            log.info("【自由模式检查】✅ 检测到自由模式,跳过时间和状态检查,periodId={}, periodName={}", 
+                    param.getPeriodId(), period.getPeriodName());
             return true;
         }
+        
+        log.info("【自由模式检查】固定模式,继续进行时间和状态检查...");
 
         // 固定模式:检查时间范围和状态
         // 获取公司用户时间段信息

+ 14 - 46
fs-service/src/main/resources/mapper/course/FsCourseQuestionBankMapper.xml

@@ -149,52 +149,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </select>
 
     <update id="updateFsCourseQuestionBankBatch">
-        update fs_course_question_bank
-        <trim prefix="SET" suffixOverrides=",">
-            <trim prefix="sort = CASE" suffix="END,">
-                <foreach collection="list" item="item">
-                    WHEN title = #{item.title} THEN #{item.sort}
-                </foreach>
-            </trim>
-            <trim prefix="type = CASE" suffix="END,">
-                <foreach collection="list" item="item">
-                    WHEN title = #{item.title} THEN #{item.type}
-                </foreach>
-            </trim>
-            <trim prefix="status = CASE" suffix="END,">
-                <foreach collection="list" item="item">
-                    WHEN title = #{item.title} THEN #{item.status}
-                </foreach>
-            </trim>
-            <trim prefix="question = CASE" suffix="END,">
-                <foreach collection="list" item="item">
-                    WHEN title = #{item.title} THEN #{item.question}
-                </foreach>
-            </trim>
-            <trim prefix="answer = CASE" suffix="END,">
-                <foreach collection="list" item="item">
-                    WHEN title = #{item.title} THEN #{item.answer}
-                </foreach>
-            </trim>
-            <trim prefix="create_by = CASE" suffix="END,">
-                <foreach collection="list" item="item">
-                    WHEN title = #{item.title} THEN #{item.createBy}
-                </foreach>
-            </trim>
-            <trim prefix="question_type = CASE" suffix="END,">
-                <foreach collection="list" item="item">
-                    WHEN title = #{item.title} THEN #{item.questionType}
-                </foreach>
-            </trim>
-            <trim prefix="question_sub_type = CASE" suffix="END,">
-                <foreach collection="list" item="item">
-                    WHEN title = #{item.title} THEN #{item.questionSubType}
-                </foreach>
-            </trim>
-        </trim>
-        WHERE title IN
-        <foreach collection="list" item="item" open="(" separator="," close=")">
-            #{item.title}
+        <foreach collection="list" item="item" separator=";">
+            update fs_course_question_bank
+            <set>
+                <if test="item.sort != null">sort = #{item.sort},</if>
+                <if test="item.type != null">type = #{item.type},</if>
+                <if test="item.status != null">status = #{item.status},</if>
+                <if test="item.question != null">question = #{item.question},</if>
+                <if test="item.answer != null">answer = #{item.answer},</if>
+                <if test="item.createBy != null">create_by = #{item.createBy},</if>
+                <if test="item.questionType != null">question_type = #{item.questionType},</if>
+                <if test="item.questionSubType != null">question_sub_type = #{item.questionSubType},</if>
+                <if test="item.userId != null">user_id = #{item.userId},</if>
+            </set>
+            where title = #{item.title}
         </foreach>
     </update>
 </mapper>