From fbdd6af3039a83cd4727a03cecb7c5914277371f Mon Sep 17 00:00:00 2001 From: qirong <2032486488@qq.com> Date: 星期五, 28 七月 2023 14:44:08 +0800 Subject: [PATCH] 个人练习模板功能 --- src/main/java/com/mindskip/xzs/controller/admin/ExamPaperController.java | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mindskip/xzs/controller/admin/ExamPaperController.java b/src/main/java/com/mindskip/xzs/controller/admin/ExamPaperController.java index 14173e7..0f7dfc1 100644 --- a/src/main/java/com/mindskip/xzs/controller/admin/ExamPaperController.java +++ b/src/main/java/com/mindskip/xzs/controller/admin/ExamPaperController.java @@ -3,7 +3,10 @@ import com.mindskip.xzs.base.BaseApiController; import com.mindskip.xzs.base.RestResponse; import com.mindskip.xzs.domain.ExamPaper; +import com.mindskip.xzs.domain.ExamPaperSubject; +import com.mindskip.xzs.service.ExamPaperDepartmentService; import com.mindskip.xzs.service.ExamPaperService; +import com.mindskip.xzs.service.ExamPaperSubjectService; import com.mindskip.xzs.utility.DateTimeUtil; import com.mindskip.xzs.utility.PageInfoHelper; import com.mindskip.xzs.viewmodel.admin.exam.ExamPaperPageRequestVM; @@ -20,18 +23,25 @@ public class ExamPaperController extends BaseApiController { private final ExamPaperService examPaperService; + private final ExamPaperSubjectService examPaperSubjectService; + private final ExamPaperDepartmentService examPaperDepartmentService; @Autowired - public ExamPaperController(ExamPaperService examPaperService) { + public ExamPaperController(ExamPaperService examPaperService, ExamPaperSubjectService examPaperSubjectService, ExamPaperDepartmentService examPaperDepartmentService) { this.examPaperService = examPaperService; + this.examPaperSubjectService = examPaperSubjectService; + this.examPaperDepartmentService = examPaperDepartmentService; } @RequestMapping(value = "/page", method = RequestMethod.POST) public RestResponse<PageInfo<ExamResponseVM>> pageList(@RequestBody ExamPaperPageRequestVM model) { + model.setType("0"); PageInfo<ExamPaper> pageInfo = examPaperService.page(model); PageInfo<ExamResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> { ExamResponseVM vm = modelMapper.map(e, ExamResponseVM.class); vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime())); + vm.setSubjectId(examPaperSubjectService.getByExamPaperId(vm.getId()) + .stream().map(ExamPaperSubject::getSubjectId).toArray(Integer[]::new)); return vm; }); return RestResponse.ok(page); @@ -45,6 +55,9 @@ PageInfo<ExamResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> { ExamResponseVM vm = modelMapper.map(e, ExamResponseVM.class); vm.setCreateTime(DateTimeUtil.dateFormat(e.getCreateTime())); + Integer[] ids = examPaperSubjectService.getByExamPaperId(vm.getId()) + .stream().map(ExamPaperSubject::getSubjectId).toArray(Integer[]::new); + vm.setSubjectId(ids); return vm; }); return RestResponse.ok(page); @@ -53,7 +66,7 @@ @RequestMapping(value = "/edit", method = RequestMethod.POST) - public RestResponse<ExamPaperEditRequestVM> edit(@RequestBody @Valid ExamPaperEditRequestVM model) { + public RestResponse<ExamPaperEditRequestVM> edit(@RequestBody @Valid ExamPaperEditRequestVM model) throws Exception { ExamPaper examPaper = examPaperService.savePaperFromVM(model, getCurrentUser()); ExamPaperEditRequestVM newVM = examPaperService.examPaperToVM(examPaper.getId()); return RestResponse.ok(newVM); @@ -70,6 +83,8 @@ ExamPaper examPaper = examPaperService.selectById(id); examPaper.setDeleted(true); examPaperService.updateByIdFilter(examPaper); + examPaperDepartmentService.removeByExamPaperId(id); + examPaperSubjectService.removeByExamPaperId(id); return RestResponse.ok(); } } -- Gitblit v1.8.0