From 983a2d36e9d3ca4ff2da89bbaca687fc55e92610 Mon Sep 17 00:00:00 2001
From: qirong <2032486488@qq.com>
Date: 星期二, 20 六月 2023 09:22:54 +0800
Subject: [PATCH] 随机试卷

---
 src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java b/src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java
index 52c3abc..9331d13 100644
--- a/src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java
+++ b/src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java
@@ -8,6 +8,7 @@
 import com.mindskip.xzs.event.UserEvent;
 import com.mindskip.xzs.service.ExamPaperAnswerService;
 import com.mindskip.xzs.service.ExamPaperService;
+import com.mindskip.xzs.service.ExamPaperSubjectService;
 import com.mindskip.xzs.service.SubjectService;
 import com.mindskip.xzs.utility.DateTimeUtil;
 import com.mindskip.xzs.utility.ExamUtil;
@@ -24,6 +25,7 @@
 
 import javax.validation.Valid;
 import java.util.Date;
+import java.util.stream.Collectors;
 
 @RestController("StudentExamPaperAnswerController")
 @RequestMapping(value = "/api/student/exampaper/answer")
@@ -33,13 +35,15 @@
     private final ExamPaperService examPaperService;
     private final SubjectService subjectService;
     private final ApplicationEventPublisher eventPublisher;
+    private final ExamPaperSubjectService examPaperSubjectService;
 
     @Autowired
-    public ExamPaperAnswerController(ExamPaperAnswerService examPaperAnswerService, ExamPaperService examPaperService, SubjectService subjectService, ApplicationEventPublisher eventPublisher) {
+    public ExamPaperAnswerController(ExamPaperAnswerService examPaperAnswerService, ExamPaperService examPaperService, SubjectService subjectService, ApplicationEventPublisher eventPublisher, ExamPaperSubjectService examPaperSubjectService) {
         this.examPaperAnswerService = examPaperAnswerService;
         this.examPaperService = examPaperService;
         this.subjectService = subjectService;
         this.eventPublisher = eventPublisher;
+        this.examPaperSubjectService = examPaperSubjectService;
     }
 
 
@@ -49,12 +53,19 @@
         PageInfo<ExamPaperAnswer> pageInfo = examPaperAnswerService.studentPage(model);
         PageInfo<ExamPaperAnswerPageResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> {
             ExamPaperAnswerPageResponseVM vm = modelMapper.map(e, ExamPaperAnswerPageResponseVM.class);
-            Subject subject = subjectService.selectById(vm.getSubjectId());
+            ExamPaperAnswer examPaperAnswer = examPaperAnswerService.getById(vm.getId());
+            Integer[] ids = examPaperSubjectService.getByExamPaperId(examPaperAnswer.getExamPaperId())
+                    .stream().map(ExamPaperSubject::getSubjectId).toArray(Integer[]::new);
+            String name = "";
+            if(ids.length>0){
+                name = subjectService.selectByIds(ids)
+                        .stream().map(Subject::getName).collect(Collectors.joining(","));
+            }
             vm.setDoTime(ExamUtil.secondToVM(e.getDoTime()));
             vm.setSystemScore(ExamUtil.scoreToVM(e.getSystemScore()));
             vm.setUserScore(ExamUtil.scoreToVM(e.getUserScore()));
             vm.setPaperScore(ExamUtil.scoreToVM(e.getPaperScore()));
-            vm.setSubjectName(subject.getName());
+            vm.setSubjectName(name);
             vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime()));
             return vm;
         });

--
Gitblit v1.8.0