浏览代码

群成员数量限制

yuanliang 11 月之前
父节点
当前提交
c321c9487d

+ 1 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/dao/CourseScheduleStudentPaymentDao.java

@@ -30,7 +30,7 @@ public interface CourseScheduleStudentPaymentDao extends BaseMapper<CourseSchedu
      * @author zx
      * @date 2022/3/23 16:18
      */
-    Set<Long> queryStudentIds(@Param("courseGroupId") Long courseGroupId,
+    List<Long> queryStudentIds(@Param("courseGroupId") Long courseGroupId,
                               @Param("courseGroupType") String courseGroupType);
 
     /**

+ 11 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/ImGroupServiceImpl.java

@@ -308,7 +308,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
     public String create(ImGroupWrapper.ImGroup imGroup) throws Exception {
         // 群成员数量限制校验
         SysConfig config = sysConfigService.findByParamName(SysConfigConstant.GROUP_MEMBER_LIMIT);
-        if (config != null && Integer.parseInt(config.getParamValue()) < imGroup.getStudentIdList().size()) {
+        if (config != null && Integer.parseInt(config.getParamValue()) < (imGroup.getStudentIdList().size() + 1)) {
             throw new BizException("群成员人数上限为:" + config.getParamValue() + "人");
         }
 
@@ -367,6 +367,15 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
             throw new BizException("添加的群成员不能为空");
 
         }
+        // 群成员数量限制校验
+        int memberCount = imGroupMemberService.countGroupMember(groupId);
+        // 查询群成员人数限制
+        SysConfig config = sysConfigService.findByParamName(SysConfigConstant.GROUP_MEMBER_LIMIT);
+        if (Objects.nonNull(config) && Integer.parseInt(config.getParamValue()) > 0
+                && (memberCount + studentIdList.size()) > Integer.parseInt(config.getParamValue())) {
+            throw new BizException("群成员数量已达上限");
+        }
+
         List<ImGroupMember> groupMemberList = imGroupMemberService.initGroupMembers(groupId,
                 studentIdList, ImGroupMemberRoleType.STUDENT);
         imGroupMemberService.join(groupMemberList, groupId);
@@ -391,7 +400,7 @@ public class ImGroupServiceImpl extends ServiceImpl<ImGroupDao, ImGroup> impleme
             return null;
         }
         //获取学员列表,按购买时间顺序升序排列返回
-        Set<Long> studentIds = courseScheduleStudentPaymentDao.queryStudentIds(courseGroupId, courseGroupType);
+        Set<Long> studentIds = new LinkedHashSet<>(courseScheduleStudentPaymentDao.queryStudentIds(courseGroupId, courseGroupType));
         // studentIds集合中所有null元素移除
         studentIds.removeAll(Collections.singleton(null));
         if (CollectionUtils.isEmpty(studentIds)) {