| | |
| | | import com.mindskip.xzs.repository.SubjectMapper; |
| | | import com.mindskip.xzs.service.SubjectService; |
| | | import com.mindskip.xzs.viewmodel.admin.education.SubjectPageRequestVM; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | return subjectMapper.allSubject(deptIds, admin); |
| | | } |
| | | |
| | | public List<Subject> studentSubList() { |
| | | // 只查自己部门的课目 |
| | | List<Integer> deptIds = webContext.getAdminDeptIds(); |
| | | return subjectMapper.allSubject(deptIds, Boolean.FALSE); |
| | | } |
| | | |
| | | @Override |
| | | public Integer levelBySubjectId(Integer id) { |
| | | return this.selectById(id).getLevel(); |
| | |
| | | try { |
| | | subjectMapper.insert(subject); |
| | | } catch (Exception e) { |
| | | return RestResponse.fail(500, "科目名不能重复"); |
| | | return RestResponse.fail(500, "课目名不能重复"); |
| | | } |
| | | |
| | | SubjectDept subjectDept = new SubjectDept(); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void edit(EditSubjectForm form) { |
| | | // 删除原先的课目,再新增 |
| | | subjectDeptMapper.deleteByDeptId(form.getDeptId()); |
| | | List<SubjectDept> toAddList = form.getSubjectIds().stream().map(subjectId -> { |
| | | SubjectDept subjectDept = new SubjectDept(); |
| | | subjectDept.setDeptId(form.getDeptId()); |
| | | subjectDept.setSubjectId(subjectId); |
| | | return subjectDept; |
| | | }).collect(Collectors.toList()); |
| | | subjectDeptMapper.add(toAddList); |
| | | if (ObjectUtils.isNotEmpty(form.getDeptId())) { |
| | | // 删除原先的课目,再新增 |
| | | subjectDeptMapper.deleteByDeptId(form.getDeptId()); |
| | | List<SubjectDept> toAddList = form.getSubjectIds().stream().map(subjectId -> { |
| | | SubjectDept subjectDept = new SubjectDept(); |
| | | subjectDept.setDeptId(form.getDeptId()); |
| | | subjectDept.setSubjectId(subjectId); |
| | | return subjectDept; |
| | | }).collect(Collectors.toList()); |
| | | if (ObjectUtils.isNotEmpty(toAddList)) { |
| | | subjectDeptMapper.add(toAddList); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 检查名称是否存在 |
| | | * |
| | | * @param id |
| | | * @param name |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Boolean selectByName(Integer id, String name) { |
| | | Subject subject = subjectMapper.selectByName(id,name); |
| | | return Objects.nonNull(subject); |
| | | } |
| | | } |