|  | @@ -17,6 +17,7 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext.MessageSender;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.collection.MapUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import org.apache.commons.collections.ListUtils;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
	
		
			
				|  | @@ -126,7 +127,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  		if(Objects.isNull(courseSchedules)&&courseSchedules.size()<=0){
 | 
	
		
			
				|  |  |  			throw new BizException("参数错误!");
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -		checkCourseSchedule(courseSchedules);
 | 
	
		
			
				|  |  | +		checkNewCourseSchedules(courseSchedules);
 | 
	
		
			
				|  |  |          createCourseScheduleName(courseSchedules);
 | 
	
		
			
				|  |  |  		courseScheduleDao.batchAddCourseSchedules(courseSchedules);
 | 
	
		
			
				|  |  |  	}
 | 
	
	
		
			
				|  | @@ -250,6 +251,104 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  		return teacherCourseSchedulesWithDate;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public void checkNewCourseSchedules(List<CourseSchedule> courseSchedules){
 | 
	
		
			
				|  |  | +		//第一节课
 | 
	
		
			
				|  |  | +		CourseSchedule firstCourseSchedule = courseSchedules.stream().min(Comparator.comparing(CourseSchedule::getStartClassTime)).get();
 | 
	
		
			
				|  |  | +		//最后一节课
 | 
	
		
			
				|  |  | +		CourseSchedule latestCourseSchedule = courseSchedules.stream().max(Comparator.comparing(CourseSchedule::getStartClassTime)).get();
 | 
	
		
			
				|  |  | +		//获取第一节课和最后一节课所包含的时间段内已存在的课程
 | 
	
		
			
				|  |  | +		List<CourseSchedule> existCourseSchedules = courseScheduleDao.findByDateZone(firstCourseSchedule.getStartClassTime(), latestCourseSchedule.getEndClassTime());
 | 
	
		
			
				|  |  | +		//只需要调整课程信息的课程编号列表
 | 
	
		
			
				|  |  | +		List<Long> updateCourseScheduleIds = courseSchedules
 | 
	
		
			
				|  |  | +				.stream()
 | 
	
		
			
				|  |  | +				.filter(courseSchedule -> Objects.nonNull(courseSchedule.getId()))
 | 
	
		
			
				|  |  | +				.map(CourseSchedule::getId)
 | 
	
		
			
				|  |  | +				.collect(Collectors.toList());
 | 
	
		
			
				|  |  | +		//排除只需调整的课程
 | 
	
		
			
				|  |  | +		existCourseSchedules=existCourseSchedules.stream()
 | 
	
		
			
				|  |  | +				.filter(courseSchedule -> !updateCourseScheduleIds.contains(courseSchedule.getId()))
 | 
	
		
			
				|  |  | +				.collect(Collectors.toList());
 | 
	
		
			
				|  |  | +		//合并新课程和已存在的课程
 | 
	
		
			
				|  |  | +		List<CourseSchedule> allCourseSchedules;
 | 
	
		
			
				|  |  | +		if(!CollectionUtils.isEmpty(existCourseSchedules)){
 | 
	
		
			
				|  |  | +			allCourseSchedules = ListUtils.sum(courseSchedules, existCourseSchedules);
 | 
	
		
			
				|  |  | +		}else{
 | 
	
		
			
				|  |  | +			allCourseSchedules = courseSchedules;
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		//所有课程的班级编号
 | 
	
		
			
				|  |  | +		List<Integer> classGroupIds = courseSchedules
 | 
	
		
			
				|  |  | +				.stream()
 | 
	
		
			
				|  |  | +				.map(CourseSchedule::getClassGroupId)
 | 
	
		
			
				|  |  | +				.distinct()
 | 
	
		
			
				|  |  | +				.collect(Collectors.toList());
 | 
	
		
			
				|  |  | +		//班级与学生的关联记录
 | 
	
		
			
				|  |  | +		List<ClassGroupStudentMapper> classGroupStudentMappers = classGroupStudentMapperDao.findByClassGroups(classGroupIds);
 | 
	
		
			
				|  |  | +		Map<Integer, List<ClassGroupStudentMapper>> classGroupStudentsMap = classGroupStudentMappers
 | 
	
		
			
				|  |  | +				.stream()
 | 
	
		
			
				|  |  | +				.collect(Collectors.groupingBy(ClassGroupStudentMapper::getClassGroupId));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		//将课程计划按照开课时间排序
 | 
	
		
			
				|  |  | +		allCourseSchedules.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
 | 
	
		
			
				|  |  | +		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.ISO_EXPANDED_DATE_TIME_FORMAT));
 | 
	
		
			
				|  |  | +					errInfo.append("至");
 | 
	
		
			
				|  |  | +					errInfo.append(DateUtil.dateToString(backCourseSchedule.getEndClassTime(),DateUtil.ISO_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());
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  | +	public void checkOldCourseSchedules(List<CourseSchedule> courseSchedules) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  	/**
 | 
	
		
			
				|  |  |  	 * 判断课程安排中是否存在冲突
 | 
	
		
			
				|  |  |  	 * 计算课程课次
 | 
	
	
		
			
				|  | @@ -720,11 +819,6 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  			String classNamesStr=StringUtils.join(classGroupNamesByClassGroups,",");
 | 
	
		
			
				|  |  |  			throw new BizException(classNamesStr+"班级未排课");
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | -//		for (Integer key:classCourseNumMap.keySet()){
 | 
	
		
			
				|  |  | -//			if(classCourseNumMap.get(key)<=0){
 | 
	
		
			
				|  |  | -//				throw new BizException("存在未排课的班级");
 | 
	
		
			
				|  |  | -//			}
 | 
	
		
			
				|  |  | -//		}
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 |