Browse Source

Merge branch 'master' of https://gitee.com/zouxuan/mec

yonge 5 years ago
parent
commit
e2695f28d1

+ 5 - 6
mec-web/src/main/java/com/ym/mec/web/controller/ClassGroupController.java

@@ -21,13 +21,10 @@ public class ClassGroupController extends BaseController {
     @Autowired
     private ClassGroupService classGroupService;
 
-    @ApiOperation(value = "新增班级")
+    @ApiOperation(value = "新增单技班班级")
     @PostMapping("/add")
-    public Object add(@RequestBody ClassGroup classGroup) {
-        Date date = new Date();
-        classGroup.setCreateTime(date);
-        classGroup.setUpdateTime(date);
-        classGroupService.insert(classGroup);
+    public Object add(@RequestBody ClassGroup classGroup) throws Exception {
+        classGroupService.addClassGroup(classGroup);
         return succeed();
     }
 
@@ -66,4 +63,6 @@ public class ClassGroupController extends BaseController {
         return succeed(classGroupService.findAllClassGroupByMusicGroupIdAndType(musicGroupId, type));
     }
 
+
+
 }

+ 10 - 1
mec-web/src/main/java/com/ym/mec/web/dal/dao/ClassGroupStudentMapperDao.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.ClassGroupStudentMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 public interface ClassGroupStudentMapperDao extends BaseDAO<Long, ClassGroupStudentMapper> {
 
-	
+
+    /**
+     * 批量插入学生
+     * @param classGroupStudentMapperList
+     * @return
+     */
+    int classGroupStudentsInsert(@Param("classGroupStudentMapperList") List<ClassGroupStudentMapper> classGroupStudentMapperList);
 }

+ 16 - 5
mec-web/src/main/java/com/ym/mec/web/dal/entity/ClassGroup.java

@@ -17,18 +17,21 @@ public class ClassGroup {
 	private Integer id;
 	
 	/**  */
-	@ApiModelProperty(value = "乐团编号",required = false)
+	@ApiModelProperty(value = "乐团编号",required = true)
 	private Integer musicGroupId;
 	
 	/**  */
-	@ApiModelProperty(value = "科目编号",required = false)
+	@ApiModelProperty(value = "科目编号(多个,号分割)",required = true)
 	private String subjectIdList;
 
-	@ApiModelProperty(value = "科目名称",required = false)
+	@ApiModelProperty(value = "学生编号(多个,号分割)",required = true)
+	private String userIds;
+
+	@ApiModelProperty(value = "科目名称",required = false,hidden = true)
 	private String subjectName;
 
 	/** 班级名称 */
-	@ApiModelProperty(value = "班级名称",required = false)
+	@ApiModelProperty(value = "班级名称",required = true)
 	private String name;
 	
 	/** 学生数 */
@@ -42,7 +45,7 @@ public class ClassGroup {
 	private java.util.Date updateTime;
 	
 	/** 班级类型(普通班级、合奏班级) */
-	@ApiModelProperty(value = "班级类型(普通班级、合奏班级、提高课班级、VIP班级)",required = false)
+	@ApiModelProperty(value = "班级类型(普通班级、合奏班级、提高课班级、VIP班级)",required = true)
 	private ClassGroupTypeEnum type;
 
 	/** 班级类型(普通班级、合奏班级) */
@@ -129,6 +132,14 @@ public class ClassGroup {
 		this.subjectName = subjectName;
 	}
 
+	public String getUserIds() {
+		return userIds;
+	}
+
+	public void setUserIds(String userIds) {
+		this.userIds = userIds;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 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 Integer classGroupId;
+	private Long classGroupId;
 	
 	/** 学生 */
 	@ApiModelProperty(value = "学生编号",required = false)
@@ -43,11 +43,11 @@ public class ClassGroupStudentMapper {
 		return this.id;
 	}
 			
-	public void setClassGroupId(Integer classGroupId){
+	public void setClassGroupId(Long classGroupId){
 		this.classGroupId = classGroupId;
 	}
 	
-	public Integer getClassGroupId(){
+	public Long getClassGroupId(){
 		return this.classGroupId;
 	}
 			

+ 7 - 0
mec-web/src/main/java/com/ym/mec/web/service/ClassGroupService.java

@@ -30,4 +30,11 @@ public interface ClassGroupService extends BaseService<Integer, ClassGroup> {
      */
     List<ClassGroup> findAllClassGroupByMusicGroupIdAndType(int musicGroupId, ClassGroupTypeEnum type);
 
+    /**
+     * 添加单技班
+     * @param classGroup
+     * @return
+     */
+    ClassGroup addClassGroup(ClassGroup classGroup) throws Exception;
+
 }

+ 10 - 0
mec-web/src/main/java/com/ym/mec/web/service/ClassGroupStudentMapperService.java

@@ -2,7 +2,17 @@ package com.ym.mec.web.service;
 
 import com.ym.mec.common.service.BaseService;
 import com.ym.mec.web.dal.entity.ClassGroupStudentMapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 public interface ClassGroupStudentMapperService extends BaseService<Long, ClassGroupStudentMapper> {
 
+    /**
+     * 批量插入班级关联的学生
+     * @param classGroupStudentMapperList
+     * @return
+     */
+    int classGroupStudentsInsert(@Param("classGroupStudentMapperList") List<ClassGroupStudentMapper> classGroupStudentMapperList);
+
 }

+ 35 - 1
mec-web/src/main/java/com/ym/mec/web/service/impl/ClassGroupServiceImpl.java

@@ -1,6 +1,9 @@
 package com.ym.mec.web.service.impl;
 
+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.ClassGroupStudentMapperService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -9,8 +12,10 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.web.dal.dao.ClassGroupDao;
 import com.ym.mec.web.dal.entity.ClassGroup;
 import com.ym.mec.web.service.ClassGroupService;
+import org.springframework.transaction.annotation.Transactional;
 
-import java.util.List;
+import java.lang.reflect.Array;
+import java.util.*;
 
 @Service
 public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>  implements ClassGroupService {
@@ -18,6 +23,9 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
 	@Autowired
 	private ClassGroupDao classGroupDao;
 
+	@Autowired
+	private ClassGroupStudentMapperService classGroupStudentMapperService;
+
 	@Override
 	public BaseDAO<Integer, ClassGroup> getDAO() {
 		return classGroupDao;
@@ -41,4 +49,30 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
     public List<ClassGroup> findAllClassGroupByMusicGroupIdAndType(int musicGroupId, ClassGroupTypeEnum type) {
 		return classGroupDao.findAllClassGroupByMusicGroupIdAndType(musicGroupId,type);
     }
+
+	@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;
+	}
 }

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

@@ -9,6 +9,8 @@ import com.ym.mec.web.dal.dao.ClassGroupStudentMapperDao;
 import com.ym.mec.web.dal.entity.ClassGroupStudentMapper;
 import com.ym.mec.web.service.ClassGroupStudentMapperService;
 
+import java.util.List;
+
 @Service
 public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, ClassGroupStudentMapper>  implements ClassGroupStudentMapperService {
 	
@@ -19,5 +21,9 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
 	public BaseDAO<Long, ClassGroupStudentMapper> getDAO() {
 		return classGroupStudentMapperDao;
 	}
-	
+
+    @Override
+    public int classGroupStudentsInsert(List<ClassGroupStudentMapper> classGroupStudentMapperList) {
+		return classGroupStudentMapperDao.classGroupStudentsInsert(classGroupStudentMapperList);
+    }
 }

+ 8 - 0
mec-web/src/main/resources/config/mybatis/ClassGroupStudentMapperMapper.xml

@@ -63,4 +63,12 @@
     <select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM class_group_student_mapper
 	</select>
+
+    <!-- 班级学生批量插入 -->
+    <insert id="classGroupStudentsInsert" parameterType="java.util.List">
+        INSERT INTO class_group_student_mapper (id_,class_group_id_,user_id_,status_,create_time_)
+        <foreach collection="classGroupStudentMapperList" item="item" index="index" separator=",">
+            (#{item.id},#{item.classGroupId},#{item.userId},#{item.status},#{item.createTime})
+        </foreach>
+    </insert>
 </mapper>