Browse Source

填空题答案去除前后空格

yangfeng 1 năm trước cách đây
mục cha
commit
2653115a21

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

@@ -1064,14 +1064,14 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
      * @param dtoList
      */
     public void compareByOrder(List<QuestionAnswer> answerList, QuestionAnswer userAnswer, List<BlankAnswerResultDTO> dtoList) {
-        List<QuestionAnswer> list = answerList.stream().filter(a -> a.getTag().equals(userAnswer.getTag())).collect(toList());
-        if (!CollectionUtils.isEmpty(list)) {
-            QuestionAnswer tmp = list.get(0);
-            String[] answerArray = tmp.getContent().split("\\|\\|");
+        QuestionAnswer qa = answerList.stream().filter(a -> a.getTag().equals(userAnswer.getTag())).findFirst().orElse(null);
+        if (!Objects.isNull(qa)) {
+            String[] answerArray = qa.getContent().trim().split("\\|\\|");
             if (!Objects.isNull(answerArray) && answerArray.length > 0) {
                 List<String> asList = Arrays.asList(answerArray);
                 if (asList.contains(userAnswer.getContent().trim())) {
-                    dtoList.add(new BlankAnswerResultDTO(userAnswer.getTag(), userAnswer.getContent().trim(), true, !Objects.isNull(tmp.getPathScore()) ? tmp.getPathScore().doubleValue() : null));
+                    dtoList.add(new BlankAnswerResultDTO(userAnswer.getTag(), userAnswer.getContent().trim(), true,
+                            !Objects.isNull(qa.getPathScore()) ? qa.getPathScore().doubleValue() : null));
                 } else {
                     dtoList.add(new BlankAnswerResultDTO(userAnswer.getTag(), userAnswer.getContent().trim(), false, null));
                 }
@@ -1091,7 +1091,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamMapper, Exam> implements IE
         Iterator<QuestionAnswer> iterator = answerList.iterator();
         while (iterator.hasNext()) {
             QuestionAnswer qa = iterator.next();
-            String[] answerArray = qa.getContent().split("\\|\\|");
+            String[] answerArray = qa.getContent().trim().split("\\|\\|");
             if (!Objects.isNull(answerArray) && answerArray.length > 0) {
                 List<String> asList = Arrays.asList(answerArray);
                 if (asList.contains(userAnswer.getContent().trim())) {