Sfoglia il codice sorgente

修复简答题答案被清空的bug

yangfeng 1 anno fa
parent
commit
2491982249

+ 13 - 11
web/src/main/java/com/ynfy/buss/exam/exam/service/impl/ExamServiceImpl.java

@@ -392,8 +392,12 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
     public void setAnswerTag(UserExamDTO userExamDTO) {
         List<UserExamQuestion> userExamQuestionList = userExamDTO.getUserExamQuestionList();
         if (!CollectionUtils.isEmpty(userExamQuestionList)) {
-            userExamQuestionList.stream().forEach(userExamQuestion -> userExamQuestion
-                    .setAnswer(generateQuestionAnswerTag(userExamQuestion.getAnswer(), userExamQuestion.getQuestion())));
+            userExamQuestionList.forEach(userExamQuestion -> {
+                if (QuestionType.RADIO.getCode().equals(userExamQuestion.getQuestionType()) || QuestionType.MULTI.getCode().equals(userExamQuestion.getQuestionType())
+                        || QuestionType.JUDGE.getCode().equals(userExamQuestion.getQuestionType())) {
+                    userExamQuestion.setAnswer(generateQuestionAnswerTag(userExamQuestion.getAnswer(), userExamQuestion.getQuestion()));
+                }
+            });
         }
     }
 
@@ -409,15 +413,13 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
         if (Objects.isNull(question)) {
             return null;
         }
-        if (QuestionType.RADIO.getCode().equals(question.getType()) || QuestionType.MULTI.getCode().equals(question.getType())
-                || QuestionType.JUDGE.getCode().equals(question.getType())) {
-            List<QuestionAnswer> answerList = question.getAnswerList();
-            if (StringUtils.isNotBlank(userAnswer) && !CollectionUtils.isEmpty(answerList)) {
-                List<String> answers = Arrays.asList(userAnswer.split(","));
-                List<QuestionAnswer> resultAnswerList = answerList.stream().filter(item -> answers.contains(item.getId())).collect(Collectors.toList());
-                List<String> tagList = resultAnswerList.stream().map(QuestionAnswer::getTag).collect(Collectors.toList());
-                return tagList.stream().sorted().collect(Collectors.joining(","));
-            }
+
+        List<QuestionAnswer> answerList = question.getAnswerList();
+        if (StringUtils.isNotBlank(userAnswer) && !CollectionUtils.isEmpty(answerList)) {
+            List<String> answers = Arrays.asList(userAnswer.split(","));
+            List<QuestionAnswer> resultAnswerList = answerList.stream().filter(item -> answers.contains(item.getId())).collect(Collectors.toList());
+            List<String> tagList = resultAnswerList.stream().map(QuestionAnswer::getTag).collect(Collectors.toList());
+            return tagList.stream().sorted().collect(Collectors.joining(","));
         }
         return null;
     }