|
@@ -268,6 +268,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
|
|
.filter(courseSchedule -> Objects.nonNull(courseSchedule.getId()))
|
|
.filter(courseSchedule -> Objects.nonNull(courseSchedule.getId()))
|
|
.map(CourseSchedule::getId)
|
|
.map(CourseSchedule::getId)
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
+
|
|
//排除只需调整的课程
|
|
//排除只需调整的课程
|
|
existCourseSchedules=existCourseSchedules.stream()
|
|
existCourseSchedules=existCourseSchedules.stream()
|
|
.filter(courseSchedule -> !updateCourseScheduleIds.contains(courseSchedule.getId()))
|
|
.filter(courseSchedule -> !updateCourseScheduleIds.contains(courseSchedule.getId()))
|
|
@@ -280,7 +281,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
|
|
allCourseSchedules = courseSchedules;
|
|
allCourseSchedules = courseSchedules;
|
|
}
|
|
}
|
|
//所有课程的班级编号
|
|
//所有课程的班级编号
|
|
- List<Integer> classGroupIds = courseSchedules
|
|
|
|
|
|
+ List<Integer> classGroupIds = allCourseSchedules
|
|
.stream()
|
|
.stream()
|
|
.map(CourseSchedule::getClassGroupId)
|
|
.map(CourseSchedule::getClassGroupId)
|
|
.distinct()
|
|
.distinct()
|
|
@@ -291,58 +292,72 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
|
|
.stream()
|
|
.stream()
|
|
.collect(Collectors.groupingBy(ClassGroupStudentMapper::getClassGroupId));
|
|
.collect(Collectors.groupingBy(ClassGroupStudentMapper::getClassGroupId));
|
|
|
|
|
|
|
|
+
|
|
|
|
+ courseScheduleDao.findCourseScheduleIdAndUserIdsMap(new ArrayList<>());
|
|
|
|
+
|
|
//将课程计划按照开课时间排序
|
|
//将课程计划按照开课时间排序
|
|
allCourseSchedules.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
allCourseSchedules.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
if(allCourseSchedules.size()>1){
|
|
if(allCourseSchedules.size()>1){
|
|
- for (int i=0;i<allCourseSchedules.size()-1;i++){
|
|
|
|
- //当前课程
|
|
|
|
- CourseSchedule preCourseSchedule = allCourseSchedules.get(i);
|
|
|
|
- //后面一节课程
|
|
|
|
- CourseSchedule backCourseSchedule = allCourseSchedules.get(i+1);
|
|
|
|
- //判断存在时间重叠的课程
|
|
|
|
- if(backCourseSchedule.getStartClassTime().before(preCourseSchedule.getEndClassTime())){
|
|
|
|
- //提示信息
|
|
|
|
- StringBuffer errInfo = new StringBuffer("在");
|
|
|
|
- errInfo.append(DateUtil.dateToString(preCourseSchedule.getStartClassTime(),DateUtil.EXPANDED_DATE_TIME_FORMAT));
|
|
|
|
- errInfo.append("至");
|
|
|
|
- errInfo.append(DateUtil.dateToString(backCourseSchedule.getEndClassTime(),DateUtil.EXPANDED_DATE_TIME_FORMAT));
|
|
|
|
- errInfo.append("时间段内");
|
|
|
|
- //如果存在时间重叠,则需要判断前后两节课的教师和学生是否存在冲突
|
|
|
|
- //教师冲突检测
|
|
|
|
- if(Objects.nonNull(preCourseSchedule.getActualTeacherId())
|
|
|
|
- &&preCourseSchedule.getActualTeacherId().equals(backCourseSchedule.getActualTeacherId())){
|
|
|
|
- errInfo.append("安排的教师有课程冲突");
|
|
|
|
- throw new BizException(errInfo.toString());
|
|
|
|
- }
|
|
|
|
- //学生冲突检测
|
|
|
|
- if(preCourseSchedule.getClassGroupId().equals(backCourseSchedule.getClassGroupId())){
|
|
|
|
- //如果班级相同,则学生肯定存在冲突
|
|
|
|
- errInfo.append("安排的课程存在学生冲突");
|
|
|
|
- throw new BizException(errInfo.toString());
|
|
|
|
- }
|
|
|
|
- //如果班级不同,则需要检测两个班级是否存在重复的学生
|
|
|
|
- List<ClassGroupStudentMapper> preClassGroupStudents=classGroupStudentsMap.get(preCourseSchedule.getClassGroupId());
|
|
|
|
- List<ClassGroupStudentMapper> backClassGroupStudents=classGroupStudentsMap.get(backCourseSchedule.getClassGroupId());
|
|
|
|
- //如果有一个存在没有学生的班级则不存在冲突
|
|
|
|
- if(CollectionUtils.isEmpty(preClassGroupStudents)||CollectionUtils.isEmpty(backClassGroupStudents)){
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- //当前课程所在班级的学生编号列表
|
|
|
|
- List<Integer> preClassGroupStudentIds = preClassGroupStudents.stream()
|
|
|
|
- .map(ClassGroupStudentMapper::getUserId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- //后面一节课程所在班级的学生编号列表
|
|
|
|
- List<Integer> backClassGroupStudentIds = backClassGroupStudents.stream()
|
|
|
|
- .map(ClassGroupStudentMapper::getUserId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- List<Integer> repeatStudentIds = preClassGroupStudentIds.stream()
|
|
|
|
- .filter(backClassGroupStudentIds::contains)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- if(!CollectionUtils.isEmpty(repeatStudentIds)){
|
|
|
|
- errInfo.append("安排的课程存在学生冲突");
|
|
|
|
- throw new BizException(errInfo.toString());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ //记录连续冲突的次数
|
|
|
|
+ Integer repeatTimes=1;
|
|
|
|
+ for (int i=1;i<allCourseSchedules.size();i++){
|
|
|
|
+ for(int j=repeatTimes;j>0;j--){
|
|
|
|
+ //当前课程
|
|
|
|
+ CourseSchedule preCourseSchedule = allCourseSchedules.get(i-j);
|
|
|
|
+ //后面一节课程
|
|
|
|
+ CourseSchedule backCourseSchedule = allCourseSchedules.get(i);
|
|
|
|
+ //判断前后两届课是否存在冲突
|
|
|
|
+ if(backCourseSchedule.getStartClassTime().before(preCourseSchedule.getEndClassTime())){
|
|
|
|
+ //提示信息
|
|
|
|
+ StringBuffer errInfo = new StringBuffer("在");
|
|
|
|
+ errInfo.append(DateUtil.dateToString(preCourseSchedule.getStartClassTime(),DateUtil.EXPANDED_DATE_TIME_FORMAT));
|
|
|
|
+ errInfo.append("至");
|
|
|
|
+ errInfo.append(DateUtil.dateToString(backCourseSchedule.getEndClassTime(),DateUtil.EXPANDED_DATE_TIME_FORMAT));
|
|
|
|
+ errInfo.append("时间段内");
|
|
|
|
+ //如果存在时间重叠,则需要判断前后两节课的教师和学生是否存在冲突
|
|
|
|
+ //教师冲突检测
|
|
|
|
+ if(Objects.nonNull(preCourseSchedule.getActualTeacherId())
|
|
|
|
+ &&preCourseSchedule.getActualTeacherId().equals(backCourseSchedule.getActualTeacherId())){
|
|
|
|
+ errInfo.append("安排的教师有课程冲突");
|
|
|
|
+ throw new BizException(errInfo.toString());
|
|
|
|
+ }
|
|
|
|
+ //学生冲突检测
|
|
|
|
+ if(preCourseSchedule.getClassGroupId().equals(backCourseSchedule.getClassGroupId())){
|
|
|
|
+ //如果班级相同,则学生肯定存在冲突
|
|
|
|
+ errInfo.append("安排的课程存在学生冲突");
|
|
|
|
+ throw new BizException(errInfo.toString());
|
|
|
|
+ }
|
|
|
|
+ //如果班级不同,则需要检测两个班级是否存在重复的学生
|
|
|
|
+ List<ClassGroupStudentMapper> preClassGroupStudents=classGroupStudentsMap.get(preCourseSchedule.getClassGroupId());
|
|
|
|
+ List<ClassGroupStudentMapper> backClassGroupStudents=classGroupStudentsMap.get(backCourseSchedule.getClassGroupId());
|
|
|
|
+ //如果有一个存在没有学生的班级则不存在冲突
|
|
|
|
+ if(CollectionUtils.isEmpty(preClassGroupStudents)||CollectionUtils.isEmpty(backClassGroupStudents)){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //当前课程所在班级的学生编号列表
|
|
|
|
+ List<Integer> preClassGroupStudentIds = preClassGroupStudents.stream()
|
|
|
|
+ .map(ClassGroupStudentMapper::getUserId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ //后面一节课程所在班级的学生编号列表
|
|
|
|
+ List<Integer> backClassGroupStudentIds = backClassGroupStudents.stream()
|
|
|
|
+ .map(ClassGroupStudentMapper::getUserId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ List<Integer> repeatStudentIds = preClassGroupStudentIds.stream()
|
|
|
|
+ .filter(backClassGroupStudentIds::contains)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ if(!CollectionUtils.isEmpty(repeatStudentIds)){
|
|
|
|
+ errInfo.append("安排的课程存在学生冲突");
|
|
|
|
+ throw new BizException(errInfo.toString());
|
|
|
|
+ }
|
|
|
|
+ if(j==repeatTimes){
|
|
|
|
+ repeatTimes+=1;
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ if(j==repeatTimes){
|
|
|
|
+ repeatTimes=1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|