Sfoglia il codice sorgente

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

zouxuan 5 anni fa
parent
commit
91cfedbaa0

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

@@ -271,5 +271,5 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
      * @return
      */
     int countStudentNotStartCourseNumWithCourseType(@Param("studentId") Integer studentId,
-                                                    @Param("type")CourseSchedule.CourseScheduleType courseScheduleType);
+                                                    @Param("courseScheduleType")CourseSchedule.CourseScheduleType courseScheduleType);
 }

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupStudentFee.java

@@ -81,6 +81,8 @@ public class MusicGroupStudentFee {
 
 	private String subjectName;
 
+	private Integer remainNetworkClassTimes;
+
 	public MusicGroupStudentFee(String musicGroupId, Integer userId, Integer subjectId,
 								BigDecimal courseFee, Date nextPaymentDate, BigDecimal temporaryCourseFee,PaymentStatus paymentStatus) {
 		this.musicGroupId = musicGroupId;
@@ -224,6 +226,13 @@ public class MusicGroupStudentFee {
 		this.temporaryCourseFee = temporaryCourseFee;
 	}
 
+	public Integer getRemainNetworkClassTimes() {
+		return remainNetworkClassTimes;
+	}
+
+	public void setRemainNetworkClassTimes(Integer remainNetworkClassTimes) {
+		this.remainNetworkClassTimes = remainNetworkClassTimes;
+	}
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 4 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/MessageTypeEnum.java

@@ -62,6 +62,10 @@ public enum MessageTypeEnum implements BaseEnum<String, MessageTypeEnum> {
     TRIAL_PRACTICE_CREATE_STUDENT_PUSH("TRIAL_PRACTICE_CREATE_STUDENT_PUSH", "试听课安排"),
     TRIAL_PRACTICE_CREATE_TEACHER_PUSH("TRIAL_PRACTICE_CREATE_TEACHER_PUSH", "试听课安排"),
 
+    /**乐团网管课*/
+    MUSIC_NETWORK_CRATE_TEACHER("MUSIC_NETWORK_CRATE_TEACHER", "乐团网管课安排"),
+    MUSIC_NETWORK_CRATE_STUDENT("MUSIC_NETWORK_CRATE_STUDENT", "乐团课通知"),
+
     /** 课外训练消息 */
     EXTRA_REMIND_PUSH("EXTRA_REMIND_PUSH", "作业提醒"),
     EXTRA_REMIND_IM("EXTRA_REMIND_IM", "作业提醒"),

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -1601,6 +1601,10 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                         salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal(studentNum.toString());
                     }
 
+                    if (classGroup4MixDto.getCourseType().equals(CourseSchedule.CourseScheduleType.MUSIC_NETWORK)) {
+                        salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal("1");
+                    }
+
                     CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
                     courseScheduleTeacherSalary.setCourseScheduleId(courseSchedule.getId());
                     courseScheduleTeacherSalary.setGroupType(courseSchedule.getGroupType());
@@ -1901,6 +1905,10 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                         salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal(studentNum.toString());
                     }
 
+                    if (classGroup4MixDto.getCourseType().equals(CourseSchedule.CourseScheduleType.MUSIC_NETWORK)) {
+                        salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal("1");
+                    }
+
                     CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
                     courseScheduleTeacherSalary.setCourseScheduleId(courseSchedule.getId());
                     courseScheduleTeacherSalary.setGroupType(courseSchedule.getGroupType());
@@ -2167,6 +2175,10 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                         salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal(studentNum.toString());
                     }
 
+                    if (classGroup4MixDto.getCourseType().equals(CourseSchedule.CourseScheduleType.MUSIC_NETWORK)) {
+                        salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal("1");
+                    }
+
                     CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
                     courseScheduleTeacherSalary.setCourseScheduleId(courseSchedule.getId());
                     courseScheduleTeacherSalary.setMusicGroupId(musicGroupId);

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupTeacherMapperServiceImpl.java

