|  | @@ -1,22 +1,19 @@
 | 
											
												
													
														|  |  package com.ym.mec.biz.service.impl;
 |  |  package com.ym.mec.biz.service.impl;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import java.math.BigDecimal;
 |  |  import java.math.BigDecimal;
 | 
											
												
													
														|  | -import java.util.ArrayList;
 |  | 
 | 
											
												
													
														|  | -import java.util.Date;
 |  | 
 | 
											
												
													
														|  | -import java.util.HashMap;
 |  | 
 | 
											
												
													
														|  | -import java.util.List;
 |  | 
 | 
											
												
													
														|  | -import java.util.Map;
 |  | 
 | 
											
												
													
														|  | 
 |  | +import java.util.*;
 | 
											
												
													
														|  |  import java.util.stream.Collectors;
 |  |  import java.util.stream.Collectors;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import javax.annotation.Resource;
 |  |  import javax.annotation.Resource;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -import com.ym.mec.biz.dal.dao.SubjectDao;
 |  | 
 | 
											
												
													
														|  | -import com.ym.mec.biz.dal.dao.TeacherDao;
 |  | 
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.auth.api.entity.SysMenu;
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.biz.dal.dao.*;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.entity.*;
 |  |  import com.ym.mec.biz.dal.entity.*;
 | 
											
												
													
														|  |  import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
 |  |  import com.ym.mec.biz.service.MusicGroupSubjectPlanService;
 | 
											
												
													
														|  |  import com.ym.mec.common.entity.ImResult;
 |  |  import com.ym.mec.common.entity.ImResult;
 | 
											
												
													
														|  |  import com.ym.mec.common.entity.ImUserModel;
 |  |  import com.ym.mec.common.entity.ImUserModel;
 | 
											
												
													
														|  |  import com.ym.mec.im.ImFeignService;
 |  |  import com.ym.mec.im.ImFeignService;
 | 
											
												
													
														|  | 
 |  | +import com.ym.mec.util.date.DateUtil;
 | 
											
												
													
														|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
											
												
													
														|  |  import org.springframework.stereotype.Service;
 |  |  import org.springframework.stereotype.Service;
 | 
											
												
													
														|  |  import org.springframework.transaction.annotation.Transactional;
 |  |  import org.springframework.transaction.annotation.Transactional;
 | 
											
										
											
												
													
														|  | @@ -25,7 +22,6 @@ import com.ym.mec.auth.api.client.SysUserFeignService;
 | 
											
												
													
														|  |  import com.ym.mec.auth.api.entity.SysUser;
 |  |  import com.ym.mec.auth.api.entity.SysUser;
 | 
											
												
													
														|  |  import com.ym.mec.auth.api.enums.SysUserType;
 |  |  import com.ym.mec.auth.api.enums.SysUserType;
 | 
											
												
													
														|  |  import com.ym.mec.auth.api.enums.UserLockFlag;
 |  |  import com.ym.mec.auth.api.enums.UserLockFlag;
 | 
											
												
													
														|  | -import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
 |  | 
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.dto.StudentApplyDetailDto;
 |  |  import com.ym.mec.biz.dal.dto.StudentApplyDetailDto;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.dto.StudentFeeDto;
 |  |  import com.ym.mec.biz.dal.dto.StudentFeeDto;
 | 
											
												
													
														|  |  import com.ym.mec.biz.dal.dto.StudentInfo;
 |  |  import com.ym.mec.biz.dal.dto.StudentInfo;
 | 
											
										
											
												
													
														|  | @@ -55,6 +51,16 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private TeacherDao teacherDao;
 |  |      private TeacherDao teacherDao;
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  | 
 |  | +    private ClassGroupDao classGroupDao;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private ClassGroupStudentMapperDao classGroupStudentMapperDao;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private MusicGroupStudentFeeDao musicGroupStudentFeeDao;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private MusicGroupPaymentCalenderDao musicGroupPaymentCalenderDao;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  | 
 |  | +    private MusicGroupSubjectPlanDao musicGroupSubjectPlanDao;
 | 
											
												
													
														|  | 
 |  | +    @Autowired
 | 
											
												
													
														|  |      private SubjectDao subjectDao;
 |  |      private SubjectDao subjectDao;
 | 
											
												
													
														|  |      @Autowired
 |  |      @Autowired
 | 
											
												
													
														|  |      private ImFeignService imFeignService;
 |  |      private ImFeignService imFeignService;
 | 
											
										
											
												
													
														|  | @@ -356,6 +362,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
											
												
													
														|  |              throw new Exception("该学员已存在");
 |  |              throw new Exception("该学员已存在");
 | 
											
												
													
														|  |          }else {
 |  |          }else {
 | 
											
												
													
														|  |              SysUser sysUser = studentRegistrationDao.getSysUserByPhone(studentRegistration.getParentsPhone());
 |  |              SysUser sysUser = studentRegistrationDao.getSysUserByPhone(studentRegistration.getParentsPhone());
 | 
											
												
													
														|  | 
 |  | +            Integer userId;
 | 
											
												
													
														|  |              if(sysUser == null){
 |  |              if(sysUser == null){
 | 
											
												
													
														|  |                  //新增user
 |  |                  //新增user
 | 
											
												
													
														|  |                  sysUser = new SysUser();
 |  |                  sysUser = new SysUser();
 | 
											
										
											
												
													
														|  | @@ -364,18 +371,55 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 | 
											
												
													
														|  |                  sysUser.setGender(studentRegistration.getGender());
 |  |                  sysUser.setGender(studentRegistration.getGender());
 | 
											
												
													
														|  |                  sysUser.setUserType(SysUserType.STUDENT);
 |  |                  sysUser.setUserType(SysUserType.STUDENT);
 | 
											
												
													
														|  |                  teacherDao.addSysUser(sysUser);
 |  |                  teacherDao.addSysUser(sysUser);
 | 
											
												
													
														|  | 
 |  | +                userId = sysUser.getId();
 | 
											
												
													
														|  |                  //注册到融云
 |  |                  //注册到融云
 | 
											
												
													
														|  | -                ImResult register = imFeignService.register(new ImUserModel(sysUser.getId().toString(), sysUser.getUsername(), sysUser.getAvatar()));
 |  | 
 | 
											
												
													
														|  | 
 |  | +                ImResult register = imFeignService.register(new ImUserModel(userId.toString(), sysUser.getUsername(), sysUser.getAvatar()));
 | 
											
												
													
														|  |                  sysUser.setImToken(register.getToken());
 |  |                  sysUser.setImToken(register.getToken());
 | 
											
												
													
														|  |                  teacherDao.updateUser(sysUser);
 |  |                  teacherDao.updateUser(sysUser);
 | 
											
												
													
														|  | 
 |  | +            }else {
 | 
											
												
													
														|  | 
 |  | +                userId = sysUser.getId();
 | 
											
												
													
														|  |              }
 |  |              }
 | 
											
												
													
														|  | 
 |  | +            studentRegistration.setUserId(userId);
 | 
											
												
													
														|  |              //学生报名表
 |  |              //学生报名表
 | 
											
												
													
														|  |              studentRegistrationDao.insert(studentRegistration);
 |  |              studentRegistrationDao.insert(studentRegistration);
 | 
											
												
													
														|  | -            //学生注册
 |  | 
 | 
											
												
													
														|  | -            //缴费金额
 |  | 
 | 
											
												
													
														|  | -            //学员加入的金额
 |  | 
 | 
											
												
													
														|  | 
 |  | +            if(studentRegistration.getClassGroupId() != null){
 | 
											
												
													
														|  | 
 |  | +                ClassGroup classGroup = classGroupDao.get(studentRegistration.getClassGroupId());
 | 
											
												
													
														|  | 
 |  | +                if(classGroup != null){
 | 
											
												
													
														|  | 
 |  | +                    if(classGroup.getMusicGroupId().equals(studentRegistration.getMusicGroupId())){
 | 
											
												
													
														|  | 
 |  | +                        throw new Exception("班级录入错误");
 | 
											
												
													
														|  | 
 |  | +                    }else {
 | 
											
												
													
														|  | 
 |  | +                        //修改实际学生人数
 | 
											
												
													
														|  | 
 |  | +                        classGroup.setStudentNum(classGroup.getStudentNum() + 1);
 | 
											
												
													
														|  | 
 |  | +                        classGroup.setUpdateTime(new Date());
 | 
											
												
													
														|  | 
 |  | +                        classGroupDao.update(classGroup);
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                }else {
 | 
											
												
													
														|  | 
 |  | +                    throw new Exception("班级不存在");
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                //新增班级学生关系
 | 
											
												
													
														|  | 
 |  | +                classGroupStudentMapperDao.insert(new ClassGroupStudentMapper(studentRegistration.getClassGroupId(),userId));
 | 
											
												
													
														|  | 
 |  | +                //乐团学生费用表
 | 
											
												
													
														|  | 
 |  | +                MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
 | 
											
												
													
														|  | 
 |  | +                //获取当前月
 | 
											
												
													
														|  | 
 |  | +                Integer month = Integer.parseInt(DateUtil.getMonth(new Date()));
 | 
											
												
													
														|  | 
 |  | +                //获取下次缴费月份
 | 
											
												
													
														|  | 
 |  | +                List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.findByMusicGroupId(studentRegistration.getMusicGroupId());
 | 
											
												
													
														|  | 
 |  | +                List<Integer> months = musicGroupPaymentCalenders.stream().map(e -> e.getPaymentMonth()).collect(Collectors.toList());
 | 
											
												
													
														|  | 
 |  | +                for (int i = 0;i<months.size();i++){
 | 
											
												
													
														|  | 
 |  | +                    if(months.get(i).equals(month)){
 | 
											
												
													
														|  | 
 |  | +                        month = i == months.size()-1?months.get(0):months.get(i+1);
 | 
											
												
													
														|  | 
 |  | +                    }
 | 
											
												
													
														|  | 
 |  | +                }
 | 
											
												
													
														|  | 
 |  | +                Calendar calendar = Calendar.getInstance();
 | 
											
												
													
														|  | 
 |  | +                calendar.add(Calendar.MONTH, month);
 | 
											
												
													
														|  | 
 |  | +                DateUtil.getFirstDayOfMonth(calendar.getTime());
 | 
											
												
													
														|  | 
 |  | +                //保存乐团学生费用表
 | 
											
												
													
														|  | 
 |  | +                musicGroupStudentFeeDao.insert(new MusicGroupStudentFee(studentRegistration.getMusicGroupId(),
 | 
											
												
													
														|  | 
 |  | +                        userId,studentRegistration.getSubjectId(),musicOneSubjectClassPlan.getFee(),
 | 
											
												
													
														|  | 
 |  | +                        DateUtil.getFirstDayOfMonth(calendar.getTime()),0,studentRegistration.getTemporaryCourseFee()));
 | 
											
												
													
														|  | 
 |  | +            }
 | 
											
												
													
														|  | 
 |  | +            return userId;
 | 
											
												
													
														|  |          }
 |  |          }
 | 
											
												
													
														|  | -        return null;
 |  | 
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  }
 |  |  }
 |