zyp hace 5 días
padre
commit
f511529429

+ 3 - 0
fs-service/src/main/java/com/fs/course/mapper/FsCourseRedPacketLogMapper.java

@@ -157,4 +157,7 @@ public interface FsCourseRedPacketLogMapper
     @Select("SELECT company_id, SUM(amount) as money FROM fs_course_red_packet_log    WHERE status = 0 and create_time >= DATE_SUB(CURDATE(), INTERVAL 2 DAY)  AND create_time < DATE_SUB(CURDATE(), INTERVAL 1 DAY) GROUP BY company_id  ")
     List<RedPacketMoneyVO> selectFsCourseAddRedPacketLogByCompany();
 
+    @Select("select * from fs_course_red_packet_log where video_id = #{videoId} and user_id = #{userId} and period_id = #{periodId} limit 1")
+    FsCourseRedPacketLog selectUserFsCourseRedPacketLog(@Param("videoId") Long videoId, @Param("userId")Long userId, @Param("periodId")Long periodId);
+
 }

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

@@ -88,4 +88,6 @@ public interface IFsCourseQuestionBankService
      * @return  list
      */
     List<FsCourseQuestionBankImportDTO> exportData(FsCourseQuestionBank fsCourseQuestionBank);
+
+    R courseAnswerByFsUser(FsCourseQuestionAnswerUParam param);
 }

+ 109 - 4
fs-service/src/main/java/com/fs/course/service/impl/FsCourseQuestionBankServiceImpl.java

@@ -9,14 +9,12 @@ import com.fs.common.exception.ServiceException;
 import com.fs.common.utils.DateUtils;
 import com.fs.common.utils.StringUtils;
 import com.fs.course.config.CourseConfig;
-import com.fs.course.domain.FsCourseAnswerLogs;
-import com.fs.course.domain.FsCourseQuestionBank;
-import com.fs.course.domain.FsCourseWatchLog;
-import com.fs.course.domain.FsUserCourseCategory;
+import com.fs.course.domain.*;
 import com.fs.course.dto.FsCourseQuestionBankImportDTO;
 import com.fs.course.mapper.*;
 import com.fs.course.param.FsCourseQuestionAnswerUParam;
 import com.fs.course.service.IFsCourseQuestionBankService;
+import com.fs.his.domain.FsUser;
 import com.fs.his.mapper.FsUserMapper;
 import com.fs.his.service.IFsStorePaymentService;
 import com.fs.system.service.ISysConfigService;
@@ -134,6 +132,113 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
         return fsCourseQuestionBankMapper.deleteFsCourseQuestionBankById(id);
     }
 
