Procházet zdrojové kódy

修复getOnePaper返回时自动持久化的问题

4228306 před 5 roky
rodič
revize
5e07793be8

+ 14 - 3
src/main/java/com/yaoxiang/diagnosis/service/PaperService.java

@@ -98,7 +98,7 @@ public class PaperService {
     public Paper getOnePaper(Long id) {
         AuthUser user = SecurityUtil.getCurrentUser();
         boolean student = Constants.USER_TYPE_STUDENT.equals(user.getUser().getUserType());
-        Paper paper = paperRepo.getOne(id);
+        Paper paper = paperRepo.findById(id).orElse(null);
         if (paper == null || paper.getStatus() == Constants.NOTREADY) {
             return null;
         }
@@ -113,12 +113,23 @@ public class PaperService {
         Map<Long, List<QuestionOption>> group = options.stream().collect(Collectors.groupingBy(QuestionOption::getQid));
         for (Question question : questions) {
             List<QuestionOption> optionList = group.get(question.getId());
+            List<QuestionOption> os = new ArrayList<>();
             //学生要去掉答案
             if (student) {
                 question.setCorrectNum(0);
-                optionList.forEach(o -> o.setCorrect(null));
+                //避免自动持久化
+                for (QuestionOption o : optionList) {
+                    QuestionOption option = new QuestionOption();
+                    option.setId(o.getId());
+                    option.setContent(o.getContent());
+                    option.setOindex(o.getOindex());
+                    option.setQid(o.getQid());
+                    os.add(option);
+                }
+                question.setOptions(os);
+            } else {
+                question.setOptions(optionList);
             }
-            question.setOptions(optionList);
         }
         return paper;
     }