Joburgess 5 years ago
parent
commit
dbc1d25a1a

+ 12 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleDao.java

@@ -510,7 +510,7 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
      * @param startTime: 开始时间
      * @param endTime:   结束时间
      * @return java.util.List<com.ym.mec.biz.dal.entity.CourseSchedule>
-     * @describe 获取时间段内的课程
+     * @describe 获取时间段内未开始的课程
      * @author Joburgess
      * @date 2019/10/31
      */
@@ -518,6 +518,17 @@ public interface CourseScheduleDao extends BaseDAO<Long, CourseSchedule> {
                                         @Param("endTime") Date endTime);
 
     /**
+     * @param startTime: 开始时间
+     * @param endTime:   结束时间
+     * @return java.util.List<com.ym.mec.biz.dal.entity.CourseSchedule>
+     * @describe 获取时间段内所有的课程
+     * @author Joburgess
+     * @date 2019/10/31
+     */
+    List<CourseSchedule> findAllCourseByDateZone(@Param("startTime") Date startTime,
+                                        @Param("endTime") Date endTime);
+
+    /**
      * 查询学生明天的课程数
      *
      * @return

+ 46 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -364,7 +364,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 			latestCourseSchedule = courseSchedules.stream().max(Comparator.comparing(CourseSchedule::getEndClassTime)).get();
 		}
 		//获取第一节课和最后一节课所包含的时间段内已存在的课程
-		List<CourseSchedule> existCourseSchedules = courseScheduleDao.findByDateZone(firstCourseSchedule.getStartClassTime(), latestCourseSchedule.getEndClassTime());
+		List<CourseSchedule> existCourseSchedules = courseScheduleDao.findAllCourseByDateZone(firstCourseSchedule.getStartClassTime(), latestCourseSchedule.getEndClassTime());
 
 		//只需要调整课程信息的课程编号列表
 		List<Long> updateCourseScheduleIds = courseSchedules
@@ -442,18 +442,12 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 							continue;
 						}
 
-                        //提示信息
-                        StringBuffer errInfo = new StringBuffer("在");
-                        errInfo.append(DateUtil.dateToString(preCourseSchedule.getStartClassTime(),"yyyy-MM-dd HH:mm"));
-                        errInfo.append("至");
-                        errInfo.append(DateUtil.dateToString(backCourseSchedule.getEndClassTime(),"yyyy-MM-dd HH:mm"));
-                        errInfo.append("的时间段内");
                         //如果存在时间重叠,则需要判断前后两节课的教师和学生是否存在冲突
                         //主教冲突检测
                         if(Objects.nonNull(preCourseSchedule.getActualTeacherId())
                                 &&preCourseSchedule.getActualTeacherId().equals(backCourseSchedule.getActualTeacherId())){
-                            errInfo.append("安排的主教有课程冲突");
-                            throw new BizException(errInfo.toString());
+
+                            throw new BizException(courseCheckInfo(preCourseSchedule,backCourseSchedule,existCourseScheduleIds,1));
                         }
                         //助教冲突检测
 						if(Objects.isNull(preCourseSchedule.getId())){
@@ -484,15 +478,13 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 									.stream().filter(backCourseSchedule.getTeachingTeacherIdList()::contains)
 									.collect(Collectors.toList());
 							if(!CollectionUtils.isEmpty(repeatIds)){
-								errInfo.append("安排的助教存在冲突");
-								throw new BizException(errInfo.toString());
+								throw new BizException(courseCheckInfo(preCourseSchedule,backCourseSchedule,existCourseScheduleIds,2));
 							}
 						}
                         //学生冲突检测
                         if(preCourseSchedule.getClassGroupId().equals(backCourseSchedule.getClassGroupId())){
                             //如果班级相同,则学生肯定存在冲突
-                            errInfo.append("安排的课程存在学生冲突");
-                            throw new BizException(errInfo.toString());
+                            throw new BizException(courseCheckInfo(preCourseSchedule,backCourseSchedule,existCourseScheduleIds,3));
                         }
                         //如果班级不同,则需要检测两个班级是否存在重复的学生
                         List<ClassGroupStudentMapper> preClassGroupStudents=classGroupStudentsMap.get(preCourseSchedule.getClassGroupId());
@@ -513,8 +505,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
                                 .filter(backClassGroupStudentIds::contains)
                                 .collect(Collectors.toList());
                         if(!CollectionUtils.isEmpty(repeatStudentIds)){
-                            errInfo.append("安排的课程存在学生冲突");
-                            throw new BizException(errInfo.toString());
+                            throw new BizException(courseCheckInfo(preCourseSchedule,backCourseSchedule,existCourseScheduleIds,3));
                         }
                         if(j==repeatTimes){
                             repeatTimes+=1;
@@ -528,6 +519,46 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 		}
 	}
 
+	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"));
+		errInfo.append("至");
+		errInfo.append(DateUtil.dateToString(backCourseSchedule.getEndClassTime(),"yyyy-MM-dd HH:mm"));
+		errInfo.append("的时间段内");
+		errInfo.append("安排的课程存在冲突,");
+		errInfo.append("冲突课程为:");
+		if(Objects.nonNull(preCourseSchedule.getId())&&existCourseScheduleIds.contains(preCourseSchedule.getId())){
+			errInfo.append(preCourseSchedule.getName());
+			errInfo.append("(");
+			errInfo.append(preCourseSchedule.getId());
+			errInfo.append(")");
+		}
+		if(Objects.nonNull(backCourseSchedule.getId())&&existCourseScheduleIds.contains(backCourseSchedule.getId())){
+			errInfo.append(backCourseSchedule.getName());
+			errInfo.append("(");
+			errInfo.append(backCourseSchedule.getId());
+			errInfo.append("),");
+		}
+		errInfo.append("类型为:");
+		switch (type){
+			case 1:
+				errInfo.append("主教冲突");
+				break;
+			case 2:
+				errInfo.append("助教冲突");
+				break;
+			case 3:
+				errInfo.append("学生冲突");
+				break;
+			default:
+				errInfo.append("未知冲突");
+				break;
+		}
+
+		return errInfo.toString();
+	}
+
 	/**
 	 * 判断课程安排中是否存在冲突
 	 * 计算课程课次

+ 23 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleMapper.xml

@@ -1168,6 +1168,29 @@
             WHERE (cs.class_date_ BETWEEN DATE_FORMAT(#{startTime},'%Y%m%d') AND DATE_FORMAT(#{endTime},'%Y%m%d'))
             AND cs.status_='NOT_START'
     </select>
+    <select id="findAllCourseByDateZone" resultMap="CourseSchedule">
+        SELECT
+            cs.id_,
+            cs.class_group_id_,
+            cs.status_,
+            cs.subsidy_,
+            cs.class_date_,
+            CONCAT(cs.class_date_,' ',cs.start_class_time_) start_class_time_,
+            CONCAT(cs.class_date_,' ',cs.end_class_time_) end_class_time_,
+            cs.teacher_id_,
+            cs.actual_teacher_id_,
+            cs.create_time_,
+            cs.update_time_,
+            cs.teach_mode_,
+            cs.type_,
+            cs.name_,
+            cs.student_num_,
+            cs.leave_student_num_,
+            cs.schoole_id_
+        FROM
+            course_schedule cs
+            WHERE (cs.class_date_ BETWEEN DATE_FORMAT(#{startTime},'%Y%m%d') AND DATE_FORMAT(#{endTime},'%Y%m%d'))
+    </select>
     
     <select id="queryStudentCoursesTimesOfTomorrow" resultMap="Mapper">
     	select cssp.user_id_ key_,count(1) value_ from course_schedule cs right join course_schedule_student_payment cssp on cs.id_ = cssp.course_schedule_id_ where class_date_ = date(DATE_ADD(now(),INTERVAL 1 DAY)) group by cssp.user_id_