Browse Source

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

yonge 5 years ago
parent
commit
ddda8fbc01

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/ClassGroupStudentMapperService.java

@@ -63,4 +63,6 @@ public interface ClassGroupStudentMapperService extends BaseService<Long, ClassG
     Object queryHoliday(String year) throws IOException;
 
     List<ClassGroupStudentMapper> findMusicGroupClassGroupByType(String musicGroupId, ClassGroupTypeEnum type);
+
+    void classGroupStudentsInsert(List<ClassGroupStudentMapper> classGroupStudentMappers);
 }

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupStudentMapperServiceImpl.java

@@ -250,4 +250,9 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
     public List<ClassGroupStudentMapper> findMusicGroupClassGroupByType(String musicGroupId, ClassGroupTypeEnum type) {
         return classGroupStudentMapperDao.findMusicGroupClassGroupByType(musicGroupId,type);
     }
+
+    @Override
+    public void classGroupStudentsInsert(List<ClassGroupStudentMapper> classGroupStudentMappers) {
+        classGroupStudentMapperDao.classGroupStudentsInsert(classGroupStudentMappers);
+    }
 }

+ 92 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -15,6 +15,8 @@ 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;
 import com.ym.mec.common.entity.ImResult;
 import com.ym.mec.common.entity.ImUserModel;
 import com.ym.mec.common.exception.BizException;
@@ -48,9 +50,15 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     @Autowired
     private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
     @Autowired
+    private CourseScheduleStudentPaymentService courseScheduleStudentPaymentService;
+    @Autowired
+    private ClassGroupRelationService classGroupRelationService;
+    @Autowired
+    private CourseScheduleService courseScheduleService;
+    @Autowired
     private TeacherDao teacherDao;
     @Autowired
-    private ClassGroupDao classGroupDao;
+    private ClassGroupService classGroupDao;
     @Autowired
     private MusicGroupStudentFeeDao musicGroupStudentFeeDao;
     @Autowired
@@ -411,6 +419,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public StudentRegistration queryByUserIdAndMusicGroupId(Integer userId, String musicGroupId) {
         StudentRegistration registration = studentRegistrationDao.queryByUserIdAndMusicGroupId(userId, musicGroupId);
         SysUserCashAccount account = sysUserCashAccountDao.getLocked(userId);
@@ -502,7 +511,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 //                ClassGroupRelation classGroupRelation = classGroupRelationDao.findClassGroupRelation(classGroupId);
 //                classGroupStudentMapper.setClassGroupId(classGroupRelation.getClassGroupId());
 //                classGroupStudentMapperDao.insert(classGroupStudentMapper);
-                classGroupStudentMapperDao.addStudents(classGroupId,userId.toString(),GroupType.MUSIC);
+                addStudents(classGroup,userId);
                 Date date = new Date();
                 //获取当前月
                 Integer month = Integer.parseInt(DateUtil.getMonth(date));
@@ -568,6 +577,87 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         }
     }
 
+    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();
+        ClassGroupRelation classGroupRelation = classGroupRelationService.findClassGroupRelation(classGroupId);
+
+        //校验是否存在历史记录
+        ClassGroupStudentMapper classGroupStudentMapper = classGroupStudentMapperDao.findClassStudentMapperByUserIdAndClassGroupId(userId, classGroupId);
+        if(classGroupStudentMapper != null){
+            classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
+        }else {
+            classGroupStudentMapper = new ClassGroupStudentMapper();
+            classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId());
+            classGroupStudentMapper.setClassGroupId(classGroupId);
+            classGroupStudentMapper.setUserId(userId);
+            classGroupStudentMapper.setCreateTime(nowDate);
+            classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
+            classGroupStudentMapper.setGroupType(GroupType.MUSIC);
+            classGroupStudentMappers.add(classGroupStudentMapper);
+        }
+        //班级在合奏班中
+        if (classGroupRelation != null) {
+            classGroupStudentMapper = new ClassGroupStudentMapper();
+            classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId());
+            classGroupStudentMapper.setClassGroupId(classGroupRelation.getClassGroupId());
+            classGroupStudentMapper.setUserId(userId);
+            classGroupStudentMapper.setCreateTime(nowDate);
+            classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
+            classGroupStudentMapper.setGroupType(GroupType.MUSIC);
+            classGroupStudentMappers.add(classGroupStudentMapper);
+        }
+        imGroupMemberList.add(new ImGroupMember(userId.toString()));
+        if (classGroupStudentMappers.size() > 0) {
+            classGroupStudentMapperDao.classGroupStudentsInsert(classGroupStudentMappers);
+        }
+
+        //添加进IM群组
+        ImGroupMember[] imGroupMembers = imGroupMemberList.toArray(new ImGroupMember[imGroupMemberList.size()]);
+        imFeignService.groupJoin(new ImGroupModel(classGroup.getId().toString(), imGroupMembers, classGroup.getName()));
+
+        //2、班级人数调整
+        classGroupDao.updateClassStudentNum(classGroupId.longValue(), 1);
+
+        //3、学生加入新班级未开始课程
+        List<CourseSchedule> courseScheduleList = courseScheduleService.findNoStartCoursesByClassGroupId(classGroupId);
+
+        //4、班级在合奏班、添加合奏课程
+        if (classGroupRelation != null) {
+            //合奏班增加人数
+            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));
+        }
+
+        BigDecimal coursePrice = new BigDecimal("0");
+
+        List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
+        for (CourseSchedule courseSchedule : courseScheduleList) {
+            CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
+            courseScheduleStudentPayment.setGroupType(classGroup.getGroupType());
+            courseScheduleStudentPayment.setMusicGroupId(classGroup.getMusicGroupId());
+            courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
+            courseScheduleStudentPayment.setUserId(userId);
+            courseScheduleStudentPayment.setExpectPrice(coursePrice);
+            courseScheduleStudentPayment.setClassGroupId(classGroupId);
+            courseScheduleStudentPayment.setCreateTime(nowDate);
+            courseScheduleStudentPayment.setUpdateTime(nowDate);
+            courseScheduleStudentPayments.add(courseScheduleStudentPayment);
+        }
+
+        if (courseScheduleStudentPayments.size() == 0) {
+            return;
+        }
+        courseScheduleStudentPaymentService.batchInsert(courseScheduleStudentPayments);
+    }
+
     @Override
     public List<StudentRegistration> findClassGroupStu(String musicGroupId, Integer classGroupId) {
         //获取所有声部