|  | @@ -524,8 +524,10 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  | +	@Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |  	public List<Long> checkSnapCourseShchedules(List<CourseSchedule> courseSchedules) {
 | 
	
		
			
				|  |  |  		List<Long> courseScheduleIds = new ArrayList<>();
 | 
	
		
			
				|  |  | +		List<CourseScheduleStudentDto> courseScheduleStudents =  new ArrayList<>();
 | 
	
		
			
				|  |  |  		if(CollectionUtils.isEmpty(courseSchedules)){
 | 
	
		
			
				|  |  |  			return courseScheduleIds;
 | 
	
		
			
				|  |  |  		}
 | 
	
	
		
			
				|  | @@ -555,6 +557,9 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  		existCourseSchedules=existCourseSchedules.stream()
 | 
	
		
			
				|  |  |  				.filter(courseSchedule -> !updateCourseScheduleIds.contains(courseSchedule.getId()))
 | 
	
		
			
				|  |  |  				.collect(Collectors.toList());
 | 
	
		
			
				|  |  | +		if(existCourseSchedules ==null || existCourseSchedules.size()==0){
 | 
	
		
			
				|  |  | +			return null;
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  |  		//新课程对应的班级编号列表
 | 
	
		
			
				|  |  |  		List<Integer> newCourseScheduleClassGroupIds = courseSchedules
 | 
	
		
			
				|  |  |  				.stream()
 | 
	
	
		
			
				|  | @@ -598,111 +603,89 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  		Map<Integer, IntegerAndIntegerListDto> classGroupTeachingTeacherMap = classGroupAndUserIdsMap.stream()
 | 
	
		
			
				|  |  |  				.collect(Collectors.toMap(IntegerAndIntegerListDto::getId, integerAndIntegerListDto -> integerAndIntegerListDto));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -		//将课程计划按照开课时间排序
 | 
	
		
			
				|  |  | -		allCourseSchedules.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
 | 
	
		
			
				|  |  | -		if(allCourseSchedules.size()>1){
 | 
	
		
			
				|  |  | -			//记录连续冲突的次数
 | 
	
		
			
				|  |  | -			Integer repeatTimes=1;
 | 
	
		
			
				|  |  | -			for (int i=1;i<allCourseSchedules.size();i++){
 | 
	
		
			
				|  |  | -				for(int j=1;j<=repeatTimes;j++){
 | 
	
		
			
				|  |  | -					//当前课程
 | 
	
		
			
				|  |  | -					CourseSchedule preCourseSchedule = allCourseSchedules.get(i-j);
 | 
	
		
			
				|  |  | -					//后面一节课程
 | 
	
		
			
				|  |  | -					CourseSchedule backCourseSchedule = allCourseSchedules.get(i);
 | 
	
		
			
				|  |  | -					//判断前后两节课是否存在冲突
 | 
	
		
			
				|  |  | -					if(preCourseSchedule.getEndClassTime().before(backCourseSchedule.getStartClassTime())){
 | 
	
		
			
				|  |  | -						repeatTimes=j;
 | 
	
		
			
				|  |  | -						continue;
 | 
	
		
			
				|  |  | -					}
 | 
	
		
			
				|  |  | -					repeatTimes+=1;
 | 
	
		
			
				|  |  | -					if(existCourseScheduleIds.contains(preCourseSchedule.getId())
 | 
	
		
			
				|  |  | -							&&existCourseScheduleIds.contains(backCourseSchedule.getId())){
 | 
	
		
			
				|  |  | -						if(j==repeatTimes){
 | 
	
		
			
				|  |  | -							repeatTimes+=1;
 | 
	
		
			
				|  |  | -						}
 | 
	
		
			
				|  |  | -						continue;
 | 
	
		
			
				|  |  | -					}
 | 
	
		
			
				|  |  | +		existCourseSchedules.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
 | 
	
		
			
				|  |  | +		courseSchedules.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -					//教师冲突检测
 | 
	
		
			
				|  |  | -					if(Objects.isNull(preCourseSchedule.getId())){
 | 
	
		
			
				|  |  | -						IntegerAndIntegerListDto integerAndIntegerListDto = classGroupTeachingTeacherMap.get(preCourseSchedule.getClassGroupId());
 | 
	
		
			
				|  |  | -						if(Objects.nonNull(integerAndIntegerListDto)){
 | 
	
		
			
				|  |  | -							preCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
 | 
	
		
			
				|  |  | -						}
 | 
	
		
			
				|  |  | -					}else if(existCourseScheduleIds.contains(preCourseSchedule.getId())){
 | 
	
		
			
				|  |  | -						IntegerAndIntegerListDto integerAndIntegerListDto = courseScheduleTeacherMap.get(preCourseSchedule.getId());
 | 
	
		
			
				|  |  | -						if(Objects.nonNull(integerAndIntegerListDto)){
 | 
	
		
			
				|  |  | -							preCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
 | 
	
		
			
				|  |  | -						}
 | 
	
		
			
				|  |  | -					}
 | 
	
		
			
				|  |  | -					if(Objects.isNull(backCourseSchedule.getId())){
 | 
	
		
			
				|  |  | -						IntegerAndIntegerListDto integerAndIntegerListDto = classGroupTeachingTeacherMap.get(backCourseSchedule.getClassGroupId());
 | 
	
		
			
				|  |  | -						if(Objects.nonNull(integerAndIntegerListDto)){
 | 
	
		
			
				|  |  | -							backCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
 | 
	
		
			
				|  |  | -						}
 | 
	
		
			
				|  |  | -					}else if(existCourseScheduleIds.contains(backCourseSchedule.getId())){
 | 
	
		
			
				|  |  | -						IntegerAndIntegerListDto integerAndIntegerListDto = courseScheduleTeacherMap.get(backCourseSchedule.getId());
 | 
	
		
			
				|  |  | -						if(Objects.nonNull(integerAndIntegerListDto)){
 | 
	
		
			
				|  |  | -							backCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
 | 
	
		
			
				|  |  | -						}
 | 
	
		
			
				|  |  | -					}
 | 
	
		
			
				|  |  | -					boolean isRepeat = false;
 | 
	
		
			
				|  |  | -					if(!CollectionUtils.isEmpty(preCourseSchedule.getTeachingTeacherIdList())
 | 
	
		
			
				|  |  | -							&&!CollectionUtils.isEmpty(backCourseSchedule.getTeachingTeacherIdList())){
 | 
	
		
			
				|  |  | -						List<Integer> repeatIds = preCourseSchedule.getTeachingTeacherIdList()
 | 
	
		
			
				|  |  | -								.stream().filter(backCourseSchedule.getTeachingTeacherIdList()::contains)
 | 
	
		
			
				|  |  | -								.collect(Collectors.toList());
 | 
	
		
			
				|  |  | -						if(!CollectionUtils.isEmpty(repeatIds)){
 | 
	
		
			
				|  |  | -							isRepeat = true;
 | 
	
		
			
				|  |  | -						}
 | 
	
		
			
				|  |  | -					}
 | 
	
		
			
				|  |  | -					//学生冲突检测
 | 
	
		
			
				|  |  | -					if(preCourseSchedule.getClassGroupId().equals(backCourseSchedule.getClassGroupId())){
 | 
	
		
			
				|  |  | -						//如果班级相同,则学生肯定存在冲突
 | 
	
		
			
				|  |  | -						isRepeat = true;
 | 
	
		
			
				|  |  | -					}
 | 
	
		
			
				|  |  | -					//如果班级不同,则需要检测两个班级是否存在重复的学生
 | 
	
		
			
				|  |  | -					List<ClassGroupStudentMapper> preClassGroupStudents=classGroupStudentsMap.get(preCourseSchedule.getClassGroupId());
 | 
	
		
			
				|  |  | -					List<ClassGroupStudentMapper> backClassGroupStudents=classGroupStudentsMap.get(backCourseSchedule.getClassGroupId());
 | 
	
		
			
				|  |  | -					//当前课程所在班级的学生编号列表
 | 
	
		
			
				|  |  | -					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)
 | 
	
		
			
				|  |  | +		newNode:
 | 
	
		
			
				|  |  | +		for (CourseSchedule newCourseSchedule : courseSchedules) {
 | 
	
		
			
				|  |  | +			exitNode:
 | 
	
		
			
				|  |  | +			for (CourseSchedule existCourseSchedule : existCourseSchedules) {
 | 
	
		
			
				|  |  | +				if(newCourseSchedule.getEndClassTime().before(existCourseSchedule.getStartClassTime())){
 | 
	
		
			
				|  |  | +					continue newNode;
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				if(existCourseSchedule.getEndClassTime().before(newCourseSchedule.getStartClassTime())){
 | 
	
		
			
				|  |  | +					continue exitNode;
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +				boolean isTeacherRepeat = false;
 | 
	
		
			
				|  |  | +				boolean isStudentRepeat = false;
 | 
	
		
			
				|  |  | +				//检测老师冲突
 | 
	
		
			
				|  |  | +				existCourseSchedule.setTeachingTeacherIdList(courseScheduleTeacherMap.get(existCourseSchedule.getId()).getIds());
 | 
	
		
			
				|  |  | +				newCourseSchedule.setTeachingTeacherIdList(classGroupTeachingTeacherMap.get(newCourseSchedule.getClassGroupId()).getIds());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +				if(!CollectionUtils.isEmpty(newCourseSchedule.getTeachingTeacherIdList())
 | 
	
		
			
				|  |  | +						&&!CollectionUtils.isEmpty(existCourseSchedule.getTeachingTeacherIdList())){
 | 
	
		
			
				|  |  | +					List<Integer> repeatIds = newCourseSchedule.getTeachingTeacherIdList()
 | 
	
		
			
				|  |  | +							.stream().filter(existCourseSchedule.getTeachingTeacherIdList()::contains)
 | 
	
		
			
				|  |  |  							.collect(Collectors.toList());
 | 
	
		
			
				|  |  | -					if(!CollectionUtils.isEmpty(repeatStudentIds)){
 | 
	
		
			
				|  |  | -						isRepeat = true;
 | 
	
		
			
				|  |  | +					if(!CollectionUtils.isEmpty(repeatIds)){
 | 
	
		
			
				|  |  | +						isTeacherRepeat = true;
 | 
	
		
			
				|  |  |  					}
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -					if(isRepeat){
 | 
	
		
			
				|  |  | -						if(preCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.SNAP.getCode())
 | 
	
		
			
				|  |  | -								&&backCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.SNAP.getCode())){
 | 
	
		
			
				|  |  | -							throw new BizException("教师冲突");
 | 
	
		
			
				|  |  | -						}else if(preCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.SNAP.getCode())
 | 
	
		
			
				|  |  | -								&&backCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.VIP.getCode())){
 | 
	
		
			
				|  |  | -							throw new BizException("教师冲突");
 | 
	
		
			
				|  |  | -						}else if(preCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.VIP.getCode())
 | 
	
		
			
				|  |  | -								&&backCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.SNAP.getCode())){
 | 
	
		
			
				|  |  | -							throw new BizException("教师冲突");
 | 
	
		
			
				|  |  | -						}else{
 | 
	
		
			
				|  |  | -							if(!preCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.SNAP.getCode())
 | 
	
		
			
				|  |  | -								&&preCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.VIP.getCode())){
 | 
	
		
			
				|  |  | -								courseScheduleIds.add(preCourseSchedule.getId());
 | 
	
		
			
				|  |  | -							}
 | 
	
		
			
				|  |  | -							if(!backCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.SNAP.getCode())
 | 
	
		
			
				|  |  | -									&&backCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.VIP.getCode())){
 | 
	
		
			
				|  |  | -								courseScheduleIds.add(backCourseSchedule.getId());
 | 
	
		
			
				|  |  | -							}
 | 
	
		
			
				|  |  | -						}
 | 
	
		
			
				|  |  | -					}
 | 
	
		
			
				|  |  | +				//学生冲突检测
 | 
	
		
			
				|  |  | +				if(newCourseSchedule.getClassGroupId().equals(existCourseSchedule.getClassGroupId())){
 | 
	
		
			
				|  |  | +					//如果班级相同,则学生肯定存在冲突
 | 
	
		
			
				|  |  | +					isTeacherRepeat = true;
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				//如果班级不同,则需要检测两个班级是否存在重复的学生
 | 
	
		
			
				|  |  | +				List<ClassGroupStudentMapper> preClassGroupStudents=classGroupStudentsMap.get(newCourseSchedule.getClassGroupId());
 | 
	
		
			
				|  |  | +				List<ClassGroupStudentMapper> backClassGroupStudents=classGroupStudentsMap.get(existCourseSchedule.getClassGroupId());
 | 
	
		
			
				|  |  | +				//当前课程所在班级的学生编号列表
 | 
	
		
			
				|  |  | +				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)){
 | 
	
		
			
				|  |  | +					isStudentRepeat = true;
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  | +				if(!isTeacherRepeat && !isStudentRepeat){
 | 
	
		
			
				|  |  | +					continue;
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +				if(existCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.SNAP.getCode())||existCourseSchedule.getClassGroupType().equals(ClassGroupTypeEnum.VIP.getCode())){
 | 
	
		
			
				|  |  | +					throw new BizException("排课冲突");
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +				if(isTeacherRepeat){
 | 
	
		
			
				|  |  | +					courseScheduleIds.add(existCourseSchedule.getId());
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				if(isStudentRepeat){
 | 
	
		
			
				|  |  | +					CourseScheduleStudentDto courseScheduleStudentDto = new CourseScheduleStudentDto();
 | 
	
		
			
				|  |  | +					courseScheduleStudentDto.setId(existCourseSchedule.getId());
 | 
	
		
			
				|  |  | +					courseScheduleStudentDto.setStudentIds(repeatStudentIds);
 | 
	
		
			
				|  |  | +					courseScheduleStudents.add(courseScheduleStudentDto);
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  |  		}
 | 
	
		
			
				|  |  | +		//老师冲突删除课程课程
 | 
	
		
			
				|  |  | +		if(courseScheduleIds.size()>0){
 | 
	
		
			
				|  |  | +			courseScheduleDao.batchDeleteCourseSchedules(courseScheduleIds);
 | 
	
		
			
				|  |  | +			courseScheduleTeacherSalaryDao.batchDeleteByCourseScheduleIds(courseScheduleIds);
 | 
	
		
			
				|  |  | +			teacherAttendanceDao.batchDeleteByCourseSchedules(courseScheduleIds);
 | 
	
		
			
				|  |  | +			courseScheduleStudentPaymentDao.deleteByCourseSchedule(courseScheduleIds);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		//学生冲突删除学生课程
 | 
	
		
			
				|  |  | +		if(courseScheduleStudents.size()>0){
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  |  		return courseScheduleIds;
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 |