浏览代码

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

zouxuan 5 年之前
父节点
当前提交
8295ed6b23

+ 23 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/EmployeeInfo.java

@@ -65,7 +65,7 @@ public class EmployeeInfo {
 
 	@ApiModelProperty(value = "入职日期", required = false)
 	private java.util.Date entryDate;
-	
+
 	@ApiModelProperty(value = "分部", required = false)
 	private Integer organId;
 
@@ -87,6 +87,12 @@ public class EmployeeInfo {
 	@ApiModelProperty(value = "离职日期", required = false)
 	private java.util.Date resignationDate;
 
+	@ApiModelProperty(value = "操作人编号", required = false)
+	private Integer operatorId;
+
+	@ApiModelProperty(value = "信息来源", required = false)
+	private String sourceFrom;
+
 	/**  */
 	private java.util.Date createTime;
 
@@ -325,6 +331,22 @@ public class EmployeeInfo {
 		return this.updateTime;
 	}
 
+	public Integer getOperatorId() {
+		return operatorId;
+	}
+
+	public void setOperatorId(Integer operatorId) {
+		this.operatorId = operatorId;
+	}
+
+	public String getSourceFrom() {
+		return sourceFrom;
+	}
+
+	public void setSourceFrom(String sourceFrom) {
+		this.sourceFrom = sourceFrom;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/page/EmployeeInfoQueryInfo.java

@@ -10,6 +10,9 @@ public class EmployeeInfoQueryInfo extends QueryInfo {
 
 	@ApiModelProperty(value = "姓名/编号/手机号", required = false)
 	private String userNameOrIdOrMobile;
+	
+	@ApiModelProperty(value = "信息来源", required = false)
+	private String sourceFrom;
 
 	@ApiModelProperty(value = "分部", required = false)
 	private Integer organId;
@@ -62,4 +65,12 @@ public class EmployeeInfoQueryInfo extends QueryInfo {
 	public void setJobNature(JobNatureEnum jobNature) {
 		this.jobNature = jobNature;
 	}
+
+	public String getSourceFrom() {
+		return sourceFrom;
+	}
+
+	public void setSourceFrom(String sourceFrom) {
+		this.sourceFrom = sourceFrom;
+	}
 }

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

@@ -257,6 +257,16 @@ public interface CourseScheduleService extends BaseService<Long, CourseSchedule>
 	 */
 	void checkNewCourseSchedules(List<CourseSchedule> courseSchedules,boolean checkExistCourseSchedule);
 
+	/**
+	 * @describe 检测并校正冲突课程
+	 * @author Joburgess
+	 * @date 2020.09.09
+	 * @param courseSchedules:
+	 * @param checkExistCourseSchedule:
+	 * @return void
+	 */
+	void checkAllCourseSchedules(List<CourseSchedule> courseSchedules,boolean checkExistCourseSchedule);
+
 	void checkNewCourseSchedulesWithoutMusicGroup(List<CourseSchedule> courseSchedules,boolean checkExistCourseSchedule);
 
 	/**

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

@@ -1404,6 +1404,200 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
         }
     }
 
+
+
+	@Override
+	public void checkAllCourseSchedules(List<CourseSchedule> courseSchedules, boolean checkExistCourseSchedule) {
+		if (CollectionUtils.isEmpty(courseSchedules)) {
+			return;
+		}
+		List<String> classDates = courseSchedules.stream().map(courseSchedule -> DateUtil.dateToString(courseSchedule.getClassDate(), "yyyy-MM-dd"))
+				.collect(Collectors.toList());
+
+		List<CourseSchedule> existCourseSchedules = courseScheduleDao.findByClassDate(classDates);
+
+		//只需要调整课程信息的课程编号列表
+		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());
+
+		HashSet<Long> courseScheduleIdsSet = new HashSet<>(existCourseScheduleIds);
+
+		//合并新课程和已存在的课程
+		List<CourseSchedule> allCourseSchedules;
+		if (!CollectionUtils.isEmpty(existCourseSchedules)) {
+			allCourseSchedules = ListUtils.sum(courseSchedules, existCourseSchedules);
+		} else {
+			allCourseSchedules = courseSchedules;
+		}
+
+		//所有课程编号
+		List<Long> allCourseScheduleIds = allCourseSchedules.stream().map(CourseSchedule::getId).collect(Collectors.toList());
+		//所有课程学员签到记录
+		List<StudentAttendance> studentAttendances = studentAttendanceDao.findByCourseIds(allCourseScheduleIds);
+		//课程请假学员字典
+		Map<Long, Set<Integer>> courseLeaveStudentMap = studentAttendances.stream()
+				.filter(e -> StudentAttendanceStatusEnum.LEAVE.equals(e.getStatus()))
+				.collect(Collectors.groupingBy(StudentAttendance::getCourseScheduleId, Collectors.mapping(StudentAttendance::getUserId, Collectors.toSet())));
+
+		//所有课程的班级编号
+		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, TeachTypeEnum.TEACHING.getCode());
+		}
+		Map<Integer, IntegerAndIntegerListDto> courseScheduleTeachingTeacherMap = courseScheduleTeachingTeacherIdList.stream()
+				.collect(Collectors.toMap(IntegerAndIntegerListDto::getId, integerAndIntegerListDto -> integerAndIntegerListDto));
+
+		//班级助教关联ID集合
+		List<IntegerAndIntegerListDto> classGroupAndUserIdsMap = courseScheduleDao.findClassGroupAndUserIdsMap(newCourseScheduleClassGroupIds, TeachTypeEnum.TEACHING.getCode());
+		Map<Integer, IntegerAndIntegerListDto> classGroupTeachingTeacherMap = classGroupAndUserIdsMap.stream()
+				.collect(Collectors.toMap(IntegerAndIntegerListDto::getId, integerAndIntegerListDto -> integerAndIntegerListDto));
+
+		Set<Long> existCourseScheduleIdsSet=new HashSet<>(existCourseScheduleIds);
+
+		Map<String, List<CourseSchedule>> existClassDateCoursesMap = allCourseSchedules.stream().collect(Collectors.groupingBy(c -> DateUtil.dateToString(c.getClassDate(), "yyyy-MM-dd")));
+		Map<String, List<CourseSchedule>> newClassDateCoursesMap = courseSchedules.stream().collect(Collectors.groupingBy(c -> DateUtil.dateToString(c.getClassDate(), "yyyy-MM-dd")));
+		if (allCourseSchedules.size() > 1) {
+			for (Map.Entry<String, List<CourseSchedule>> classDateCourseEntry : newClassDateCoursesMap.entrySet()) {
+				List<CourseSchedule> existClassDateCourses = existClassDateCoursesMap.get(classDateCourseEntry.getKey());
+				if(CollectionUtils.isEmpty(existClassDateCourses)){
+					continue;
+				}
+				List<CourseSchedule> newClassDateCourses=classDateCourseEntry.getValue();
+				existClassDateCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
+				newClassDateCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
+				for (CourseSchedule preCourseSchedule : newClassDateCourses) {
+					for (CourseSchedule backCourseSchedule : existClassDateCourses) {
+
+						//判断前后两节课是否存在冲突
+						if (!preCourseSchedule.getStartClassTime().before(backCourseSchedule.getEndClassTime())
+								||!preCourseSchedule.getEndClassTime().after(backCourseSchedule.getStartClassTime())) {
+							continue;
+						}
+						if (!checkExistCourseSchedule
+								&& !courseScheduleIdsSet.contains(backCourseSchedule.getId())) {
+							continue;
+						}
+
+						//如果存在时间重叠,则需要判断前后两节课的教师和学生是否存在冲突
+						//主教冲突检测
+						if (Objects.nonNull(preCourseSchedule.getActualTeacherId())
+								&& preCourseSchedule.getActualTeacherId().equals(backCourseSchedule.getActualTeacherId())) {
+
+							throw new BizException(courseCheckInfo(preCourseSchedule, backCourseSchedule, existCourseScheduleIds, 1));
+						}
+
+						if(Objects.isNull(preCourseSchedule.getId())){
+							continue;
+						}
+
+						//助教冲突检测
+						if (Objects.isNull(preCourseSchedule.getId())) {
+							IntegerAndIntegerListDto integerAndIntegerListDto = classGroupTeachingTeacherMap.get(preCourseSchedule.getClassGroupId());
+							if (Objects.nonNull(integerAndIntegerListDto)) {
+								preCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
+							}
+						} else if (existCourseScheduleIdsSet.contains(preCourseSchedule.getId())) {
+							IntegerAndIntegerListDto integerAndIntegerListDto = courseScheduleTeachingTeacherMap.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 (existCourseScheduleIdsSet.contains(backCourseSchedule.getId())) {
+							IntegerAndIntegerListDto integerAndIntegerListDto = courseScheduleTeachingTeacherMap.get(backCourseSchedule.getId());
+							if (Objects.nonNull(integerAndIntegerListDto)) {
+								backCourseSchedule.setTeachingTeacherIdList(integerAndIntegerListDto.getIds());
+							}
+						}
+						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)) {
+								throw new BizException(courseCheckInfo(preCourseSchedule, backCourseSchedule, existCourseScheduleIds, 2));
+							}
+						}
+						//学生冲突检测
+						if (preCourseSchedule.getClassGroupId().equals(backCourseSchedule.getClassGroupId())) {
+							//如果班级相同,则学生肯定存在冲突
+							throw new BizException(courseCheckInfo(preCourseSchedule, backCourseSchedule, existCourseScheduleIds, 3));
+						}
+						//如果班级不同,则需要检测两个班级是否存在重复的学生
+						List<ClassGroupStudentMapper> preClassGroupStudents = classGroupStudentsMap.get(preCourseSchedule.getClassGroupId());
+						List<ClassGroupStudentMapper> backClassGroupStudents = classGroupStudentsMap.get(backCourseSchedule.getClassGroupId());
+						//如果有一个存在没有学生的班级则不存在冲突
+						if (CollectionUtils.isEmpty(preClassGroupStudents) || CollectionUtils.isEmpty(backClassGroupStudents)) {
+							continue;
+						}
+						//课程对应请假学员编号集合
+						Set<Integer> preLeaveStudentIds = courseLeaveStudentMap.get(preCourseSchedule.getId());
+						if(null == preLeaveStudentIds){
+							preLeaveStudentIds = Collections.EMPTY_SET;
+						}
+						Set<Integer> backLeaveStudentIds = courseLeaveStudentMap.get(backCourseSchedule.getId());
+						if(null == backLeaveStudentIds){
+							backLeaveStudentIds = Collections.EMPTY_SET;
+						}
+
+						//当前课程所在班级的学生编号列表
+						Set<Integer> finalPreLeaveStudentIds = preLeaveStudentIds;
+						List<Integer> preClassGroupStudentIds = preClassGroupStudents.stream()
+								.filter(e->!finalPreLeaveStudentIds.contains(e.getUserId()))
+								.map(ClassGroupStudentMapper::getUserId)
+								.collect(Collectors.toList());
+						//后面一节课程所在班级的学生编号列表
+						Set<Integer> finalBackLeaveStudentIds = backLeaveStudentIds;
+						Set<Integer> backClassGroupStudentIds = backClassGroupStudents.stream()
+								.filter(e->!finalBackLeaveStudentIds.contains(e.getUserId()))
+								.map(ClassGroupStudentMapper::getUserId)
+								.collect(Collectors.toSet());
+						List<Integer> repeatStudentIds = preClassGroupStudentIds.stream()
+								.filter(backClassGroupStudentIds::contains)
+								.collect(Collectors.toList());
+						if (!CollectionUtils.isEmpty(repeatStudentIds)) {
+							throw new BizException(courseCheckInfo(preCourseSchedule, backCourseSchedule, existCourseScheduleIds, 3));
+						}
+					}
+				}
+			}
+		}
+	}
+
     @Override
     public void checkNewCourseSchedulesWithoutMusicGroup(List<CourseSchedule> courseSchedules, boolean checkExistCourseSchedule) {
         if (CollectionUtils.isEmpty(courseSchedules)) {
@@ -2405,7 +2599,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 
 				for (StudentAttendance studentAttendance : studentAttendanceList) {
 					if (studentAttendance.getStatus() != StudentAttendanceStatusEnum.LEAVE
-						|| (studentAttendance.getStatus() != StudentAttendanceStatusEnum.LEAVE
+						|| (studentAttendance.getStatus() == StudentAttendanceStatusEnum.LEAVE
 							&&DateUtil.addHours(studentAttendance.getCreateTime(),4).compareTo(oldCourseSchedule.getStartClassTime())>=0)) {
 						throw new BizException("{}[{}] {}-{}课程已点名", oldCourseSchedule.getName(), oldCourseSchedule.getId(), DateUtil.dateToString(
 								oldCourseSchedule.getStartClassTime(), DateUtil.EXPANDED_DATE_TIME_FORMAT), DateUtil.dateToString(

+ 13 - 2
mec-biz/src/main/resources/config/mybatis/EmployeeInfoMapper.xml

@@ -29,6 +29,8 @@
 		<result column="bank_address_" property="bankAddress" />
 		<result column="resignation_date_" property="resignationDate" />
 		<result column="organ_id_" property="organId" />
+		<result column="operator_id_" property="operatorId" />
+		<result column="source_from_" property="sourceFrom" />
 		<result column="create_time_" property="createTime" />
 		<result column="update_time_" property="updateTime" />
 	</resultMap>
@@ -51,8 +53,8 @@
 		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
 			AS ID FROM DUAL </selectKey> -->
 		INSERT INTO employee_info
-		(id_,real_name_,mobile_no_,wechat_no_,id_card_,age_,gender_,birthdate_,emergency_contact_name_,emergency_contact_relation_,emergency_contact_phone_,live_city_,intention_city_,educational_background_,subject_id_,is_interviewed_,other_comment_,entry_date_,organ_id_,position_,job_nature_,is_probation_period_,bank_card_no_,bank_address_,resignation_date_,create_time_,update_time_)
-		VALUES(#{id},#{realName},#{mobileNo},#{wechatNo},#{idCard},#{age},#{gender},#{birthdate},#{emergencyContactName},#{emergencyContactRelation},#{emergencyContactPhone},#{liveCity},#{intentionCity},#{educationalBackground},#{subjectId},#{isInterviewed},#{otherComment},#{entryDate},#{organId},#{position,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{jobNature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{isProbationPeriod},#{bankCardNo},#{bankAddress},#{resignationDate},#{createTime},#{updateTime})
+		(id_,real_name_,mobile_no_,wechat_no_,id_card_,age_,gender_,birthdate_,emergency_contact_name_,emergency_contact_relation_,emergency_contact_phone_,live_city_,intention_city_,educational_background_,subject_id_,is_interviewed_,other_comment_,entry_date_,organ_id_,position_,job_nature_,is_probation_period_,bank_card_no_,bank_address_,resignation_date_,operator_id_,source_from_,create_time_,update_time_)
+		VALUES(#{id},#{realName},#{mobileNo},#{wechatNo},#{idCard},#{age},#{gender},#{birthdate},#{emergencyContactName},#{emergencyContactRelation},#{emergencyContactPhone},#{liveCity},#{intentionCity},#{educationalBackground},#{subjectId},#{isInterviewed},#{otherComment},#{entryDate},#{organId},#{position,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{jobNature,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{isProbationPeriod},#{bankCardNo},#{bankAddress},#{resignationDate},#{operatorId},#{sourceFrom},#{createTime},#{updateTime})
 	</insert>
 
 	<!-- 根据主键查询一条记录 -->
@@ -140,6 +142,12 @@
 			<if test="organId != null">
 				organ_id_ = #{organId},
 			</if>
+			<if test="operatorId != null">
+				operator_id_ = #{operatorId},
+			</if>
+			<if test="sourceFrom != null">
+				source_from_ = #{sourceFrom},
+			</if>
 		</set>
 		WHERE id_ = #{id}
 	</update>
@@ -160,6 +168,9 @@
 	        <if test="subjectId != null">
 	            AND subject_id_ = #{subjectId}
 	        </if>
+	        <if test="sourceFrom != null">
+	            AND source_from_ = #{sourceFrom}
+	        </if>
 	        <if test="position != null">
 	            AND position_ = #{position,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
 	        </if>

+ 16 - 0
mec-web/src/main/java/com/ym/mec/web/controller/EmployeeInfoController.java

@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.entity.EmployeeInfo;
 import com.ym.mec.biz.dal.page.EmployeeInfoQueryInfo;
 import com.ym.mec.biz.service.EmployeeInfoService;
@@ -25,11 +27,20 @@ public class EmployeeInfoController extends BaseController {
 
     @Autowired
     private EmployeeInfoService employeeInfoService;
+    
+	@Autowired
+	private SysUserFeignService sysUserFeignService;
+
 
     @ApiOperation(value = "新增员工信息")
     @PostMapping("/insert")
     @PreAuthorize("@pcs.hasPermissions('employeeInfo/insert')")
     public Object insert(@RequestBody EmployeeInfo employeeInfo) {
+    	SysUser sysUser = sysUserFeignService.queryUserInfo();
+		if (sysUser == null) {
+			return failed("用户信息获取失败");
+		}
+		employeeInfo.setOperatorId(sysUser.getId());
     	Date date = new Date();
     	employeeInfo.setUpdateTime(date);
     	employeeInfo.setCreateTime(date);
@@ -41,6 +52,11 @@ public class EmployeeInfoController extends BaseController {
     @PostMapping("/update")
     @PreAuthorize("@pcs.hasPermissions('employeeInfo/update')")
     public Object update(@RequestBody EmployeeInfo employeeInfo) {
+    	SysUser sysUser = sysUserFeignService.queryUserInfo();
+		if (sysUser == null) {
+			return failed("用户信息获取失败");
+		}
+		employeeInfo.setOperatorId(sysUser.getId());
     	Date date = new Date();
     	employeeInfo.setUpdateTime(date);
     	employeeInfoService.update(employeeInfo);