zyp 1 месяц назад
Родитель
Сommit
0893eece53

+ 7 - 0
fs-service-system/src/main/java/com/fs/course/mapper/FsCourseAnswerLogsMapper.java

@@ -112,6 +112,13 @@ public interface FsCourseAnswerLogsMapper
     FsCourseAnswerLogs selectRightLogByCourseVideo(@Param("videoId") Long videoId,@Param("userId") Long userId,@Param("qwUserId") String qwUserId);
 
 
+    @Select({"<script> " +
+            "select * from fs_course_answer_logs where watch_log_id = #{watchLogId} and is_right = 1 " +
+            "limit 1 " +
+            "</script>"})
+    FsCourseAnswerLogs selectRightLogByCourseVideoByFsUser(Long watchLogId);
+
+
     @Select({"<script> " +
             "select count(0) from fs_course_answer_logs where video_id = #{videoId} and user_id = #{userId} and is_right = 0 " +
             "<if test = 'qwUserId !=null '> " +

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

@@ -312,4 +312,10 @@ public interface FsCourseWatchLogMapper extends BaseMapper<FsCourseWatchLog> {
     List<Long> selectFsCourseWatchLogByLastmonth();
 
     FsCourseWatchLog getWatchLogByFsUser(@Param("videoId") Long videoId, @Param("fsUserId") Long fsUserId);
+
+    @Select("select * from fs_course_watch_log " +
+            "where video_id = #{videoId} " +
+            "and company_user_id = #{companyUserId} " +
+            "and user_id = #{userId} and send_type = 1 ")
+    FsCourseWatchLog getWatchCourseVideoByFsUser(Long userId, Long videoId, Long companyUserId);
 }

+ 1 - 0
fs-service-system/src/main/java/com/fs/course/param/FsCourseSendRewardUParam.java

@@ -24,5 +24,6 @@ public class FsCourseSendRewardUParam implements Serializable
     private Long qwExternalId;
     private Integer source=1;//来源 1:h5  2:小程序
     private Integer isRoom;
+    private Integer sendType;
 
 }

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

@@ -62,5 +62,15 @@ public interface IFsCourseQuestionBankService
      */
     public int deleteFsCourseQuestionBankById(Long id);
 
+    /**
+     * 企微客户答题
+     */
     R courseAnswer(FsCourseQuestionAnswerUParam param);
+
+
+    /**
+     * 会员答题
+     */
+    R courseAnswerByfsUser(FsCourseQuestionAnswerUParam param);
+
 }

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

@@ -97,6 +97,8 @@ public interface IFsUserCourseVideoService
 
     R sendReward(FsCourseSendRewardUParam param);
 
