qirong
2023-07-28 fbdd6af3039a83cd4727a03cecb7c5914277371f
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,15 +24,18 @@
    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)
    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);
@@ -51,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);
@@ -59,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);
@@ -76,6 +83,8 @@
        ExamPaper examPaper = examPaperService.selectById(id);
        examPaper.setDeleted(true);
        examPaperService.updateByIdFilter(examPaper);
        examPaperDepartmentService.removeByExamPaperId(id);
        examPaperSubjectService.removeByExamPaperId(id);
        return RestResponse.ok();
    }
}