|
@@ -9,18 +9,23 @@ import com.ym.mec.biz.dal.dao.*;
|
|
|
import com.ym.mec.biz.dal.dto.*;
|
|
|
import com.ym.mec.biz.dal.entity.*;
|
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
|
-import com.ym.mec.biz.service.CourseScheduleService;
|
|
|
-import com.ym.mec.biz.service.EduPracticeGroupService;
|
|
|
-import com.ym.mec.biz.service.OnlineMusicGroupService;
|
|
|
-import com.ym.mec.biz.service.SysConfigService;
|
|
|
+import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.constant.CommonConstants;
|
|
|
+import com.ym.mec.common.controller.BaseController;
|
|
|
+import com.ym.mec.common.entity.ImGroupMember;
|
|
|
+import com.ym.mec.common.entity.ImGroupModel;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
+import com.ym.mec.im.ImFeignService;
|
|
|
+import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.date.DateUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.util.StringUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Isolation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
@@ -37,6 +42,8 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
@Autowired
|
|
|
private MusicGroupDao musicGroupDao;
|
|
|
@Autowired
|
|
|
+ private MusicGroupStudentFeeDao musicGroupStudentFeeDao;
|
|
|
+ @Autowired
|
|
|
private StudentDao studentDao;
|
|
|
@Autowired
|
|
|
private TeacherDao teacherDao;
|
|
@@ -67,7 +74,11 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
@Autowired
|
|
|
private TeacherFreeTimeDao teacherFreeTimeDao;
|
|
|
@Autowired
|
|
|
- private EduPracticeGroupService eduPracticeGroupService;
|
|
|
+ private PracticeGroupService practiceGroupService;
|
|
|
+ @Autowired
|
|
|
+ private ImFeignService imFeignService;
|
|
|
+ @Autowired
|
|
|
+ private SysMessageService sysMessageService;
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.DEFAULT)
|
|
|
@Override
|
|
@@ -84,13 +95,21 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
if(Objects.isNull(onlineMusicGroupCourseInfo.getTeacherId())){
|
|
|
throw new BizException("请指定教师");
|
|
|
}
|
|
|
- if(Objects.isNull(onlineMusicGroupCourseInfo.getFirstCourseTime())){
|
|
|
+ if(Objects.isNull(onlineMusicGroupCourseInfo.getCourseCreateStartTime())){
|
|
|
throw new BizException("请指定首次上课时间");
|
|
|
}
|
|
|
MusicGroup musicGroup = musicGroupDao.get(onlineMusicGroupCourseInfo.getMusicGroupId());
|
|
|
if(Objects.isNull(musicGroupDao)){
|
|
|
throw new BizException("乐团不存在");
|
|
|
}
|
|
|
+ MusicGroupStudentFee studentFee = musicGroupStudentFeeDao.findByUser(onlineMusicGroupCourseInfo.getStudentId(), musicGroup.getId());
|
|
|
+ if(Objects.isNull(studentFee)){
|
|
|
+ throw new BizException("学员缴费信息不存在");
|
|
|
+ }
|
|
|
+ if(studentFee.getRemainNetworkClassTimes()<=0){
|
|
|
+ throw new BizException("该学员费用不足");
|
|
|
+ }
|
|
|
+
|
|
|
SysUser student = studentDao.lockUserReturnInfo(onlineMusicGroupCourseInfo.getStudentId());
|
|
|
if(Objects.isNull(student)){
|
|
|
throw new BizException("学员不存在");
|
|
@@ -107,7 +126,15 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
onlineMusicGroupCourseInfo.setCourseCount(8);
|
|
|
onlineMusicGroupCourseInfo.setSingleClassMinutes(25);
|
|
|
onlineMusicGroupCourseInfo.setTeachMode(TeachModeEnum.ONLINE);
|
|
|
+ CourseTimeDto courseTimeDto=new CourseTimeDto();
|
|
|
+ LocalDateTime courseStartLocalDate = LocalDateTime.ofInstant(onlineMusicGroupCourseInfo.getCourseCreateStartTime().toInstant(), DateUtil.zoneId);
|
|
|
+ courseTimeDto.setDayOfWeek(courseStartLocalDate.getDayOfWeek().getValue());
|
|
|
+ courseTimeDto.setStartClassTime(DateUtil.dateToString(onlineMusicGroupCourseInfo.getCourseCreateStartTime(), "HH:mm:ss"));
|
|
|
+ List<CourseTimeDto> ts=new ArrayList<>();
|
|
|
+ ts.add(courseTimeDto);
|
|
|
+ onlineMusicGroupCourseInfo.setCourseTimes(ts);
|
|
|
List<CourseSchedule> courses = courseScheduleService.createCourses(onlineMusicGroupCourseInfo, true);
|
|
|
+ courses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
|
|
|
Date now=new Date();
|
|
|
|
|
@@ -116,7 +143,7 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
classGroup.setSubjectIdList(onlineMusicGroupCourseInfo.getSubjectId().toString());
|
|
|
classGroup.setExpectStudentNum(1);
|
|
|
classGroup.setStudentNum(1);
|
|
|
- classGroup.setName(subject.getName()+"•"+student.getRealName());
|
|
|
+ classGroup.setName(subject.getName()+"•"+student.getUsername());
|
|
|
classGroup.setTotalClassTimes(courses.size());
|
|
|
classGroup.setType(ClassGroupTypeEnum.MUSIC_NETWORK);
|
|
|
classGroup.setDelFlag(0);
|
|
@@ -155,7 +182,10 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
//课表
|
|
|
courseSchedule.setMusicGroupId(onlineMusicGroupCourseInfo.getMusicGroupId());
|
|
|
courseSchedule.setClassGroupId(classGroup.getId());
|
|
|
+ courseSchedule.setName(classGroup.getName());
|
|
|
courseSchedule.setStatus(CourseStatusEnum.NOT_START);
|
|
|
+ courseSchedule.setTeacherId(onlineMusicGroupCourseInfo.getTeacherId());
|
|
|
+ courseSchedule.setActualTeacherId(onlineMusicGroupCourseInfo.getTeacherId());
|
|
|
courseSchedule.setCreateTime(now);
|
|
|
courseSchedule.setUpdateTime(now);
|
|
|
courseSchedule.setTeachMode(TeachModeEnum.ONLINE);
|
|
@@ -166,6 +196,9 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
}
|
|
|
courseScheduleDao.batchAddCourseSchedules(courses);
|
|
|
TeacherDefaultMusicGroupSalary teacherDefaultMusicGroupSalary = teacherDefaultMusicGroupSalaryDao.findByTeacherAndCourseType(onlineMusicGroupCourseInfo.getTeacherId(), CourseSchedule.CourseScheduleType.MUSIC_NETWORK.getCode());
|
|
|
+ if(Objects.isNull(teacherDefaultMusicGroupSalary)){
|
|
|
+ throw new BizException("请设置教师课酬");
|
|
|
+ }
|
|
|
BigDecimal teacherDefaultSalary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal("1");
|
|
|
BigDecimal studentSingleCourseCost=BigDecimal.ZERO;
|
|
|
for (CourseSchedule courseSchedule : courses) {
|
|
@@ -208,10 +241,61 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
|
|
|
teacherAttendanceDao.batchInsert(teacherAttendances);
|
|
|
|
|
|
- List<String> courseTimes = courses.stream().map(c -> DateUtil.dateToString(c.getStartClassTime(), "yyyy-MM-dd HH:mm:ss")).collect(Collectors.toList());
|
|
|
+ try {
|
|
|
+ courseScheduleService.checkNewCourseSchedulesWithoutMusicGroup(courses,false);
|
|
|
+ } catch (Exception e) {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ String errMessage=new String();
|
|
|
+ if(e.getMessage().indexOf("主教冲突")!=-1){
|
|
|
+ errMessage="抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。";
|
|
|
+ }else{
|
|
|
+ String courseName=e.getMessage().substring(e.getMessage().indexOf(")-")+2);
|
|
|
+ courseName = courseName.substring(0,courseName.indexOf("("));
|
|
|
+ errMessage="抱歉啦,当前所选时段组合,与您现有课程「";
|
|
|
+ errMessage+=courseName;
|
|
|
+ errMessage+="」时段冲突,请选择其他时段重试。";
|
|
|
+ }
|
|
|
+ throw new BizException(errMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ studentFee.setRemainNetworkClassTimes(studentFee.getRemainNetworkClassTimes()-1);
|
|
|
+ musicGroupStudentFeeDao.update(studentFee);
|
|
|
+
|
|
|
+ try{
|
|
|
+ List<String> cdstrs=new ArrayList<>();
|
|
|
+ for(int i=0;i<courses.size();i++){
|
|
|
+ cdstrs.add((i+1)+","+DateUtil.dateToString(courses.get(i).getStartClassTime(), "yyyy年MM月dd日 HH时mm分"));
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<Integer, String> userMap = new HashMap<>();
|
|
|
+ userMap.put(onlineMusicGroupCourseInfo.getStudentId(), onlineMusicGroupCourseInfo.getStudentId().toString());
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.MUSIC_NETWORK_CRATE_STUDENT,
|
|
|
+ userMap, null, 0, null, "STUDENT", student.getUsername(), musicGroup.getName(),
|
|
|
+ teacher.getRealName(), DateUtil.dateToString(courses.get(0).getStartClassTime(),"yyyy年MM月dd日 HH时mm分"));
|
|
|
+
|
|
|
+ Map<Integer, String> teacherMap = new HashMap<>();
|
|
|
+ teacherMap.put(onlineMusicGroupCourseInfo.getTeacherId(), onlineMusicGroupCourseInfo.getTeacherId().toString());
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.MUSIC_NETWORK_CRATE_TEACHER,
|
|
|
+ teacherMap, null, 0, null, "TEACHER", teacher.getRealName(), classGroup.getName(),
|
|
|
+ StringUtils.join(cdstrs, ","));
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ImGroupMember> imGroupMemberList = new ArrayList<>();
|
|
|
+ if(Objects.nonNull(musicGroup.getEducationalTeacherId())){
|
|
|
+ imGroupMemberList.add(new ImGroupMember(musicGroup.getEducationalTeacherId().toString()));
|
|
|
+ }
|
|
|
+ imGroupMemberList.add(new ImGroupMember(onlineMusicGroupCourseInfo.getStudentId().toString()));
|
|
|
+ imGroupMemberList.add(new ImGroupMember(onlineMusicGroupCourseInfo.getTeacherId().toString()));
|
|
|
+ ImGroupMember[] imGroupMembers = imGroupMemberList.toArray(new ImGroupMember[imGroupMemberList.size()]);
|
|
|
+ // 创建群组
|
|
|
+ imFeignService.groupCreate(new ImGroupModel(classGroup.getId().toString(), imGroupMembers, classGroup.getName()));
|
|
|
+
|
|
|
+ List<String> courseTimes = courses.stream().map(c -> DateUtil.dateToString(c.getStartClassTime(), "yyyy-MM-dd HH:mm")).collect(Collectors.toList());
|
|
|
|
|
|
Map<String, Object> result=new HashMap<>();
|
|
|
- result.put("courseTimes", StringUtils.join(courses,","));
|
|
|
+ result.put("courseTimes", StringUtils.join(courseTimes,","));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -294,7 +378,7 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map getTeacherFreeTimes(Integer studentId, Integer teacherId) {
|
|
|
+ public Map getTeacherFreeTimes(Integer studentId, Integer teacherId){
|
|
|
if (Objects.isNull(teacherId)) {
|
|
|
throw new BizException("请选择教师");
|
|
|
}
|
|
@@ -310,9 +394,8 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
throw new BizException("教师不存在");
|
|
|
}
|
|
|
Map result = new HashMap();
|
|
|
- Set<Integer> disableApplyWeekDay = new HashSet<>();
|
|
|
+ Set<Date> allTeacherFreeDates = new HashSet<>();
|
|
|
|
|
|
- //课程时长暂时与网管课共用
|
|
|
SysConfig practiceCourseMinutesConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_COURSE_MINUTES);
|
|
|
Integer practiceCourseMinutes = practiceCourseMinutesConfig.getParanValue(Integer.class);
|
|
|
|
|
@@ -323,67 +406,106 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
checkTeacherLeaveDate = false;
|
|
|
}
|
|
|
|
|
|
+ Set<Integer> disableApplyWeekNum = new HashSet<>();
|
|
|
+ Set<Integer> disableApplyWeekDay = new HashSet<>();
|
|
|
+
|
|
|
TeacherFreeTime teacherFreeTime = teacherFreeTimeDao.findTeacherFreeTime(teacherId);
|
|
|
JSONObject teacherFreeTimes=new JSONObject();
|
|
|
+ Integer maxTeacherCourses = null;
|
|
|
int holiday = 0;
|
|
|
if (Objects.nonNull(teacherFreeTime)) {
|
|
|
+ if (Objects.nonNull(teacherFreeTime.getTotalTimes())) {
|
|
|
+ maxTeacherCourses = teacherFreeTime.getTotalTimes();
|
|
|
+ }
|
|
|
if (Objects.nonNull(teacherFreeTime.getHoliday())) {
|
|
|
- holiday = teacherFreeTime.getHoliday();
|
|
|
+ holiday = DateUtil.normalWeekNumCalendarWeekNumMap.get(teacherFreeTime.getHoliday());
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(teacherFreeTime.getMonday())){
|
|
|
- teacherFreeTimes.put(String.valueOf(DayOfWeek.MONDAY.getValue()), JSON.parseArray(teacherFreeTime.getMonday()));
|
|
|
+ teacherFreeTimes.put(String.valueOf(Calendar.MONDAY), JSON.parseArray(teacherFreeTime.getMonday()));
|
|
|
}else{
|
|
|
- disableApplyWeekDay.add(DayOfWeek.MONDAY.getValue());
|
|
|
+ disableApplyWeekDay.add(Calendar.MONDAY);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(teacherFreeTime.getTuesday())){
|
|
|
- teacherFreeTimes.put(String.valueOf(DayOfWeek.TUESDAY.getValue()), JSON.parseArray(teacherFreeTime.getTuesday()));
|
|
|
+ teacherFreeTimes.put(String.valueOf(Calendar.TUESDAY), JSON.parseArray(teacherFreeTime.getTuesday()));
|
|
|
}else{
|
|
|
- disableApplyWeekDay.add(DayOfWeek.TUESDAY.getValue());
|
|
|
+ disableApplyWeekDay.add(Calendar.TUESDAY);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(teacherFreeTime.getWednesday())){
|
|
|
- teacherFreeTimes.put(String.valueOf(DayOfWeek.WEDNESDAY.getValue()), JSON.parseArray(teacherFreeTime.getWednesday()));
|
|
|
+ teacherFreeTimes.put(String.valueOf(Calendar.WEDNESDAY), JSON.parseArray(teacherFreeTime.getWednesday()));
|
|
|
}else{
|
|
|
- disableApplyWeekDay.add(DayOfWeek.WEDNESDAY.getValue());
|
|
|
+ disableApplyWeekDay.add(Calendar.WEDNESDAY);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(teacherFreeTime.getThursday())){
|
|
|
- teacherFreeTimes.put(String.valueOf(DayOfWeek.THURSDAY.getValue()), JSON.parseArray(teacherFreeTime.getThursday()));
|
|
|
+ teacherFreeTimes.put(String.valueOf(Calendar.THURSDAY), JSON.parseArray(teacherFreeTime.getThursday()));
|
|
|
}else{
|
|
|
- disableApplyWeekDay.add(DayOfWeek.THURSDAY.getValue());
|
|
|
+ disableApplyWeekDay.add(Calendar.THURSDAY);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(teacherFreeTime.getFriday())){
|
|
|
- teacherFreeTimes.put(String.valueOf(DayOfWeek.FRIDAY.getValue()), JSON.parseArray(teacherFreeTime.getFriday()));
|
|
|
+ teacherFreeTimes.put(String.valueOf(Calendar.FRIDAY), JSON.parseArray(teacherFreeTime.getFriday()));
|
|
|
}else{
|
|
|
- disableApplyWeekDay.add(DayOfWeek.FRIDAY.getValue());
|
|
|
+ disableApplyWeekDay.add(Calendar.FRIDAY);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(teacherFreeTime.getSaturday())){
|
|
|
- teacherFreeTimes.put(String.valueOf(DayOfWeek.SATURDAY.getValue()), JSON.parseArray(teacherFreeTime.getSaturday()));
|
|
|
+ teacherFreeTimes.put(String.valueOf(Calendar.SATURDAY), JSON.parseArray(teacherFreeTime.getSaturday()));
|
|
|
}else{
|
|
|
- disableApplyWeekDay.add(DayOfWeek.SATURDAY.getValue());
|
|
|
+ disableApplyWeekDay.add(Calendar.SATURDAY);
|
|
|
}
|
|
|
if(StringUtils.isNotBlank(teacherFreeTime.getSunday())){
|
|
|
- teacherFreeTimes.put(String.valueOf(DayOfWeek.SUNDAY.getValue()), JSON.parseArray(teacherFreeTime.getSunday()));
|
|
|
+ teacherFreeTimes.put(String.valueOf(Calendar.SUNDAY), JSON.parseArray(teacherFreeTime.getSunday()));
|
|
|
}else{
|
|
|
- disableApplyWeekDay.add(DayOfWeek.SUNDAY.getValue());
|
|
|
+ disableApplyWeekDay.add(Calendar.SUNDAY);
|
|
|
}
|
|
|
+ }else{
|
|
|
+ result.put("teacherFreeDays", new ArrayList<>());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- DateTimeFormatter ddtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- DateTimeFormatter ddf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
- DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm:ss");
|
|
|
- WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1);
|
|
|
- ZoneId zoneId = ZoneId.systemDefault();
|
|
|
-
|
|
|
- LocalDate startDay = LocalDate.now().plusDays(1);
|
|
|
- LocalDate endDay = startDay.plusDays(14);
|
|
|
-
|
|
|
- LocalDate monday = startDay.with(weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
|
|
|
- LocalDate sunday = endDay.with(weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
|
|
|
-
|
|
|
-
|
|
|
- Map<Integer, List<String>> weekNumApplyTimesMap = eduPracticeGroupService.getEnableApplyDatesWithWeek(monday.getDayOfWeek().getValue());
|
|
|
- List<CourseSchedule> allTeacherCourses = courseScheduleDao.findTeacherCoursesWithDateRange(teacherId, Date.from(startDay.atStartOfDay(zoneId).toInstant()), Date.from(endDay.atStartOfDay(zoneId).toInstant()));
|
|
|
+ Date now = new Date();
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setFirstDayOfWeek(Calendar.MONDAY);
|
|
|
+ calendar.setTime(now);
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
+ calendar.set(Calendar.MINUTE, 0);
|
|
|
+ calendar.set(Calendar.SECOND, 0);
|
|
|
+ calendar.set(Calendar.MILLISECOND, 0);
|
|
|
+ calendar.add(Calendar.DATE, 1);
|
|
|
+ Date applyStartDate = DateUtil.addDays(calendar.getTime(), 1);
|
|
|
+ Date applyEndDate = DateUtil.addDays(applyStartDate, 14);
|
|
|
+ Date firstMonday = DateUtil.getWeekDayWithDate(applyStartDate, Calendar.MONDAY);
|
|
|
+ Date secondSunday = DateUtil.getWeekDayWithDate(applyEndDate, Calendar.SUNDAY);
|
|
|
+
|
|
|
+ List<Date> enableApplyDates = practiceGroupService.getEnableApplyDates(applyStartDate, applyEndDate);
|
|
|
+ List<CourseSchedule> allTeacherCourses = courseScheduleDao.findTeacherCoursesWithDateRange(teacherId, firstMonday, secondSunday);
|
|
|
allTeacherCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
|
|
|
+ List<CourseSchedule> applyDateRangeCourses = new ArrayList<>();
|
|
|
+ Calendar courseCalendar = Calendar.getInstance();
|
|
|
+ courseCalendar.setFirstDayOfWeek(Calendar.MONDAY);
|
|
|
+ int courseWeekNum = 0;
|
|
|
+ int practiceCourseNum = 0;
|
|
|
+ for (int i = 0; i < allTeacherCourses.size(); i++) {
|
|
|
+ CourseSchedule teacherCourse = allTeacherCourses.get(i);
|
|
|
+ if ((!teacherCourse.getClassDate().before(applyStartDate))
|
|
|
+ && (teacherCourse.getClassDate().before(applyEndDate) || DateUtil.isSameDay(teacherCourse.getClassDate(), applyEndDate))) {
|
|
|
+ applyDateRangeCourses.add(teacherCourse);
|
|
|
+ }
|
|
|
+ courseCalendar.setTime(teacherCourse.getClassDate());
|
|
|
+ if (i == 0 && teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
|
|
|
+ practiceCourseNum += 1;
|
|
|
+ courseWeekNum = courseCalendar.get(Calendar.WEEK_OF_YEAR);
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(maxTeacherCourses) && practiceCourseNum >= maxTeacherCourses) {
|
|
|
+ disableApplyWeekNum.add(courseWeekNum);
|
|
|
+ }
|
|
|
+ if (courseCalendar.get(Calendar.WEEK_OF_YEAR) != courseWeekNum) {
|
|
|
+ courseWeekNum = courseCalendar.get(Calendar.WEEK_OF_YEAR);
|
|
|
+ practiceCourseNum = 0;
|
|
|
+ }
|
|
|
+ if (teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
|
|
|
+ practiceCourseNum += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
JSONObject teacherLeaveData = null;
|
|
|
if (checkTeacherLeaveDate) {
|
|
|
teacherLeaveData = allTeacherLeaveData.getJSONObject(teacherId.toString());
|
|
@@ -393,78 +515,53 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
checkTeacherLeaveDate = false;
|
|
|
}
|
|
|
|
|
|
- weekNumApplyTimesMap.remove(holiday);
|
|
|
-
|
|
|
- if (teacherId == 100473) {
|
|
|
- List<String> timeStrs = weekNumApplyTimesMap.get(DateUtil.calendarWeekNumNormalWeekNumMap.get(Calendar.MONDAY));
|
|
|
- LocalTime noonStartTime = LocalTime.parse("11:30:00", dtf);
|
|
|
- LocalTime noonEndTime = LocalTime.parse("14:30:00", dtf);
|
|
|
- LocalTime nightStartTime = LocalTime.parse("20:30:00", dtf);
|
|
|
- LocalTime defaultApplyTime;
|
|
|
- Iterator<String> iterator = timeStrs.iterator();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- defaultApplyTime = LocalTime.parse(iterator.next(), dtf);
|
|
|
- LocalTime defaultApplyEndTime = defaultApplyTime.plusMinutes(practiceCourseMinutes);
|
|
|
- if (defaultApplyTime.compareTo(noonStartTime) <= 0
|
|
|
- && defaultApplyEndTime.compareTo(noonEndTime) >= 0) {
|
|
|
- iterator.remove();
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (defaultApplyEndTime.compareTo(nightStartTime) < 0) {
|
|
|
- iterator.remove();
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- weekNumApplyTimesMap.remove(DateUtil.calendarWeekNumNormalWeekNumMap.get(Calendar.SATURDAY));
|
|
|
- weekNumApplyTimesMap.put(DateUtil.calendarWeekNumNormalWeekNumMap.get(Calendar.MONDAY), timeStrs);
|
|
|
- weekNumApplyTimesMap.put(DateUtil.calendarWeekNumNormalWeekNumMap.get(Calendar.SUNDAY), timeStrs);
|
|
|
- } else if (checkTeacherLeaveDate) {
|
|
|
- for (String dateStr : teacherLeaveData.keySet()) {
|
|
|
- LocalDate parse = LocalDate.parse(dateStr, ddf);
|
|
|
- LocalDate tempDate = LocalDate.parse(dateStr, ddf);
|
|
|
- if (tempDate.compareTo(startDay)<0
|
|
|
- ||tempDate.compareTo(tempDate)>=0){
|
|
|
- continue;
|
|
|
- }
|
|
|
- List<String> applyTimeStrs = weekNumApplyTimesMap.get(parse.getDayOfWeek().getValue());
|
|
|
- if(CollectionUtils.isEmpty(applyTimeStrs)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- Iterator<String> iterator = applyTimeStrs.iterator();
|
|
|
- JSONObject leaveDateData = teacherLeaveData.getJSONObject(dateStr);
|
|
|
- LocalTime leaveStartTime = LocalDateTime.parse(leaveDateData.getString("leave_start_time"), ddtf).toLocalTime();
|
|
|
- LocalTime leaveEndTime = LocalDateTime.parse(leaveDateData.getString("leave_end_time"), ddtf).toLocalTime();
|
|
|
- LocalTime defaultApplyTime;
|
|
|
- while (iterator.hasNext()) {
|
|
|
- defaultApplyTime = LocalTime.parse(iterator.next(), dtf);
|
|
|
- LocalTime defaultApplyEndTime = defaultApplyTime.plusMinutes(practiceCourseMinutes);
|
|
|
- if (defaultApplyTime.compareTo(leaveEndTime) <= 0
|
|
|
- && defaultApplyEndTime.compareTo(leaveStartTime) >= 0) {
|
|
|
- iterator.remove();
|
|
|
+ if (CollectionUtils.isEmpty(applyDateRangeCourses)) {
|
|
|
+ for (Date enableApplyDate : enableApplyDates) {
|
|
|
+ Date enableApplyDateCourseEndTime = DateUtil.addMinutes(enableApplyDate, practiceCourseMinutes);
|
|
|
+ if (teacherId == 100473) {
|
|
|
+ checkTeacherLeaveDate = false;
|
|
|
+ Calendar tempCalendar = Calendar.getInstance();
|
|
|
+ tempCalendar.setFirstDayOfWeek(Calendar.MONDAY);
|
|
|
+ tempCalendar.setTime(enableApplyDate);
|
|
|
+ if (tempCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
|
|
|
+ || tempCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
|
|
|
+ String date_str = DateUtil.dateToString(enableApplyDate, "yyyy-MM-dd");
|
|
|
+ Date date1 = DateUtil.stringToDate(date_str + " 11:30:00");
|
|
|
+ Date date2 = DateUtil.stringToDate(date_str + " 14:30:00");
|
|
|
+ Date date3 = DateUtil.stringToDate(date_str + " 20:30:00");
|
|
|
+ if (enableApplyDate.before(date2)
|
|
|
+ && enableApplyDateCourseEndTime.after(date1)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (date3.before(enableApplyDateCourseEndTime)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tempCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- if(!CollectionUtils.isEmpty(applyTimeStrs)){
|
|
|
- weekNumApplyTimesMap.put(parse.getDayOfWeek().getValue(), applyTimeStrs);
|
|
|
- }else{
|
|
|
- weekNumApplyTimesMap.remove(parse.getDayOfWeek().getValue());
|
|
|
+ if (checkTeacherLeaveDate) {
|
|
|
+ String dateStr = DateUtil.dateToString(enableApplyDate, "yyyy-MM-dd");
|
|
|
+ JSONObject leaveDateData = teacherLeaveData.getJSONObject(dateStr);
|
|
|
+ if (Objects.nonNull(leaveDateData)) {
|
|
|
+ Date leaveStartTime = leaveDateData.getDate("leave_start_time");
|
|
|
+ Date leaveEndTime = leaveDateData.getDate("leave_end_time");
|
|
|
+ if (enableApplyDateCourseEndTime.after(leaveStartTime)
|
|
|
+ && enableApplyDate.before(leaveEndTime)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Iterator<Integer> weekNumApplyTimeIterator = weekNumApplyTimesMap.keySet().iterator();
|
|
|
- while (weekNumApplyTimeIterator.hasNext()) {
|
|
|
- Integer weekNum=weekNumApplyTimeIterator.next();
|
|
|
- JSONArray teacherWeekDayFreeTimes = teacherFreeTimes.getJSONArray(String.valueOf(weekNum));
|
|
|
- if(Objects.nonNull(teacherWeekDayFreeTimes)){
|
|
|
- List<String> applyTimeStrs = weekNumApplyTimesMap.get(weekNum);
|
|
|
- if(CollectionUtils.isEmpty(applyTimeStrs)){
|
|
|
+ calendar.setTime(enableApplyDate);
|
|
|
+ int dayOfWeek=calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
+ if(disableApplyWeekDay.contains(dayOfWeek)){
|
|
|
continue;
|
|
|
}
|
|
|
- Iterator<String> iterator = applyTimeStrs.iterator();
|
|
|
- while (iterator.hasNext()) {
|
|
|
- LocalTime enableApplyStartTime=LocalTime.parse(iterator.next(), dtf);
|
|
|
- LocalTime enableApplyEndTime=enableApplyStartTime.plusMinutes(practiceCourseMinutes);
|
|
|
+ JSONArray teacherWeekDayFreeTimes = teacherFreeTimes.getJSONArray(String.valueOf(dayOfWeek));
|
|
|
+ if(Objects.nonNull(teacherWeekDayFreeTimes)){
|
|
|
+ LocalTime enableApplyStartTime=LocalDateTime.ofInstant(enableApplyDate.toInstant(),DateUtil.zoneId).toLocalTime();
|
|
|
+ LocalTime enableApplyEndTime=LocalDateTime.ofInstant(enableApplyDateCourseEndTime.toInstant(),DateUtil.zoneId).toLocalTime();
|
|
|
boolean isInclude=false;
|
|
|
for (Object teacherWeekDayFreeTimeObject : teacherWeekDayFreeTimes) {
|
|
|
JSONObject teacherWeekDayFreeTime=JSONObject.parseObject(teacherWeekDayFreeTimeObject.toString());
|
|
@@ -477,49 +574,160 @@ public class OnlineMusicGroupServiceImpl implements OnlineMusicGroupService {
|
|
|
}
|
|
|
}
|
|
|
if(!isInclude){
|
|
|
- iterator.remove();
|
|
|
+ continue;
|
|
|
}
|
|
|
}
|
|
|
- if(CollectionUtils.isEmpty(applyTimeStrs)){
|
|
|
- weekNumApplyTimeIterator.remove();
|
|
|
- }else{
|
|
|
- weekNumApplyTimesMap.put(weekNum,applyTimeStrs);
|
|
|
+ if (dayOfWeek != holiday) {
|
|
|
+ allTeacherFreeDates.add(enableApplyDate);
|
|
|
}
|
|
|
- }else{
|
|
|
- weekNumApplyTimeIterator.remove();
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if (CollectionUtils.isEmpty(allTeacherCourses)) {
|
|
|
- result.put("teacherFreeDays", weekNumApplyTimesMap);
|
|
|
+ if (!CollectionUtils.isEmpty(allTeacherFreeDates)) {
|
|
|
+ List<Date> tempDates = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isEmpty(tempDates)) {
|
|
|
+ tempDates = new ArrayList<>(allTeacherFreeDates);
|
|
|
+ }
|
|
|
+ tempDates.sort(Comparator.comparing(Date::getTime));
|
|
|
+ Set<String> days = tempDates.stream()
|
|
|
+ .map(date -> DateUtil.dateToString(date, "yyyy-MM-dd")).collect(Collectors.toSet());
|
|
|
+ List<Date> tempDays = days.stream().map(dateStr -> DateUtil.stringToDate(dateStr, "yyyy-MM-dd")).collect(Collectors.toList());
|
|
|
+ tempDays.sort(Comparator.comparing(Date::getTime));
|
|
|
+ result.put("teacherFreeDays", tempDays.stream().map(day -> DateUtil.dateToString(day, "yyyy-MM-dd")).collect(Collectors.toList()));
|
|
|
+ result.put("teacherFreeDates", tempDates);
|
|
|
+ } else {
|
|
|
+ result.put("teacherFreeDays", new ArrayList<>());
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- for (CourseSchedule teacherCourse : allTeacherCourses) {
|
|
|
- LocalDateTime courseStartTime = LocalDateTime.ofInstant(teacherCourse.getStartClassTime().toInstant(), zoneId);
|
|
|
- LocalDateTime courseEndTime = LocalDateTime.ofInstant(teacherCourse.getEndClassTime().toInstant(), zoneId);
|
|
|
- List<String> applyTimeStrs = weekNumApplyTimesMap.get(courseStartTime.getDayOfWeek().getValue());
|
|
|
- if (CollectionUtils.isEmpty(applyTimeStrs)) {
|
|
|
+ List<Date> tempEnableApplyDates = new ArrayList<>();
|
|
|
+ for (Date enableApplyDate : enableApplyDates) {
|
|
|
+ Date enableApplyDateCourseEndTime = DateUtil.addMinutes(enableApplyDate, practiceCourseMinutes);
|
|
|
+
|
|
|
+ if (teacherId == 100473) {
|
|
|
+ checkTeacherLeaveDate = false;
|
|
|
+ Calendar tempCalendar = Calendar.getInstance();
|
|
|
+ tempCalendar.setFirstDayOfWeek(Calendar.MONDAY);
|
|
|
+ tempCalendar.setTime(enableApplyDate);
|
|
|
+ if (tempCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
|
|
|
+ || tempCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
|
|
|
+ String date_str = DateUtil.dateToString(enableApplyDate, "yyyy-MM-dd");
|
|
|
+ Date date1 = DateUtil.stringToDate(date_str + " 11:30:00");
|
|
|
+ Date date2 = DateUtil.stringToDate(date_str + " 14:30:00");
|
|
|
+ Date date3 = DateUtil.stringToDate(date_str + " 20:30:00");
|
|
|
+ if (enableApplyDate.before(date2)
|
|
|
+ && enableApplyDateCourseEndTime.after(date1)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (date3.before(enableApplyDateCourseEndTime)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (tempCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (checkTeacherLeaveDate) {
|
|
|
+ String dateStr = DateUtil.dateToString(enableApplyDate, "yyyy-MM-dd");
|
|
|
+ JSONObject leaveDateData = teacherLeaveData.getJSONObject(dateStr);
|
|
|
+ if (Objects.nonNull(leaveDateData)) {
|
|
|
+ Date leaveStartTime = leaveDateData.getDate("leave_start_time");
|
|
|
+ Date leaveEndTime = leaveDateData.getDate("leave_end_time");
|
|
|
+ if (enableApplyDateCourseEndTime.after(leaveStartTime)
|
|
|
+ && enableApplyDate.before(leaveEndTime)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ calendar.setTime(enableApplyDate);
|
|
|
+
|
|
|
+ int dayOfWeek=calendar.get(Calendar.DAY_OF_WEEK);
|
|
|
+ if(disableApplyWeekDay.contains(dayOfWeek)){
|
|
|
continue;
|
|
|
}
|
|
|
- Iterator<String> iterator = applyTimeStrs.iterator();
|
|
|
- LocalTime defaultApplyTime;
|
|
|
- while (iterator.hasNext()) {
|
|
|
- defaultApplyTime = LocalTime.parse(iterator.next(), dtf);
|
|
|
- LocalTime defaultApplyEndTime = defaultApplyTime.plusMinutes(practiceCourseMinutes);
|
|
|
- if (defaultApplyTime.compareTo(courseEndTime.toLocalTime()) <= 0
|
|
|
- && defaultApplyEndTime.compareTo(courseStartTime.toLocalTime()) >= 0) {
|
|
|
- iterator.remove();
|
|
|
+ JSONArray teacherWeekDayFreeTimes = teacherFreeTimes.getJSONArray(String.valueOf(dayOfWeek));
|
|
|
+ if(Objects.nonNull(teacherWeekDayFreeTimes)){
|
|
|
+ LocalTime enableApplyStartTime=LocalDateTime.ofInstant(enableApplyDate.toInstant(),DateUtil.zoneId).toLocalTime();
|
|
|
+ LocalTime enableApplyEndTime=LocalDateTime.ofInstant(enableApplyDateCourseEndTime.toInstant(),DateUtil.zoneId).toLocalTime();
|
|
|
+ boolean isInclude=false;
|
|
|
+ for (Object teacherWeekDayFreeTimeObject : teacherWeekDayFreeTimes) {
|
|
|
+ JSONObject teacherWeekDayFreeTime=JSONObject.parseObject(teacherWeekDayFreeTimeObject.toString());
|
|
|
+ LocalTime teacherFreeStartTime=LocalTime.parse(teacherWeekDayFreeTime.getString("startTime"),DateUtil.timeFormatter);
|
|
|
+ LocalTime teacherFreeEndTime=LocalTime.parse(teacherWeekDayFreeTime.getString("endTime"),DateUtil.timeFormatter);
|
|
|
+ if(enableApplyEndTime.compareTo(teacherFreeEndTime)<=0
|
|
|
+ &&enableApplyStartTime.compareTo(teacherFreeStartTime)>=0){
|
|
|
+ isInclude=true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!isInclude){
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- if(CollectionUtils.isEmpty(applyTimeStrs)){
|
|
|
- weekNumApplyTimesMap.remove(courseStartTime.getDayOfWeek().getValue());
|
|
|
- }else{
|
|
|
- weekNumApplyTimesMap.put(courseStartTime.getDayOfWeek().getValue(), applyTimeStrs);
|
|
|
+
|
|
|
+ if (dayOfWeek == holiday) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!disableApplyWeekNum.contains(calendar.get(Calendar.WEEK_OF_YEAR))) {
|
|
|
+ tempEnableApplyDates.add(enableApplyDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ applyDateRangeCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
+ for (int j = 0; j < applyDateRangeCourses.size(); j++) {
|
|
|
+ CourseSchedule preCourseSchedule = applyDateRangeCourses.get(j);
|
|
|
+ CourseSchedule backCourseSchedule = j >= applyDateRangeCourses.size() - 1 ? preCourseSchedule : applyDateRangeCourses.get(j + 1);
|
|
|
+ if (preCourseSchedule.getEndClassTime().after(backCourseSchedule.getEndClassTime())) {
|
|
|
+ backCourseSchedule.setEndClassTime(preCourseSchedule.getEndClassTime());
|
|
|
+ }
|
|
|
+ if (j == 0) {
|
|
|
+ for (Date enableApplyDate : tempEnableApplyDates) {
|
|
|
+ Date enableApplyDateCourseEndTime = DateUtil.addMinutes(enableApplyDate, practiceCourseMinutes);
|
|
|
+ if (!enableApplyDateCourseEndTime.after(preCourseSchedule.getStartClassTime())) {
|
|
|
+ allTeacherFreeDates.add(enableApplyDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (j == applyDateRangeCourses.size() - 1) {
|
|
|
+ for (Date enableApplyDate : tempEnableApplyDates) {
|
|
|
+ if (!enableApplyDate.before(backCourseSchedule.getEndClassTime())) {
|
|
|
+ allTeacherFreeDates.add(enableApplyDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (j >= applyDateRangeCourses.size() - 1) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ for (Date enableApplyDate : tempEnableApplyDates) {
|
|
|
+ Date enableApplyDateCourseEndTime = DateUtil.addMinutes(enableApplyDate, practiceCourseMinutes);
|
|
|
+ if (!enableApplyDate.before(preCourseSchedule.getEndClassTime())
|
|
|
+ && !enableApplyDateCourseEndTime.after(backCourseSchedule.getStartClassTime())) {
|
|
|
+ allTeacherFreeDates.add(enableApplyDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(allTeacherFreeDates)) {
|
|
|
+ List<Date> tempDates = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isEmpty(tempDates)) {
|
|
|
+ tempDates = new ArrayList<>(allTeacherFreeDates);
|
|
|
}
|
|
|
+ tempDates.sort(Comparator.comparing(Date::getTime));
|
|
|
+ Map<String, List<String>> rt=new HashMap<>();
|
|
|
+ for (Date tempDate : tempDates) {
|
|
|
+ String dateStr = DateUtil.dateToString(tempDate, "yyyy-MM-dd");
|
|
|
+ String timeStr = DateUtil.dateToString(tempDate, "HH:mm:ss");
|
|
|
+ if(!rt.containsKey(dateStr)){
|
|
|
+ rt.put(dateStr, new ArrayList<>());
|
|
|
+ }
|
|
|
+ rt.get(dateStr).add(timeStr);
|
|
|
+ }
|
|
|
+ Set<String> days = tempDates.stream()
|
|
|
+ .map(date -> DateUtil.dateToString(date, "yyyy-MM-dd")).collect(Collectors.toSet());
|
|
|
+ List<Date> tempDays = days.stream().map(dateStr -> DateUtil.stringToDate(dateStr, "yyyy-MM-dd")).collect(Collectors.toList());
|
|
|
+ tempDays.sort(Comparator.comparing(Date::getTime));
|
|
|
+
|
|
|
+ result.put("teacherFreeDays", rt);
|
|
|
}
|
|
|
- result.put("teacherFreeDays", weekNumApplyTimesMap);
|
|
|
return result;
|
|
|
}
|
|
|
}
|