Joburgess 5 年之前
父节点
当前提交
c296452123

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/ClassGroupStudentMapperDao.java

@@ -166,4 +166,15 @@ public interface ClassGroupStudentMapperDao extends BaseDAO<Long, ClassGroupStud
      * @return java.util.List<java.util.Map<java.lang.Integer,java.lang.Integer>>
      */
     Integer countClassGroupStudentNum(@Param("classGroupId") Integer classGroupId);
+
+    /**
+     * @describe 统计指定班级的重复人数
+     * @author Joburgess
+     * @date 2019/11/22
+     * @param classGroupId: 班级编号
+     * @param userIds: 学生编号
+     * @return java.lang.Integer
+     */
+    Integer countClassGroupExitStudentNum(@Param("classGroupId") Integer classGroupId,
+                                          @Param("userIds") List<Integer> userIds);
 }

+ 23 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/VipGroupServiceImpl.java

@@ -1480,10 +1480,17 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 			throw new BizException("未找到指定的vip课程");
 		}
 		ClassGroup classGroup = classGroupDao.findByVipGroup(vipGroupId, null);
+
+		Integer exitStudentNum = classGroupStudentMapperDao.countClassGroupExitStudentNum(classGroup.getId(), studentIds);
+		if(exitStudentNum>0){
+			throw new BizException("选择的学生中存在此课程中已存在的学生");
+		}
+
 		List<CourseSchedule> surplusCourses = courseScheduleDao.findByClassGroupAndStatus(classGroup.getId(), CourseStatusEnum.NOT_START.getCode());
 		if(CollectionUtils.isEmpty(surplusCourses)){
 			throw new BizException("此vip课程没有剩余课程计划");
 		}
+
 		BigDecimal surplusCoursesPrice=new BigDecimal(0);
 		surplusCourses.forEach(courseSchedule -> {
 			if(courseSchedule.getTeachMode().equals(TeachModeEnum.OFFLINE)){
@@ -1493,6 +1500,7 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 			}
 		});
 		List<ImGroupMember> imGroupMemberList = new ArrayList<>();
+		List<ClassGroupStudentMapper> classGroupStudentMappers=new ArrayList<>();
 		//生成学生单课缴费信息
 		for (Integer studentId:studentIds) {
 			SysUserCashAccount sysUserCashAccount = sysUserCashAccountService.get(studentId);
@@ -1501,11 +1509,25 @@ public class VipGroupServiceImpl extends BaseServiceImpl<Long, VipGroup> impleme
 			}
 			courseScheduleStudentPaymentService.createCourseScheduleStudentPaymentForVipGroup(vipGroupId,studentId);
 
-			sysUserCashAccountService.updateCourseBalance(studentId,surplusCoursesPrice.negate());
+			sysUserCashAccountService.updateCourseBalance(studentId,sysUserCashAccount.getCourseBalance().subtract(surplusCoursesPrice));
+
+			//创建班级学生关联记录
+			ClassGroupStudentMapper classGroupStudentMapper=new ClassGroupStudentMapper();
+			classGroupStudentMapper.setGroupType(classGroup.getGroupType());
+			classGroupStudentMapper.setMusicGroupId(classGroup.getMusicGroupId());
+			classGroupStudentMapper.setClassGroupId(classGroup.getId());
+			classGroupStudentMapper.setStatus(ClassGroupStudentStatusEnum.NORMAL);
+			classGroupStudentMapper.setUserId(studentId);
+			classGroupStudentMappers.add(classGroupStudentMapper);
 
 			imGroupMemberList.add(new ImGroupMember(studentId.toString()));
 		}
 
+		classGroupStudentMapperDao.classGroupStudentsInsert(classGroupStudentMappers);
+
+		classGroup.setStudentNum(classGroup.getStudentNum()+classGroupStudentMappers.size());
+		classGroupDao.update(classGroup);
+
 		try {
 			ImGroupMember[] imGroupMembers = imGroupMemberList.toArray(new ImGroupMember[imGroupMemberList.size()]);
 			// 创建群组

+ 12 - 0
mec-biz/src/main/resources/config/mybatis/ClassGroupStudentMapperMapper.xml

@@ -214,4 +214,16 @@
         GROUP BY
           class_group_id_
     </select>
+    <select id="countClassGroupExitStudentNum" resultType="int">
+        SELECT
+            COUNT( user_id_ )
+        FROM
+          class_group_student_mapper
+        WHERE
+            class_group_id_ = #{classGroupId}
+            AND user_id_ IN
+            <foreach collection="userIds" item="userId" open="(" close=")" separator=",">
+                #{userId}
+            </foreach>
+    </select>
 </mapper>

+ 2 - 1
mec-biz/src/main/resources/config/mybatis/VipGroupMapper.xml

@@ -502,7 +502,8 @@
         SELECT
             su.id_,
             su.username_,
-            su.phone_
+            su.phone_,
+            suca.course_balance_
         FROM
           sys_user_cash_account suca
           LEFT JOIN sys_user su ON suca.user_id_=su.id_