@@ -256,6 +256,10 @@ public class ClassGroupTeacherMapperServiceImpl extends BaseServiceImpl<Long, Cl
                     salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal(studentNum.toString());
                 }
 
+                if (classGroupNoStartCourseSchedule.getType().equals(CourseSchedule.CourseScheduleType.MUSIC_NETWORK)) {
+                    salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal("1");
+                }
+
                 //课程与老师薪水表
                 CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
                 courseScheduleTeacherSalary.setCourseScheduleId(classGroupNoStartCourseSchedule.getId());
@@ -367,6 +371,10 @@ public class ClassGroupTeacherMapperServiceImpl extends BaseServiceImpl<Long, Cl
                     salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal(studentNum.toString());
                 }
 
+                if (classGroupNoStartCourseSchedule.getType().equals(CourseSchedule.CourseScheduleType.MUSIC_NETWORK)) {
+                    salary = JSON.parseObject(teacherDefaultMusicGroupSalary.getSalaryRuleJson()).getBigDecimal("1");
+                }
+
                 //课程与老师薪水表
                 CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary();
                 courseScheduleTeacherSalary.setCourseScheduleId(classGroupNoStartCourseSchedule.getId());
@@ -579,6 +587,10 @@ public class ClassGroupTeacherMapperServiceImpl extends BaseServiceImpl<Long, Cl
             teacherSalary = JSON.parseObject(teacherDefaultMusicGroupSalaryWithTeacherId.getSalaryRuleJson()).getBigDecimal(studentNum.toString());
         }
 
