|
|
@@ -1,13 +1,15 @@
|
|
|
package com.ruoyi.web.controller.dz;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import com.ruoyi.common.enums.BoolValues;
|
|
|
+import com.ruoyi.dz.domain.DzSchool;
|
|
|
+import com.ruoyi.dz.domain.DzClasses;
|
|
|
+import com.ruoyi.dz.mapper.DzClassesMapper;
|
|
|
+import com.ruoyi.dz.service.IDzSchoolService;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
@@ -39,6 +41,10 @@ public class DzTeacherClassController extends BaseController
|
|
|
{
|
|
|
@Autowired
|
|
|
private IDzTeacherClassService dzTeacherClassService;
|
|
|
+ @Autowired
|
|
|
+ private IDzSchoolService schoolService;
|
|
|
+ @Autowired
|
|
|
+ private DzClassesMapper dzClassesMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询教师班级关系列表
|
|
|
@@ -98,19 +104,75 @@ public class DzTeacherClassController extends BaseController
|
|
|
public AjaxResult batchBindTeacherClass(@RequestBody DzTeacherClass dzTeacherClass)
|
|
|
{
|
|
|
List<Long> insertClassIds = Arrays.stream(dzTeacherClass.getClassIds()).collect(Collectors.toList());
|
|
|
+ //区分班级是学校还是校区对应的班级
|
|
|
+ List<DzSchool> dzSchoolList = schoolService.getDzSchoolByClassIds(insertClassIds);
|
|
|
+ //关联校区
|
|
|
+ Boolean isBindSchool = false;
|
|
|
+ if (CollectionUtils.isNotEmpty(dzSchoolList)&&
|
|
|
+ null==dzSchoolList.get(0).getDeptId()||dzSchoolList.get(0).getDeptId()<=0){
|
|
|
+ isBindSchool = true;
|
|
|
+ }
|
|
|
|
|
|
DzTeacherClass cond = new DzTeacherClass().setTeacherId(dzTeacherClass.getTeacherId());
|
|
|
List<DzTeacherClass> alreadyList = dzTeacherClassService.selectDzTeacherClassList(cond);
|
|
|
List<Long> dbClassIds = alreadyList.stream().map(DzTeacherClass::getClassId).collect(Collectors.toList());
|
|
|
+ //需要将dbClassIds中与isBindSchool不相同的剔除
|
|
|
+ List<DzSchool> dzSchoolDbList = schoolService.getDzSchoolByClassIds(dbClassIds);
|
|
|
+ List<Long> schoolProcessList = new ArrayList<>();
|
|
|
+ for (DzSchool dzSchool : dzSchoolDbList) {
|
|
|
+ if (isBindSchool){
|
|
|
+ if (null==dzSchool.getDeptId()||dzSchool.getDeptId()<=0){
|
|
|
+ schoolProcessList.add(dzSchool.getId());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (null!=dzSchool.getDeptId()&&dzSchool.getDeptId()>0){
|
|
|
+ schoolProcessList.add(dzSchool.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建classId到schoolId的映射:通过查询classes表获取每个classId对应的schoolId
|
|
|
+ final Map<Long, Long> classIdToSchoolIdMap;
|
|
|
+ if (CollectionUtils.isNotEmpty(dbClassIds)) {
|
|
|
+ List<DzClasses> classesList = dzClassesMapper.selectClassesByIds(dbClassIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(classesList)) {
|
|
|
+ classIdToSchoolIdMap = classesList.stream()
|
|
|
+ .filter(clazz -> clazz.getClassId() != null && clazz.getSchoolId() != null)
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ DzClasses::getClassId,
|
|
|
+ DzClasses::getSchoolId,
|
|
|
+ (existing, replacement) -> existing
|
|
|
+ ));
|
|
|
+ } else {
|
|
|
+ classIdToSchoolIdMap = new HashMap<>();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ classIdToSchoolIdMap = new HashMap<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果schoolProcessList为空就过滤,否则将schoolId不在schoolProcessList内的过滤
|
|
|
+ if (CollectionUtils.isNotEmpty(schoolProcessList)) {
|
|
|
+ alreadyList = alreadyList.stream()
|
|
|
+ .filter(item -> {
|
|
|
+ Long schoolId = classIdToSchoolIdMap.get(item.getClassId());
|
|
|
+ return schoolId != null && schoolProcessList.contains(schoolId);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ } else {
|
|
|
+ // 如果schoolProcessList为空,过滤掉所有记录
|
|
|
+ alreadyList = new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ final List<Long> finalDbClassIds = alreadyList.stream().map(DzTeacherClass::getClassId).collect(Collectors.toList());
|
|
|
|
|
|
- // 2. 找出需要删除的班级ID(存在于dbClassIds但不存在于insertClassIds)
|
|
|
- List<Long> deleteClassIds = dbClassIds.stream()
|
|
|
+ // 2. 找出需要删除的班级ID(存在于finalDbClassIds但不存在于insertClassIds)
|
|
|
+ List<Long> deleteClassIds = finalDbClassIds.stream()
|
|
|
.filter(dbId -> !insertClassIds.contains(dbId))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- // 3. 找出需要新增的班级ID(存在于insertClassIds但不存在于dbClassIds)
|
|
|
+ // 3. 找出需要新增的班级ID(存在于insertClassIds但不存在于finalDbClassIds)
|
|
|
List<Long> newClassIds = insertClassIds.stream()
|
|
|
- .filter(insertId -> !dbClassIds.contains(insertId))
|
|
|
+ .filter(insertId -> !finalDbClassIds.contains(insertId))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
// 4. 执行删除操作
|
|
|
@@ -137,6 +199,7 @@ public class DzTeacherClassController extends BaseController
|
|
|
DzTeacherClass insert = new DzTeacherClass();
|
|
|
insert.setTeacherId(teacherId);
|
|
|
insert.setClassId(classId);
|
|
|
+ insert.setSchoolId(dzTeacherClass.getSchoolId());
|
|
|
insert.setStatus(BoolValues.yes.getValue()); // 设置有效状态
|
|
|
return insert;
|
|
|
})
|