Browse Source

1.添加校验

yuanliang 1 year ago
parent
commit
a202971f59

+ 37 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantGroupServiceImpl.java

@@ -138,8 +138,15 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
         if (count > 0) {
             throw new BizException("小组名称已存在");
         }
-        this.save(entity);
         Long adminId = tenantGroup.getAdminId();
+        Teacher teacher = teacherDao.selectById(adminId);
+        if (!tenantGroup.getTenantId().equals(teacher.getTenantId())) {
+            throw new BizException("负责人机构已经变更,请重新选择");
+        }
+        List<Long> userIds = tenantGroup.getUserIds();
+        checkStudent(tenantGroup.getTenantId(), userIds,null);
+
+        this.save(entity);
         if (adminId != null && Boolean.TRUE.equals(imGroupCreate)) {
             // 建群
             try {
@@ -156,7 +163,6 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 throw new BizException("创建机构小组群失败");
             }
             // 加群成员
-            List<Long> userIds = tenantGroup.getUserIds();
             if (CollectionUtils.isNotEmpty(userIds)) {
                 try {
                     imGroupService.addGroupMember(entity.getImGroupId(), new HashSet<>(userIds));
@@ -167,7 +173,6 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
             }
         }
         // 加群成员
-        List<Long> userIds = tenantGroup.getUserIds();
         if (CollectionUtils.isNotEmpty(userIds)) {
             studentDao.update(null, Wrappers.<Student>lambdaUpdate()
                     .in(Student::getUserId, userIds)
@@ -197,6 +202,13 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
             throw new BizException("小组名称已经存在");
         }
 
+        Long adminId = tenantGroup.getAdminId();
+        Teacher teacher = teacherDao.selectById(adminId);
+        if (!tenantGroup.getTenantId().equals(teacher.getTenantId())) {
+            throw new BizException("负责人机构已经变更,请重新选择");
+        }
+        checkStudent(tenantGroup.getTenantId(), tenantGroup.getUserIds(),tenantGroup.getId());
+
         TenantGroup entity = JSON.parseObject(tenantGroup.jsonString(), TenantGroup.class);
         entity.setImGroupId(oldGroup.getImGroupId());
         // 是否建群
@@ -526,4 +538,26 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 .eq(Student::getTenantGroupId, tenantGroupId);
         return studentDao.selectList(queryWrapper);
     }
+
+    private void checkStudent(Long tenantId, List<Long> userIds,Long tenantGroupId) {
+        if (CollectionUtils.isEmpty(userIds)) {
+            return;
+        }
+        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .in(Student::getUserId, userIds);
+        List<Student> students = studentDao.selectList(queryWrapper);
+        if (userIds.size() != students.size()) {
+            throw new BizException("参数错误");
+        }
+        for (Student student : students) {
+            if (!tenantId.equals(student.getTenantId())) {
+                throw new BizException("学生已经在其他机构");
+            }
+            Long groupId = student.getTenantGroupId();
+            if (groupId != -1L && !groupId.equals(tenantGroupId)) {
+                throw new BizException("学生已经在其他小组");
+            }
+        }
+    }
 }

+ 1 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantGroupMapper.xml

@@ -30,7 +30,7 @@
                 AND t.admin_id_ = #{param.adminId}
             </if>
         </where>
-        ORDER BY t.id_ ASC
+        ORDER BY t.id_ DESC
     </select>
 
 </mapper>

+ 6 - 3
cooleshow-user/user-biz/src/main/resources/config/mybatis/UserTenantBindRecordMapper.xml

@@ -61,9 +61,9 @@
                 AND t.user_type_ = #{param.userType}
             </if>
             <if test="param.tenantGroupId != null">
-                <if test="param.userType == 'TEACHER'">
-                    AND tg.id_ =#{param.tenantGroupId}
-                </if>
+<!--                <if test="param.userType == 'TEACHER'">-->
+<!--                    AND tg.id_ =#{param.tenantGroupId}-->
+<!--                </if>-->
                 <if test="param.userType == 'STUDENT'">
                     AND st.tenant_group_id_ = #{param.tenantGroupId}
                 </if>
@@ -90,6 +90,9 @@
         <if test="param.userType == 'TEACHER'">
             group by t.user_id_
         </if>
+        <if test="param.tenantGroupId != null and param.userType == 'TEACHER'">
+            HAVING find_in_set(#{param.tenantGroupId},tenantGroupId)
+        </if>
         order by field(t.bind_status_,1,0) ,t.bind_time_ desc
     </select>