|
@@ -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) {
|