+    @Override
+    public R courseAnswerByFsUser(FsCourseQuestionAnswerUParam param) {
+        FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
+        if (user==null){
+            return R.error("未识别到领取信息");
+        }
+        //获取配置参数
+        String json = configService.selectConfigByKey("course.config");
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+
+        //本次答题正确个数
+        int thisRightCount = 0;
+        //用户答错次数
+        int errorCount = 0;
+        List<FsCourseQuestionBank> incorrectQuestions = new ArrayList<>();
+        //日志id
+        Long logId = null;
+
+        new FsCourseAnswerLogs();
+        FsCourseAnswerLogs rightLog;
+        //判断短链类型
+
+        FsCourseWatchLog log = courseWatchLogMapper.getWatchLogByFsUser(param.getVideoId(), param.getUserId(), param.getCompanyUserId());
+        if (log==null){
+            return R.error("无记录");
+        }
+        if (log.getLogType()!=2){
+            return R.error("未完课");
+        }
+        logId = log.getLogId();
+
+        rightLog = courseAnswerLogsMapper.selectRightLogByCourseVideo(param.getVideoId(), param.getUserId(), param.getQwUserId());
+        if (rightLog != null) {
+            if (log.getRewardType() != null) {
+                // 增加判断,去查询红包记录是否已发送成功,如果成功,则返回当前提示,否则返回答题成功(让其可以继续答题,直到红包领取完成)
+                FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+                if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
+                    return R.error("该课程已答题完成,不可重复答题");
+                } else {
+                    return R.ok("答题成功");
+                }
+            } else {
+                return R.ok("答题成功");
+            }
+        }
+        errorCount = courseAnswerLogsMapper.selectErrorCountByCourseVideo(param.getVideoId(), param.getUserId(),param.getQwUserId());
+
+
+
+        if (errorCount >= config.getAnswerErrorCount()) {
+            return R.error("该课题到达答错次数限制");
+        }
+        int remainCount = config.getAnswerErrorCount()-errorCount-1;
+
+        // 一次性获取所有问题的正确答案
+        Map<Long, FsCourseQuestionBank> correctAnswersMap = fsCourseQuestionBankMapper.selectFsCourseQuestionBankByIds(
+                param.getQuestions().stream().map(FsCourseQuestionBank::getId).collect(Collectors.toList())
+        ).stream().collect(Collectors.toMap(FsCourseQuestionBank::getId, question -> question));
+
+        for (FsCourseQuestionBank questionBank : param.getQuestions()) {
+            FsCourseQuestionBank correctAnswer = correctAnswersMap.get(questionBank.getId());
+            if (correctAnswer.getType() == 1) {
+                if (questionBank.getAnswer().equals(correctAnswer.getAnswer())) {
+                    thisRightCount++;
+                } else {
+                    correctAnswer.setAnswer(null);
+                    incorrectQuestions.add(correctAnswer);
+                }
+            } else if (correctAnswer.getType() == 2) {
+                String[] userAnswers = convertStringToArray(questionBank.getAnswer());
+                String[] correctAnswers = convertStringToArray(correctAnswer.getAnswer());
+
+                Arrays.sort(userAnswers);
+                Arrays.sort(correctAnswers);
+
+                if (Arrays.equals(userAnswers, correctAnswers)) {
+                    thisRightCount++;
+                } else {
+                    correctAnswer.setAnswer(null);
+                    incorrectQuestions.add(correctAnswer);
+                }
+            }
+        }
+
+        FsCourseAnswerLogs logs = new FsCourseAnswerLogs();
+        logs.setWatchLogId(logId);
+        logs.setUserId(param.getUserId());
+        logs.setVideoId(param.getVideoId());
+        logs.setCourseId(param.getCourseId());
+        logs.setCompanyId(param.getCompanyId());
+        logs.setCompanyUserId(param.getCompanyUserId());
+        logs.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null );
+        logs.setQuestionJson(JSONObject.toJSONString(param.getQuestions()));
+        logs.setCreateTime(new Date());
+        logs.setPeriodId(param.getPeriodId());
+
+        if (thisRightCount == param.getQuestions().size()) {
+            logs.setIsRight(1);
+            courseAnswerLogsMapper.insertFsCourseAnswerLogs(logs);
+            return R.ok("答题成功");
+        } else {
+            logs.setIsRight(0);
+            courseAnswerLogsMapper.insertFsCourseAnswerLogs(logs);
+            return R.ok("答题失败").put("incorrectQuestions", incorrectQuestions).put("remain",remainCount);
+        }
+    }
+
     @Override
     @Transactional
     public R courseAnswer(FsCourseQuestionAnswerUParam param,Boolean isH5User) {

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

@@ -506,7 +506,6 @@ public class FsUserCourseServiceImpl implements IFsUserCourseService
         String courseJson = JSON.toJSONString(courseMap);
         link.setRealLink(realLink + courseJson);
 
-        link.setLink(random);
         link.setCreateTime(new Date());
 
         //获取过期时间

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

@@ -879,7 +879,18 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
             return R.error("无记录");
         }
         if (log.getRewardType() != null) {
-            return R.error("奖励已发放");
+            FsCourseRedPacketLog fsCourseRedPacketLog = redPacketLogMapper.selectUserFsCourseRedPacketLog(param.getVideoId(), param.getUserId(),param.getPeriodId());
+            if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 1) {
+                return R.error("奖励已发放");
+            }
+            if(fsCourseRedPacketLog != null && fsCourseRedPacketLog.getStatus() == 0) {
+                if(StringUtils.isNotEmpty(fsCourseRedPacketLog.getResult())){
+                    R r = JSON.parseObject(fsCourseRedPacketLog.getResult(), R.class);
+                    return r;
+                } else {
+                    return R.error();
+                }
+            }
         }
 
 

+ 1 - 1
fs-user-app/src/main/java/com/fs/app/controller/CourseWxH5Controller.java

@@ -109,7 +109,7 @@ public class CourseWxH5Controller extends AppBaseController {
         if (param.getDuration()==null){
             logger.info("zyp \n【未识别到时长】:{}",param.getUserId());
         }
-        return questionBankService.courseAnswer(param, true);
+        return questionBankService.courseAnswerByFsUser(param);
     }
 
     @ApiOperation("发放奖励")