|
@@ -187,35 +187,37 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
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());
|
|
|
+ List<FsCourseQuestionBank> questions = param.getQuestions();
|
|
|
+ if (questions != null && !questions.isEmpty()) {
|
|
|
+ Map<Long, FsCourseQuestionBank> correctAnswersMap = fsCourseQuestionBankMapper.selectFsCourseQuestionBankByIds(
|
|
|
+ questions.stream().map(FsCourseQuestionBank::getId).collect(Collectors.toList())
|
|
|
+ ).stream().collect(Collectors.toMap(FsCourseQuestionBank::getId, question -> question));
|
|
|
+
|
|
|
+ for (FsCourseQuestionBank questionBank : questions) {
|
|
|
+ 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);
|
|
|
+ Arrays.sort(userAnswers);
|
|
|
+ Arrays.sort(correctAnswers);
|
|
|
|
|
|
- if (Arrays.equals(userAnswers, correctAnswers)) {
|
|
|
- thisRightCount++;
|
|
|
- } else {
|
|
|
- correctAnswer.setAnswer(null);
|
|
|
- incorrectQuestions.add(correctAnswer);
|
|
|
+ if (Arrays.equals(userAnswers, correctAnswers)) {
|
|
|
+ thisRightCount++;
|
|
|
+ } else {
|
|
|
+ correctAnswer.setAnswer(null);
|
|
|
+ incorrectQuestions.add(correctAnswer);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
FsCourseAnswerLogs logs = new FsCourseAnswerLogs();
|
|
|
logs.setWatchLogId(logId);
|
|
|
logs.setUserId(param.getUserId());
|
|
@@ -224,11 +226,11 @@ public class FsCourseQuestionBankServiceImpl implements IFsCourseQuestionBankSer
|
|
|
logs.setCompanyId(param.getCompanyId());
|
|
|
logs.setCompanyUserId(param.getCompanyUserId());
|
|
|
logs.setQwUserId(param.getQwUserId() != null ? param.getQwUserId() : null );
|
|
|
- logs.setQuestionJson(JSONObject.toJSONString(param.getQuestions()));
|
|
|
+ logs.setQuestionJson(JSONObject.toJSONString(questions));
|
|
|
logs.setCreateTime(new Date());
|
|
|
logs.setPeriodId(param.getPeriodId());
|
|
|
|
|
|
- if (thisRightCount == param.getQuestions().size()) {
|
|
|
+ if (thisRightCount == questions.size()) {
|
|
|
logs.setIsRight(1);
|
|
|
courseAnswerLogsMapper.insertFsCourseAnswerLogs(logs);
|
|
|
return R.ok("答题成功");
|