Parcourir la source

设置题目的答案

yangfeng il y a 1 an
Parent
commit
9483c6ccb9

+ 8 - 0
web/src/main/java/com/ynfy/buss/exam/question/service/IQuestionService.java

@@ -123,4 +123,12 @@ public interface IQuestionService extends IService<Question> {
 
     IPage<Question> listQuestionByPracticeMode(Integer pageNo, Integer pageSize,
                                                String repositoryId, Integer questionType, Integer mode);
+
+
+    /**
+     * 设置题目的答案
+     *
+     * @param questionList
+     */
+    void setQuestionAnswer(List<Question> questionList);
 }

+ 15 - 3
web/src/main/java/com/ynfy/buss/exam/question/service/impl/QuestionServiceImpl.java

@@ -584,14 +584,27 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                 pageList = page(page, queryWrapper);
                 break;
         }
-        List<String> questionIds = pageList.getRecords().stream().map(Question::getId).collect(Collectors.toList());
+
+        //设置题目的答案
+        setQuestionAnswer(pageList.getRecords());
+        return pageList;
+    }
+
+    /**
+     * 设置题目的答案
+     *
+     * @param questionList
+     */
+    @Override
+    public void setQuestionAnswer(List<Question> questionList) {
+        List<String> questionIds = questionList.stream().map(Question::getId).collect(Collectors.toList());
 
         //获取题目答案
         List<QuestionAnswer> answerList = questionAnswerService.listAnswerByQuestionIds(questionIds);
         if (!CollectionUtils.isEmpty(answerList)) {
             Map<String, List<QuestionAnswer>> answerMap = answerList.stream().collect(Collectors
                     .groupingBy(QuestionAnswer::getQuestionId, Collectors.toList()));
-            pageList.getRecords().forEach(item -> {
+            questionList.forEach(item -> {
                 List<QuestionAnswer> answers = answerMap.get(item.getId());
                 if (!CollectionUtils.isEmpty(answers)) {
                     //答案排序
@@ -599,6 +612,5 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
                 }
             });
         }
-        return pageList;
     }
 }