From 24c9d860ced4d058b866a9fb548a8ef1d1412c20 Mon Sep 17 00:00:00 2001
From: 龚焕茏 <2842157468@qq.com>
Date: 星期一, 06 五月 2024 18:04:10 +0800
Subject: [PATCH] 新增标签菜单添加、查询、删除、修改,学生绑定、展示、修改

---
 src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java |   38 +++++++++++++++++++++++++++++---------
 1 files changed, 29 insertions(+), 9 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..3fb94ec 100644
--- a/src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java
+++ b/src/main/java/com/mindskip/xzs/controller/student/ExamPaperAnswerController.java
@@ -6,14 +6,14 @@
 import com.mindskip.xzs.domain.enums.ExamPaperAnswerStatusEnum;
 import com.mindskip.xzs.event.CalculateExamPaperAnswerCompleteEvent;
 import com.mindskip.xzs.event.UserEvent;
-import com.mindskip.xzs.service.ExamPaperAnswerService;
-import com.mindskip.xzs.service.ExamPaperService;
-import com.mindskip.xzs.service.SubjectService;
+import com.mindskip.xzs.service.*;
 import com.mindskip.xzs.utility.DateTimeUtil;
 import com.mindskip.xzs.utility.ExamUtil;
 import com.mindskip.xzs.utility.PageInfoHelper;
 import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperEditRequestVM;
+import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperEditRequestVO;
 import com.mindskip.xzs.viewmodel.student.exam.ExamPaperReadVM;
+import com.mindskip.xzs.viewmodel.student.exam.ExamPaperReadVO;
 import com.mindskip.xzs.viewmodel.student.exam.ExamPaperSubmitVM;
 import com.mindskip.xzs.viewmodel.student.exampaper.ExamPaperAnswerPageResponseVM;
 import com.mindskip.xzs.viewmodel.student.exampaper.ExamPaperAnswerPageVM;
@@ -24,6 +24,7 @@
 
 import javax.validation.Valid;
 import java.util.Date;
+import java.util.stream.Collectors;
 
 @RestController("StudentExamPaperAnswerController")
 @RequestMapping(value = "/api/student/exampaper/answer")
@@ -33,13 +34,17 @@
     private final ExamPaperService examPaperService;
     private final SubjectService subjectService;
     private final ApplicationEventPublisher eventPublisher;
+    private final ExamPaperSubjectService examPaperSubjectService;
+    private final ExamTemplatesUserCountService examTemplatesUserCountService;
 
     @Autowired
-    public ExamPaperAnswerController(ExamPaperAnswerService examPaperAnswerService, ExamPaperService examPaperService, SubjectService subjectService, ApplicationEventPublisher eventPublisher) {
+    public ExamPaperAnswerController(ExamPaperAnswerService examPaperAnswerService, ExamPaperService examPaperService, SubjectService subjectService, ApplicationEventPublisher eventPublisher, ExamPaperSubjectService examPaperSubjectService, ExamTemplatesUserCountService examTemplatesUserCountService) {
         this.examPaperAnswerService = examPaperAnswerService;
         this.examPaperService = examPaperService;
         this.subjectService = subjectService;
         this.eventPublisher = eventPublisher;
+        this.examPaperSubjectService = examPaperSubjectService;
+        this.examTemplatesUserCountService = examTemplatesUserCountService;
     }
 
 
@@ -49,12 +54,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 +91,14 @@
         userEventLog.setContent(content);
         eventPublisher.publishEvent(new CalculateExamPaperAnswerCompleteEvent(examPaperAnswerInfo));
         eventPublisher.publishEvent(new UserEvent(userEventLog));
+        //棣栭〉闅忔満璇曞嵎鎿嶄綔
+        if(examPaperSubmitVM.getTemplatesId() != null){
+            ExamTemplatesUserCount examTemplatesUserCount = new ExamTemplatesUserCount();
+            examTemplatesUserCount.setUserId(user.getId());
+            examTemplatesUserCount.setExamPaperId(examPaperSubmitVM.getId());
+            examTemplatesUserCount.setExamTemplatesId(examPaperSubmitVM.getTemplatesId());
+            examTemplatesUserCountService.add(examTemplatesUserCount);
+        }
         return RestResponse.ok(scoreVm);
     }
 
@@ -105,10 +125,10 @@
     }
 
     @RequestMapping(value = "/read/{id}", method = RequestMethod.POST)
-    public RestResponse<ExamPaperReadVM> read(@PathVariable Integer id) {
+    public RestResponse<ExamPaperReadVO> read(@PathVariable Integer id) {
         ExamPaperAnswer examPaperAnswer = examPaperAnswerService.selectById(id);
-        ExamPaperReadVM vm = new ExamPaperReadVM();
-        ExamPaperEditRequestVM paper = examPaperService.examPaperToVM(examPaperAnswer.getExamPaperId());
+        ExamPaperReadVO vm = new ExamPaperReadVO();
+        ExamPaperEditRequestVO paper = examPaperService.examPaperToVM(examPaperAnswer.getExamPaperId());
         ExamPaperSubmitVM answer = examPaperAnswerService.examPaperAnswerToVM(examPaperAnswer.getId());
         vm.setPaper(paper);
         vm.setAnswer(answer);

--
Gitblit v1.8.0