|  | @@ -8,15 +8,15 @@ 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.dal.page.PracticeGroupQueryInfo;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.PracticeGroupService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.SysConfigService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.SysMessageService;
 | 
	
		
			
				|  |  | -import com.ym.mec.biz.service.TeacherService;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.service.*;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.controller.BaseController;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
		
			
				|  |  |  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.common.page.PageInfo;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.service.IdGeneratorService;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.im.ImFeignService;
 | 
	
		
			
				|  |  |  import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 | 
	
	
		
			
				|  | @@ -24,6 +24,7 @@ import com.ym.mec.util.collection.MapUtil;
 | 
	
		
			
				|  |  |  import com.ym.mec.util.date.DateUtil;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  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;
 | 
	
	
		
			
				|  | @@ -31,6 +32,9 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
 | 
	
		
			
				|  |  |  import org.springframework.util.CollectionUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  | +import java.time.*;
 | 
	
		
			
				|  |  | +import java.time.format.DateTimeFormatter;
 | 
	
		
			
				|  |  | +import java.time.temporal.WeekFields;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -79,6 +83,24 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |      private ImFeignService imFeignService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private TeacherFreeTimeDao teacherFreeTimeDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private CourseScheduleService courseScheduleService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private IdGeneratorService idGeneratorService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private PayService payService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private StudentPaymentOrderService studentPaymentOrderService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysUserCashAccountService sysUserCashAccountService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysUserCashAccountDetailService sysUserCashAccountDetailService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysConfigDao sysConfigDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private StudentPaymentOrderDao studentPaymentOrderDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private GroupService groupService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private static Map<Integer, Map<Integer, List<Integer>>> schoolSubjectTeachersMap;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -92,7 +114,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private static Date activityStartDate, activityEndDate, applyStartDay, courseExpireDate;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private static List<String> applyDayTimes=new ArrayList<>();
 | 
	
		
			
				|  |  | +    private static List<String> applyDayTimes = new ArrayList<>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      static {
 | 
	
		
			
				|  |  |          applyStartDay = DateUtil.stringToDate("2020-02-08 00:00:00");
 | 
	
	
		
			
				|  | @@ -735,28 +757,28 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<CourseSchedule> userCourses = courseScheduleDao.findUserCourses(userId, allTeacherIds);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        if(!CollectionUtils.isEmpty(userCourses)){
 | 
	
		
			
				|  |  | +        if (!CollectionUtils.isEmpty(userCourses)) {
 | 
	
		
			
				|  |  |              Map<CourseSchedule.CourseScheduleType, List<CourseSchedule>> courseTypeCourseMap = userCourses.stream().collect(Collectors.groupingBy(CourseSchedule::getType));
 | 
	
		
			
				|  |  | -            List<CourseSchedule> vipCourses=courseTypeCourseMap.get(CourseSchedule.CourseScheduleType.VIP);
 | 
	
		
			
				|  |  | -            if(!CollectionUtils.isEmpty(vipCourses)){
 | 
	
		
			
				|  |  | +            List<CourseSchedule> vipCourses = courseTypeCourseMap.get(CourseSchedule.CourseScheduleType.VIP);
 | 
	
		
			
				|  |  | +            if (!CollectionUtils.isEmpty(vipCourses)) {
 | 
	
		
			
				|  |  |                  for (CourseSchedule vipCourse : vipCourses) {
 | 
	
		
			
				|  |  | -                    if(!includeTeacherIds.contains(vipCourse.getTeacherId())){
 | 
	
		
			
				|  |  | +                    if (!includeTeacherIds.contains(vipCourse.getTeacherId())) {
 | 
	
		
			
				|  |  |                          includeTeacherIds.add(vipCourse.getTeacherId());
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            List<CourseSchedule> singleCourses=courseTypeCourseMap.get(CourseSchedule.CourseScheduleType.SINGLE);
 | 
	
		
			
				|  |  | -            if(!CollectionUtils.isEmpty(singleCourses)){
 | 
	
		
			
				|  |  | +            List<CourseSchedule> singleCourses = courseTypeCourseMap.get(CourseSchedule.CourseScheduleType.SINGLE);
 | 
	
		
			
				|  |  | +            if (!CollectionUtils.isEmpty(singleCourses)) {
 | 
	
		
			
				|  |  |                  for (CourseSchedule singleCourse : singleCourses) {
 | 
	
		
			
				|  |  | -                    if(!includeTeacherIds.contains(singleCourse.getTeacherId())){
 | 
	
		
			
				|  |  | +                    if (!includeTeacherIds.contains(singleCourse.getTeacherId())) {
 | 
	
		
			
				|  |  |                          includeTeacherIds.add(singleCourse.getTeacherId());
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            List<CourseSchedule> highCourses=courseTypeCourseMap.get(CourseSchedule.CourseScheduleType.HIGH);
 | 
	
		
			
				|  |  | -            if(!CollectionUtils.isEmpty(highCourses)){
 | 
	
		
			
				|  |  | +            List<CourseSchedule> highCourses = courseTypeCourseMap.get(CourseSchedule.CourseScheduleType.HIGH);
 | 
	
		
			
				|  |  | +            if (!CollectionUtils.isEmpty(highCourses)) {
 | 
	
		
			
				|  |  |                  for (CourseSchedule highCourse : highCourses) {
 | 
	
		
			
				|  |  | -                    if(!includeTeacherIds.contains(highCourse.getTeacherId())){
 | 
	
		
			
				|  |  | +                    if (!includeTeacherIds.contains(highCourse.getTeacherId())) {
 | 
	
		
			
				|  |  |                          includeTeacherIds.add(highCourse.getTeacherId());
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -765,7 +787,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          for (ExtendTeacherBasicDto organAndSubjectTeacher : organAndSubjectTeachers) {
 | 
	
		
			
				|  |  |              if (!includeTeacherIds.contains(organAndSubjectTeacher.getId())
 | 
	
		
			
				|  |  | -                &&1 == organAndSubjectTeacher.getIsSupportExtraPracticeLesson()) {
 | 
	
		
			
				|  |  | +                    && 1 == organAndSubjectTeacher.getIsSupportExtraPracticeLesson()) {
 | 
	
		
			
				|  |  |                  includeTeacherIds.add(organAndSubjectTeacher.getId());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -774,11 +796,11 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |              return new ArrayList<>();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        List<SimpleUserDto> userInfos=new ArrayList<>();
 | 
	
		
			
				|  |  | -        Map<Integer, ExtendTeacherBasicDto> idTeacherMap = organAndSubjectTeachers.stream().collect(Collectors.toMap(ExtendTeacherBasicDto::getId,teacher->teacher));
 | 
	
		
			
				|  |  | +        List<SimpleUserDto> userInfos = new ArrayList<>();
 | 
	
		
			
				|  |  | +        Map<Integer, ExtendTeacherBasicDto> idTeacherMap = organAndSubjectTeachers.stream().collect(Collectors.toMap(ExtendTeacherBasicDto::getId, teacher -> teacher));
 | 
	
		
			
				|  |  |          for (Integer includeTeacherId : includeTeacherIds) {
 | 
	
		
			
				|  |  |              ExtendTeacherBasicDto teacher = idTeacherMap.get(includeTeacherId);
 | 
	
		
			
				|  |  | -            userInfos.add(new SimpleUserDto(includeTeacherId,teacher.getRealName()));
 | 
	
		
			
				|  |  | +            userInfos.add(new SimpleUserDto(includeTeacherId, teacher.getRealName()));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return userInfos;
 | 
	
	
		
			
				|  | @@ -815,15 +837,15 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Set<Integer> disableApplyWeekNum = new HashSet<>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        TeacherFreeTime teacherFreeTime=teacherFreeTimeDao.findTeacherFreeTime(teacherId);
 | 
	
		
			
				|  |  | -        Integer maxTeacherCourses=null;
 | 
	
		
			
				|  |  | -        int holiday=0;
 | 
	
		
			
				|  |  | -        if(Objects.nonNull(teacherFreeTime)){
 | 
	
		
			
				|  |  | -            if(Objects.nonNull(teacherFreeTime.getTotalTimes())){
 | 
	
		
			
				|  |  | -                maxTeacherCourses=teacherFreeTime.getTotalTimes();
 | 
	
		
			
				|  |  | +        TeacherFreeTime teacherFreeTime = teacherFreeTimeDao.findTeacherFreeTime(teacherId);
 | 
	
		
			
				|  |  | +        Integer maxTeacherCourses = null;
 | 
	
		
			
				|  |  | +        int holiday = 0;
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(teacherFreeTime)) {
 | 
	
		
			
				|  |  | +            if (Objects.nonNull(teacherFreeTime.getTotalTimes())) {
 | 
	
		
			
				|  |  | +                maxTeacherCourses = teacherFreeTime.getTotalTimes();
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if(Objects.nonNull(teacherFreeTime.getHoliday())){
 | 
	
		
			
				|  |  | -                holiday=DateUtil.normalWeekNumCalendarWeekNumMap.get(teacherFreeTime.getHoliday());
 | 
	
		
			
				|  |  | +            if (Objects.nonNull(teacherFreeTime.getHoliday())) {
 | 
	
		
			
				|  |  | +                holiday = DateUtil.normalWeekNumCalendarWeekNumMap.get(teacherFreeTime.getHoliday());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -841,15 +863,15 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          Date firstMonday = DateUtil.getWeekDayWithDate(applyStartDate, Calendar.MONDAY);
 | 
	
		
			
				|  |  |          Date secondSunday = DateUtil.getWeekDayWithDate(applyEndDate, Calendar.SUNDAY);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        Date yesterday=null;
 | 
	
		
			
				|  |  | -        Date tomorrow=null;
 | 
	
		
			
				|  |  | -        if(Objects.nonNull(firstClassTime)){
 | 
	
		
			
				|  |  | -            Calendar tempCalendar=Calendar.getInstance();
 | 
	
		
			
				|  |  | +        Date yesterday = null;
 | 
	
		
			
				|  |  | +        Date tomorrow = null;
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(firstClassTime)) {
 | 
	
		
			
				|  |  | +            Calendar tempCalendar = Calendar.getInstance();
 | 
	
		
			
				|  |  |              tempCalendar.setTime(firstClassTime);
 | 
	
		
			
				|  |  | -            tempCalendar.add(Calendar.DATE,-1);
 | 
	
		
			
				|  |  | -            yesterday=tempCalendar.getTime();
 | 
	
		
			
				|  |  | -            tempCalendar.add(Calendar.DATE,2);
 | 
	
		
			
				|  |  | -            tomorrow=tempCalendar.getTime();
 | 
	
		
			
				|  |  | +            tempCalendar.add(Calendar.DATE, -1);
 | 
	
		
			
				|  |  | +            yesterday = tempCalendar.getTime();
 | 
	
		
			
				|  |  | +            tempCalendar.add(Calendar.DATE, 2);
 | 
	
		
			
				|  |  | +            tomorrow = tempCalendar.getTime();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<Date> enableApplyDates = getEnableApplyDates(applyStartDate, applyEndDate);
 | 
	
	
		
			
				|  | @@ -868,11 +890,11 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |                  applyDateRangeCourses.add(teacherCourse);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              courseCalendar.setTime(teacherCourse.getClassDate());
 | 
	
		
			
				|  |  | -            if (i==0&&teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
 | 
	
		
			
				|  |  | -                practiceCourseNum+=1;
 | 
	
		
			
				|  |  | +            if (i == 0 && teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
 | 
	
		
			
				|  |  | +                practiceCourseNum += 1;
 | 
	
		
			
				|  |  |                  courseWeekNum = courseCalendar.get(Calendar.WEEK_OF_YEAR);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if(Objects.nonNull(maxTeacherCourses)&&practiceCourseNum>=maxTeacherCourses){
 | 
	
		
			
				|  |  | +            if (Objects.nonNull(maxTeacherCourses) && practiceCourseNum >= maxTeacherCourses) {
 | 
	
		
			
				|  |  |                  disableApplyWeekNum.add(courseWeekNum);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              if (courseCalendar.get(Calendar.WEEK_OF_YEAR) != courseWeekNum) {
 | 
	
	
		
			
				|  | @@ -880,7 +902,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |                  practiceCourseNum = 0;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              if (teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
 | 
	
		
			
				|  |  | -                practiceCourseNum+=1;
 | 
	
		
			
				|  |  | +                practiceCourseNum += 1;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -896,13 +918,13 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          if (CollectionUtils.isEmpty(applyDateRangeCourses)) {
 | 
	
		
			
				|  |  |              for (Date enableApplyDate : enableApplyDates) {
 | 
	
		
			
				|  |  |                  if (Objects.nonNull(firstClassTime)) {
 | 
	
		
			
				|  |  | -                    if(DateUtil.isSameDay(enableApplyDate, firstClassTime)){
 | 
	
		
			
				|  |  | +                    if (DateUtil.isSameDay(enableApplyDate, firstClassTime)) {
 | 
	
		
			
				|  |  |                          continue;
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    if(DateUtil.isSameDay(enableApplyDate, tomorrow)){
 | 
	
		
			
				|  |  | +                    if (DateUtil.isSameDay(enableApplyDate, tomorrow)) {
 | 
	
		
			
				|  |  |                          continue;
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    if(DateUtil.isSameDay(enableApplyDate, yesterday)){
 | 
	
		
			
				|  |  | +                    if (DateUtil.isSameDay(enableApplyDate, yesterday)) {
 | 
	
		
			
				|  |  |                          continue;
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -943,43 +965,43 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  calendar.setTime(enableApplyDate);
 | 
	
		
			
				|  |  | -                if (calendar.get(Calendar.DAY_OF_WEEK)!=holiday) {
 | 
	
		
			
				|  |  | +                if (calendar.get(Calendar.DAY_OF_WEEK) != holiday) {
 | 
	
		
			
				|  |  |                      allTeacherFreeDates.add(enableApplyDate);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              if (!CollectionUtils.isEmpty(allTeacherFreeDates)) {
 | 
	
		
			
				|  |  | -                List<Date> tempDates=new ArrayList<>();
 | 
	
		
			
				|  |  | -                if(Objects.nonNull(firstClassTime)){
 | 
	
		
			
				|  |  | +                List<Date> tempDates = new ArrayList<>();
 | 
	
		
			
				|  |  | +                if (Objects.nonNull(firstClassTime)) {
 | 
	
		
			
				|  |  |                      calendar.setTime(firstClassTime);
 | 
	
		
			
				|  |  |                      calendar.add(Calendar.DATE, -6);
 | 
	
		
			
				|  |  |                      calendar.set(Calendar.HOUR_OF_DAY, 0);
 | 
	
		
			
				|  |  |                      calendar.set(Calendar.MINUTE, 0);
 | 
	
		
			
				|  |  |                      calendar.set(Calendar.SECOND, 0);
 | 
	
		
			
				|  |  |                      calendar.set(Calendar.MILLISECOND, 0);
 | 
	
		
			
				|  |  | -                    applyStartDate=calendar.getTime();
 | 
	
		
			
				|  |  | +                    applyStartDate = calendar.getTime();
 | 
	
		
			
				|  |  |                      calendar.setTime(firstClassTime);
 | 
	
		
			
				|  |  |                      calendar.add(Calendar.DATE, 7);
 | 
	
		
			
				|  |  |                      calendar.set(Calendar.HOUR_OF_DAY, 0);
 | 
	
		
			
				|  |  |                      calendar.set(Calendar.MINUTE, 0);
 | 
	
		
			
				|  |  |                      calendar.set(Calendar.SECOND, 0);
 | 
	
		
			
				|  |  |                      calendar.set(Calendar.MILLISECOND, 0);
 | 
	
		
			
				|  |  | -                    applyEndDate=calendar.getTime();
 | 
	
		
			
				|  |  | +                    applyEndDate = calendar.getTime();
 | 
	
		
			
				|  |  |                      for (Date teacherFreeDate : allTeacherFreeDates) {
 | 
	
		
			
				|  |  | -                        if(!teacherFreeDate.before(applyStartDate)
 | 
	
		
			
				|  |  | -                            &&!teacherFreeDate.after(applyEndDate)){
 | 
	
		
			
				|  |  | +                        if (!teacherFreeDate.before(applyStartDate)
 | 
	
		
			
				|  |  | +                                && !teacherFreeDate.after(applyEndDate)) {
 | 
	
		
			
				|  |  |                              tempDates.add(teacherFreeDate);
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                if(CollectionUtils.isEmpty(tempDates)){
 | 
	
		
			
				|  |  | -                    tempDates=new ArrayList<>(allTeacherFreeDates);
 | 
	
		
			
				|  |  | +                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());
 | 
	
		
			
				|  |  | +                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("teacherFreeDays", tempDays.stream().map(day -> DateUtil.dateToString(day, "yyyy-MM-dd")).collect(Collectors.toList()));
 | 
	
		
			
				|  |  |                  result.put("teacherFreeDates", tempDates);
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  result.put("teacherFreeDays", new ArrayList<>());
 | 
	
	
		
			
				|  | @@ -991,13 +1013,13 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          for (Date enableApplyDate : enableApplyDates) {
 | 
	
		
			
				|  |  |              Date enableApplyDateCourseEndTime = DateUtil.addMinutes(enableApplyDate, practiceCourseMinutes);
 | 
	
		
			
				|  |  |              if (Objects.nonNull(firstClassTime)) {
 | 
	
		
			
				|  |  | -                if(DateUtil.isSameDay(enableApplyDate, firstClassTime)){
 | 
	
		
			
				|  |  | +                if (DateUtil.isSameDay(enableApplyDate, firstClassTime)) {
 | 
	
		
			
				|  |  |                      continue;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                if(DateUtil.isSameDay(enableApplyDate, tomorrow)){
 | 
	
		
			
				|  |  | +                if (DateUtil.isSameDay(enableApplyDate, tomorrow)) {
 | 
	
		
			
				|  |  |                      continue;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                if(DateUtil.isSameDay(enableApplyDate, yesterday)){
 | 
	
		
			
				|  |  | +                if (DateUtil.isSameDay(enableApplyDate, yesterday)) {
 | 
	
		
			
				|  |  |                      continue;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -1039,7 +1061,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              calendar.setTime(enableApplyDate);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            if (calendar.get(Calendar.DAY_OF_WEEK)==holiday) {
 | 
	
		
			
				|  |  | +            if (calendar.get(Calendar.DAY_OF_WEEK) == holiday) {
 | 
	
		
			
				|  |  |                  continue;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1091,38 +1113,38 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(allTeacherFreeDates)) {
 | 
	
		
			
				|  |  | -            List<Date> tempDates=new ArrayList<>();
 | 
	
		
			
				|  |  | -            if(Objects.nonNull(firstClassTime)){
 | 
	
		
			
				|  |  | +            List<Date> tempDates = new ArrayList<>();
 | 
	
		
			
				|  |  | +            if (Objects.nonNull(firstClassTime)) {
 | 
	
		
			
				|  |  |                  calendar.setTime(firstClassTime);
 | 
	
		
			
				|  |  |                  calendar.add(Calendar.DATE, -6);
 | 
	
		
			
				|  |  |                  calendar.set(Calendar.HOUR_OF_DAY, 0);
 | 
	
		
			
				|  |  |                  calendar.set(Calendar.MINUTE, 0);
 | 
	
		
			
				|  |  |                  calendar.set(Calendar.SECOND, 0);
 | 
	
		
			
				|  |  |                  calendar.set(Calendar.MILLISECOND, 0);
 | 
	
		
			
				|  |  | -                applyStartDate=calendar.getTime();
 | 
	
		
			
				|  |  | +                applyStartDate = calendar.getTime();
 | 
	
		
			
				|  |  |                  calendar.setTime(firstClassTime);
 | 
	
		
			
				|  |  |                  calendar.add(Calendar.DATE, 7);
 | 
	
		
			
				|  |  |                  calendar.set(Calendar.HOUR_OF_DAY, 0);
 | 
	
		
			
				|  |  |                  calendar.set(Calendar.MINUTE, 0);
 | 
	
		
			
				|  |  |                  calendar.set(Calendar.SECOND, 0);
 | 
	
		
			
				|  |  |                  calendar.set(Calendar.MILLISECOND, 0);
 | 
	
		
			
				|  |  | -                applyEndDate=calendar.getTime();
 | 
	
		
			
				|  |  | +                applyEndDate = calendar.getTime();
 | 
	
		
			
				|  |  |                  for (Date teacherFreeDate : allTeacherFreeDates) {
 | 
	
		
			
				|  |  | -                    if(!teacherFreeDate.before(applyStartDate)
 | 
	
		
			
				|  |  | -                            &&!teacherFreeDate.after(applyEndDate)){
 | 
	
		
			
				|  |  | +                    if (!teacherFreeDate.before(applyStartDate)
 | 
	
		
			
				|  |  | +                            && !teacherFreeDate.after(applyEndDate)) {
 | 
	
		
			
				|  |  |                          tempDates.add(teacherFreeDate);
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            if(CollectionUtils.isEmpty(tempDates)){
 | 
	
		
			
				|  |  | -                tempDates=new ArrayList<>(allTeacherFreeDates);
 | 
	
		
			
				|  |  | +            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());
 | 
	
		
			
				|  |  | +            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("teacherFreeDays", tempDays.stream().map(day -> DateUtil.dateToString(day, "yyyy-MM-dd")).collect(Collectors.toList()));
 | 
	
		
			
				|  |  |              result.put("teacherFreeDates", tempDates);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return result;
 | 
	
	
		
			
				|  | @@ -1455,9 +1477,9 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |              Calendar applyStartCalendar = Calendar.getInstance();
 | 
	
		
			
				|  |  |              applyStartCalendar.setTime(enableApplyDayStartTime);
 | 
	
		
			
				|  |  |              for (String applyDayTime : applyDayTimes) {
 | 
	
		
			
				|  |  | -                String temp=DateUtil.dateToString(applyStartCalendar.getTime(),"yyyy-MM-dd");
 | 
	
		
			
				|  |  | -                temp=temp+" "+applyDayTime;
 | 
	
		
			
				|  |  | -                result.add(DateUtil.stringToDate(temp,"yyyy-MM-dd HH:mm:ss"));
 | 
	
		
			
				|  |  | +                String temp = DateUtil.dateToString(applyStartCalendar.getTime(), "yyyy-MM-dd");
 | 
	
		
			
				|  |  | +                temp = temp + " " + applyDayTime;
 | 
	
		
			
				|  |  | +                result.add(DateUtil.stringToDate(temp, "yyyy-MM-dd HH:mm:ss"));
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return result;
 | 
	
	
		
			
				|  | @@ -1466,13 +1488,13 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 | 
	
		
			
				|  |  |      public Map practiceApply(PracticeGroup practiceGroup) {
 | 
	
		
			
				|  |  | -        if(Objects.isNull(practiceGroup.getUserId())){
 | 
	
		
			
				|  |  | +        if (Objects.isNull(practiceGroup.getUserId())) {
 | 
	
		
			
				|  |  |              throw new BizException("请选择老师");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          Map result = new HashMap();
 | 
	
		
			
				|  |  |          SysConfig practiceSubjectIdListConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_SUBJECT_ID_LIST);
 | 
	
		
			
				|  |  |          if (Objects.isNull(practiceGroup.getSubjectId())
 | 
	
		
			
				|  |  | -                ||!Arrays.asList(practiceSubjectIdListConfig.getParanValue().split(",")).contains(practiceGroup.getSubjectId().toString())) {
 | 
	
		
			
				|  |  | +                || !Arrays.asList(practiceSubjectIdListConfig.getParanValue().split(",")).contains(practiceGroup.getSubjectId().toString())) {
 | 
	
		
			
				|  |  |              result.put("status", "DISABLE_SUBJECT");
 | 
	
		
			
				|  |  |              result.put("info", "预约失败,声部选择错误,请重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
	
		
			
				|  | @@ -1548,13 +1570,13 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          practiceGroup.setCoursesStartDate(allCourseDates.get(0));
 | 
	
		
			
				|  |  |          practiceGroup.setCoursesExpireDate(courseExpireDate);
 | 
	
		
			
				|  |  |          Teacher teacher = teacherService.getDetail(practiceGroup.getUserId());
 | 
	
		
			
				|  |  | -        if(Objects.isNull(teacher)){
 | 
	
		
			
				|  |  | +        if (Objects.isNull(teacher)) {
 | 
	
		
			
				|  |  |              throw new BizException("老师不存在");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          List<SimpleUserDto> enableApplyTeachers = getEnableApplyTeachers(practiceGroup.getStudentId(), practiceGroup.getSubjectId());
 | 
	
		
			
				|  |  |          Set<Integer> enableApplyTeacherIds = enableApplyTeachers.stream().map(SimpleUserDto::getUserId).collect(Collectors.toSet());
 | 
	
		
			
				|  |  | -        if(!enableApplyTeacherIds.contains(practiceGroup.getUserId())){
 | 
	
		
			
				|  |  | +        if (!enableApplyTeacherIds.contains(practiceGroup.getUserId())) {
 | 
	
		
			
				|  |  |              throw new BizException("预约失败,老师选择错误,请重试");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1567,51 +1589,51 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        TeacherFreeTime teacherFreeTime=teacherFreeTimeDao.findTeacherFreeTime(practiceGroup.getUserId());
 | 
	
		
			
				|  |  | -        Integer maxTeacherCourses=null;
 | 
	
		
			
				|  |  | -        if(Objects.nonNull(teacherFreeTime)){
 | 
	
		
			
				|  |  | -            if(Objects.nonNull(teacherFreeTime.getTotalTimes())){
 | 
	
		
			
				|  |  | -                maxTeacherCourses=teacherFreeTime.getTotalTimes();
 | 
	
		
			
				|  |  | +        TeacherFreeTime teacherFreeTime = teacherFreeTimeDao.findTeacherFreeTime(practiceGroup.getUserId());
 | 
	
		
			
				|  |  | +        Integer maxTeacherCourses = null;
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(teacherFreeTime)) {
 | 
	
		
			
				|  |  | +            if (Objects.nonNull(teacherFreeTime.getTotalTimes())) {
 | 
	
		
			
				|  |  | +                maxTeacherCourses = teacherFreeTime.getTotalTimes();
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Date monday1 = DateUtil.getWeekDayWithDate(allCourseDates.get(0), Calendar.MONDAY);
 | 
	
		
			
				|  |  |          Date sunday1 = DateUtil.getWeekDayWithDate(allCourseDates.get(0), Calendar.SUNDAY);
 | 
	
		
			
				|  |  |          int tp1 = courseScheduleDao.countTeacherPracticeCourse(practiceGroup.getUserId(), monday1, sunday1);
 | 
	
		
			
				|  |  | -        if(Objects.nonNull(maxTeacherCourses)&&tp1>=maxTeacherCourses){
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(maxTeacherCourses) && tp1 >= maxTeacherCourses) {
 | 
	
		
			
				|  |  |              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |              result.put("status", "TEACHER_PRACTICE_REPEAT");
 | 
	
		
			
				|  |  | -            result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() +"」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  | +            result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Date monday2 = DateUtil.getWeekDayWithDate(allCourseDates.get(1), Calendar.MONDAY);
 | 
	
		
			
				|  |  |          Date sunday2 = DateUtil.getWeekDayWithDate(allCourseDates.get(1), Calendar.SUNDAY);
 | 
	
		
			
				|  |  |          int tp2 = courseScheduleDao.countTeacherPracticeCourse(practiceGroup.getUserId(), monday2, sunday2);
 | 
	
		
			
				|  |  | -        if(Objects.nonNull(maxTeacherCourses)&&tp2>=maxTeacherCourses){
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(maxTeacherCourses) && tp2 >= maxTeacherCourses) {
 | 
	
		
			
				|  |  |              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |              result.put("status", "TEACHER_PRACTICE_REPEAT");
 | 
	
		
			
				|  |  | -            result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() +"」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  | +            result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Date monday3 = DateUtil.getWeekDayWithDate(allCourseDates.get(2), Calendar.MONDAY);
 | 
	
		
			
				|  |  |          Date sunday3 = DateUtil.getWeekDayWithDate(allCourseDates.get(2), Calendar.SUNDAY);
 | 
	
		
			
				|  |  |          int tp3 = courseScheduleDao.countTeacherPracticeCourse(practiceGroup.getUserId(), monday3, sunday3);
 | 
	
		
			
				|  |  | -        if(Objects.nonNull(maxTeacherCourses)&&tp3>=maxTeacherCourses){
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(maxTeacherCourses) && tp3 >= maxTeacherCourses) {
 | 
	
		
			
				|  |  |              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |              result.put("status", "TEACHER_PRACTICE_REPEAT");
 | 
	
		
			
				|  |  | -            result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() +"」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  | +            result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Date monday4 = DateUtil.getWeekDayWithDate(allCourseDates.get(3), Calendar.MONDAY);
 | 
	
		
			
				|  |  |          Date sunday4 = DateUtil.getWeekDayWithDate(allCourseDates.get(3), Calendar.SUNDAY);
 | 
	
		
			
				|  |  |          int tp4 = courseScheduleDao.countTeacherPracticeCourse(practiceGroup.getUserId(), monday4, sunday4);
 | 
	
		
			
				|  |  | -        if(Objects.nonNull(maxTeacherCourses)&&tp4>=maxTeacherCourses){
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(maxTeacherCourses) && tp4 >= maxTeacherCourses) {
 | 
	
		
			
				|  |  |              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |              result.put("status", "TEACHER_PRACTICE_REPEAT");
 | 
	
		
			
				|  |  | -            result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() +"」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  | +            result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -1621,7 +1643,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          List<CourseSchedule> courseSchedules9 = courseScheduleDao.findTeacherCoursesWithIncludeDateRange(practiceGroup.getUserId(), allCourseDates.get(3), DateUtil.addMinutes(allCourseDates.get(3), practiceCourseMinutes));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(courseSchedules6) || !CollectionUtils.isEmpty(courseSchedules7)
 | 
	
		
			
				|  |  | -                ||!CollectionUtils.isEmpty(courseSchedules8) || !CollectionUtils.isEmpty(courseSchedules9)) {
 | 
	
		
			
				|  |  | +                || !CollectionUtils.isEmpty(courseSchedules8) || !CollectionUtils.isEmpty(courseSchedules9)) {
 | 
	
		
			
				|  |  |              if (courseSchedules6 == null) {
 | 
	
		
			
				|  |  |                  courseSchedules6 = new ArrayList<>();
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -1641,7 +1663,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |                  if (courseSchedules6.get(i).getGroupType().equals(GroupType.PRACTICE)) {
 | 
	
		
			
				|  |  |                      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |                      result.put("status", "TEACHER_PRACTICE_REPEAT");
 | 
	
		
			
				|  |  | -                    result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() +"」老师已被预约,请选择其他时段或更换老师后重试。");
 | 
	
		
			
				|  |  | +                    result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请选择其他时段或更换老师后重试。");
 | 
	
		
			
				|  |  |                      return result;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -1785,28 +1807,28 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(studentRepeatCourse1)) {
 | 
	
		
			
				|  |  |              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |              result.put("status", "STUDENT_COURSE_REPEAT");
 | 
	
		
			
				|  |  | -            result.put("info", "抱歉啦,当前所选时段组合,与您现有课程「"+studentRepeatCourse1.get(0).getName()+"」时段冲突,请选择其他时段重试。");
 | 
	
		
			
				|  |  | +            result.put("info", "抱歉啦,当前所选时段组合,与您现有课程「" + studentRepeatCourse1.get(0).getName() + "」时段冲突,请选择其他时段重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          List<CourseSchedule> studentRepeatCourse2 = courseScheduleDao.findStudentCoursesWithIncludeDateRange(practiceGroup.getStudentId(), allCourseDates.get(1), DateUtil.addMinutes(allCourseDates.get(1), practiceCourseMinutes));
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(studentRepeatCourse2)) {
 | 
	
		
			
				|  |  |              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |              result.put("status", "STUDENT_COURSE_REPEAT");
 | 
	
		
			
				|  |  | -            result.put("info", "抱歉啦,当前所选时段组合,与您现有课程「"+studentRepeatCourse2.get(0).getName()+"」时段冲突,请选择其他时段重试。");
 | 
	
		
			
				|  |  | +            result.put("info", "抱歉啦,当前所选时段组合,与您现有课程「" + studentRepeatCourse2.get(0).getName() + "」时段冲突,请选择其他时段重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          List<CourseSchedule> studentRepeatCourse3 = courseScheduleDao.findStudentCoursesWithIncludeDateRange(practiceGroup.getStudentId(), allCourseDates.get(2), DateUtil.addMinutes(allCourseDates.get(2), practiceCourseMinutes));
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(studentRepeatCourse3)) {
 | 
	
		
			
				|  |  |              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |              result.put("status", "STUDENT_COURSE_REPEAT");
 | 
	
		
			
				|  |  | -            result.put("info", "抱歉啦,当前所选时段组合,与您现有课程「"+studentRepeatCourse3.get(0).getName()+"」时段冲突,请选择其他时段重试。");
 | 
	
		
			
				|  |  | +            result.put("info", "抱歉啦,当前所选时段组合,与您现有课程「" + studentRepeatCourse3.get(0).getName() + "」时段冲突,请选择其他时段重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          List<CourseSchedule> studentRepeatCourse4 = courseScheduleDao.findStudentCoursesWithIncludeDateRange(practiceGroup.getStudentId(), allCourseDates.get(3), DateUtil.addMinutes(allCourseDates.get(3), practiceCourseMinutes));
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(studentRepeatCourse4)) {
 | 
	
		
			
				|  |  |              TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |              result.put("status", "STUDENT_COURSE_REPEAT");
 | 
	
		
			
				|  |  | -            result.put("info", "抱歉啦,当前所选时段组合,与您现有课程「"+studentRepeatCourse4.get(0).getName()+"」时段冲突,请选择其他时段重试。");
 | 
	
		
			
				|  |  | +            result.put("info", "抱歉啦,当前所选时段组合,与您现有课程「" + studentRepeatCourse4.get(0).getName() + "」时段冲突,请选择其他时段重试。");
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
 | 
	
	
		
			
				|  | @@ -1817,7 +1839,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          List<CourseSchedule> courseSchedules3 = courseScheduleDao.findTeacherCoursesWithIncludeDateRange(practiceGroup.getUserId(), allCourseDates.get(2), DateUtil.addMinutes(allCourseDates.get(2), practiceCourseMinutes));
 | 
	
		
			
				|  |  |          List<CourseSchedule> courseSchedules5 = courseScheduleDao.findTeacherCoursesWithIncludeDateRange(practiceGroup.getUserId(), allCourseDates.get(3), DateUtil.addMinutes(allCourseDates.get(3), practiceCourseMinutes));
 | 
	
		
			
				|  |  |          if (!CollectionUtils.isEmpty(courseSchedules1) || !CollectionUtils.isEmpty(courseSchedules2)
 | 
	
		
			
				|  |  | -                ||!CollectionUtils.isEmpty(courseSchedules3) || !CollectionUtils.isEmpty(courseSchedules5)) {
 | 
	
		
			
				|  |  | +                || !CollectionUtils.isEmpty(courseSchedules3) || !CollectionUtils.isEmpty(courseSchedules5)) {
 | 
	
		
			
				|  |  |              if (courseSchedules1 == null) {
 | 
	
		
			
				|  |  |                  courseSchedules1 = new ArrayList<>();
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -1842,7 +1864,7 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |                      } else {
 | 
	
		
			
				|  |  |                          TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  |                          result.put("status", "TEACHER_PRACTICE_REPEAT");
 | 
	
		
			
				|  |  | -                        result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() +"」老师已被预约,请选择其他时段或更换老师后重试。");
 | 
	
		
			
				|  |  | +                        result.put("info", "抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请选择其他时段或更换老师后重试。");
 | 
	
		
			
				|  |  |                          return result;
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -1963,4 +1985,595 @@ public class PracticeGroupServiceImpl extends BaseServiceImpl<Long, PracticeGrou
 | 
	
		
			
				|  |  |          return result;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Map getPayPracticeApplyParams(Integer userId) {
 | 
	
		
			
				|  |  | +        Map result = new HashMap();
 | 
	
		
			
				|  |  | +        SysConfig practiceSubjectIdListConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_SUBJECT_ID_LIST);
 | 
	
		
			
				|  |  | +        SysConfig practiceApplyStartTimeConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_APPLY_START_TIME);
 | 
	
		
			
				|  |  | +        SysConfig practiceApplyEndTimeConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_APPLY_END_TIME);
 | 
	
		
			
				|  |  | +        SysConfig practiceApplyIntervalTimeConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_APPLY_INTERVAL_TIME);
 | 
	
		
			
				|  |  | +        SysConfig practiceCourseMinutesConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_COURSE_MINUTES);
 | 
	
		
			
				|  |  | +        SysConfig practicePayMaxMonthConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_PAY_MAX_MONTH);
 | 
	
		
			
				|  |  | +        SysConfig practicePayDrillTimesOnOneWeekConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_PAY_DRILL_TIMES_ON_ONE_WEEK);
 | 
	
		
			
				|  |  | +        Student student = studentDao.get(userId);
 | 
	
		
			
				|  |  | +        List<Subject> subjects = subjectDao.findBySubjectByIdList(practiceSubjectIdListConfig.getParanValue());
 | 
	
		
			
				|  |  | +        List<Integer> subjectIds = Arrays.asList(practiceSubjectIdListConfig.getParanValue().split(",")).stream().mapToInt(idStr -> Integer.valueOf(idStr)).boxed().collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        List<Integer> userDefaultSubjectIds = Objects.isNull(student) || Objects.isNull(student.getSubjectIdList()) ? null : Arrays.asList(student.getSubjectIdList().split(",")).stream().mapToInt(idStr -> Integer.valueOf(idStr)).boxed().collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        if (!CollectionUtils.isEmpty(userDefaultSubjectIds)) {
 | 
	
		
			
				|  |  | +            userDefaultSubjectIds = userDefaultSubjectIds.stream().filter(userDefaultSubjectId -> subjectIds.contains(userDefaultSubjectId)).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            userDefaultSubjectIds = new ArrayList<>();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        result.put("subjects", subjects);
 | 
	
		
			
				|  |  | +        result.put("practiceApplyStartTime", practiceApplyStartTimeConfig.getParanValue());
 | 
	
		
			
				|  |  | +        result.put("practiceApplyEndTime", practiceApplyEndTimeConfig.getParanValue());
 | 
	
		
			
				|  |  | +        result.put("userDefaultSubjectIds", StringUtils.join(userDefaultSubjectIds.toArray(), ","));
 | 
	
		
			
				|  |  | +        result.put("practiceApplyIntervalMinutes", practiceApplyIntervalTimeConfig.getParanValue(Integer.class));
 | 
	
		
			
				|  |  | +        result.put("practiceCourseMinutes", practiceCourseMinutesConfig.getParanValue(Integer.class));
 | 
	
		
			
				|  |  | +        result.put("practicePayMaxMonth", practicePayMaxMonthConfig.getParanValue(Integer.class));
 | 
	
		
			
				|  |  | +        result.put("practicePayDrillTimesOnOneWeek", practicePayDrillTimesOnOneWeekConfig.getParanValue(Integer.class));
 | 
	
		
			
				|  |  | +        return result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Map<Integer, List<String>> getEnableApplyDatesWithWeek() {
 | 
	
		
			
				|  |  | +        Map<Integer, List<String>> result = new HashMap<>();
 | 
	
		
			
				|  |  | +        for (int i = 1; i <= 7; i++) {
 | 
	
		
			
				|  |  | +            List<String> tempTimes = new ArrayList<>();
 | 
	
		
			
				|  |  | +            for (String applyDayTime : applyDayTimes) {
 | 
	
		
			
				|  |  | +                tempTimes.add(applyDayTime);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            result.put(i, tempTimes);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Map getPayPracticeTeacherFreeTimes(Integer userId, Integer teacherId, Integer buyMonths, Date firstClassTime) {
 | 
	
		
			
				|  |  | +        if (Objects.isNull(teacherId)) {
 | 
	
		
			
				|  |  | +            throw new BizException("请选择教师");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        SysUser student = sysUserFeignService.queryUserById(userId);
 | 
	
		
			
				|  |  | +        if (Objects.isNull(student)) {
 | 
	
		
			
				|  |  | +            throw new BizException("用户不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (Objects.isNull(student.getOrganId())) {
 | 
	
		
			
				|  |  | +            throw new BizException("未找到用户分部属性");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Teacher teacher = teacherDao.get(teacherId);
 | 
	
		
			
				|  |  | +        if (Objects.isNull(teacher)) {
 | 
	
		
			
				|  |  | +            throw new BizException("教师不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        Map result = new HashMap();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SysConfig practiceCourseMinutesConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_COURSE_MINUTES);
 | 
	
		
			
				|  |  | +        Integer practiceCourseMinutes = practiceCourseMinutesConfig.getParanValue(Integer.class);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        boolean checkTeacherLeaveDate = true;
 | 
	
		
			
				|  |  | +        SysConfig allTeacherLeaveDataConfig = sysConfigService.findByParamName(SysConfigService.TEACHER_LEAVE_DATA);
 | 
	
		
			
				|  |  | +        JSONObject allTeacherLeaveData = JSONObject.parseObject(allTeacherLeaveDataConfig.getParanValue());
 | 
	
		
			
				|  |  | +        if (Objects.isNull(allTeacherLeaveData)) {
 | 
	
		
			
				|  |  | +            checkTeacherLeaveDate = false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        TeacherFreeTime teacherFreeTime = teacherFreeTimeDao.findTeacherFreeTime(teacherId);
 | 
	
		
			
				|  |  | +        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();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        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();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        LocalDateTime now = LocalDateTime.now();
 | 
	
		
			
				|  |  | +        now.plusDays(1);
 | 
	
		
			
				|  |  | +        Date applyStartDate = Date.from(now.atZone(zoneId).toInstant());
 | 
	
		
			
				|  |  | +        now.plusMonths(buyMonths);
 | 
	
		
			
				|  |  | +        Date applyEndDate = Date.from(now.atZone(zoneId).toInstant());
 | 
	
		
			
				|  |  | +        Date firstMonday = DateUtil.getWeekDayWithDate(applyStartDate, Calendar.MONDAY);
 | 
	
		
			
				|  |  | +        Date secondSunday = DateUtil.getWeekDayWithDate(applyEndDate, Calendar.SUNDAY);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Map<Integer, List<String>> weekNumApplyTimesMap = getEnableApplyDatesWithWeek();
 | 
	
		
			
				|  |  | +        List<CourseSchedule> allTeacherCourses = courseScheduleDao.findTeacherCoursesWithDateRange(teacherId, firstMonday, secondSunday);
 | 
	
		
			
				|  |  | +        allTeacherCourses.sort(Comparator.comparing(CourseSchedule::getStartClassTime));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        JSONObject teacherLeaveData = null;
 | 
	
		
			
				|  |  | +        if (checkTeacherLeaveDate) {
 | 
	
		
			
				|  |  | +            teacherLeaveData = allTeacherLeaveData.getJSONObject(teacherId.toString());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (Objects.isNull(teacherLeaveData)) {
 | 
	
		
			
				|  |  | +            checkTeacherLeaveDate = false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(firstClassTime)) {
 | 
	
		
			
				|  |  | +            LocalDateTime localFirstClassTime = LocalDateTime.ofInstant(firstClassTime.toInstant(), zoneId);
 | 
	
		
			
				|  |  | +            weekNumApplyTimesMap.remove(localFirstClassTime.getDayOfWeek().getValue());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        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);
 | 
	
		
			
				|  |  | +                List<String> applyTimeStrs = weekNumApplyTimesMap.get(parse.getDayOfWeek().getValue());
 | 
	
		
			
				|  |  | +                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(leaveStartTime) <= 0
 | 
	
		
			
				|  |  | +                            && defaultApplyEndTime.compareTo(leaveEndTime) >= 0) {
 | 
	
		
			
				|  |  | +                        iterator.remove();
 | 
	
		
			
				|  |  | +                        continue;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                weekNumApplyTimesMap.put(parse.getDayOfWeek().getValue(), applyTimeStrs);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(allTeacherCourses)) {
 | 
	
		
			
				|  |  | +            result.put("teacherFreeDays", weekNumApplyTimesMap);
 | 
	
		
			
				|  |  | +            return result;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        int courseWeekNum = 0;
 | 
	
		
			
				|  |  | +        int practiceCourseNum = 0;
 | 
	
		
			
				|  |  | +        boolean hasDisableWeek = false;
 | 
	
		
			
				|  |  | +        LocalDateTime tempClassDateTime;
 | 
	
		
			
				|  |  | +        for (int i = 0; i < allTeacherCourses.size(); i++) {
 | 
	
		
			
				|  |  | +            CourseSchedule teacherCourse = allTeacherCourses.get(i);
 | 
	
		
			
				|  |  | +            tempClassDateTime = LocalDateTime.ofInstant(teacherCourse.getClassDate().toInstant(), zoneId);
 | 
	
		
			
				|  |  | +            if (i == 0 && teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
 | 
	
		
			
				|  |  | +                practiceCourseNum += 1;
 | 
	
		
			
				|  |  | +                courseWeekNum = tempClassDateTime.get(weekFields.weekOfYear());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (Objects.nonNull(maxTeacherCourses) && practiceCourseNum >= maxTeacherCourses) {
 | 
	
		
			
				|  |  | +                hasDisableWeek = true;
 | 
	
		
			
				|  |  | +                break;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (tempClassDateTime.get(weekFields.weekOfYear()) != courseWeekNum) {
 | 
	
		
			
				|  |  | +                courseWeekNum = tempClassDateTime.get(weekFields.weekOfYear());
 | 
	
		
			
				|  |  | +                practiceCourseNum = 0;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
 | 
	
		
			
				|  |  | +                practiceCourseNum += 1;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (hasDisableWeek) {
 | 
	
		
			
				|  |  | +            result.put("teacherFreeDays", new HashMap<>());
 | 
	
		
			
				|  |  | +            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)) {
 | 
	
		
			
				|  |  | +                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();
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            weekNumApplyTimesMap.put(courseStartTime.getDayOfWeek().getValue(), applyTimeStrs);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        result.put("teacherFreeDays", weekNumApplyTimesMap);
 | 
	
		
			
				|  |  | +        return result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 | 
	
		
			
				|  |  | +    public HttpResponseResult buyPracticeGroup(PracticeGroupBuyDto practiceGroupBuyParams) {
 | 
	
		
			
				|  |  | +        if (Objects.isNull(practiceGroupBuyParams.getUserId())) {
 | 
	
		
			
				|  |  | +            return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择教师");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (Objects.isNull(practiceGroupBuyParams.getSubjectId())) {
 | 
	
		
			
				|  |  | +            return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择声部");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (Objects.isNull(practiceGroupBuyParams.getBuyMonths())) {
 | 
	
		
			
				|  |  | +            return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择需要购买的月数");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (Objects.isNull(practiceGroupBuyParams.getDrillTimesOnWeek())) {
 | 
	
		
			
				|  |  | +            return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择单周陪练次数");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isEmpty(practiceGroupBuyParams.getDrillTimes())) {
 | 
	
		
			
				|  |  | +            return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "请选择训练时间");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (practiceGroupBuyParams.getDrillTimesOnWeek() != practiceGroupBuyParams.getDrillTimes().size()) {
 | 
	
		
			
				|  |  | +            return BaseController.failed(HttpStatus.EXPECTATION_FAILED,"训练时间与陪练次数不匹配");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SysUser sysUser = sysUserFeignService.queryUserById(practiceGroupBuyParams.getStudentId());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Subject subject = subjectDao.get(practiceGroupBuyParams.getSubjectId());
 | 
	
		
			
				|  |  | +        if (Objects.isNull(subject)) {
 | 
	
		
			
				|  |  | +            return BaseController.failed(HttpStatus.EXPECTATION_FAILED, "预约失败,声部选择错误,请重试。");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Teacher teacher = teacherService.getDetail(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +        if (Objects.isNull(teacher)) {
 | 
	
		
			
				|  |  | +            throw new BizException("老师不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SysConfig practiceCourseMinutesConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_COURSE_MINUTES);
 | 
	
		
			
				|  |  | +        Integer practiceCourseMinutes = practiceCourseMinutesConfig.getParanValue(Integer.class);
 | 
	
		
			
				|  |  | +        SysConfig practiceCourseSalaryConfig = sysConfigService.findByParamName(SysConfigService.PRACTICE_COURSE_SALARY);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Date now=new Date();
 | 
	
		
			
				|  |  | +        PracticeGroup userLatestPracticeGroup = practiceGroupDao.findUserLatestPracticeGroup(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +        LocalDate courseStartDay=LocalDate.now();
 | 
	
		
			
				|  |  | +        if(Objects.nonNull(userLatestPracticeGroup)){
 | 
	
		
			
				|  |  | +            LocalDate lastExpiredDay=LocalDateTime.ofInstant(userLatestPracticeGroup.getCoursesExpireDate().toInstant(),DateUtil.zoneId).toLocalDate();
 | 
	
		
			
				|  |  | +            if(Objects.nonNull(lastExpiredDay)&&lastExpiredDay.compareTo(courseStartDay)>=0){
 | 
	
		
			
				|  |  | +                courseStartDay=lastExpiredDay;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        courseStartDay=courseStartDay.plusDays(1);
 | 
	
		
			
				|  |  | +        Date courseStartDate=Date.from(courseStartDay.atStartOfDay(DateUtil.zoneId).toInstant());
 | 
	
		
			
				|  |  | +        practiceGroupBuyParams.setCoursesStartDate(courseStartDate);
 | 
	
		
			
				|  |  | +        LocalDate currentExpiredDay = courseStartDay.plusMonths(practiceGroupBuyParams.getBuyMonths());
 | 
	
		
			
				|  |  | +        Date courseExpiredDate=Date.from(currentExpiredDay.atStartOfDay(DateUtil.zoneId).toInstant());
 | 
	
		
			
				|  |  | +        practiceGroupBuyParams.setCoursesStartDate(courseExpiredDate);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        LocalDate courseStartMonday=courseStartDay.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.MONDAY.getValue());
 | 
	
		
			
				|  |  | +        LocalDate courseExpiredSunday=currentExpiredDay.with(DateUtil.weekFields.dayOfWeek(), DayOfWeek.SUNDAY.getValue());
 | 
	
		
			
				|  |  | +        Date courseStartMondayDate = Date.from(courseStartMonday.atStartOfDay(DateUtil.zoneId).toInstant());
 | 
	
		
			
				|  |  | +        Date courseExpiredSundayDate = Date.from(courseExpiredSunday.atStartOfDay(DateUtil.zoneId).toInstant());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<CourseSchedule> allTeacherCourses = courseScheduleDao.findTeacherCoursesWithDateRange(practiceGroupBuyParams.getUserId(), courseStartMondayDate, courseExpiredSundayDate);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        TeacherFreeTime teacherFreeTime = teacherFreeTimeDao.findTeacherFreeTime(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +        Integer maxTeacherCourses = null;
 | 
	
		
			
				|  |  | +        if (Objects.nonNull(teacherFreeTime)) {
 | 
	
		
			
				|  |  | +            if (Objects.nonNull(teacherFreeTime.getTotalTimes())) {
 | 
	
		
			
				|  |  | +                maxTeacherCourses = teacherFreeTime.getTotalTimes();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        int courseWeekNum = 0;
 | 
	
		
			
				|  |  | +        int practiceCourseNum = 0;
 | 
	
		
			
				|  |  | +        LocalDateTime tempClassDateTime;
 | 
	
		
			
				|  |  | +        for (int i = 0; i < allTeacherCourses.size(); i++) {
 | 
	
		
			
				|  |  | +            CourseSchedule teacherCourse = allTeacherCourses.get(i);
 | 
	
		
			
				|  |  | +            tempClassDateTime = LocalDateTime.ofInstant(teacherCourse.getClassDate().toInstant(), DateUtil.zoneId);
 | 
	
		
			
				|  |  | +            if (i == 0 && teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
 | 
	
		
			
				|  |  | +                practiceCourseNum += 1;
 | 
	
		
			
				|  |  | +                courseWeekNum = tempClassDateTime.get(DateUtil.weekFields.weekOfYear());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (Objects.nonNull(maxTeacherCourses) && practiceCourseNum >= maxTeacherCourses) {
 | 
	
		
			
				|  |  | +                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
	
		
			
				|  |  | +                return BaseController.failed(HttpStatus.MULTIPLE_CHOICES,"抱歉啦,当前所选时段组合,「" + teacher.getRealName() + "」老师已被预约,请重新选择时段或更换老师后重试。");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (tempClassDateTime.get(DateUtil.weekFields.weekOfYear()) != courseWeekNum) {
 | 
	
		
			
				|  |  | +                courseWeekNum = tempClassDateTime.get(DateUtil.weekFields.weekOfYear());
 | 
	
		
			
				|  |  | +                practiceCourseNum = 0;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (teacherCourse.getGroupType().equals(GroupType.PRACTICE)) {
 | 
	
		
			
				|  |  | +                practiceCourseNum += 1;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        allTeacherCourses=new ArrayList<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        practiceGroupBuyParams.setName(subject.getName() + "•" + sysUser.getUsername());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<CourseSchedule> practiceCourses = createPracticeCourses(practiceGroupBuyParams, practiceCourseMinutes);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            courseScheduleService.checkNewCourseSchedules(practiceCourses,false);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            return BaseController.failed(HttpStatus.FOUND, "课程冲突");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        practiceGroupBuyParams.setOrganId(sysUser.getOrganId());
 | 
	
		
			
				|  |  | +        practiceGroupBuyParams.setSingleClassMinutes(practiceCourseMinutes);
 | 
	
		
			
				|  |  | +        practiceGroupDao.insert(practiceGroupBuyParams);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //创建班级信息
 | 
	
		
			
				|  |  | +        ClassGroup classGroup = new ClassGroup();
 | 
	
		
			
				|  |  | +        classGroup.setSubjectIdList(practiceGroupBuyParams.getSubjectId().toString());
 | 
	
		
			
				|  |  | +        classGroup.setExpectStudentNum(1);
 | 
	
		
			
				|  |  | +        classGroup.setStudentNum(1);
 | 
	
		
			
				|  |  | +        classGroup.setName(practiceGroupBuyParams.getName());
 | 
	
		
			
				|  |  | +        classGroup.setTotalClassTimes(practiceCourses.size());
 | 
	
		
			
				|  |  | +        classGroup.setType(ClassGroupTypeEnum.PRACTICE);
 | 
	
		
			
				|  |  | +        classGroup.setDelFlag(0);
 | 
	
		
			
				|  |  | +        classGroup.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +        classGroup.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +        classGroup.setCreateTime(now);
 | 
	
		
			
				|  |  | +        classGroup.setUpdateTime(now);
 | 
	
		
			
				|  |  | +        classGroupDao.insert(classGroup);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //创建班级老师关联记录
 | 
	
		
			
				|  |  | +        ClassGroupTeacherMapper classGroupTeacherMapper = new ClassGroupTeacherMapper();
 | 
	
		
			
				|  |  | +        classGroupTeacherMapper.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +        classGroupTeacherMapper.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +        classGroupTeacherMapper.setTeacherRole(TeachTypeEnum.BISHOP);
 | 
	
		
			
				|  |  | +        classGroupTeacherMapper.setUserId(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +        classGroupTeacherMapper.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +        classGroupTeacherMapper.setCreateTime(now);
 | 
	
		
			
				|  |  | +        classGroupTeacherMapper.setUpdateTime(now);
 | 
	
		
			
				|  |  | +        classGroupTeacherMapperDao.insert(classGroupTeacherMapper);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //创建班级与老师课酬记录
 | 
	
		
			
				|  |  | +        ClassGroupTeacherSalary classGroupTeacherSalary = new ClassGroupTeacherSalary();
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setTeacherRole(TeachTypeEnum.BISHOP);
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setUserId(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setSalary(new BigDecimal(practiceCourseSalaryConfig.getParanValue(Integer.class)));
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setOnlineClassesSalary(new BigDecimal(practiceCourseSalaryConfig.getParanValue(Integer.class)));
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setCreateTime(now);
 | 
	
		
			
				|  |  | +        classGroupTeacherSalary.setUpdateTime(now);
 | 
	
		
			
				|  |  | +        classGroupTeacherSalaryDao.insert(classGroupTeacherSalary);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //班级学生关联表
 | 
	
		
			
				|  |  | +        ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
 | 
	
		
			
				|  |  | +        classGroupStudentMapper.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +        classGroupStudentMapper.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +        classGroupStudentMapper.setUserId(practiceGroupBuyParams.getStudentId());
 | 
	
		
			
				|  |  | +        classGroupStudentMapper.setCreateTime(now);
 | 
	
		
			
				|  |  | +        classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
 | 
	
		
			
				|  |  | +        classGroupStudentMapper.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +        classGroupStudentMapperDao.insert(classGroupStudentMapper);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<CourseScheduleTeacherSalary> courseScheduleTeacherSalaries = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<TeacherAttendance> teacherAttendances = new ArrayList<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for (CourseSchedule courseSchedule : practiceCourses) {
 | 
	
		
			
				|  |  | +            //课表
 | 
	
		
			
				|  |  | +            courseSchedule.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +            courseSchedule.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +            courseSchedule.setStatus(CourseStatusEnum.NOT_START);
 | 
	
		
			
				|  |  | +            courseSchedule.setCreateTime(now);
 | 
	
		
			
				|  |  | +            courseSchedule.setUpdateTime(now);
 | 
	
		
			
				|  |  | +            courseSchedule.setTeachMode(TeachModeEnum.ONLINE);
 | 
	
		
			
				|  |  | +            courseSchedule.setType(CourseSchedule.CourseScheduleType.PRACTICE);
 | 
	
		
			
				|  |  | +            courseSchedule.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +            courseSchedule.setIsLock(1);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        courseScheduleDao.batchAddCourseSchedules(practiceCourses);
 | 
	
		
			
				|  |  | +        for (CourseSchedule courseSchedule : practiceCourses) {
 | 
	
		
			
				|  |  | +            //课程与老师薪水表
 | 
	
		
			
				|  |  | +            CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setCourseScheduleId(courseSchedule.getId());
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setTeacherRole(classGroupTeacherMapper.getTeacherRole());
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setUserId(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setExpectSalary(new BigDecimal(practiceCourseSalaryConfig.getParanValue()));
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setCreateTime(now);
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setUpdateTime(now);
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalary.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +            courseScheduleTeacherSalaries.add(courseScheduleTeacherSalary);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //学生缴费记录
 | 
	
		
			
				|  |  | +            CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setUserId(practiceGroupBuyParams.getStudentId());
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setExpectPrice(BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setCreateTime(now);
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayment.setUpdateTime(now);
 | 
	
		
			
				|  |  | +            courseScheduleStudentPayments.add(courseScheduleStudentPayment);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //教师签到记录
 | 
	
		
			
				|  |  | +            TeacherAttendance teacherAttendance = new TeacherAttendance();
 | 
	
		
			
				|  |  | +            teacherAttendance.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +            teacherAttendance.setTeacherId(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +            teacherAttendance.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +            teacherAttendance.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +            teacherAttendance.setCourseScheduleId(courseSchedule.getId());
 | 
	
		
			
				|  |  | +            teacherAttendance.setCreateTime(now);
 | 
	
		
			
				|  |  | +            teacherAttendances.add(teacherAttendance);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        courseScheduleTeacherSalaryDao.batchInsert(courseScheduleTeacherSalaries);
 | 
	
		
			
				|  |  | +        teacherAttendanceDao.batchInsert(teacherAttendances);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        StudentPaymentOrder studentPaymentOrder=new StudentPaymentOrder();
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setUserId(practiceGroupBuyParams.getStudentId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setGroupType(GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +        String orderNo=idGeneratorService.generatorId("payment") + "";
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setType(OrderTypeEnum.SMALL_CLASS_TO_BUY);
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setExpectAmount(new BigDecimal(practiceCourseSalaryConfig.getParanValue(Integer.class)));
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setMusicGroupId(practiceGroupBuyParams.getId().toString());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setActualAmount(studentPaymentOrder.getExpectAmount());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setClassGroupId(classGroup.getId());
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setVersion(0);
 | 
	
		
			
				|  |  | +        studentPaymentOrderService.insert(studentPaymentOrder);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        BigDecimal amount=new BigDecimal(0);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if(practiceGroupBuyParams.isUseBalancePayment() || studentPaymentOrder.getExpectAmount().doubleValue() == 0){
 | 
	
		
			
				|  |  | +            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(practiceGroupBuyParams.getStudentId());
 | 
	
		
			
				|  |  | +            if(userCashAccount == null){
 | 
	
		
			
				|  |  | +                throw new BizException("用户账户找不到");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setPaymentChannel("BALANCE");
 | 
	
		
			
				|  |  | +            if(userCashAccount.getBalance().subtract(studentPaymentOrder.getExpectAmount()).doubleValue() >= 0){
 | 
	
		
			
				|  |  | +                // 更新订单信息
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setActualAmount(new BigDecimal(0));
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setBalancePaymentAmount(studentPaymentOrder.getExpectAmount());
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setUpdateTime(now);
 | 
	
		
			
				|  |  | +                studentPaymentOrder.setOrganId(practiceGroupBuyParams.getOrganId());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                sysUserCashAccountService.updateBalance(practiceGroupBuyParams.getStudentId(), studentPaymentOrder.getExpectAmount().negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,"陪练课购买");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                Map<String,Object> result=new HashMap<>();
 | 
	
		
			
				|  |  | +                result.put("orderNo",studentPaymentOrder.getOrderNo());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                return BaseController.succeed();
 | 
	
		
			
				|  |  | +            }else{
 | 
	
		
			
				|  |  | +                if (userCashAccount.getBalance().doubleValue() > 0) {
 | 
	
		
			
				|  |  | +                    sysUserCashAccountService.updateBalance(practiceGroupBuyParams.getStudentId(), userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "陪练课购买");
 | 
	
		
			
				|  |  | +                    amount = studentPaymentOrder.getExpectAmount().subtract(userCashAccount.getBalance());
 | 
	
		
			
				|  |  | +                    studentPaymentOrder.setActualAmount(amount);
 | 
	
		
			
				|  |  | +                    studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
 | 
	
		
			
				|  |  | +        Map<String, BigDecimal> classFee = new HashMap<>();
 | 
	
		
			
				|  |  | +        classFee.put("course",amount);
 | 
	
		
			
				|  |  | +        classFee.put("instrument",BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +        classFee.put("accessories",BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +        classFee.put("other",BigDecimal.ZERO);
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            Map<String,Object> payMap = payService.getPayMap(
 | 
	
		
			
				|  |  | +                    amount,
 | 
	
		
			
				|  |  | +                    orderNo,
 | 
	
		
			
				|  |  | +                    baseApiUrl+"/api-student/studentOrder/notify",
 | 
	
		
			
				|  |  | +                    baseApiUrl+"/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
 | 
	
		
			
				|  |  | +                    "vip课购买",
 | 
	
		
			
				|  |  | +                    practiceGroupBuyParams.getName(),
 | 
	
		
			
				|  |  | +                    practiceGroupBuyParams.getStudentId(),
 | 
	
		
			
				|  |  | +                    classFee,
 | 
	
		
			
				|  |  | +                    practiceGroupBuyParams.getOrganId()
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            Map<String,BigDecimal> routingFee = (Map<String,BigDecimal>)payMap.get("routingFee");
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setOrganId(practiceGroupBuyParams.getOrganId());
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setComAmount(routingFee.get("COM"));
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setPerAmount(routingFee.get("PER"));
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
 | 
	
		
			
				|  |  | +            studentPaymentOrder.setUpdateTime(now);
 | 
	
		
			
				|  |  | +            studentPaymentOrderService.update(studentPaymentOrder);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return BaseController.succeed(payMap);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            throw new BizException("调用支付接口出错", e);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private List<CourseSchedule> createPracticeCourses(PracticeGroupBuyDto practiceGroupBuyParams, Integer practiceCourseMinutes){
 | 
	
		
			
				|  |  | +        List<CourseSchedule> courseSchedules=new ArrayList<>();
 | 
	
		
			
				|  |  | +        LocalDate courseStartDay=LocalDateTime.ofInstant(practiceGroupBuyParams.getCoursesStartDate().toInstant(),DateUtil.zoneId).toLocalDate();
 | 
	
		
			
				|  |  | +        LocalDate courseEndDay=LocalDateTime.ofInstant(practiceGroupBuyParams.getCoursesExpireDate().toInstant(),DateUtil.zoneId).toLocalDate();
 | 
	
		
			
				|  |  | +        while (courseStartDay.compareTo(courseEndDay)<0){
 | 
	
		
			
				|  |  | +            int dayOfWeek = courseStartDay.get(DateUtil.weekFields.dayOfWeek());
 | 
	
		
			
				|  |  | +            for (PracticeDrillTimeDto drillTime : practiceGroupBuyParams.getDrillTimes()) {
 | 
	
		
			
				|  |  | +                if(dayOfWeek==drillTime.getWeekNum()){
 | 
	
		
			
				|  |  | +                    CourseSchedule courseSchedule=new CourseSchedule();
 | 
	
		
			
				|  |  | +                    String courseStartDayStr = DateUtil.dateFormatter.format(courseStartDay);
 | 
	
		
			
				|  |  | +                    String courseStartDateTimeStr = courseStartDayStr+" "+drillTime.getTimeStr();
 | 
	
		
			
				|  |  | +                    LocalDateTime courseStartDateTime = LocalDateTime.parse(courseStartDateTimeStr,DateUtil.dateTimeFormatter);
 | 
	
		
			
				|  |  | +                    LocalDateTime courseEndDateTime = courseStartDateTime.plusMinutes(practiceCourseMinutes);
 | 
	
		
			
				|  |  | +                    courseSchedule.setClassDate(Date.from(courseStartDay.atStartOfDay(DateUtil.zoneId).toInstant()));
 | 
	
		
			
				|  |  | +                    courseSchedule.setStartClassTime(Date.from(courseStartDateTime.atZone(DateUtil.zoneId).toInstant()));
 | 
	
		
			
				|  |  | +                    courseSchedule.setEndClassTime(Date.from(courseEndDateTime.atZone(DateUtil.zoneId).toInstant()));
 | 
	
		
			
				|  |  | +                    courseSchedule.setName(practiceGroupBuyParams.getName());
 | 
	
		
			
				|  |  | +                    courseSchedule.setTeacherId(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +                    courseSchedule.setActualTeacherId(practiceGroupBuyParams.getUserId());
 | 
	
		
			
				|  |  | +                    courseSchedule.setTeachMode(TeachModeEnum.ONLINE);
 | 
	
		
			
				|  |  | +                    courseSchedule.setType(CourseSchedule.CourseScheduleType.PRACTICE);
 | 
	
		
			
				|  |  | +                    courseSchedule.setStatus(CourseStatusEnum.NOT_START);
 | 
	
		
			
				|  |  | +                    courseSchedules.add(courseSchedule);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return courseSchedules;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class,isolation = Isolation.READ_COMMITTED)
 | 
	
		
			
				|  |  | +    public void orderCallback(StudentPaymentOrder order) {
 | 
	
		
			
				|  |  | +        StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(order.getId());
 | 
	
		
			
				|  |  | +        if(studentPaymentOrder.getStatus().equals(DealStatusEnum.SUCCESS)){
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(order.getStatus().equals(DealStatusEnum.SUCCESS)){
 | 
	
		
			
				|  |  | +            courseScheduleDao.updateGroupCourseLock(order.getMusicGroupId(),GroupType.PRACTICE,0);
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            groupService.deleteGroupInfo(order.getMusicGroupId(),GroupType.PRACTICE);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        studentPaymentOrderDao.update(order);
 | 
	
		
			
				|  |  | +        SysUserCashAccount sysUserCashAccount = sysUserCashAccountService.get(order.getUserId());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //插入缴费明细
 | 
	
		
			
				|  |  | +        //收入
 | 
	
		
			
				|  |  | +        SysUserCashAccountDetail sysUserIncomeCashAccountDetail = new SysUserCashAccountDetail();
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setUserId(order.getUserId());
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setAmount(order.getActualAmount());
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setBalance(sysUserCashAccount.getBalance().add(order.getActualAmount()));
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setAttribute(order.getTransNo());
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setChannel(studentPaymentOrder.getPaymentChannel());
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setComAmount(studentPaymentOrder.getComAmount());
 | 
	
		
			
				|  |  | +        sysUserIncomeCashAccountDetail.setPerAmount(studentPaymentOrder.getPerAmount());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //支出
 | 
	
		
			
				|  |  | +        SysUserCashAccountDetail sysUserExpendCashAccountDetail = new SysUserCashAccountDetail();
 | 
	
		
			
				|  |  | +        sysUserExpendCashAccountDetail.setUserId(order.getUserId());
 | 
	
		
			
				|  |  | +        sysUserExpendCashAccountDetail.setType(PlatformCashAccountDetailTypeEnum.PAY_FEE);
 | 
	
		
			
				|  |  | +        sysUserExpendCashAccountDetail.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +        sysUserExpendCashAccountDetail.setAmount(order.getActualAmount().negate());
 | 
	
		
			
				|  |  | +        sysUserExpendCashAccountDetail.setBalance(sysUserCashAccount.getBalance());
 | 
	
		
			
				|  |  | +        sysUserExpendCashAccountDetail.setAttribute(order.getTransNo());
 | 
	
		
			
				|  |  | +        sysUserExpendCashAccountDetail.setChannel(studentPaymentOrder.getPaymentChannel());
 | 
	
		
			
				|  |  | +        if(studentPaymentOrder.getComAmount() != null){
 | 
	
		
			
				|  |  | +            sysUserExpendCashAccountDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(studentPaymentOrder.getPerAmount() != null){
 | 
	
		
			
				|  |  | +            sysUserExpendCashAccountDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        sysUserCashAccountDetailService.insert(sysUserIncomeCashAccountDetail);
 | 
	
		
			
				|  |  | +        sysUserCashAccountDetailService.insert(sysUserExpendCashAccountDetail);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |