|  | @@ -18,10 +18,10 @@ import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.page.PageInfo;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  | +import com.ym.mec.jiari.JiaRiFeignService;
 | 
	
		
			
				|  |  |  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.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.BeanUtils;
 | 
	
	
		
			
				|  | @@ -79,6 +79,8 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  	private SubjectDao subjectDao;
 | 
	
		
			
				|  |  |  	@Autowired
 | 
	
		
			
				|  |  |  	private ClassGroupTeacherSalaryDao classGroupTeacherSalaryDao;
 | 
	
		
			
				|  |  | +	@Autowired
 | 
	
		
			
				|  |  | +	private JiaRiFeignService jiaRiFeignService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  |  	public BaseDAO<Long, CourseSchedule> getDAO() {
 | 
	
	
		
			
				|  | @@ -840,6 +842,117 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  	}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  	@Override
 | 
	
		
			
				|  |  | +	public void vipCourseAdjust(VipGroupCourseAdjustInfoDto vipGroupCourseAdjustInfo) {
 | 
	
		
			
				|  |  | +		if(Objects.isNull(vipGroupCourseAdjustInfo.getVipGroupId())){
 | 
	
		
			
				|  |  | +			throw new BizException("请指定小课");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		if(Objects.isNull(vipGroupCourseAdjustInfo.getCourseCreateStartTime())){
 | 
	
		
			
				|  |  | +			throw new BizException("请指定排课起始时间;");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		if(CollectionUtils.isEmpty(vipGroupCourseAdjustInfo.getCourseTimes())){
 | 
	
		
			
				|  |  | +			throw new BizException("请指定排课周期");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		if(StringUtils.isBlank(vipGroupCourseAdjustInfo.getCourseScheduleIds())){
 | 
	
		
			
				|  |  | +			throw new BizException("请指定需要调整的小课课程");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		Date courseCreateStartTime = vipGroupCourseAdjustInfo.getCourseCreateStartTime();
 | 
	
		
			
				|  |  | +		Date now = new Date();
 | 
	
		
			
				|  |  | +		if(courseCreateStartTime.before(now)){
 | 
	
		
			
				|  |  | +			throw new BizException("排课起始时间不能小于当前时间");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		VipGroup vipGroup=vipGroupDao.get(vipGroupCourseAdjustInfo.getVipGroupId().longValue());
 | 
	
		
			
				|  |  | +		if(Objects.isNull(vipGroup)){
 | 
	
		
			
				|  |  | +			throw new BizException("指定课程不存在");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		ClassGroup classGroup=classGroupDao.findByGroupAndType(vipGroupCourseAdjustInfo.getVipGroupId().toString(),GroupType.VIP.getCode());
 | 
	
		
			
				|  |  | +		if(Objects.isNull(classGroup)){
 | 
	
		
			
				|  |  | +			throw new BizException("对应班级不存在");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		//所有课程编号
 | 
	
		
			
				|  |  | +		List<Long> courseScheduleIds = Arrays.asList(vipGroupCourseAdjustInfo.getCourseScheduleIds().split(","))
 | 
	
		
			
				|  |  | +				.stream().map(Long::parseLong).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +		//所有的课程
 | 
	
		
			
				|  |  | +		List<CourseSchedule> courseSchedules = courseScheduleDao.findByCourseScheduleIds(courseScheduleIds);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		if(courseScheduleIds.size()!=courseScheduleIds.size()){
 | 
	
		
			
				|  |  | +			throw new BizException("部分课程不存在");
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		//课程对应的签到列表
 | 
	
		
			
				|  |  | +		List<TeacherAttendance> teacherAttendances = teacherAttendanceDao.findTeacherIdByCourseSchedule(courseScheduleIds);
 | 
	
		
			
				|  |  | +		Map<Long, List<TeacherAttendance>> teacherAttendanceCourseMap = teacherAttendances.stream()
 | 
	
		
			
				|  |  | +				.collect(Collectors.groupingBy(TeacherAttendance::getCourseScheduleId));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		Calendar calendar = Calendar.getInstance();
 | 
	
		
			
				|  |  | +		calendar.setTime(courseCreateStartTime);
 | 
	
		
			
				|  |  | +		List<Date> courseStartDates = new ArrayList<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		Map<String, Integer> holidayDays = new HashMap<>();
 | 
	
		
			
				|  |  | +		Map<Integer, Map<String, Integer>> holiday = new HashMap<>();;
 | 
	
		
			
				|  |  | +		if (vipGroupCourseAdjustInfo.isHoliday()) {
 | 
	
		
			
				|  |  | +			holiday = jiaRiFeignService.query(calendar.get(Calendar.YEAR));
 | 
	
		
			
				|  |  | +			holidayDays = holiday.get(calendar.get(Calendar.YEAR));
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +		while (true) {
 | 
	
		
			
				|  |  | +			if(vipGroupCourseAdjustInfo.isHoliday() && !holiday.containsKey(calendar.get(Calendar.YEAR))){
 | 
	
		
			
				|  |  | +				holiday = jiaRiFeignService.query(calendar.get(Calendar.YEAR));
 | 
	
		
			
				|  |  | +				holidayDays = holiday.get(calendar.get(Calendar.YEAR));
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			if (vipGroupCourseAdjustInfo.isHoliday() && holidayDays.containsKey(DateUtil.format(calendar.getTime(),"MMdd"))) {
 | 
	
		
			
				|  |  | +				calendar.add(Calendar.DATE, 1);
 | 
	
		
			
				|  |  | +				continue;
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			int i = calendar.get(Calendar.DAY_OF_WEEK);
 | 
	
		
			
				|  |  | +			if(i==1){
 | 
	
		
			
				|  |  | +				i=7;
 | 
	
		
			
				|  |  | +			}else{
 | 
	
		
			
				|  |  | +				i=--i;
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			for (CourseTimeDto courseTime : vipGroupCourseAdjustInfo.getCourseTimes()) {
 | 
	
		
			
				|  |  | +				if(Objects.isNull(courseTime.getDayOfWeek())){
 | 
	
		
			
				|  |  | +					throw new BizException("排课循环周期错误");
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				if(courseTime.getDayOfWeek()<1||courseTime.getDayOfWeek()>7){
 | 
	
		
			
				|  |  | +					throw new BizException("排课循环周期错误");
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				if(courseTime.getDayOfWeek()==i){
 | 
	
		
			
				|  |  | +					String dateYmdStr = DateUtil.dateToString(calendar.getTime(), DateUtil.ISO_EXPANDED_DATE_FORMAT);
 | 
	
		
			
				|  |  | +					dateYmdStr = dateYmdStr + " " +courseTime.getStartClassTime();
 | 
	
		
			
				|  |  | +					Date courseStartTime = DateUtil.stringToDate(dateYmdStr, "yyyy-MM-dd HH:mm");
 | 
	
		
			
				|  |  | +					Date courseEndTime = DateUtil.addMinutes(courseStartTime,vipGroup.getSingleClassMinutes());
 | 
	
		
			
				|  |  | +					courseStartDates.add(DateUtil.stringToDate(dateYmdStr, DateUtil.EXPANDED_DATE_TIME_FORMAT));
 | 
	
		
			
				|  |  | +					courseSchedules.get(courseStartDates.size()-1).setStatus(CourseStatusEnum.NOT_START);
 | 
	
		
			
				|  |  | +					courseSchedules.get(courseStartDates.size()-1).setClassDate(courseStartTime);
 | 
	
		
			
				|  |  | +					courseSchedules.get(courseStartDates.size()-1).setStartClassTime(courseStartTime);
 | 
	
		
			
				|  |  | +					courseSchedules.get(courseStartDates.size()-1).setEndClassTime(courseEndTime);
 | 
	
		
			
				|  |  | +					List<TeacherAttendance> tempTeacherAttendances=teacherAttendanceCourseMap.get(courseSchedules.get(courseStartDates.size()-1).getId());
 | 
	
		
			
				|  |  | +					if(!CollectionUtils.isEmpty(tempTeacherAttendances)){
 | 
	
		
			
				|  |  | +						TeacherAttendance teacherAttendance=tempTeacherAttendances.get(0);
 | 
	
		
			
				|  |  | +						if(Objects.nonNull(teacherAttendance.getSignInTime())
 | 
	
		
			
				|  |  | +								||Objects.nonNull(teacherAttendance.getSignOutTime())){
 | 
	
		
			
				|  |  | +							throw new BizException("选择的课程中存在已经签到的课程");
 | 
	
		
			
				|  |  | +						}
 | 
	
		
			
				|  |  | +					}
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +				if(courseStartDates.size()==courseScheduleIds.size()){
 | 
	
		
			
				|  |  | +					break;
 | 
	
		
			
				|  |  | +				}
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			if(courseStartDates.size()==courseScheduleIds.size()){
 | 
	
		
			
				|  |  | +				break;
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  | +			calendar.add(Calendar.DATE, 1);
 | 
	
		
			
				|  |  | +		}
 | 
	
		
			
				|  |  | +		checkNewCourseSchedules(courseSchedules,false);
 | 
	
		
			
				|  |  | +		courseScheduleDao.batchUpdate(courseSchedules);
 | 
	
		
			
				|  |  | +		classGroupService.updateClassGroupInfo(classGroup.getId());
 | 
	
		
			
				|  |  | +	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +	@Override
 | 
	
		
			
				|  |  |  	public void courseAdjust(List<CourseSchedule> newCourseSchedules) {
 | 
	
		
			
				|  |  |  		Date now=new Date();
 | 
	
		
			
				|  |  |  		//课程信息处理
 | 
	
	
		
			
				|  | @@ -851,6 +964,7 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  				.collect(Collectors.groupingBy(CourseSchedule::getId));
 | 
	
		
			
				|  |  |  		List<Map<Long, Integer>> courseSettlementMaps = courseScheduleTeacherSalaryDao.checkCoursesIsSettlement(courseScheduleIds);
 | 
	
		
			
				|  |  |  		Map<Long, Long> courseSettlementMap = MapUtil.convertIntegerMap(courseSettlementMaps);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  		newCourseSchedules.forEach(newCourseSchedule->{
 | 
	
		
			
				|  |  |  			Long isSettlement = courseSettlementMap.get(newCourseSchedule.getId().longValue());
 | 
	
		
			
				|  |  |  			if(Objects.nonNull(isSettlement)&&isSettlement>0){
 | 
	
	
		
			
				|  | @@ -871,6 +985,11 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 | 
	
		
			
				|  |  |  				}
 | 
	
		
			
				|  |  |  				newCourseSchedule.setSchoolId(oldCourseSchedule.getSchoolId());
 | 
	
		
			
				|  |  |  			}
 | 
	
		
			
				|  |  | +			if(oldCourseSchedule.getType().equals(CourseSchedule.CourseScheduleType.VIP)){
 | 
	
		
			
				|  |  | +				VipGroup vipGroup=vipGroupDao.get(Long.valueOf(oldCourseSchedule.getMusicGroupId()));
 | 
	
		
			
				|  |  | +				Date endClassTime = DateUtil.addMinutes(newCourseSchedule.getStartClassTime(),vipGroup.getSingleClassMinutes());
 | 
	
		
			
				|  |  | +				newCourseSchedule.setEndClassTime(endClassTime);
 | 
	
		
			
				|  |  | +			}
 | 
	
		
			
				|  |  |  			if(Objects.isNull(newCourseSchedule.getTeachMode())){
 | 
	
		
			
				|  |  |  				newCourseSchedule.setTeachMode(oldCourseSchedule.getTeachMode());
 | 
	
		
			
				|  |  |  			}
 |