|
@@ -1,22 +1,18 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import com.ym.mec.biz.dal.entity.CourseSchedule;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentRegistration;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
import com.ym.mec.biz.dal.enums.ClassGroupStudentStatusEnum;
|
|
|
-import com.ym.mec.biz.service.CourseScheduleService;
|
|
|
-import com.ym.mec.biz.service.CourseScheduleStudentPaymentService;
|
|
|
-import com.ym.mec.biz.service.StudentRegistrationService;
|
|
|
+import com.ym.mec.biz.service.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.ym.mec.biz.dal.dao.ClassGroupStudentMapperDao;
|
|
|
-import com.ym.mec.biz.dal.entity.ClassGroupStudentMapper;
|
|
|
-import com.ym.mec.biz.service.ClassGroupStudentMapperService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, ClassGroupStudentMapper> implements ClassGroupStudentMapperService {
|
|
@@ -30,6 +26,10 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
|
|
|
StudentRegistrationService studentRegistrationService;
|
|
|
@Autowired
|
|
|
private CourseScheduleStudentPaymentService courseScheduleStudentPaymentService;
|
|
|
+ @Autowired
|
|
|
+ private ClassGroupService classGroupService;
|
|
|
+ @Autowired
|
|
|
+ private ClassGroupRelationService classGroupRelationService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, ClassGroupStudentMapper> getDAO() {
|
|
@@ -55,7 +55,10 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
|
|
|
student.setClassGroupId(null);
|
|
|
studentRegistrationService.update(student);
|
|
|
|
|
|
- //2、删除学生对应班级的单技课程和对应合奏课程
|
|
|
+ //2、班级人数调整
|
|
|
+ classGroupService.updateClassStudentNum(classGroupId.longValue(), -1);
|
|
|
+
|
|
|
+ //3、删除学生对应班级的课程
|
|
|
List<CourseSchedule> courseScheduleList = courseScheduleService.findNoStartCoursesByClassGroupId(classGroupId);
|
|
|
courseScheduleStudentPaymentService.deleteStudentCourseSchedule(userId, courseScheduleList);
|
|
|
return true;
|
|
@@ -63,6 +66,103 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
|
|
|
|
|
|
@Override
|
|
|
public List<StudentRegistration> findClassStudentList(Integer classGroupId, ClassGroupStudentStatusEnum status) {
|
|
|
- return classGroupStudentMapperDao.findClassStudentList(classGroupId,status);
|
|
|
+ return classGroupStudentMapperDao.findClassStudentList(classGroupId, status);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean adjustClassGroup(Integer userId, Integer oldClassGroupId, Integer classGroupId) throws Exception {
|
|
|
+ ClassGroupStudentMapper classStudentMapper = findClassStudentMapperByUserIdAndClassGroupId(userId, oldClassGroupId);
|
|
|
+ if (classStudentMapper == null) {
|
|
|
+ throw new Exception("原班级学生不存在");
|
|
|
+ }
|
|
|
+ Date date = new Date();
|
|
|
+ //1、更新学生对应班级关系
|
|
|
+ classStudentMapper.setClassGroupId(classGroupId);
|
|
|
+ update(classStudentMapper);
|
|
|
+ //班级人数调整
|
|
|
+ classGroupService.updateClassStudentNum(oldClassGroupId.longValue(), -1);
|
|
|
+ classGroupService.updateClassStudentNum(classGroupId.longValue(), 1);
|
|
|
+
|
|
|
+ //2、删除学生对应原班级未开始课程
|
|
|
+ List<CourseSchedule> courseScheduleList = courseScheduleService.findNoStartCoursesByClassGroupId(oldClassGroupId);
|
|
|
+ courseScheduleStudentPaymentService.deleteStudentCourseSchedule(userId, courseScheduleList);
|
|
|
+
|
|
|
+ //3、学生加入新班级未开始课程
|
|
|
+ courseScheduleList = courseScheduleService.findNoStartCoursesByClassGroupId(classGroupId);
|
|
|
+
|
|
|
+ BigDecimal coursePrice = new BigDecimal("0");
|
|
|
+ List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
|
|
|
+ for (CourseSchedule courseSchedule : courseScheduleList) {
|
|
|
+ CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
|
|
|
+ courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
|
|
|
+ courseScheduleStudentPayment.setUserId(userId);
|
|
|
+ courseScheduleStudentPayment.setExpectPrice(coursePrice);
|
|
|
+ courseScheduleStudentPayment.setClassGroupId(classGroupId);
|
|
|
+ courseScheduleStudentPayment.setCreateTime(date);
|
|
|
+ courseScheduleStudentPayment.setUpdateTime(date);
|
|
|
+ courseScheduleStudentPayments.add(courseScheduleStudentPayment);
|
|
|
+ }
|
|
|
+
|
|
|
+ courseScheduleStudentPaymentService.batchInsert(courseScheduleStudentPayments);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public boolean addStudents(Integer classGroupId, String userIdsStr) throws Exception {
|
|
|
+ ClassGroup classGroup = classGroupService.get(classGroupId);
|
|
|
+ if (classGroup == null) {
|
|
|
+ throw new Exception("添加学员的班级不存在");
|
|
|
+ }
|
|
|
+ Date nowDate = new Date();
|
|
|
+ HashSet<String> userIdStrSet = new HashSet<>(Arrays.asList(userIdsStr.split(",")));
|
|
|
+
|
|
|
+ //1、班级关系添加
|
|
|
+ List<ClassGroupStudentMapper> classGroupStudentMappers = new ArrayList<>();
|
|
|
+ for (String userIdStr : userIdStrSet) {
|
|
|
+ ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
|
|
|
+ classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId());
|
|
|
+ classGroupStudentMapper.setClassGroupId(classGroupId);
|
|
|
+ classGroupStudentMapper.setUserId(Integer.parseInt(userIdStr));
|
|
|
+ classGroupStudentMapper.setCreateTime(nowDate);
|
|
|
+ classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
|
|
|
+ classGroupStudentMappers.add(classGroupStudentMapper);
|
|
|
+ }
|
|
|
+ classGroupStudentMapperDao.classGroupStudentsInsert(classGroupStudentMappers);
|
|
|
+
|
|
|
+ //2、班级人数调整
|
|
|
+ classGroupService.updateClassStudentNum(classGroupId.longValue(), userIdStrSet.size());
|
|
|
+
|
|
|
+ //3、学生加入新班级未开始课程
|
|
|
+ List<CourseSchedule> courseScheduleList = courseScheduleService.findNoStartCoursesByClassGroupId(classGroupId);
|
|
|
+
|
|
|
+ //4、班级在合奏班、添加合奏课程
|
|
|
+ ClassGroupRelation classGroupRelation = classGroupRelationService.findClassGroupRelation(classGroupId);
|
|
|
+ if(classGroupRelation != null){
|
|
|
+ //合奏班增加人数
|
|
|
+ classGroupService.updateClassStudentNum(classGroupRelation.getClassGroupId().longValue(), userIdStrSet.size());
|
|
|
+ List<CourseSchedule> mixCourseScheduleList = courseScheduleService.findNoStartCoursesByClassGroupId(classGroupRelation.getClassGroupId());
|
|
|
+ courseScheduleList.addAll(mixCourseScheduleList);
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal coursePrice = new BigDecimal("0");
|
|
|
+
|
|
|
+ List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
|
|
|
+ for (CourseSchedule courseSchedule : courseScheduleList) {
|
|
|
+ for (String userIdStr : userIdStrSet) {
|
|
|
+ CourseScheduleStudentPayment courseScheduleStudentPayment = new CourseScheduleStudentPayment();
|
|
|
+ courseScheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
|
|
|
+ courseScheduleStudentPayment.setUserId(Integer.parseInt(userIdStr));
|
|
|
+ courseScheduleStudentPayment.setExpectPrice(coursePrice);
|
|
|
+ courseScheduleStudentPayment.setClassGroupId(classGroupId);
|
|
|
+ courseScheduleStudentPayment.setCreateTime(nowDate);
|
|
|
+ courseScheduleStudentPayment.setUpdateTime(nowDate);
|
|
|
+ courseScheduleStudentPayments.add(courseScheduleStudentPayment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ courseScheduleStudentPaymentService.batchInsert(courseScheduleStudentPayments);
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|