+        if (courseSchedule.getType().equals(CourseSchedule.CourseScheduleType.MUSIC_NETWORK)) {
+            teacherSalary = JSON.parseObject(teacherDefaultMusicGroupSalaryWithTeacherId.getSalaryRuleJson()).getBigDecimal("1");
+        }
+
         CourseScheduleTeacherSalary courseScheduleTeacherSalary = new CourseScheduleTeacherSalary(
                 courseSchedule.getId(),
                 teachType,

+ 80 - 35
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -45,16 +45,17 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public boolean create(MusicGroupPaymentCalender musicGroupPaymentCalender) {
-		
+
 		Date date = new Date();
-		List<MusicGroupStudentFee> list = null;
+		List<MusicGroupStudentFee> musicGroupStudentFeeList = null;
 
 		musicGroupPaymentCalender.setCreateTime(date);
 		musicGroupPaymentCalender.setUpdateTime(date);
 		musicGroupPaymentCalender.setDeadlinePaymentDate(DateUtil.addDays(musicGroupPaymentCalender.getStartPaymentDate(), 3));
-		//判断缴费开始时间、结束时间是否被其他缴费记录占用
-		int count = musicGroupPaymentCalenderDao.queryIntersectionByPaymentDate(musicGroupPaymentCalender.getMusicGroupId(), musicGroupPaymentCalender.getStartPaymentDate(), musicGroupPaymentCalender.getDeadlinePaymentDate());
-		if(count > 0){
+		// 判断缴费开始时间、结束时间是否被其他缴费记录占用
+		int count = musicGroupPaymentCalenderDao.queryIntersectionByPaymentDate(musicGroupPaymentCalender.getMusicGroupId(),
+				musicGroupPaymentCalender.getStartPaymentDate(), musicGroupPaymentCalender.getDeadlinePaymentDate());
+		if (count > 0) {
 			throw new BizException("缴费时间存在冲突,请修改缴费开始日期");
 		}
 		if (date.after(musicGroupPaymentCalender.getDeadlinePaymentDate())) {
@@ -62,33 +63,52 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 		} else if (date.after(musicGroupPaymentCalender.getStartPaymentDate())) {
 			musicGroupPaymentCalender.setPaymentStatus(PaymentStatusEnum.OPEN);
 			// 统计缴费人数
-			list = musicGroupStudentFeeDao.queryByMusicGroupId(musicGroupPaymentCalender.getMusicGroupId());
-			if (list == null) {
-				list = new ArrayList<MusicGroupStudentFee>();
+			musicGroupStudentFeeList = musicGroupStudentFeeDao.queryByMusicGroupId(musicGroupPaymentCalender.getMusicGroupId());
+			if (musicGroupStudentFeeList == null) {
+				musicGroupStudentFeeList = new ArrayList<MusicGroupStudentFee>();
 			}
-			musicGroupPaymentCalender.setExpectNum(list.size());
+			musicGroupPaymentCalender.setExpectNum(musicGroupStudentFeeList.size());
 		} else {
 			musicGroupPaymentCalender.setPaymentStatus(PaymentStatusEnum.NO);
 		}
 
 		this.insert(musicGroupPaymentCalender);
 
+		List<MusicGroupStudentFee> updateMusicGroupStudentFeeList = new ArrayList<MusicGroupStudentFee>();
+
 		List<MusicGroupPaymentCalenderDetail> musicGroupPaymentCalenderDetailList = new ArrayList<MusicGroupPaymentCalenderDetail>();
 		if (musicGroupPaymentCalender.getPaymentStatus() == PaymentStatusEnum.OPEN) {
-			if (list != null && list.size() > 0) {
+			if (musicGroupStudentFeeList != null && musicGroupStudentFeeList.size() > 0) {
+				
 				MusicGroupPaymentCalenderDetail musicGroupPaymentCalenderDetail = null;
 				// 创建缴费明细
-				for (MusicGroupStudentFee mgsf : list) {
+				for (MusicGroupStudentFee mgsf : musicGroupStudentFeeList) {
 					musicGroupPaymentCalenderDetail = new MusicGroupPaymentCalenderDetail();
 					musicGroupPaymentCalenderDetail.setMusicGroupPaymentCalenderId(musicGroupPaymentCalender.getId());
 					musicGroupPaymentCalenderDetail.setCreateTime(date);
 					musicGroupPaymentCalenderDetail.setExpectAmount(mgsf.getCourseFee());
-					musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.NON_PAYMENT);
+					if (mgsf.getCourseFee().doubleValue() == 0) {
+						musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
+					} else {
+						musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.NON_PAYMENT);
+					}
 					musicGroupPaymentCalenderDetail.setUpdateTime(date);
 					musicGroupPaymentCalenderDetail.setUserId(mgsf.getUserId());
 
 					musicGroupPaymentCalenderDetailList.add(musicGroupPaymentCalenderDetail);
 				}
+
+				// 更新学员缴费状态
+				for (MusicGroupStudentFee mgsf : musicGroupStudentFeeList) {
+					if (mgsf.getCourseFee().doubleValue() == 0) {
+						mgsf.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
+						mgsf.setRemainNetworkClassTimes(mgsf.getRemainNetworkClassTimes() + 1);
+					} else {
+						mgsf.setPaymentStatus(PaymentStatus.NON_PAYMENT);
+					}
+					mgsf.setUpdateTime(date);
+					updateMusicGroupStudentFeeList.add(mgsf);
+				}
 			}
 		}
 
@@ -96,6 +116,10 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			musicGroupPaymentCalenderDetailDao.batchInsert(musicGroupPaymentCalenderDetailList);
 		}
 
+		if (updateMusicGroupStudentFeeList.size() > 0) {
+			musicGroupStudentFeeDao.batchUpdate(updateMusicGroupStudentFeeList);
+		}
+
 		return true;
 	}
 
@@ -107,54 +131,75 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 		statusList.add(PaymentStatusEnum.NO);
 		statusList.add(PaymentStatusEnum.OPEN);
 		List<MusicGroupPaymentCalender> musicGroupPaymentCalenderList = musicGroupPaymentCalenderDao.queryByPaymentStatus(statusList);
-		
+
 		List<MusicGroupPaymentCalender> updateMusicGroupPaymentCalenderList = new ArrayList<MusicGroupPaymentCalender>();
 
 		MusicGroupPaymentCalenderDetail musicGroupPaymentCalenderDetail = null;
+		List<MusicGroupStudentFee> updateMusicGroupStudentFeeList = new ArrayList<MusicGroupStudentFee>();
 		List<MusicGroupPaymentCalenderDetail> musicGroupPaymentCalenderDetailList = new ArrayList<MusicGroupPaymentCalenderDetail>();
-		
-		for(MusicGroupPaymentCalender mgpc : musicGroupPaymentCalenderList){
-			
-			if(date.after(mgpc.getDeadlinePaymentDate())){
-				//“进行中”更新至“已结束”
+
+		for (MusicGroupPaymentCalender mgpc : musicGroupPaymentCalenderList) {
+
+			if (date.after(mgpc.getDeadlinePaymentDate())) {
+				// “进行中”更新至“已结束”
 				mgpc.setUpdateTime(date);
 				mgpc.setPaymentStatus(PaymentStatusEnum.YES);
 				updateMusicGroupPaymentCalenderList.add(mgpc);
-				
-				//学生状态更新已结束
-				
+
+				// 学生状态更新已结束
+
 			} else if (date.after(mgpc.getStartPaymentDate())) {
-				//“未开始”更新至“进行中”
+				// “未开始”更新至“进行中”
 				mgpc.setUpdateTime(date);
 				mgpc.setPaymentStatus(PaymentStatusEnum.OPEN);
 				updateMusicGroupPaymentCalenderList.add(mgpc);
-				
-				//学生状态更新进行中
-				List<MusicGroupStudentFee> list = musicGroupStudentFeeDao.queryByMusicGroupId(mgpc.getMusicGroupId());
-				
+
+				// 学生状态更新进行中
+				List<MusicGroupStudentFee> musicGroupStudentFeeList = musicGroupStudentFeeDao.queryByMusicGroupId(mgpc.getMusicGroupId());
+
 				// 创建缴费明细
-				for (MusicGroupStudentFee mgsf : list) {
+				for (MusicGroupStudentFee mgsf : musicGroupStudentFeeList) {
 					musicGroupPaymentCalenderDetail = new MusicGroupPaymentCalenderDetail();
 					musicGroupPaymentCalenderDetail.setMusicGroupPaymentCalenderId(mgpc.getId());
 					musicGroupPaymentCalenderDetail.setCreateTime(date);
 					musicGroupPaymentCalenderDetail.setExpectAmount(mgsf.getCourseFee());
-					musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.NON_PAYMENT);
+					if (mgsf.getCourseFee().doubleValue() == 0) {
+						musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
+					} else {
+						musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.NON_PAYMENT);
+					}
 					musicGroupPaymentCalenderDetail.setUpdateTime(date);
 					musicGroupPaymentCalenderDetail.setUserId(mgsf.getUserId());
 
 					musicGroupPaymentCalenderDetailList.add(musicGroupPaymentCalenderDetail);
 				}
+
+				// 更新学员缴费状态
+				for (MusicGroupStudentFee mgsf : musicGroupStudentFeeList) {
+					if (mgsf.getCourseFee().doubleValue() == 0) {
+						mgsf.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
+						mgsf.setRemainNetworkClassTimes(mgsf.getRemainNetworkClassTimes() + 1);
+					} else {
+						mgsf.setPaymentStatus(PaymentStatus.NON_PAYMENT);
+					}
+					mgsf.setUpdateTime(date);
+					updateMusicGroupStudentFeeList.add(mgsf);
+				}
 			}
 		}
-		
-		if(updateMusicGroupPaymentCalenderList.size() > 0){
+
+		if (updateMusicGroupPaymentCalenderList.size() > 0) {
 			musicGroupPaymentCalenderDao.batchUpdate(updateMusicGroupPaymentCalenderList);
 		}
 
 		if (musicGroupPaymentCalenderDetailList.size() > 0) {
 			musicGroupPaymentCalenderDetailDao.batchInsert(musicGroupPaymentCalenderDetailList);
 		}
-		
+
+		if (updateMusicGroupStudentFeeList.size() > 0) {
+			musicGroupStudentFeeDao.batchUpdate(updateMusicGroupStudentFeeList);
+		}
+
 		return true;
 	}
 
@@ -228,7 +273,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			throw new BizException("修改失败,缴费状态不匹配");
 		}
 		calender.setStartPaymentDate(startTime);
-		calender.setDeadlinePaymentDate(DateUtil.addDays(startTime,3));
+		calender.setDeadlinePaymentDate(DateUtil.addDays(startTime, 3));
 		calender.setUpdateTime(new Date());
 		musicGroupPaymentCalenderDao.update(calender);
 	}
@@ -253,9 +298,9 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 	public Object getDetail(Long id) {
 		MusicGroupPaymentCalender calender = musicGroupPaymentCalenderDao.get(id);
 		BigDecimal sumActualAmount = musicGroupPaymentCalenderDetailDao.sumActualAmount(id);
-		Map<String,Object> result = new HashMap<>(2);
-		result.put("calender",calender);
-		result.put("sumActualAmount",sumActualAmount);
+		Map<String, Object> result = new HashMap<>(2);
+		result.put("calender", calender);
+		result.put("sumActualAmount", sumActualAmount);
 		return result;
 	}
 }

