From b0b59f3d9ee0340268e74e1e7a810e9087372160 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期一, 27 五月 2024 15:19:06 +0800 Subject: [PATCH] 课目关联部门 --- src/main/java/com/mindskip/xzs/controller/admin/EducationController.java | 41 ++++++++++++++++++++++++++++++++--------- 1 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/mindskip/xzs/controller/admin/EducationController.java b/src/main/java/com/mindskip/xzs/controller/admin/EducationController.java index d44d44b..a6b772d 100644 --- a/src/main/java/com/mindskip/xzs/controller/admin/EducationController.java +++ b/src/main/java/com/mindskip/xzs/controller/admin/EducationController.java @@ -5,36 +5,37 @@ import com.mindskip.xzs.base.RestResponse; import com.mindskip.xzs.domain.ExamPaperSubject; import com.mindskip.xzs.domain.Subject; +import com.mindskip.xzs.domain.SubjectDept; +import com.mindskip.xzs.domain.vo.SubjectDeptVO; +import com.mindskip.xzs.repository.SubjectDeptMapper; import com.mindskip.xzs.service.*; import com.mindskip.xzs.utility.PageInfoHelper; import com.mindskip.xzs.viewmodel.admin.education.SubjectEditRequestVM; import com.mindskip.xzs.viewmodel.admin.education.SubjectPageRequestVM; import com.mindskip.xzs.viewmodel.admin.education.SubjectResponseVM; import com.github.pagehelper.PageInfo; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.List; +import java.util.stream.Collectors; @RestController("AdminEducationController") @RequestMapping(value = "/api/admin/education") +@RequiredArgsConstructor public class EducationController extends BaseApiController { private final SubjectService subjectService; + private final SubjectDeptMapper subjectDeptMapper; private final QuestionSubjectService questionSubjectService; private final ExamPaperSubjectService examPaperSubjectService; private final ExamPaperDepartmentService examPaperDepartmentService; private final ExamPaperService examPaperService; - @Autowired - public EducationController(SubjectService subjectService, QuestionSubjectService questionSubjectService, ExamPaperSubjectService examPaperSubjectService, ExamPaperDepartmentService examPaperDepartmentService, ExamPaperService examPaperService) { - this.subjectService = subjectService; - this.questionSubjectService = questionSubjectService; - this.examPaperSubjectService = examPaperSubjectService; - this.examPaperDepartmentService = examPaperDepartmentService; - this.examPaperService = examPaperService; - } @RequestMapping(value = "/subject/list", method = RequestMethod.POST) public RestResponse<List<Subject>> list() { @@ -45,10 +46,20 @@ @RequestMapping(value = "/subject/page", method = RequestMethod.POST) public RestResponse<PageInfo<SubjectResponseVM>> pageList(@RequestBody SubjectPageRequestVM model) { PageInfo<Subject> pageInfo = subjectService.page(model); - PageInfo<SubjectResponseVM> page = PageInfoHelper.copyMap(pageInfo, e -> modelMapper.map(e, SubjectResponseVM.class)); + PageInfo<SubjectResponseVM> page = PageInfoHelper.copyMap(pageInfo, item -> { + SubjectResponseVM vo = new SubjectResponseVM(); + BeanUtils.copyProperties(item, vo); + List<SubjectDeptVO> subjectDeptVOS = subjectDeptMapper.deptBySubjectId(item.getId()); + List<Integer> deptIds = subjectDeptVOS.stream().map(SubjectDeptVO::getDeptId).collect(Collectors.toList()); + String deptNames = subjectDeptVOS.stream().map(SubjectDeptVO::getDeptName).collect(Collectors.joining("銆�")); + vo.setDeptIds(deptIds); + vo.setDeptNames(deptNames); + return vo; + }); return RestResponse.ok(page); } + @Transactional(rollbackFor = Exception.class) @RequestMapping(value = "/subject/edit", method = RequestMethod.POST) public RestResponse edit(@RequestBody @Valid SubjectEditRequestVM model) { Subject subject = modelMapper.map(model, Subject.class); @@ -58,6 +69,15 @@ } else { subjectService.updateByIdFilter(subject); } + // 澶勭悊閮ㄩ棬 + subjectDeptMapper.removeBySubjectId(subject.getId()); + List<SubjectDept> subjectDeptList = model.getDeptIds().stream().map(deptId -> { + SubjectDept subjectDept = new SubjectDept(); + subjectDept.setSubjectId(subject.getId()); + subjectDept.setDeptId(deptId); + return subjectDept; + }).collect(Collectors.toList()); + subjectDeptMapper.add(subjectDeptList); return RestResponse.ok(); } @@ -65,6 +85,9 @@ public RestResponse<SubjectEditRequestVM> select(@PathVariable Integer id) { Subject subject = subjectService.selectById(id); SubjectEditRequestVM vm = modelMapper.map(subject, SubjectEditRequestVM.class); + List<SubjectDeptVO> subjectDeptVOS = subjectDeptMapper.deptBySubjectId(id); + List<Integer> deptIds = subjectDeptVOS.stream().map(SubjectDeptVO::getDeptId).collect(Collectors.toList()); + vm.setDeptIds(deptIds); return RestResponse.ok(vm); } -- Gitblit v1.8.0