+    R sendRewardByFsUser(FsCourseSendRewardUParam param);
+
     /**
      * 获取课程视频分页列表
      * @return FsUserCourseVideoPageListVO

+ 95 - 26
fs-service-system/src/main/java/com/fs/course/service/impl/FsCourseQuestionBankServiceImpl.java

@@ -161,32 +161,6 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
             }
             logId = log.getLogId();
 
-//            if (param.getDuration()==null){
-//                return R.error("请重新进入链接直接答题领奖");
-//            }
-//            //判断用户是否看到完课百分比
-//            FsUserCourseVideo video = courseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
-//            // 计算观看百分比,避免除以0
-//            long percentage = 0L;
-//            long watchPercentage = 0L;
-//            if (video.getDuration() != 0) {
-//                percentage = (param.getDuration() * 100 / video.getDuration());
-//                watchPercentage = (log.getDuration() * 100 / video.getDuration());
-//            }
-//
-//            if (percentage < config.getAnswerRate() && watchPercentage<config.getAnswerRate()){
-//                return R.error("请先观看完整课程再答题哦~");
-//            }
-//
-//
-
-//
-//
-//            log.setLogType(2);
-//            log.setFinishTime(new Date());
-//            courseWatchLogMapper.updateFsCourseWatchLog(log);
-
-
             rightLog = courseAnswerLogsMapper.selectRightLogByCourseVideo(param.getVideoId(), param.getUserId(), param.getQwUserId());
             if (rightLog != null) {
                 if (log.getRewardType() != null) {
@@ -257,6 +231,101 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
     }
 
 
+    @Override
+    @Transactional
+    public R courseAnswerByfsUser(FsCourseQuestionAnswerUParam param) {
+        FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
+        if (StringUtils.isEmpty(user.getMpOpenId())){
+            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<>();
+
+        //查询看课记录
+        FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByFsUser(param.getUserId(),param.getVideoId(),param.getCompanyUserId());
+
+        if (log==null){
+            return R.error("无记录");
+        }
+        if (log.getLogType()!=2){
+            return R.error("未完课");
+        }
+
+        FsCourseAnswerLogs rightLog = courseAnswerLogsMapper.selectRightLogByCourseVideoByFsUser(log.getLogId());
+        if (rightLog != null) {
+            if (log.getRewardType() != null) {
+                return R.error("该课程已答题完成,不可重复答题");
+            } 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(log.getLogId());
+        logs.setUserId(param.getUserId());
+        logs.setVideoId(param.getVideoId());
+        logs.setCourseId(param.getCourseId());
+        logs.setCompanyId(param.getCompanyId());
+        logs.setCompanyUserId(param.getCompanyUserId());
+        logs.setQuestionJson(JSONObject.toJSONString(param.getQuestions()));
+        logs.setCreateTime(new Date());
+
+        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);
+        }
+    }
+
+
     public static String[] convertStringToArray(String inputString) {
         String cleanString = inputString.replaceAll("[\\[\\]\"\\s]", "");
         return cleanString.split(",");

+ 35 - 0
fs-service-system/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -670,6 +670,41 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
         }
     }
 
+    @Override
+    public R sendRewardByFsUser(FsCourseSendRewardUParam param) {
+        FsUser user = fsUserMapper.selectFsUserByUserId(param.getUserId());
+        if (StringUtils.isEmpty(user.getMpOpenId())){
+            return R.error("未识别到领取信息");
+        }
+        FsCourseWatchLog log = courseWatchLogMapper.getWatchCourseVideoByFsUser(param.getUserId(), param.getVideoId(), param.getCompanyUserId());
+        if (log == null) {
+            return R.error("无记录");
+        }
+        if (log.getRewardType() != null) {
+            return R.error("奖励已发放");
+        }
+
+
+        // 获取视频信息
+        FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
+
+        // 获取配置信息
+        String json = configService.selectConfigByKey("course.config");
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+
+        // 根据奖励类型发放不同奖励
+        switch (config.getRewardType()) {
+            // 红包奖励
+            case 1:
+                return sendRedPacketReward(param, user, log, video, config);
+            // 积分奖励
+            case 2:
+                return sendIntegralReward(user, log, config);
+            default:
+                return R.error("参数错误!");
+        }
+    }
+
     /**
      * 发放红包奖励
      *

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

@@ -3,10 +3,13 @@ package com.fs.app.controller;
 
 import cn.hutool.json.JSONUtil;
 import com.fs.app.annotation.Login;
+import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.domain.ResponseResult;
 import com.fs.course.config.CourseConfig;
 import com.fs.course.domain.FsCourseWatchLog;
+import com.fs.course.param.FsCourseQuestionAnswerUParam;
+import com.fs.course.param.FsCourseSendRewardUParam;
 import com.fs.course.param.FsUserCourseVideoFinishUParam;
 import com.fs.course.param.newfs.FsUserCourseAddCompanyUserParam;
 import com.fs.course.param.newfs.FsUserCourseVideoLinkParam;
@@ -71,61 +74,53 @@ public class CourseWxH5Controller extends AppBaseController {
     }
 
 
-//    @ApiOperation("添加看课记录")
-//    @PostMapping("/addWatchLogByLink")
-//    public R addWatchLogByLink(@RequestBody FsUserCourseAddCompanyUserParam param)
-//    {
-//
-//       return null;
-//    }
-//
-//
-//
-//    @ApiOperation("获取真实链接")
-//    @GetMapping("/getRealLink")
-//    public R getRealLink(@RequestParam("sortLink")String link)
-//    {
-//        return courseLinkService.getRealLink(link);
-//    }
-//
-//
+    @ApiOperation("获取真实链接")
+    @GetMapping("/getRealLink")
+    public R getRealLink(@RequestParam("sortLink")String link)
+    {
+        return courseLinkService.getRealLink(link);
+    }
+
+
     @ApiOperation("更新看课时长")
     @PostMapping("/updateWatchDuration")
     public R updateWatchDuration(@RequestBody FsUserCourseVideoFinishUParam param)
     {
         return courseVideoService.updateWatchDuration(param);
     }
-//
-//
-//    @ApiOperation("获取缓冲流量")
-//    @PostMapping("/getInternetTraffic")
-//    public R getInternetTraffic(@RequestBody FsUserCourseVideoFinishUParam param) {
-//        return courseVideoService.getInternetTraffic(param);
-//    }
 
-//    @ApiOperation("答题")
-//    @PostMapping("/courseAnswer")
-//    public R courseAnswer(@RequestBody FsCourseQuestionAnswerUParam param)
-//    {
-//        logger.info("zyp \n【答题】:{}",param.getQuestions());
-//        if (param.getDuration()==null){
-//            logger.info("zyp \n【未识别到时长】:{}",param.getUserId());
-//        }
-//        return questionBankService.courseAnswer(param);
-//    }
 
-//    @ApiOperation("发放奖励")
-//    @PostMapping("/sendReward")
-//    @RepeatSubmit
-//    public R sendReward(@RequestBody FsCourseSendRewardUParam param)
-//    {
-//        logger.info("zyp \n【发放奖励】:{}",param);
-//        return courseVideoService.sendReward(param);
-//    }
-//
-//    @PostMapping("/getErrMsg")
-//    public void getErrMsg(@RequestParam("msg") String msg) {
-//        logger.error("zyp \n【h5看课中途报错】:{}",msg);
-//    }
+    @ApiOperation("获取缓冲流量")
+    @PostMapping("/getInternetTraffic")
+    public R getInternetTraffic(@RequestBody FsUserCourseVideoFinishUParam param) {
+        return courseVideoService.getInternetTraffic(param);
+    }
+
+
+    @ApiOperation("答题")
+    @PostMapping("/courseAnswer")
+    public R courseAnswer(@RequestBody FsCourseQuestionAnswerUParam param)
+    {
+        logger.info("zyp \n【答题】:{}",param.getQuestions());
+        if (param.getDuration()==null){
+            logger.info("zyp \n【未识别到时长】:{}",param.getUserId());
+        }
+        return questionBankService.courseAnswer(param);
+    }
+
+    @ApiOperation("发放奖励")
+    @PostMapping("/sendReward")
+    @RepeatSubmit
+    public R sendReward(@RequestBody FsCourseSendRewardUParam param)
+    {
+        logger.info("zyp \n【发放奖励】:{}",param);
+        return courseVideoService.sendRewardByFsUser(param);
+    }
+
+
+    @PostMapping("/getErrMsg")
+    public void getErrMsg(@RequestParam("msg") String msg) {
+        logger.error("zyp \n【h5看课中途报错】:{}",msg);
+    }
 
 }