hanyuwei 5 lat temu
rodzic
commit
b0464f041d

+ 8 - 7
mooctest-site-server/src/main/java/cn/iselab/mooctest/site/web/logic/impl/GroupLogicImpl.java

@@ -44,9 +44,6 @@ import java.util.stream.Collectors;
 @Service
 public class GroupLogicImpl extends BaseLogic implements GroupLogic {
 
- /*   @Autowired
-    private GroupLogicImpl groupLogic;*/
-
     @Autowired
     private GroupService groupService;
 
@@ -215,7 +212,7 @@ public class GroupLogicImpl extends BaseLogic implements GroupLogic {
         if (group.getOwnerId() == userDto.getId()) {
             throw new IllegalOperationException("Cannot join Group YOU OWN!");
         }
-        if(groupService.getWorkerCount(groupId) == group.getClassSize()){
+        if(groupService.getWorkerCount(groupId) >=group.getClassSize()){
             throw new HttpBadRequestException("班级人数已达上限,请联系管理员");
         }
         UserVO uv = Converter.convert(UserVO.class, groupService.addUserIntoGroup(userDto.getId(), groupId));
@@ -352,11 +349,15 @@ public class GroupLogicImpl extends BaseLogic implements GroupLogic {
         params.setHeadRows(1);
         List<User> result = ExcelImportUtil.importExcel(file.getInputStream(),
                User.class, params);
-        List<UserVO> addlist=new ArrayList<>();
+        Group group = groupService.getGroup(groupId);
+        if(result.size()>(group.getClassSize()-groupService.getWorkerCount(groupId))){
+            throw new HttpBadRequestException("批量导入人数超出班级上限");
+        }
+        List<UserVO> batchAddList=new ArrayList<>();
         for(User user:result){
             UserVO  userVO = this.addUserIntoGroup(user.getEmail(), groupId);
-            addlist.add(userVO);
+            batchAddList.add(userVO);
         }
-        return addlist;
+        return batchAddList;
     }
 }