From f7a47d7de0eaab8c45877659642397fadd2a5dda Mon Sep 17 00:00:00 2001
From: 17808 <1780814303@qq.com>
Date: 星期四, 09 十一月 2023 10:44:44 +0800
Subject: [PATCH] 成绩统计后端

---
 src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java |   18 +++++++++++++++---
 1 files changed, 15 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..a8e582f 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;
         });
@@ -79,6 +90,7 @@
         userEventLog.setContent(content);
         eventPublisher.publishEvent(new CalculateExamPaperAnswerCompleteEvent(examPaperAnswerInfo));
         eventPublisher.publishEvent(new UserEvent(userEventLog));
+
         return RestResponse.ok(scoreVm);
     }
 

--
Gitblit v1.8.0