| 
					
				 | 
			
			
				@@ -1,65 +1,19 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.ym.mec.biz.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.math.BigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Arrays; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Calendar; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.HashMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.HashSet; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Iterator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Set; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.enums.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.service.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.auth.api.client.SysUserFeignService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.auth.api.entity.SysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.auth.api.entity.SysUserRole; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.auth.api.enums.SysUserType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.auth.api.enums.UserLockFlag; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.MusicGroupDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.MusicGroupStudentFeeDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.MusicGroupSubjectPlanDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.StudentRegistrationDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.SubjectDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.SysConfigDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.SysUserCashAccountDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.TeacherDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.dao.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dto.StudentAddDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dto.StudentApplyDetailDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dto.StudentFeeDetailDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dto.StudentInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.ClassGroup; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.ClassGroupRelation; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.ClassGroupStudentMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.CourseSchedule; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.CourseScheduleStudentPayment; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.Goods; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.MusicGroup; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.MusicGroupStudentFee; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.MusicGroupSubjectGoodsGroup; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.MusicGroupSubjectPlan; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.StudentPaymentOrder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.StudentRegistration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.Subject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.SysUserCashAccount; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.entity.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.dal.enums.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.page.StudentRegistrationQueryInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.ym.mec.biz.service.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.dal.BaseDAO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.entity.ImGroupMember; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.common.entity.ImGroupModel; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -74,6 +28,16 @@ import com.ym.mec.thirdparty.message.MessageSenderPluginContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.util.collection.MapUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.util.date.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.util.http.HttpUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.annotation.Resource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.math.BigDecimal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, StudentRegistration> implements StudentRegistrationService { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -512,6 +476,9 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (studentRegistration == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             throw new Exception("参数校验失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(studentAddDto.getSignClassId() == null && studentAddDto.getMixClassId() == null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            throw new Exception("参数校验失败: 单技班或合奏班必填一项"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         String musicGroupId = studentRegistration.getMusicGroupId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         StudentRegistration phoneAndMusicGroupId = studentRegistrationDao.getByPhoneAndMusicGroupId(musicGroupId, studentRegistration.getParentsPhone()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -560,156 +527,134 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             sysMessageService.batchSeoMessage(musicGroupDao.queryUserIdByRoleId(roleIds, musicGroup.getOrganId() + ""), MessageTypeEnum.BACKSTAGE_MUSIC_GROUP_ADD_STUDENT, "", musicGroup.getName(), studentRegistration.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //增加报名学生数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             musicGroupSubjectPlanService.addApplyStudentNum(musicGroupId, studentRegistration.getSubjectId(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Integer classGroupId = studentRegistration.getClassGroupId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (classGroupId != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                ClassGroup classGroup = classGroupDao.get(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (classGroup != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!classGroup.getMusicGroupId().equals(musicGroupId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        throw new Exception("班级录入错误"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        //修改实际学生人数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        classGroup.setStudentNum(classGroup.getStudentNum() + 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        classGroup.setUpdateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        classGroupDao.update(classGroup); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    throw new Exception("班级不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //添加班级关联 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                addStudents(classGroup, userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                Date date = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //保存乐团学生费用表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (studentAddDto.getCourseFee() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(musicGroupId, studentRegistration.getActualSubjectId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentAddDto.setCourseFee(musicOneSubjectClassPlan.getFee()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                Date nextPaymentDate = musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                musicGroupStudentFeeDao.insert(new MusicGroupStudentFee(musicGroupId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        userId, studentRegistration.getSubjectId(), studentAddDto.getCourseFee(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        nextPaymentDate, studentAddDto.getTemporaryCourseFee())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //生成订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrder.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrder.setGroupType(GroupType.MUSIC); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrder.setType(OrderTypeEnum.APPLY); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrder.setStatus(DealStatusEnum.WAIT_PAY); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrder.setMusicGroupId(musicGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrder.setClassGroupId(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //生成订单明细 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                List<StudentPaymentOrderDetail> studentPaymentOrderDetails = studentAddDto.getStudentPaymentOrderDetails(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (studentPaymentOrderDetails == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentPaymentOrderDetails = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrderDetail.setPrice(studentAddDto.getTemporaryCourseFee()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrderDetail.setType(OrderDetailTypeEnum.COURSE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrderDetails.add(studentPaymentOrderDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //汇总金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                BigDecimal reduce = studentPaymentOrderDetails.stream().map(e -> e.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (reduce == BigDecimal.ZERO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentRegistration.setPaymentStatus(PaymentStatusEnum.YES); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentPaymentOrder.setActualAmount(reduce); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentPaymentOrder.setPayTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrder.setExpectAmount(reduce); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //当前学员是否以前存在过当前乐团 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //添加班级关联 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addStudents(studentAddDto, userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Date date = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //保存乐团学生费用表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (studentAddDto.getCourseFee() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(musicGroupId, studentRegistration.getActualSubjectId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentAddDto.setCourseFee(musicOneSubjectClassPlan.getFee()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Date nextPaymentDate = musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            musicGroupStudentFeeDao.insert(new MusicGroupStudentFee(musicGroupId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    userId, studentRegistration.getSubjectId(), studentAddDto.getCourseFee(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    nextPaymentDate, studentAddDto.getTemporaryCourseFee())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //生成订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrder.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrder.setGroupType(GroupType.MUSIC); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrder.setType(OrderTypeEnum.APPLY); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrder.setStatus(DealStatusEnum.WAIT_PAY); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrder.setMusicGroupId(musicGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrder.setClassGroupId(studentAddDto.getSignClassId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //生成订单明细 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<StudentPaymentOrderDetail> studentPaymentOrderDetails = studentAddDto.getStudentPaymentOrderDetails(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (studentPaymentOrderDetails == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentPaymentOrderDetails = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrderDetail.setPrice(studentAddDto.getTemporaryCourseFee()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrderDetail.setType(OrderDetailTypeEnum.COURSE); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrderDetails.add(studentPaymentOrderDetail); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //汇总金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal reduce = studentPaymentOrderDetails.stream().map(e -> e.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (reduce == BigDecimal.ZERO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentRegistration.setPaymentStatus(PaymentStatusEnum.YES); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentPaymentOrder.setActualAmount(reduce); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentPaymentOrder.setPayTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrder.setExpectAmount(reduce); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //当前学员是否以前存在过当前乐团 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 //                StudentRegistration registration = studentRegistrationDao.queryByUserIdAndMusicGroupId(userId, musicGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if(phoneAndMusicGroupId != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentRegistration.setId(phoneAndMusicGroupId.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentRegistrationDao.update(studentRegistration); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    studentRegistrationDao.insertBasic(studentRegistration); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrderService.insert(studentPaymentOrder); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrderDetails.forEach(e -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    e.setPaymentOrderId(studentPaymentOrder.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetails); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                Map<Integer, String> receivers = new HashMap<>(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                receivers.put(studentRegistration.getUserId(), studentRegistration.getParentsPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (reduce == BigDecimal.ZERO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.YIMEI, MessageTypeEnum.SMS_MUSIC_GROUP_ADD_STUDENT_FREE, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            receivers, null, 0, null, studentRegistration.getParentsName(), studentRegistration.getName(), musicGroup.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    String studentApplyUrl = sysConfigDao.findConfigValue(SysConfigService.STUDENT_APPLY_URL) + musicGroupId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.YIMEI, MessageTypeEnum.SMS_MUSIC_GROUP_ADD_STUDENT, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            receivers, null, 0, null, studentRegistration.getParentsName(), studentRegistration.getName(), musicGroup.getName(),HttpUtil.getSortUrl(studentApplyUrl)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if(phoneAndMusicGroupId != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentRegistration.setId(phoneAndMusicGroupId.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentRegistrationDao.update(studentRegistration); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                studentRegistrationDao.insertBasic(studentRegistration); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrderService.insert(studentPaymentOrder); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrderDetails.forEach(e -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                e.setPaymentOrderId(studentPaymentOrder.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetails); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<Integer, String> receivers = new HashMap<>(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            receivers.put(studentRegistration.getUserId(), studentRegistration.getParentsPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (reduce == BigDecimal.ZERO) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.YIMEI, MessageTypeEnum.SMS_MUSIC_GROUP_ADD_STUDENT_FREE, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        receivers, null, 0, null, studentRegistration.getParentsName(), studentRegistration.getName(), musicGroup.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                String studentApplyUrl = sysConfigDao.findConfigValue(SysConfigService.STUDENT_APPLY_URL) + musicGroupId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.YIMEI, MessageTypeEnum.SMS_MUSIC_GROUP_ADD_STUDENT, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        receivers, null, 0, null, studentRegistration.getParentsName(), studentRegistration.getName(), musicGroup.getName(),HttpUtil.getSortUrl(studentApplyUrl)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return userId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    public void addStudents(ClassGroup classGroup, Integer userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Date nowDate = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //1、班级关系添加 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        List<ClassGroupStudentMapper> classGroupStudentMappers = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        List<ImGroupMember> imGroupMemberList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Integer classGroupId = classGroup.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //校验是否存在历史记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        ClassGroupStudentMapper classGroupStudentMapper = classGroupStudentMapperDao.findClassStudentMapperByUserIdAndClassGroupId(userId, classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private List<CourseSchedule> addStudent(Integer classGroupId,Integer userId,Date date,List<CourseSchedule> courseScheduleList){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ClassGroup classGroup = classGroupDao.get(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ClassGroupStudentMapper classGroupStudentMapper = classGroupStudentMapperDao.findClassStudentMapperByUserIdAndClassGroupId(userId, classGroupId,null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if(classGroupStudentMapper != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            classGroupStudentMapper.setClassGroupId(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            classGroupStudentMapper.setClassGroupId(classGroup.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapperDao.update(classGroupStudentMapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapper = new ClassGroupStudentMapper(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapper.setClassGroupId(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapper.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            classGroupStudentMapper.setCreateTime(nowDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            classGroupStudentMapper.setCreateTime(date); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapper.setGroupType(GroupType.MUSIC); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             classGroupStudentMapperDao.insert(classGroupStudentMapper); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //添加进IM群组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         ImGroupMember[] imGroupMembers = {new ImGroupMember(userId.toString())}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        imFeignService.groupJoin(new ImGroupModel(classGroup.getId().toString(), imGroupMembers, classGroup.getName())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        imFeignService.groupJoin(new ImGroupModel(classGroupId.toString(), imGroupMembers, classGroup.getName())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //2、班级人数调整 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        classGroupDao.updateClassStudentNum(classGroupId.longValue(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//        classGroupDao.updateClassStudentNum(classGroupId.longValue(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //3、学生加入新班级未开始课程 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        List<CourseSchedule> courseScheduleList = courseScheduleService.findNoStartCoursesByClassGroupId(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        ClassGroupRelation classGroupRelation = classGroupRelationService.findClassGroupRelation(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if(classGroupRelation != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            ClassGroupStudentMapper classGroupStudentMapperMix = classGroupStudentMapperDao.findClassStudentMapperByUserIdAndClassGroupId(userId, classGroupRelation.getClassGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if(classGroupStudentMapperMix != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix.setStatus(ClassGroupStudentStatusEnum.NORMAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix.setClassGroupId(classGroupRelation.getClassGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperDao.update(classGroupStudentMapperMix); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix = new ClassGroupStudentMapper(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix.setMusicGroupId(classGroup.getMusicGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix.setClassGroupId(classGroupRelation.getClassGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix.setCreateTime(nowDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix.setStatus(ClassGroupStudentStatusEnum.NORMAL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperMix.setGroupType(GroupType.MUSIC); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                classGroupStudentMapperDao.insert(classGroupStudentMapperMix); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            classGroupDao.updateClassStudentNum(classGroupRelation.getClassGroupId().longValue(), 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            List<CourseSchedule> mixCourseScheduleList = courseScheduleService.findNoStartCoursesByClassGroupId(classGroupRelation.getClassGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            courseScheduleList.addAll(mixCourseScheduleList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //添加进合奏班IM群组 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            imFeignService.groupJoin(new ImGroupModel(classGroupRelation.getClassGroupId().toString(), imGroupMembers, null)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<CourseSchedule> noStartCoursesByClassGroupId = courseScheduleService.findNoStartCoursesByClassGroupId(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(noStartCoursesByClassGroupId != null && noStartCoursesByClassGroupId.size() > 0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            courseScheduleList.addAll(noStartCoursesByClassGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return courseScheduleList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        BigDecimal coursePrice = new BigDecimal("0"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void addStudents(StudentAddDto studentAddDto, Integer userId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date nowDate = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String musicGroupId = studentAddDto.getStudentRegistration().getMusicGroupId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer signClassId = studentAddDto.getSignClassId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<CourseSchedule> courseScheduleList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(signClassId != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addStudent(signClassId,userId,nowDate,courseScheduleList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer mixClassId = studentAddDto.getMixClassId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(mixClassId != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addStudent(mixClassId,userId,nowDate,courseScheduleList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer highClassId = studentAddDto.getHighClassId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(highClassId != null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            addStudent(mixClassId,userId,nowDate,courseScheduleList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String snapClassIds = studentAddDto.getSnapClassIds(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(StringUtils.isNotEmpty(snapClassIds)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String[] split = snapClassIds.split(","); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (int i = 0;i < split.length;i++){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                addStudent(Integer.parseInt(split[i]),userId,nowDate,courseScheduleList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         for (CourseSchedule courseSchedule : courseScheduleList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            courseScheduleStudentPayment.setGroupType(classGroup.getGroupType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            courseScheduleStudentPayment.setMusicGroupId(classGroup.getMusicGroupId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            courseScheduleStudentPayment.setGroupType(GroupType.MUSIC); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            courseScheduleStudentPayment.setMusicGroupId(musicGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             courseScheduleStudentPayment.setUserId(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            courseScheduleStudentPayment.setExpectPrice(coursePrice); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            courseScheduleStudentPayment.setClassGroupId(classGroupId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            courseScheduleStudentPayment.setExpectPrice(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            courseScheduleStudentPayment.setClassGroupId(signClassId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             courseScheduleStudentPayment.setCreateTime(nowDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             courseScheduleStudentPayment.setUpdateTime(nowDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             courseScheduleStudentPayments.add(courseScheduleStudentPayment); 
			 |