qirong
2023-06-26 77be36cc9077b09186e69440f3204f9e623c335a
src/main/java/com/mindskip/xzs/controller/admin/ExamPaperController.java
@@ -4,6 +4,7 @@
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;
@@ -23,11 +24,13 @@
    private final ExamPaperService examPaperService;
    private final ExamPaperSubjectService examPaperSubjectService;
    private final ExamPaperDepartmentService examPaperDepartmentService;
    @Autowired
    public ExamPaperController(ExamPaperService examPaperService, ExamPaperSubjectService examPaperSubjectService) {
    public ExamPaperController(ExamPaperService examPaperService, ExamPaperSubjectService examPaperSubjectService, ExamPaperDepartmentService examPaperDepartmentService) {
        this.examPaperService = examPaperService;
        this.examPaperSubjectService = examPaperSubjectService;
        this.examPaperDepartmentService = examPaperDepartmentService;
    }
    @RequestMapping(value = "/page", method = RequestMethod.POST)
@@ -51,6 +54,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);
@@ -59,7 +65,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);
@@ -76,6 +82,8 @@
        ExamPaper examPaper = examPaperService.selectById(id);
        examPaper.setDeleted(true);
        examPaperService.updateByIdFilter(examPaper);
        examPaperDepartmentService.removeByExamPaperId(id);
        examPaperSubjectService.removeByExamPaperId(id);
        return RestResponse.ok();
    }
}