+ 3 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -1684,6 +1684,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             musicGroupStudentFee.setLatestPaidTime(date);
             musicGroupStudentFee.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
             musicGroupStudentFee.setTemporaryCourseFee(new BigDecimal(0));
+            Integer getRemainNetworkClassTimes = musicGroupStudentFee.getRemainNetworkClassTimes() == null ? 0 : musicGroupStudentFee.getRemainNetworkClassTimes();
+            musicGroupStudentFee.setRemainNetworkClassTimes(getRemainNetworkClassTimes+1);
 //            musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId, musicGroupStudentFee.getNextPaymentDate(), musicGroupStudentFee));
             musicGroupStudentFeeDao.update(musicGroupStudentFee);
 
@@ -1701,7 +1703,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             //更新实际缴费人数
             MusicGroupPaymentCalender musicGroupPaymentCalender = musicGroupPaymentCalenderDao.getForLock(userLastCalenderDetail.getMusicGroupPaymentCalenderId());
             Integer actualNum = musicGroupPaymentCalender.getActualNum() == null ? 0:musicGroupPaymentCalender.getActualNum();
-            musicGroupPaymentCalender.setActualNum(actualNum);
+            musicGroupPaymentCalender.setActualNum(actualNum+1);
             musicGroupPaymentCalender.setUpdateTime(date);
             musicGroupPaymentCalenderDao.update(musicGroupPaymentCalender);
 

