| | |
| | | package com.mindskip.xzs.controller.admin; |
| | | |
| | | |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.mindskip.xzs.base.BaseApiController; |
| | | 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.form.AddSubjectForm; |
| | | import com.mindskip.xzs.domain.form.EditSubjectForm; |
| | | import com.mindskip.xzs.domain.vo.CascaderDataVO; |
| | |
| | | import com.mindskip.xzs.domain.vo.SubjectDeptVO; |
| | | import com.mindskip.xzs.repository.DepartmentMapper; |
| | | import com.mindskip.xzs.repository.SubjectDeptMapper; |
| | | import com.mindskip.xzs.repository.SubjectMapper; |
| | | 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 com.mindskip.xzs.vo.SubjectVO; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.util.*; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController("AdminEducationController") |
| | |
| | | public class EducationController extends BaseApiController { |
| | | |
| | | private final SubjectService subjectService; |
| | | private final SubjectMapper subjectMapper; |
| | | private final SubjectDeptMapper subjectDeptMapper; |
| | | private final QuestionSubjectService questionSubjectService; |
| | | private final ExamPaperSubjectService examPaperSubjectService; |
| | |
| | | |
| | | @PostMapping("/subject/add") |
| | | public RestResponse<Object> add(@RequestBody @Validated AddSubjectForm form) { |
| | | subjectService.add(form); |
| | | return subjectService.add(form); |
| | | } |
| | | |
| | | @PostMapping("/subject/save") |
| | | public RestResponse<Object> save(@RequestBody @Validated Subject form) { |
| | | |
| | | form.setDeleted(Boolean.FALSE); |
| | | try { |
| | | subjectMapper.insert(form); |
| | | } catch (Exception e) { |
| | | return RestResponse.fail(500, "课目名不能重复"); |
| | | } |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | | @PostMapping("/subject/edit1") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public RestResponse<Object> edit1(@RequestBody Subject form) { |
| | | form.setDeleted(Boolean.FALSE); |
| | | |
| | | try { |
| | | subjectService.updateById(form); |
| | | } catch (Exception e) { |
| | | return RestResponse.fail(500, "课目名不能重复"); |
| | | } |
| | | return RestResponse.ok(); |
| | | } |
| | | |
| | | @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/page1", method = RequestMethod.POST) |
| | | public RestResponse<Object> page(@RequestBody SubjectPageRequestVM model) { |
| | | |
| | | PageInfo<SubjectVO> page = PageHelper.startPage(model.getPageIndex(), model.getPageSize(), "id desc").doSelectPageInfo(() -> |
| | | departmentMapper.page1(model)); |
| | | return RestResponse.ok(page); |
| | | } |
| | | |
| | | @RequestMapping(value = "/subject/page", method = RequestMethod.POST) |
| | |
| | | } |
| | | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequestMapping(value = "/subject/delete/{id}", method = RequestMethod.POST) |
| | | public RestResponse delete(@PathVariable Integer id) { |
| | | Subject subject = subjectService.selectById(id); |
| | | subject.setDeleted(true); |
| | | subjectService.updateByIdFilter(subject); |
| | | subjectService.deleteById(id); |
| | | questionSubjectService.removeSubjectId(id); |
| | | Integer[] ids = examPaperSubjectService.getBySubjectId(id) |
| | | .stream().map(ExamPaperSubject::getExamPaperId).toArray(Integer[]::new); |
| | | examPaperService.removeByIds(ids); |
| | | examPaperDepartmentService.removeByExamPaperIds(ids); |
| | | if (ids.length > 0) { |
| | | examPaperService.removeByIds(ids); |
| | | examPaperDepartmentService.removeByExamPaperIds(ids); |
| | | } |
| | | examPaperSubjectService.removeBySubjectId(id); |
| | | return RestResponse.ok(); |
| | | } |