Forráskód Böngészése

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

zouxuan 5 éve
szülő
commit
373f15298e

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CourseSchedule.java

@@ -129,6 +129,16 @@ public class CourseSchedule {
 
 	private Integer isSettlement;
 
+	private String classGroupType;
+
+	public String getClassGroupType() {
+		return classGroupType;
+	}
+
+	public void setClassGroupType(String classGroupType) {
+		this.classGroupType = classGroupType;
+	}
+
 	public Integer getIsSettlement() {
 		return isSettlement;
 	}

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleService.java

@@ -192,6 +192,15 @@ public interface CourseScheduleService extends BaseService<Long, CourseSchedule>
 	void checkNewCourseSchedules(List<CourseSchedule> courseSchedules,boolean checkExistCourseSchedule);
 
 	/**
+	 * @describe 临时课检测
+	 * @author Joburgess
+	 * @date 2019/12/6
+	 * @param courseSchedules: 课程计划列表
+	 * @return void
+	 */
+	List<Long> checkSnapCourseShchedules(List<CourseSchedule> courseSchedules);
+
+	/**
 	 * 获取乐团班级未开始的课程
 	 *
 	 * @param classGroupIds

+ 179 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -523,7 +523,185 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 		}
 	}
 
-	private String courseCheckInfo(CourseSchedule preCourseSchedule,CourseSchedule backCourseSchedule,List<Long> existCourseScheduleIds,Integer type){
+	@Override
+	public List<Long> checkSnapCourseShchedules(List<CourseSchedule> courseSchedules) {
+		List<Long> courseScheduleIds = new ArrayList<>();
+		if(CollectionUtils.isEmpty(courseSchedules)){
+			return courseScheduleIds;
+		}
+		//第一节课
+		CourseSchedule firstCourseSchedule;
+		//最后一节课
+		CourseSchedule latestCourseSchedule;
+		if(courseSchedules.size()==1){
+			firstCourseSchedule = courseSchedules.get(0);
+			latestCourseSchedule = courseSchedules.get(0);
+		}else{
+			firstCourseSchedule = courseSchedules.stream().min(Comparator.comparing(CourseSchedule::getStartClassTime)).get();
+			latestCourseSchedule = courseSchedules.stream().max(Comparator.comparing(CourseSchedule::getEndClassTime)).get();
+		}
+		//获取第一节课和最后一节课所包含的时间段内已存在的课程
+		List<CourseSchedule> existCourseSchedules = courseScheduleDao
+				.findAllCourseByDateZone(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<Integer> newCourseScheduleClassGroupIds = courseSchedules
+				.stream()
+				.map(CourseSchedule::getClassGroupId)
+				.distinct()
+				.collect(Collectors.toList());
+
+		List<Long> existCourseScheduleIds = existCourseSchedules.stream()
+				.map(CourseSchedule::getId)
+				.collect(Collectors.toList());
+
+		//合并新课程和已存在的课程
+		List<CourseSchedule> allCourseSchedules;
+		if(!CollectionUtils.isEmpty(existCourseSchedules)){
+			allCourseSchedules = ListUtils.sum(courseSchedules, existCourseSchedules);
+		}else{
+			allCourseSchedules = courseSchedules;
+		}
+		//所有课程的班级编号
+		List<Integer> classGroupIds = allCourseSchedules
+				.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));
+
+		//根据课程获取教师id关联集合
+		List<IntegerAndIntegerListDto> courseScheduleTeachingTeacherIdList = new ArrayList<>();
+		if(!CollectionUtils.isEmpty(existCourseScheduleIds)){
+			courseScheduleTeachingTeacherIdList = courseScheduleDao.findCourseScheduleIdAndUserIdsMap(existCourseScheduleIds, null);
+		}
+		Map<Integer, IntegerAndIntegerListDto> courseScheduleTeacherMap = courseScheduleTeachingTeacherIdList.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;
+					}
+
+					//教师冲突检测
+					if(Objects.isNull(preCourseSchedule.getId())){
+						IntegerAndIntegerListDto integerAndIntegerListDto = courseScheduleTeacherMap.get(preCourseSchedule.getId());
+						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 = courseScheduleTeacherMap.get(backCourseSchedule.getId());
+						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)
+							.collect(Collectors.toList());
+					if(!CollectionUtils.isEmpty(repeatStudentIds)){
+						isRepeat = 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());
+							}
+						}
+					}
+				}
+			}
+		}
+		return courseScheduleIds;
+	}
+
+	private String courseCheckInfo(CourseSchedule preCourseSchedule, CourseSchedule backCourseSchedule, List<Long> existCourseScheduleIds, Integer type){
 		//提示信息
 		StringBuffer errInfo = new StringBuffer("在");
 		errInfo.append(DateUtil.dateToString(preCourseSchedule.getStartClassTime(),"yyyy-MM-dd HH:mm"));

+ 3 - 1
mec-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -30,6 +30,7 @@
         <result column="schoole_id_" property="schoolId"/>
         <result column="schoole_name_" property="schoolName"/>
         <result column="class_group_name_" property="classGroupName"/>
+        <result column="class_group_type_" property="classGroupType"/>
     </resultMap>
     
     <resultMap type="com.ym.mec.biz.dal.dto.Mapper" id="Mapper">
@@ -1237,7 +1238,8 @@
             cs.name_,
             cs.student_num_,
             cs.leave_student_num_,
-            cs.schoole_id_
+            cs.schoole_id_,
+            cg.type_ class_group_type_
         FROM
             course_schedule cs left join class_group cg on cs.class_group_id_ = cg.id_
         WHERE (cs.class_date_ BETWEEN DATE_FORMAT(#{startTime},'%Y%m%d') AND DATE_FORMAT(#{endTime},'%Y%m%d'))