浏览代码

增加新增合奏班接口

周箭河 5 年之前
父节点
当前提交
8a98b261a4

+ 3 - 2
mec-web/src/main/java/com/ym/mec/web/controller/ClassGroupController.java

@@ -29,8 +29,9 @@ public class ClassGroupController extends BaseController {
 
     @ApiOperation(value = "新增合奏班")
     @PostMapping("/addMixClass")
-    public Object addMixClass(@ApiParam(value = "班级编号,号分割", required = true) String classGroupIds) throws Exception {
-        return succeed(classGroupService.addMixClassGroup(classGroupIds));
+    public Object addMixClass(@ApiParam(value = "乐团编号", required = true) @RequestParam Integer musicGroupId,
+            @ApiParam(value = "班级编号,号分割", required = true) String classGroupIds) throws Exception {
+        return succeed(classGroupService.addMixClassGroup(musicGroupId,classGroupIds));
     }
 
     @ApiOperation(value = "删除班级")

+ 8 - 0
mec-web/src/main/java/com/ym/mec/web/dal/dao/ClassGroupDao.java

@@ -42,8 +42,16 @@ public interface ClassGroupDao extends BaseDAO<Integer, ClassGroup> {
 
     /**
      * 查询合奏班包含子班的名字信息
+     *
      * @param classGroupId
      * @return
      */
     ClassGroup findMixClassChildClassGroupNames(@Param("classGroupId") int classGroupId);
+
+    /**
+     * 跟班级ids查询班级信息
+     * @param ids
+     * @return
+     */
+    List<ClassGroup> findClassGroupByIds(@Param("ids") String ids);
 }

+ 10 - 1
mec-web/src/main/java/com/ym/mec/web/dal/dao/ClassGroupRelationDao.java

@@ -2,8 +2,17 @@ package com.ym.mec.web.dal.dao;
 
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.web.dal.entity.ClassGroupRelation;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 public interface ClassGroupRelationDao extends BaseDAO<Integer, ClassGroupRelation> {
 
-	
+
+    /**
+     * 批量插入班级关联关系
+     * @param classGroupRelationList
+     * @return
+     */
+    int classGroupRelationsInsert(@Param("classGroupRelationList") List<ClassGroupRelation> classGroupRelationList);
 }

+ 3 - 3
mec-web/src/main/java/com/ym/mec/web/dal/entity/ClassGroupStudentMapper.java

@@ -14,7 +14,7 @@ public class ClassGroupStudentMapper {
 	
 	/** 班级 */
 	@ApiModelProperty(value = "班级编号",required = false)
-	private Long classGroupId;
+	private int classGroupId;
 	
 	/** 学生 */
 	@ApiModelProperty(value = "学生编号",required = false)
@@ -43,11 +43,11 @@ public class ClassGroupStudentMapper {
 		return this.id;
 	}
 			
-	public void setClassGroupId(Long classGroupId){
+	public void setClassGroupId(int classGroupId){
 		this.classGroupId = classGroupId;
 	}
 	
-	public Long getClassGroupId(){
+	public int getClassGroupId(){
 		return this.classGroupId;
 	}
 			

+ 11 - 0
mec-web/src/main/java/com/ym/mec/web/service/ClassGroupRelationService.java

@@ -2,7 +2,18 @@ package com.ym.mec.web.service;
 
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.web.dal.entity.ClassGroupRelation;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 public interface ClassGroupRelationService extends BaseService<Integer, ClassGroupRelation> {
 
+
+    /**
+     * 批量插入班级关联关系
+     * @param classGroupRelationList
+     * @return
+     */
+    int classGroupRelationsInsert(List<ClassGroupRelation> classGroupRelationList);
+
 }

+ 9 - 2
mec-web/src/main/java/com/ym/mec/web/service/ClassGroupService.java

@@ -2,6 +2,8 @@ package com.ym.mec.web.service;
 
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.web.dal.entity.ClassGroup;
+import com.ym.mec.web.dal.entity.ClassGroupRelation;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -49,8 +51,13 @@ public interface ClassGroupService extends BaseService<Integer, ClassGroup> {
      * @return
      * @throws Exception
      */
-    ClassGroup addMixClassGroup(String classGroupIds) throws Exception;
-
+    ClassGroup addMixClassGroup(int musicGroupId,String classGroupIds) throws Exception;
 
+    /**
+     * 跟班级ids查询班级信息
+     * @param ids
+     * @return
+     */
+    List<ClassGroup> findClassGroupByIds(String ids);
 
 }

+ 7 - 1
mec-web/src/main/java/com/ym/mec/web/service/impl/ClassGroupRelationServiceImpl.java

@@ -9,6 +9,8 @@ import com.ym.mec.web.dal.dao.ClassGroupRelationDao;
 import com.ym.mec.web.dal.entity.ClassGroupRelation;
 import com.ym.mec.web.service.ClassGroupRelationService;
 
+import java.util.List;
+
 @Service
 public class ClassGroupRelationServiceImpl extends BaseServiceImpl<Integer, ClassGroupRelation>  implements ClassGroupRelationService {
 	
@@ -19,5 +21,9 @@ public class ClassGroupRelationServiceImpl extends BaseServiceImpl<Integer, Clas
 	public BaseDAO<Integer, ClassGroupRelation> getDAO() {
 		return classGroupRelationDao;
 	}
-	
+
+    @Override
+    public int classGroupRelationsInsert(List<ClassGroupRelation> classGroupRelationList) {
+		return classGroupRelationDao.classGroupRelationsInsert(classGroupRelationList);
+    }
 }

+ 99 - 57
mec-web/src/main/java/com/ym/mec/web/service/impl/ClassGroupServiceImpl.java

@@ -1,7 +1,9 @@
 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.service.ClassGroupRelationService;
 import com.ym.mec.web.service.ClassGroupStudentMapperService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -16,75 +18,115 @@ 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);
+        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.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 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("合奏班1");
+        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);
+    }
+
 }

+ 5 - 0
mec-web/src/main/resources/config/mybatis/ClassGroupMapper.xml

@@ -164,4 +164,9 @@
         LEFT JOIN class_group cg ON cgr.sub_class_group_id_=cg.id_
         WHERE cgr.class_group_id_=#{classGroupId} AND del_flag_='0'
     </select>
+
+    <!-- 根据ids查询班级列表 -->
+    <select id="findClassGroupByIds" resultMap="ClassGroup">
+        SELECT * FROM class_group WHERE FIND_IN_SET(id_,#{ids})
+    </select>
 </mapper>

+ 19 - 8
mec-web/src/main/resources/config/mybatis/ClassGroupRelationMapper.xml

@@ -15,13 +15,15 @@
 
     <!-- 根据主键查询一条记录 -->
     <select id="get" resultMap="ClassGroupRelation">
-		SELECT * FROM class_group_relation WHERE id_ = #{id} 
-	</select>
+        SELECT * FROM class_group_relation WHERE id_ = #{id}
+    </select>
 
     <!-- 全查询 -->
     <select id="findAll" resultMap="ClassGroupRelation">
-		SELECT * FROM class_group_relation ORDER BY id_
-	</select>
+        SELECT *
+        FROM class_group_relation
+        ORDER BY id_
+    </select>
 
     <!-- 向数据库增加一条记录 -->
     <insert id="insert" parameterType="com.ym.mec.web.dal.entity.ClassGroupRelation" useGeneratedKeys="true"
@@ -51,8 +53,8 @@
 
     <!-- 根据主键删除一条记录 -->
     <delete id="delete">
-		DELETE FROM class_group_relation WHERE id_ = #{id} 
-	</delete>
+        DELETE FROM class_group_relation WHERE id_ = #{id}
+    </delete>
 
     <!-- 分页查询 -->
     <select id="queryPage" resultMap="ClassGroupRelation" parameterType="map">
@@ -62,6 +64,15 @@
 
     <!-- 查询当前表的总记录数 -->
     <select id="queryCount" resultType="int">
-		SELECT COUNT(*) FROM class_group_relation
-	</select>
+        SELECT COUNT(*)
+        FROM class_group_relation
+    </select>
+
+    <!-- 班级关系批量插入 -->
+    <insert id="classGroupRelationsInsert" parameterType="java.util.List">
+        INSERT INTO class_group_relation (id_,class_group_id_,sub_class_group_id_,create_time_)
+        <foreach collection="classGroupRelationList" item="item" index="index" separator=",">
+            (#{item.id},#{item.classGroupId},#{item.subClassGroupId},#{item.createTime})
+        </foreach>
+    </insert>
 </mapper>