|
@@ -6,6 +6,7 @@ import com.schoolinout.common.utils.DateUtils;
|
|
|
import com.schoolinout.common.utils.SecurityUtils;
|
|
|
import com.schoolinout.common.utils.bean.BeanUtils;
|
|
|
import com.schoolinout.system.domain.Clazz;
|
|
|
+import com.schoolinout.system.domain.TeacherClassRelation;
|
|
|
import com.schoolinout.system.domain.dto.AddClassDto;
|
|
|
import com.schoolinout.system.domain.dto.InsertTeacherClassRelationDto;
|
|
|
import com.schoolinout.system.domain.vo.OptionVo;
|
|
@@ -19,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.rmi.ServerException;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -29,6 +31,9 @@ import java.util.stream.Collectors;
|
|
|
*/
|
|
|
@Service
|
|
|
public class ClazzServiceImpl implements IClazzService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IClazzService curProxy;
|
|
|
@Autowired
|
|
|
private ClazzMapper clazzMapper;
|
|
|
@Autowired
|
|
@@ -76,15 +81,62 @@ public class ClazzServiceImpl implements IClazzService {
|
|
|
/**
|
|
|
* 修改班级管理
|
|
|
*
|
|
|
- * @param clazz 班级管理
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateClazz(Clazz clazz) {
|
|
|
- clazz.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
+ public int updateClazz(AddClassDto form) {
|
|
|
+ Long classId = form.getId();
|
|
|
+ List<Long> newTeacherIds = form.getTeacherIds();
|
|
|
+
|
|
|
+ // 处理班级与教师直接的关系
|
|
|
+ curProxy.handlerClassTeacherRelation(form, classId, newTeacherIds);
|
|
|
+
|
|
|
+ // 更新班级信息
|
|
|
+ Clazz clazz = new Clazz();
|
|
|
+ BeanUtils.copyBeanProp(clazz, form);
|
|
|
return clazzMapper.updateClazz(clazz);
|
|
|
}
|
|
|
|
|
|
+ @Transactional(rollbackFor = RuntimeException.class)
|
|
|
+ public void handlerClassTeacherRelation(AddClassDto form, Long classId, List<Long> newTeacherIds) {
|
|
|
+ // 先查询原班级关系数据
|
|
|
+ TeacherClassRelation queryRelation = new TeacherClassRelation();
|
|
|
+ queryRelation.setClassId(classId);
|
|
|
+ List<TeacherClassRelation> existingRelations = relationMapper.selectTeacherClassRelationList(queryRelation);
|
|
|
+
|
|
|
+ // 将现有关系映射为教师ID集合
|
|
|
+ Set<Long> existingTeacherIds = existingRelations.stream()
|
|
|
+ .map(TeacherClassRelation::getTeacherId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 如果新的教师列表为空,或者需要移除所有现有教师
|
|
|
+ if (newTeacherIds == null || newTeacherIds.isEmpty()) {
|
|
|
+ // 删除所有现有关系
|
|
|
+ relationMapper.deleteAllRelationsForClass(form.getSchoolId(), classId);
|
|
|
+ } else {
|
|
|
+ // 计算需要删除的教师ID
|
|
|
+ List<Long> teacherIdsToRemove = existingTeacherIds.stream()
|
|
|
+ .filter(teacherId -> !newTeacherIds.contains(teacherId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 计算需要添加的教师ID
|
|
|
+ List<Long> teacherIdsToAdd = newTeacherIds.stream()
|
|
|
+ .filter(teacherId -> !existingTeacherIds.contains(teacherId))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 执行批量删除
|
|
|
+ if (!teacherIdsToRemove.isEmpty()) {
|
|
|
+ relationMapper.deleteRelationBatch(form.getSchoolId(), classId, teacherIdsToRemove);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行批量插入
|
|
|
+ if (!teacherIdsToAdd.isEmpty()) {
|
|
|
+ relationMapper.insertRelationBatch(form.getSchoolId(), classId, teacherIdsToAdd);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 批量删除班级管理
|
|
|
*
|
|
@@ -128,7 +180,7 @@ public class ClazzServiceImpl implements IClazzService {
|
|
|
|
|
|
// step3:如果存在绑定老师,则新增关系的绑定
|
|
|
List<Long> teacherIds = form.getTeacherIds();
|
|
|
- if (!teacherIds.isEmpty()) {
|
|
|
+ if (teacherIds != null && !teacherIds.isEmpty()) {
|
|
|
// 插入数据
|
|
|
Clazz finalClazz = clazz;
|
|
|
List<InsertTeacherClassRelationDto> insertList = teacherIds.stream()
|
|
@@ -137,6 +189,6 @@ public class ClazzServiceImpl implements IClazzService {
|
|
|
return relationMapper.insertTeacherClassRelationBatch(insertList);
|
|
|
}
|
|
|
|
|
|
- return 0;
|
|
|
+ return 1;
|
|
|
}
|
|
|
}
|