Explorar el Código

1.机构小组IM群需求调整

yuanliang hace 1 año
padre
commit
26fc6f03ba

+ 1 - 1
cooleshow-app/src/main/java/com/yonge/cooleshow/tenant/controller/TenantGroupController.java

@@ -72,7 +72,7 @@ public class TenantGroupController {
         group.setCreateBy(sysUser.getId());
         group.setTenantId(sysUser.getTenantId());
         // 新增数据
-        tenantGroupService.add(group);
+        tenantGroupService.add(group, tenantGroup.getImGroupCreate());
 
         return R.defaultR();
     }

+ 2 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TenantGroupService.java

@@ -33,9 +33,10 @@ public interface TenantGroupService extends IService<TenantGroup>  {
     /**
      * 添加
      * @param tenantGroup TenantGroupWrapper.TenantGroup
+     * @param imGroupCreate 是否创建群聊
      * @return Boolean
      */
-    Boolean add(TenantGroupWrapper.TenantGroup tenantGroup);
+    Boolean add(TenantGroupWrapper.TenantGroup tenantGroup, Boolean imGroupCreate);
 
     /**
      * 更新

+ 7 - 7
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java

@@ -630,10 +630,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
         }
 
         // 加入机构小组群
-        if (studentInfo.getTenantGroupId() != -1L && !studentInfo.getTenantGroupId().equals(student.getTenantGroupId())) {
-            quitFromTenantGroupIM(student.getTenantGroupId(), student.getUserId());
-            add2TenantGroupIM(studentInfo.getTenantGroupId(), studentInfo.getId());
-        }
+//        if (studentInfo.getTenantGroupId() != -1L && !studentInfo.getTenantGroupId().equals(student.getTenantGroupId())) {
+//            quitFromTenantGroupIM(student.getTenantGroupId(), student.getUserId());
+//            add2TenantGroupIM(studentInfo.getTenantGroupId(), studentInfo.getId());
+//        }
 
 
         // 手机号码修改
@@ -796,9 +796,9 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
         }
 
         // 加入机构小组群
-        if (studentInfo.getTenantGroupId() != -1L) {
-            add2TenantGroupIM(student.getTenantGroupId(), student.getUserId());
-        }
+//        if (studentInfo.getTenantGroupId() != -1L) {
+//            add2TenantGroupIM(student.getTenantGroupId(), student.getUserId());
+//        }
 
         return true;
     }

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

@@ -126,7 +126,7 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public Boolean add(TenantGroupWrapper.TenantGroup tenantGroup) {
+    public Boolean add(TenantGroupWrapper.TenantGroup tenantGroup, Boolean imGroupCreate) {
         TenantGroup entity = JSON.parseObject(tenantGroup.jsonString(), TenantGroup.class);
         Integer count = this.lambdaQuery()
                 .eq(TenantGroup::getTenantId, tenantGroup.getTenantId())
@@ -137,7 +137,7 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
         }
         this.save(entity);
         Long adminId = tenantGroup.getAdminId();
-        if (adminId != null) {
+        if (adminId != null && Boolean.TRUE.equals(imGroupCreate)) {
             // 建群
             try {
                 ImGroupWrapper.ImGroup imGroup = new ImGroupWrapper.ImGroup();
@@ -201,6 +201,22 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 SysUser sysUser = sysUserService.getByUserId(entity.getAdminId());
                 String imGroupId = createImGroup(entity.getAdminId(), sysUser.getUsername());
                 entity.setImGroupId(imGroupId);
+
+                // 添加群成员
+                List<Long> userIds = tenantGroup.getUserIds();
+                if (CollectionUtils.isNotEmpty(userIds)) {
+                    // 加群成员
+                    try {
+                        imGroupService.addGroupMember(oldGroup.getImGroupId(), new HashSet<>(userIds));
+                    } catch (Exception e) {
+                        log.error("加入机构小组群失败", e);
+                        throw new BizException("加入机构小组群失败");
+                    }
+                }
+                studentDao.update(null, Wrappers.<Student>lambdaUpdate()
+                        .in(Student::getUserId, userIds)
+                        .eq(Student::getTenantId, tenantGroup.getTenantId())
+                        .set(Student::getTenantGroupId, entity.getId()));
             }
         }
         // 修改小组负责人,调整群主,更换群主需要新的群主为该群成员
@@ -217,20 +233,20 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
         List<Long> removeGroupUsers = oldGroupUsers.stream()
                 .filter(next -> !newGroupUsers.contains(next)).collect(Collectors.toList());
         // 移除的群成员,退群
-        ImGroup imGroup = imGroupService.getById(Optional.ofNullable(entity.getImGroupId()).orElse("-1"));
+//        ImGroup imGroup = imGroupService.getById(Optional.ofNullable(entity.getImGroupId()).orElse("-1"));
         if (!removeGroupUsers.isEmpty()) {
-            if (imGroup != null) {
-                try {
-                    for (Long removeUserId : removeGroupUsers) {
-                        imGroupCoreService.groupQuit(removeUserId, ClientEnum.STUDENT.getCode(),
-                                oldGroup.getImGroupId(),
-                                true);
-                    }
-                } catch (Exception e) {
-                    log.error("群成员移出群失败", e);
-                    throw new BizException("群成员移出群失败");
-                }
-            }
+//            if (imGroup != null) {
+//                try {
+//                    for (Long removeUserId : removeGroupUsers) {
+//                        imGroupCoreService.groupQuit(removeUserId, ClientEnum.STUDENT.getCode(),
+//                                oldGroup.getImGroupId(),
+//                                true);
+//                    }
+//                } catch (Exception e) {
+//                    log.error("群成员移出群失败", e);
+//                    throw new BizException("群成员移出群失败");
+//                }
+//            }
             studentDao.update(null, Wrappers.<Student>lambdaUpdate()
                     .in(Student::getUserId, removeGroupUsers)
                     .eq(Student::getTenantId, tenantGroup.getTenantId())
@@ -241,14 +257,14 @@ public class TenantGroupServiceImpl extends ServiceImpl<TenantGroupMapper, Tenan
                 .collect(Collectors.toList());
         if (!newAddGroupUsers.isEmpty()) {
             // 加群成员
-            if (imGroup != null) {
-                try {
-                    imGroupService.addGroupMember(oldGroup.getImGroupId(), new HashSet<>(newAddGroupUsers));
-                } catch (Exception e) {
-                    log.error("加入机构小组群失败", e);
-                    throw new BizException("加入机构小组群失败");
-                }
-            }
+//            if (imGroup != null) {
+//                try {
+//                    imGroupService.addGroupMember(oldGroup.getImGroupId(), new HashSet<>(newAddGroupUsers));
+//                } catch (Exception e) {
+//                    log.error("加入机构小组群失败", e);
+//                    throw new BizException("加入机构小组群失败");
+//                }
+//            }
             studentDao.update(null, Wrappers.<Student>lambdaUpdate()
                     .in(Student::getUserId, newAddGroupUsers)
                     .eq(Student::getTenantId, tenantGroup.getTenantId())

+ 1 - 1
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/TenantGroupController.java

@@ -73,7 +73,7 @@ public class TenantGroupController {
         group.setCreateBy(sysUser.getId());
         group.setTenantId(sysUser.getTenantId());
         // 新增数据
-        tenantGroupService.add(group);
+        tenantGroupService.add(group, tenantGroup.getImGroupCreate());
 
         return R.defaultR();
     }