+ 345 - 137
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OnlineMusicGroupServiceImpl.java

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

+ 6 - 11
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderDetailMapper.xml

@@ -199,17 +199,12 @@
 		SELECT * FROM music_group_payment_calender_detail where music_group_payment_calender_id_ = #{calenderId}
 	</select>
     <select id="findMusicGroupStudentWithSubject" resultType="com.ym.mec.biz.dal.dto.SimpleUserDto">
-		SELECT
-		DISTINCT su.id_ userId,su.username_ userName, su.avatar_ avatar, su.phone_ phone
-		FROM music_group_payment_calender_detail mgpcd
-		LEFT JOIN student_registration sr ON sr.user_id_=mgpcd.user_id_
-		LEFT JOIN sys_user su ON su.id_=mgpcd.user_id_
-		WHERE sr.music_group_id_=#{musicGroupId}
-		AND sr.subject_id_= #{subjectId}
-		AND music_group_payment_calender_id_ IN
-		(SELECT id_ FROM (SELECT id_ FROM music_group_payment_calender
-		WHERE music_group_id_=#{musicGroupId} AND payment_status_ IN (1,2)
-		ORDER BY start_payment_date_ DESC LIMIT 1) t);
+		SELECT DISTINCT su.id_ userId,su.username_ userName, su.avatar_ avatar, su.phone_ phone
+		from music_group_student_fee_ mgstf
+		LEFT JOIN sys_user su ON su.id_=mgstf.user_id_
+		WHERE mgstf.music_group_id_=#{musicGroupId}
+		AND mgstf.subject_id_=#{subjectId}
+		AND mgstf.remain_network_class_times_>0
 	</select>
 	<select id="sumActualAmount" resultType="java.math.BigDecimal">
 		SELECT SUM(mgpcd.actual_amount_) FROM music_group_payment_calender_detail mgpcd

