| | |
| | | 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() { |
| | |
| | | return RestResponse.ok(subjects); |
| | | } |
| | | |
| | | @RequestMapping(value = "/subject/select/dept/{deptId}", method = RequestMethod.GET) |
| | | public RestResponse<List<Subject>> listByDeptId(@PathVariable("deptId") Integer deptId) { |
| | | List<Subject> subjects = subjectService.listByDeptId(deptId); |
| | | return RestResponse.ok(subjects); |
| | | } |
| | | |
| | | @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); |
| | |
| | | } 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(); |
| | | } |
| | | |
| | |
| | | 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); |
| | | } |
| | | |
| | | |
| | | @RequestMapping(value = "/subject/delete/{id}", method = RequestMethod.POST) |
| | | public RestResponse delete(@PathVariable Integer id) { |
| | | Subject subject = subjectService.selectById(id); |