|  | @@ -21,6 +21,7 @@ import com.ym.mec.common.entity.ImResult;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.entity.ImUserModel;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.page.PageInfo;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.redis.service.RedisCache;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import com.ym.mec.im.ImFeignService;
 | 
	
		
			
				|  |  |  import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 | 
	
	
		
			
				|  | @@ -93,6 +94,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |      private ClassGroupStudentMapperService classGroupStudentMapperService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysUserFeignService sysUserFeignService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private RedisCache<String, Object> redisCache;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public BaseDAO<Long, StudentRegistration> getDAO() {
 | 
	
	
		
			
				|  | @@ -123,7 +126,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public Integer batchUpdateSubject(Integer userId, Integer subId, String musicGroupId) throws Exception {
 | 
	
		
			
				|  |  |          SysUser sysUser = sysUserFeignService.queryUserInfo();
 | 
	
		
			
				|  |  | -        if(sysUser == null){
 | 
	
		
			
				|  |  | +        if (sysUser == null) {
 | 
	
		
			
				|  |  |              throw new BizException("获取用户信息失败");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //获取当前学员的当前声部
 | 
	
	
		
			
				|  | @@ -133,7 +136,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //批量调剂(未缴费学员)
 | 
	
		
			
				|  |  |          int i = studentRegistrationDao.batchUpdateSubject(userId, subId, musicGroupId);
 | 
	
		
			
				|  |  | -        if(i > 0){
 | 
	
		
			
				|  |  | +        if (i > 0) {
 | 
	
		
			
				|  |  |              //当前专业报名人数减一
 | 
	
		
			
				|  |  |              musicGroupSubjectPlanService.addApplyStudentNum(musicGroupId, studentRegistration.getActualSubjectId(), -1);
 | 
	
		
			
				|  |  |              //修改专业已报名人数
 | 
	
	
		
			
				|  | @@ -143,8 +146,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |              roleIds.add(SysUserRole.SECTION_MANAGER);
 | 
	
		
			
				|  |  |              roleIds.add(SysUserRole.OPERATION_EXECUTIVE);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    		String[] organIds = { musicGroup.getOrganId() + "" };
 | 
	
		
			
				|  |  | -            sysMessageService.batchSeoMessage(musicGroupDao.queryUserIdByRoleId(roleIds,organIds), MessageTypeEnum.BACKSTAGE_STUDENT_SUBJECT_CHANGE, "", musicGroup.getName());
 | 
	
		
			
				|  |  | +            String[] organIds = {musicGroup.getOrganId() + ""};
 | 
	
		
			
				|  |  | +            sysMessageService.batchSeoMessage(musicGroupDao.queryUserIdByRoleId(roleIds, organIds), MessageTypeEnum.BACKSTAGE_STUDENT_SUBJECT_CHANGE, "", musicGroup.getName());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return i;
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -190,6 +193,11 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public StudentRegistration addStudent(StudentRegistration studentRegistration) throws IOException {
 | 
	
		
			
				|  |  | +    	String key = "_student_registration";
 | 
	
		
			
				|  |  | +    	long threadId = Thread.currentThread().getId();
 | 
	
		
			
				|  |  | +    	if(!redisCache.getLocked(key, threadId, 10)){
 | 
	
		
			
				|  |  | +    		throw new BizException("系统繁忙,请稍后再试");
 | 
	
		
			
				|  |  | +    	}
 | 
	
		
			
				|  |  |          Date date = new Date();
 | 
	
		
			
				|  |  |          Integer userId = 0;
 | 
	
		
			
				|  |  |          SysUser sysUser = studentRegistrationDao.getSysUserByPhone(studentRegistration.getParentsPhone());
 | 
	
	
		
			
				|  | @@ -202,7 +210,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |              sysUser.setDelFlag(com.ym.mec.auth.api.enums.YesOrNoEnum.NO);
 | 
	
		
			
				|  |  |              sysUser.setUserType(SysUserType.STUDENT);
 | 
	
		
			
				|  |  |              sysUser.setGender(studentRegistration.getGender());
 | 
	
		
			
				|  |  | -            if(studentRegistration.getOrganId() != null){
 | 
	
		
			
				|  |  | +            if (studentRegistration.getOrganId() != null) {
 | 
	
		
			
				|  |  |                  sysUser.setOrganId(studentRegistration.getOrganId());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              sysUser.setRealName(studentRegistration.getParentsName());
 | 
	
	
		
			
				|  | @@ -224,8 +232,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |          studentRegistration.setCreateTime(date);
 | 
	
		
			
				|  |  |          studentRegistration.setUpdateTime(date);
 | 
	
		
			
				|  |  |          studentRegistration.setUserId(sysUser.getId());
 | 
	
		
			
				|  |  | -        studentRegistrationDao.updateCurrentClass(studentRegistration);
 | 
	
		
			
				|  |  |          studentRegistrationDao.insert(studentRegistration);
 | 
	
		
			
				|  |  | +        studentRegistrationDao.updateCurrentClass(studentRegistration);
 | 
	
		
			
				|  |  |          //增加报名学生数
 | 
	
		
			
				|  |  |          musicGroupSubjectPlanService.addApplyStudentNum(studentRegistration.getMusicGroupId(), studentRegistration.getSubjectId(), 1);
 | 
	
		
			
				|  |  |          //报名成功后,发送短信
 | 
	
	
		
			
				|  | @@ -240,6 +248,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |                  MessageTypeEnum.SMS_APPLY_MESSAGE, map, null, 0, "",
 | 
	
		
			
				|  |  |                  studentRegistration.getParentsName(), subject.getName(), HttpUtil.getSortUrl(studentApplyUrl),
 | 
	
		
			
				|  |  |                  DateUtil.format(musicGroup.getApplyExpireDate(), DateUtil.DATE_FORMAT_MIN), serverPhone);
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        redisCache.releaseLocked(key, threadId);
 | 
	
		
			
				|  |  |          return studentRegistration;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -248,8 +258,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |          return studentRegistrationDao.queryStudentInfo(userId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | +    @Transactional
 | 
	
		
			
				|  |  |      public StudentPaymentOrder addOrder(StudentRegistration studentRegistration, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList) throws Exception {
 | 
	
		
			
				|  |  |          Date date = new Date();
 | 
	
		
			
				|  |  |          StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
	
		
			
				|  | @@ -331,12 +341,15 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |          if (studentRegistration.getTemporaryCourseFee() == null && musicOneSubjectClassPlan.getPaidStudentNum() > musicOneSubjectClassPlan.getExpectedStudentNum()) {
 | 
	
		
			
				|  |  |              throw new BizException("乐团人数已满");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        musicGroupSubjectPlanService.update(musicOneSubjectClassPlan);
 | 
	
		
			
				|  |  | +        int count = musicGroupSubjectPlanService.update(musicOneSubjectClassPlan);
 | 
	
		
			
				|  |  | +        if (count <= 0) {
 | 
	
		
			
				|  |  | +            throw new BizException("系统繁忙请重新");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          return studentPaymentOrder;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | +    @Transactional
 | 
	
		
			
				|  |  |      public StudentPaymentOrder reAddOrder(Integer userId, BigDecimal amount, String orderNo, String paymentChannel, BigDecimal courseFee, List<MusicGroupSubjectGoodsGroup> goodsGroups, List<Goods> goodsList, List<Goods> otherGoodsList, String musicGroupId, StudentPaymentOrder oldOrder) {
 | 
	
		
			
				|  |  |          //关闭老订单
 | 
	
		
			
				|  |  |          oldOrder.setStatus(DealStatusEnum.CLOSE);
 | 
	
	
		
			
				|  | @@ -424,7 +437,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |          StudentRegistration registration = studentRegistrationDao.queryByUserIdAndMusicGroupId(userId, musicGroupId);
 | 
	
		
			
				|  |  |          SysUserCashAccount account = sysUserCashAccountDao.getLocked(userId);
 | 
	
		
			
				|  |  |          registration.setBalance(account.getBalance());
 | 
	
		
			
				|  |  | -        registration.setTransferStudent(registration.getTemporaryCourseFee() == null?0:1);
 | 
	
		
			
				|  |  | +        registration.setTransferStudent(registration.getTemporaryCourseFee() == null ? 0 : 1);
 | 
	
		
			
				|  |  |          return registration;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -484,8 +497,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |              Set<Integer> roleIds = new HashSet<>(1);
 | 
	
		
			
				|  |  |              roleIds.add(SysUserRole.OPERATION_EXECUTIVE);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    		String[] organIds = { musicGroup.getOrganId() + "" };
 | 
	
		
			
				|  |  | -            sysMessageService.batchSeoMessage(musicGroupDao.queryUserIdByRoleId(roleIds,organIds), MessageTypeEnum.BACKSTAGE_MUSIC_GROUP_ADD_STUDENT, "", musicGroup.getName(), studentRegistration.getName());
 | 
	
		
			
				|  |  | +            String[] organIds = {musicGroup.getOrganId() + ""};
 | 
	
		
			
				|  |  | +            sysMessageService.batchSeoMessage(musicGroupDao.queryUserIdByRoleId(roleIds, organIds), MessageTypeEnum.BACKSTAGE_MUSIC_GROUP_ADD_STUDENT, "", musicGroup.getName(), studentRegistration.getName());
 | 
	
		
			
				|  |  |              //增加报名学生数
 | 
	
		
			
				|  |  |              musicGroupSubjectPlanService.addApplyStudentNum(musicGroupId, studentRegistration.getSubjectId(), 1);
 | 
	
		
			
				|  |  |              Integer classGroupId = studentRegistration.getClassGroupId();
 | 
	
	
		
			
				|  | @@ -511,7 +524,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |  //                ClassGroupRelation classGroupRelation = classGroupRelationDao.findClassGroupRelation(classGroupId);
 | 
	
		
			
				|  |  |  //                classGroupStudentMapper.setClassGroupId(classGroupRelation.getClassGroupId());
 | 
	
		
			
				|  |  |  //                classGroupStudentMapperDao.insert(classGroupStudentMapper);
 | 
	
		
			
				|  |  | -                addStudents(classGroup,userId);
 | 
	
		
			
				|  |  | +                addStudents(classGroup, userId);
 | 
	
		
			
				|  |  |                  Date date = new Date();
 | 
	
		
			
				|  |  |                  //获取当前月
 | 
	
		
			
				|  |  |                  Integer month = Integer.parseInt(DateUtil.getMonth(date));
 | 
	
	
		
			
				|  | @@ -554,7 +567,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |                  studentPaymentOrderDetails.add(studentPaymentOrderDetail);
 | 
	
		
			
				|  |  |                  //汇总金额
 | 
	
		
			
				|  |  |                  BigDecimal reduce = studentPaymentOrderDetails.stream().map(e -> e.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
 | 
	
		
			
				|  |  | -                if(reduce == BigDecimal.ZERO){
 | 
	
		
			
				|  |  | +                if (reduce == BigDecimal.ZERO) {
 | 
	
		
			
				|  |  |                      studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  |                      studentRegistration.setPaymentStatus(PaymentStatusEnum.YES);
 | 
	
		
			
				|  |  |                      studentPaymentOrder.setActualAmount(reduce);
 | 
	
	
		
			
				|  | @@ -569,15 +582,15 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |                  studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetails);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              studentRegistrationDao.updateCurrentClass(studentRegistration);
 | 
	
		
			
				|  |  | -            Map<Integer,String> receivers = new HashMap<>(1);
 | 
	
		
			
				|  |  | -            receivers.put(studentRegistration.getUserId(),studentRegistration.getParentsPhone());
 | 
	
		
			
				|  |  | -            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.YIMEI,MessageTypeEnum.SMS_MUSIC_GROUP_ADD_STUDENT,
 | 
	
		
			
				|  |  | -                    receivers,null,0,null,studentRegistration.getParentsName(),studentRegistration.getName(),musicGroup.getName());
 | 
	
		
			
				|  |  | +            Map<Integer, String> receivers = new HashMap<>(1);
 | 
	
		
			
				|  |  | +            receivers.put(studentRegistration.getUserId(), studentRegistration.getParentsPhone());
 | 
	
		
			
				|  |  | +            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.YIMEI, MessageTypeEnum.SMS_MUSIC_GROUP_ADD_STUDENT,
 | 
	
		
			
				|  |  | +                    receivers, null, 0, null, studentRegistration.getParentsName(), studentRegistration.getName(), musicGroup.getName());
 | 
	
		
			
				|  |  |              return userId;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public void addStudents(ClassGroup classGroup, Integer userId){
 | 
	
		
			
				|  |  | +    public void addStudents(ClassGroup classGroup, Integer userId) {
 | 
	
		
			
				|  |  |          Date nowDate = new Date();
 | 
	
		
			
				|  |  |          //1、班级关系添加
 | 
	
		
			
				|  |  |          List<ClassGroupStudentMapper> classGroupStudentMappers = new ArrayList<>();
 | 
	
	
		
			
				|  | @@ -587,9 +600,9 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //校验是否存在历史记录
 | 
	
		
			
				|  |  |          ClassGroupStudentMapper classGroupStudentMapper = classGroupStudentMapperDao.findClassStudentMapperByUserIdAndClassGroupId(userId, classGroupId);
 | 
	
		
			
				|  |  | -        if(classGroupStudentMapper != null){
 | 
	
		
			
				|  |  | +        if (classGroupStudentMapper != null) {
 | 
	
		
			
				|  |  |              classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
 | 
	
		
			
				|  |  | -        }else {
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  |              classGroupStudentMapper = new ClassGroupStudentMapper();
 | 
	
		
			
				|  |  |              classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId());
 | 
	
		
			
				|  |  |              classGroupStudentMapper.setClassGroupId(classGroupId);
 | 
	
	
		
			
				|  | @@ -774,7 +787,10 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |          //减去缴费人数
 | 
	
		
			
				|  |  |          if (studentPaymentOrder.getStatus().equals(DealStatusEnum.FAILED)) {
 | 
	
		
			
				|  |  |              musicOneSubjectClassPlan.setPaidStudentNum(musicOneSubjectClassPlan.getPaidStudentNum() - 1);
 | 
	
		
			
				|  |  | -            musicGroupSubjectPlanService.update(musicOneSubjectClassPlan);
 | 
	
		
			
				|  |  | +            int updateCount = musicGroupSubjectPlanService.update(musicOneSubjectClassPlan);
 | 
	
		
			
				|  |  | +            if(updateCount <= 0){
 | 
	
		
			
				|  |  | +                throw new BizException("减去缴费人数失败");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              //发送缴费成功通知(短信 + push)
 | 
	
		
			
				|  |  |              String studentApplyUrl = sysConfigDao.findConfigValue(SysConfigService.STUDENT_APPLY_URL + studentRegistration.getMusicGroupId());
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -883,7 +899,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
	
		
			
				|  |  |          List<ClassGroupStudentMapper> classGroupStudentMappers = classGroupStudentMapperDao.findMusicGroupClassGroupByType(musicGroupId, type);
 | 
	
		
			
				|  |  |          for (StudentRegistration student : students) {
 | 
	
		
			
				|  |  |              for (ClassGroupStudentMapper classGroupStudentMapper : classGroupStudentMappers) {
 | 
	
		
			
				|  |  | -                if(classGroupStudentMapper.getUserId().equals(student.getUserId())){
 | 
	
		
			
				|  |  | +                if (classGroupStudentMapper.getUserId().equals(student.getUserId())) {
 | 
	
		
			
				|  |  |                      students.remove(student);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 |