+ 5 - 1
mec-biz/src/main/resources/config/mybatis/MusicGroupStudentFeeMapper.xml

@@ -22,6 +22,7 @@
         <result column="temporary_course_fee_" property="temporaryCourseFee"/>
         <result column="is_lock_" property="isLock"/>
         <result column="payment_period_list_" property="paymentPeriodList"/>
+        <result column="remain_network_class_times_" property="remainNetworkClassTimes" />
         <association property="sysUser" javaType="com.ym.mec.auth.api.entity.SysUser">
             <result column="username_" property="username" />
             <result column="phone_" property="phone" />
@@ -87,6 +88,9 @@
             <if test="temporaryCourseFee != null">
                 temporary_course_fee_ = #{temporaryCourseFee},
             </if>
+            <if test="remainNetworkClassTimes != null">
+                remain_network_class_times_ = #{remainNetworkClassTimes},
+            </if>
             <if test="isLock != null">
                 is_lock_ = #{isLock},
             </if>
@@ -162,7 +166,7 @@
 	</select>
 
     <select id="findByUser" resultMap="MusicGroupStudentFee">
-        SELECT * FROM music_group_student_fee_ WHERE music_group_id_ = #{musicGroupId} AND user_id_ = #{userId}
+        SELECT * FROM music_group_student_fee_ WHERE music_group_id_ = #{musicGroupId} AND user_id_ = #{userId} FOR UPDATE
     </select>
     
     <update id="updateNextPaymentDate" parameterType="map">

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/StudentRegistrationMapper.xml

@@ -610,7 +610,7 @@
     </select>
     <select id="findMusicGroupAllStudentSubjects" resultMap="com.ym.mec.biz.dal.dao.SubjectDao.Subject">
         SELECT DISTINCT s.* FROM student_registration sr
-        LEFT JOIN subject s ON sr.subject_id_=s.id_
+        LEFT JOIN subject s ON sr.actual_subject_id_=s.id_
         WHERE sr.music_group_id_=#{musicGroupId};
     </select>
 </mapper>

+ 1 - 1
mec-common/common-core/src/main/java/com/ym/mec/common/entity/HttpResponseResult.java

@@ -53,7 +53,7 @@ public class HttpResponseResult<T> {
 		this.msg = msg;
 	}
 
-	public Object getData() {
+	public T getData() {
 		return data;
 	}
 

+ 1 - 5
mec-web/src/main/java/com/ym/mec/web/controller/education/EduOnlineMusicGroupController.java

@@ -23,10 +23,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.Arrays;
 import java.util.List;
@@ -126,7 +123,6 @@ public class EduOnlineMusicGroupController extends BaseController {
         if (sysUser == null) {
             return failed("用户信息获取失败");
         }
-
         return succeed(onlineMusicGroupService.createOnlineMusicClassGroup(onlineMusicGroupCourseInfo));
     }