Browse Source

增加小班,添加学员接口

周箭河 5 years ago
parent
commit
dd325f0caf

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

@@ -45,4 +45,13 @@ public interface ClassGroupStudentMapperService extends BaseService<Long, ClassG
      * @return
      */
     boolean adjustClassGroup(Integer userId,Integer oldClassGroupId,Integer classGroupId) throws Exception;
+
+    /**
+     * 添加学员
+     * @param classGroupId
+     * @param userIdsStr
+     * @return
+     * @throws Exception
+     */
+    boolean addStudents(Integer classGroupId,String userIdsStr) throws Exception;
 }

+ 49 - 3
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupStudentMapperServiceImpl.java

@@ -12,9 +12,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, ClassGroupStudentMapper> implements ClassGroupStudentMapperService {
@@ -106,4 +104,52 @@ public class ClassGroupStudentMapperServiceImpl extends BaseServiceImpl<Long, Cl
         courseScheduleStudentPaymentService.batchInsert(courseScheduleStudentPayments);
         return true;
     }
+
+    @Override
+    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);
+
+        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;
+    }
 }

+ 12 - 0
mec-web/src/main/java/com/ym/mec/web/controller/ClassGroupStudentController.java

@@ -52,4 +52,16 @@ public class ClassGroupStudentController extends BaseController {
         return succeed(classGroupStudentMapperService.adjustClassGroup(userId, oldClassGroupId, classGroupId));
     }
 
+
+    @ApiOperation(value = "添加学(小班课)")
+    @PostMapping("/addStudents")
+    @PreAuthorize("@pcs.hasPermissions('classGroupStudent/addStudents')")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "classGroupId", value = "小课班班级id", required = true, dataType = "int"),
+            @ApiImplicitParam(name = "userIdsStr", value = "学生UserId,逗号分隔", required = true, dataType = "String")
+    })
+    public HttpResponseResult addStudents(Integer classGroupId, String userIdsStr) throws Exception {
+        return succeed(classGroupStudentMapperService.addStudents(classGroupId, userIdsStr));
+    }
+
 }