|
@@ -1,7 +1,10 @@
|
|
|
package com.ym.mec.web.service.impl;
|
|
|
|
|
|
+import com.ym.mec.web.dal.entity.ClassGroupRelation;
|
|
|
import com.ym.mec.web.dal.entity.ClassGroupStudentMapper;
|
|
|
import com.ym.mec.web.dal.enums.ClassGroupStudentStatusEnum;
|
|
|
+import com.ym.mec.web.dal.enums.ClassGroupTypeEnum;
|
|
|
+import com.ym.mec.web.service.ClassGroupRelationService;
|
|
|
import com.ym.mec.web.service.ClassGroupStudentMapperService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -16,75 +19,118 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
-public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup> implements ClassGroupService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private ClassGroupDao classGroupDao;
|
|
|
+public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup> implements ClassGroupService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ClassGroupStudentMapperService classGroupStudentMapperService;
|
|
|
+ @Autowired
|
|
|
+ private ClassGroupDao classGroupDao;
|
|
|
+ @Autowired
|
|
|
+ private ClassGroupRelationService classGroupRelationService;
|
|
|
|
|
|
- @Override
|
|
|
- public BaseDAO<Integer, ClassGroup> getDAO() {
|
|
|
- return classGroupDao;
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private ClassGroupStudentMapperService classGroupStudentMapperService;
|
|
|
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Integer, ClassGroup> getDAO() {
|
|
|
+ return classGroupDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<ClassGroup> findClassGroup4Teacher(Integer teacherId) {
|
|
|
return classGroupDao.findClassGroup4Teacher(teacherId);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<ClassGroup> findClassGroup(Integer musicGroupId,Integer mixClassGroupId) {
|
|
|
- if(null==mixClassGroupId){
|
|
|
- return classGroupDao.findAllMixClassGroup(musicGroupId);
|
|
|
- }else{
|
|
|
- return classGroupDao.findMixClassChildClassGroup(mixClassGroupId);
|
|
|
- }
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public List<ClassGroup> findClassGroup(Integer musicGroupId, Integer mixClassGroupId) {
|
|
|
+ if (null == mixClassGroupId) {
|
|
|
+ return classGroupDao.findAllMixClassGroup(musicGroupId);
|
|
|
+ } else {
|
|
|
+ return classGroupDao.findMixClassChildClassGroup(mixClassGroupId);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public List<ClassGroup> findAllNormalClassGroupByMusicGroupId(int musicGroupId) {
|
|
|
- return classGroupDao.findAllNormalClassGroupByMusicGroupId(musicGroupId);
|
|
|
+ return classGroupDao.findAllNormalClassGroupByMusicGroupId(musicGroupId);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<ClassGroup> findAllMixClassGroupByMusicGroupId(int musicGroupId) {
|
|
|
- List<ClassGroup> allMixClassGroup = classGroupDao.findAllMixClassGroup(musicGroupId);
|
|
|
- for (ClassGroup mixClassGroup:allMixClassGroup){
|
|
|
- mixClassGroup.setClassNames(classGroupDao.findMixClassChildClassGroupNames(mixClassGroup.getId()).getName());
|
|
|
- }
|
|
|
- return allMixClassGroup;
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public List<ClassGroup> findAllMixClassGroupByMusicGroupId(int musicGroupId) {
|
|
|
+ List<ClassGroup> allMixClassGroup = classGroupDao.findAllMixClassGroup(musicGroupId);
|
|
|
+ for (ClassGroup mixClassGroup : allMixClassGroup) {
|
|
|
+ mixClassGroup.setClassNames(classGroupDao.findMixClassChildClassGroupNames(mixClassGroup.getId()).getName());
|
|
|
+ }
|
|
|
+ return allMixClassGroup;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public ClassGroup addClassGroup(ClassGroup classGroup) throws Exception {
|
|
|
+ Date date;
|
|
|
+ date = new Date();
|
|
|
+ classGroup.setCreateTime(date);
|
|
|
+ classGroup.setUpdateTime(date);
|
|
|
+ classGroup.setType(ClassGroupTypeEnum.NORMAL);
|
|
|
+ String userIds = classGroup.getUserIds();
|
|
|
+ String[] userIdArr = userIds.split(",");
|
|
|
+
|
|
|
+ classGroup.setStudentNum(userIdArr.length);
|
|
|
+ Long classGroupId = this.insert(classGroup);
|
|
|
+
|
|
|
+ //2、插入班级学生关联关系
|
|
|
+ List<ClassGroupStudentMapper> classGroupStudentList = new ArrayList<>();
|
|
|
+ for (String userId : userIdArr) {
|
|
|
+ ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
|
|
|
+ classGroupStudentMapper.setClassGroupId(classGroupId.intValue());
|
|
|
+ classGroupStudentMapper.setUserId(Integer.getInteger(userId));
|
|
|
+ classGroupStudentMapper.setCreateTime(date);
|
|
|
+ classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
|
|
|
+ classGroupStudentList.add(classGroupStudentMapper);
|
|
|
+ }
|
|
|
+ classGroupStudentMapperService.classGroupStudentsInsert(classGroupStudentList);
|
|
|
|
|
|
- @Override
|
|
|
+ return classGroup;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public ClassGroup addClassGroup(ClassGroup classGroup) throws Exception {
|
|
|
- Date date;
|
|
|
- date = new Date();
|
|
|
- classGroup.setCreateTime(date);
|
|
|
- classGroup.setUpdateTime(date);
|
|
|
- String userIds = classGroup.getUserIds();
|
|
|
- String[] userIdArr = userIds.split(",");
|
|
|
-
|
|
|
- classGroup.setStudentNum(userIdArr.length);
|
|
|
- long classGroupId = this.insert(classGroup);
|
|
|
- List<ClassGroupStudentMapper> classGroupStudentList = new ArrayList<>();
|
|
|
- for (String userId:userIdArr) {
|
|
|
- ClassGroupStudentMapper classGroupStudentMapper = new ClassGroupStudentMapper();
|
|
|
- classGroupStudentMapper.setClassGroupId(classGroupId);
|
|
|
- classGroupStudentMapper.setUserId(Integer.getInteger(userId));
|
|
|
- classGroupStudentMapper.setCreateTime(date);
|
|
|
- classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
|
|
|
- classGroupStudentList.add(classGroupStudentMapper);
|
|
|
- }
|
|
|
- classGroupStudentMapperService.classGroupStudentsInsert(classGroupStudentList);
|
|
|
-
|
|
|
- return classGroup;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ClassGroup addMixClassGroup(String classGroupIds) throws Exception {
|
|
|
- return null;
|
|
|
- }
|
|
|
+ public ClassGroup addMixClassGroup(int musicGroupId,String name, String classGroupIds) throws Exception {
|
|
|
+ Date date;
|
|
|
+ date = new Date();
|
|
|
+
|
|
|
+ List<ClassGroup> classGroups = findClassGroupByIds(classGroupIds);
|
|
|
+ int studentNum = 0; //学生数
|
|
|
+ String subjectIds = "";
|
|
|
+ for (ClassGroup classGroup : classGroups) {
|
|
|
+ studentNum += classGroup.getStudentNum();
|
|
|
+ subjectIds += subjectIds.isEmpty() ? classGroup.getSubjectIdList() : "," + classGroup.getSubjectIdList();
|
|
|
+ }
|
|
|
+
|
|
|
+ //1、插入班级
|
|
|
+ ClassGroup classGroup = new ClassGroup();
|
|
|
+ classGroup.setMusicGroupId(musicGroupId);
|
|
|
+ classGroup.setSubjectIdList(subjectIds);
|
|
|
+ classGroup.setName(name);
|
|
|
+ classGroup.setType(ClassGroupTypeEnum.MIX);
|
|
|
+ classGroup.setCreateTime(date);
|
|
|
+ classGroup.setUpdateTime(date);
|
|
|
+ Long classGroupId = this.insert(classGroup);
|
|
|
+
|
|
|
+ //2、插入班级关联关系
|
|
|
+ List<ClassGroupRelation> classGroupRelationList = new ArrayList<>();
|
|
|
+ for (ClassGroup cGroup : classGroups) {
|
|
|
+ ClassGroupRelation classGroupRelation = new ClassGroupRelation();
|
|
|
+ classGroupRelation.setClassGroupId(classGroupId.intValue());
|
|
|
+ classGroupRelation.setSubClassGroupId(cGroup.getId());
|
|
|
+ classGroupRelation.setCreateTime(date);
|
|
|
+ classGroupRelationList.add(classGroupRelation);
|
|
|
+ }
|
|
|
+ classGroupRelationService.classGroupRelationsInsert(classGroupRelationList);
|
|
|
+ return classGroup;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ClassGroup> findClassGroupByIds(String ids) {
|
|
|
+ return classGroupDao.findClassGroupByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
}
|