|
@@ -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(",");
|