feat: (REQ-3057) 更换群主逻辑优化
This commit is contained in:
parent
6e52b5f923
commit
90e2b203f2
@ -87,7 +87,7 @@ public class ChatGroupUser implements Serializable {
|
||||
* 数据来源,create_group:创建群组;user_change:人员变更
|
||||
*/
|
||||
@TableField("data_source")
|
||||
private ChatGroupUserDataSourceEnum dataSource;
|
||||
private String dataSource;
|
||||
|
||||
/**
|
||||
* 备注,目前记录群成员失败加入群原因
|
||||
|
||||
@ -2,27 +2,22 @@ package cn.axzo.im.handler.chatgroup;
|
||||
|
||||
import cn.axzo.basics.auth.dto.SaasRoleUserRelation;
|
||||
import cn.axzo.basics.common.exception.ServiceException;
|
||||
import cn.axzo.basics.profiles.dto.basic.PersonProfileDto;
|
||||
import cn.axzo.framework.rocketmq.Event;
|
||||
import cn.axzo.framework.rocketmq.EventConsumer;
|
||||
import cn.axzo.framework.rocketmq.EventHandler;
|
||||
import cn.axzo.im.center.api.vo.req.UserAccountReq;
|
||||
import cn.axzo.im.center.api.vo.req.chatgroup.ChatGroupUserGenericSearchReq;
|
||||
import cn.axzo.im.center.api.vo.resp.UserAccountResp;
|
||||
import cn.axzo.im.center.api.vo.req.chatgroup.ChatGroupGenericSearchReq;
|
||||
import cn.axzo.im.center.api.vo.req.chatgroup.UserAddChatGroupReq;
|
||||
import cn.axzo.im.center.common.enums.AppTypeEnum;
|
||||
import cn.axzo.im.center.common.enums.ChatGroupUserDataSourceEnum;
|
||||
import cn.axzo.im.center.common.enums.ChatGroupUserTypeEnum;
|
||||
import cn.axzo.im.channel.netease.INotifyService;
|
||||
import cn.axzo.im.entity.ChatGroupUser;
|
||||
import cn.axzo.im.entity.ChatGroup;
|
||||
import cn.axzo.im.event.inner.EventTypeEnum;
|
||||
import cn.axzo.im.event.payload.SaasRoleUserRelationUpsertPayload;
|
||||
import cn.axzo.im.gateway.ProfilesApiGateway;
|
||||
import cn.axzo.im.gateway.TyrApiGateway;
|
||||
import cn.axzo.im.service.AccountService;
|
||||
import cn.axzo.im.service.ChatGroupService;
|
||||
import cn.axzo.im.service.ChatGroupUserService;
|
||||
import cn.axzo.tyr.client.model.res.SaasRoleRes;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
@ -41,20 +36,20 @@ import java.util.stream.Collectors;
|
||||
* @desc 群聊创建MQ消费
|
||||
*/
|
||||
@Slf4j
|
||||
//@Component
|
||||
//@RequiredArgsConstructor
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class ChatGroupChangeOwnerEventHandler implements EventHandler, InitializingBean {
|
||||
|
||||
// @Autowired
|
||||
@Autowired
|
||||
private EventConsumer eventConsumer;
|
||||
|
||||
// @Autowired
|
||||
@Autowired
|
||||
private TyrApiGateway tyrApiGateway;
|
||||
|
||||
// @Autowired
|
||||
@Autowired
|
||||
private ChatGroupUserService chatGroupUserService;
|
||||
|
||||
// @Autowired
|
||||
@Autowired
|
||||
private ChatGroupService chatGroupService;
|
||||
|
||||
@Override
|
||||
@ -121,32 +116,33 @@ public class ChatGroupChangeOwnerEventHandler implements EventHandler, Initializ
|
||||
String newImAccountOwner = this.chatGroupService.registerAccountIfAbsent(AppTypeEnum.CMP.getCode(), userRelation.getNaturalPersonId().toString(), userRelation.getOuId());
|
||||
|
||||
//1 用户是群主的群聊集合
|
||||
ChatGroupUserGenericSearchReq req = new ChatGroupUserGenericSearchReq();
|
||||
req.setType(ChatGroupUserTypeEnum.OWNER);
|
||||
ChatGroupGenericSearchReq req = new ChatGroupGenericSearchReq();
|
||||
req.setWorkspaceId(userRelation.getWorkspaceId());
|
||||
List<ChatGroupUser> chatGroupUsers = chatGroupUserService.genericQuery(req);
|
||||
List<ChatGroup> chatGroups = chatGroupService.genericQuery(req);
|
||||
|
||||
if (CollectionUtils.isEmpty(chatGroupUsers)) {
|
||||
if (CollectionUtils.isEmpty(chatGroups)) {
|
||||
log.info("ChatGroupChangeOwnerEventHandler-角色变更,personId:{},没有群是群主", userRelation.getNaturalPersonId());
|
||||
return;
|
||||
}
|
||||
for(ChatGroupUser chatGroupUser : chatGroupUsers) {
|
||||
switch (chatGroupUser.getCrowType()) {
|
||||
for(ChatGroup chatGroup : chatGroups) {
|
||||
switch (chatGroup.getCrowType()) {
|
||||
case WORKSPACE:
|
||||
if (!this.checkChangeOwnerWhenWorkspace(newValues, chatGroupUser.getAccId(), newImAccountOwner)) {
|
||||
log.info("ChatGroupChangeOwnerEventHandler-checkChangeOwnerWhenWorkspace,chatGroupId:{},newImAccount:{},不更换群主", chatGroupUser.getChatGroupId(), newImAccountOwner);
|
||||
if (!this.checkChangeOwnerWhenWorkspace(newValues, chatGroup.getGroupOwner(), newImAccountOwner)) {
|
||||
log.info("ChatGroupChangeOwnerEventHandler-checkChangeOwnerWhenWorkspace,chatGroupId:{},newImAccount:{},不更换群主", chatGroup.getId(), newImAccountOwner);
|
||||
continue;
|
||||
}
|
||||
// 2 更换群主
|
||||
this.chatGroupService.changeOwner(chatGroupUser.getChatGroupId(), chatGroupUser.getAccId(), newImAccountOwner, ChatGroupUserDataSourceEnum.USER_CHANGE);
|
||||
// 2 用户添加进群/更换群主
|
||||
this.chatGroupService.userAddChatGroup(UserAddChatGroupReq.builder().chatGroupId(chatGroup.getId()).members(Sets.newHashSet(newImAccountOwner)).build());
|
||||
this.chatGroupService.changeOwner(chatGroup.getId(), chatGroup.getGroupOwner(), newImAccountOwner, ChatGroupUserDataSourceEnum.USER_CHANGE);
|
||||
break;
|
||||
case OU:
|
||||
if (!checkChangeOwnerWhenOu(newValues, chatGroupUser.getAccId(), newImAccountOwner, userRelation.getOuId(), chatGroupUser.getOuId())) {
|
||||
log.info("ChatGroupChangeOwnerEventHandler-checkChangeOwnerWhenOu,chatGroupId:{},newImAccount:{},不更换群主", chatGroupUser.getChatGroupId(), newImAccountOwner);
|
||||
if (!checkChangeOwnerWhenOu(newValues, chatGroup.getGroupOwner(), newImAccountOwner, userRelation.getOuId(), chatGroup.getOuId())) {
|
||||
log.info("ChatGroupChangeOwnerEventHandler-checkChangeOwnerWhenOu,chatGroupId:{},newImAccount:{},不更换群主", chatGroup.getId(), newImAccountOwner);
|
||||
continue;
|
||||
}
|
||||
//2 更换群主
|
||||
this.chatGroupService.changeOwner(chatGroupUser.getChatGroupId(), chatGroupUser.getAccId(), newImAccountOwner, ChatGroupUserDataSourceEnum.USER_CHANGE);
|
||||
// 2 用户添加进群/更换群主
|
||||
this.chatGroupService.userAddChatGroup(UserAddChatGroupReq.builder().chatGroupId(chatGroup.getId()).members(Sets.newHashSet(newImAccountOwner)).build());
|
||||
this.chatGroupService.changeOwner(chatGroup.getId(), chatGroup.getGroupOwner(), newImAccountOwner, ChatGroupUserDataSourceEnum.USER_CHANGE);
|
||||
break;
|
||||
case TEAM:
|
||||
break;
|
||||
|
||||
@ -3,7 +3,6 @@ package cn.axzo.im.service;
|
||||
import cn.axzo.im.center.api.vo.req.chatgroup.ChatGroupCreateReq;
|
||||
import cn.axzo.im.center.api.vo.req.chatgroup.ChatGroupUserGenericSearchReq;
|
||||
import cn.axzo.im.center.common.enums.ChatGroupStatusEnum;
|
||||
import cn.axzo.im.center.common.enums.ChatGroupUserDataSourceEnum;
|
||||
import cn.axzo.im.center.common.enums.ChatGroupUserTypeEnum;
|
||||
import cn.axzo.im.entity.ChatGroupUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
@ -22,13 +21,13 @@ public interface ChatGroupUserService extends IService<ChatGroupUser> {
|
||||
* 创建群聊成员
|
||||
*/
|
||||
Boolean chatGroupUserCreate(Long chatGroupId, String tid,String accId, ChatGroupStatusEnum status, String remark
|
||||
, ChatGroupCreateReq.CrowTypeEnum crowType, ChatGroupUserTypeEnum type, Long workspaceId, Long ouId, ChatGroupUserDataSourceEnum dataSource);
|
||||
, ChatGroupCreateReq.CrowTypeEnum crowType, ChatGroupUserTypeEnum type, Long workspaceId, Long ouId, String dataSource);
|
||||
|
||||
/**
|
||||
* 批量创建群聊成员
|
||||
*/
|
||||
Boolean chatGroupUserBatchCreate(Long chatGroupId, String tid, Set<String> members, ChatGroupStatusEnum status, String remark
|
||||
, ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, ChatGroupUserDataSourceEnum dataSource);
|
||||
, ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, String dataSource);
|
||||
|
||||
/**
|
||||
* 删除群聊成员
|
||||
@ -52,7 +51,7 @@ public interface ChatGroupUserService extends IService<ChatGroupUser> {
|
||||
* @param oldAccId 原有账号
|
||||
* @param newAccId 新账号
|
||||
*/
|
||||
void changeOwner(Long chatGroupId, String oldAccId, String newAccId, ChatGroupUserDataSourceEnum dataSource);
|
||||
void changeOwner(Long chatGroupId, String oldAccId, String newAccId, String dataSource);
|
||||
|
||||
/**
|
||||
* 通过groupId/accid更新属性(后续有其他属性则添加)
|
||||
|
||||
@ -105,9 +105,6 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
|
||||
@Resource
|
||||
private AccountService accountService;
|
||||
|
||||
@Resource
|
||||
private INotifyService iNotifyService;
|
||||
|
||||
@Autowired
|
||||
private ChatGroupConfig chatGroupConfig;
|
||||
|
||||
@ -129,9 +126,6 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
|
||||
@Autowired
|
||||
private WorkspaceApiGateway workspaceApiGateway;
|
||||
|
||||
@Autowired
|
||||
private OrganizationalNodeApiGateway organizationalNodeApiGateway;
|
||||
|
||||
@Autowired
|
||||
private OrganizationalNodeUserApiGateway organizationalNodeUserApiGateway;
|
||||
|
||||
@ -162,7 +156,7 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
|
||||
ChatGroup chatGroup = this.buildChatGroupCreate(req, response, resp.getOwnerImAccount(), req.getOuId(), resp.getTeamNodeId());
|
||||
// 保存db
|
||||
this.saveOrUpdate(chatGroup);
|
||||
this.chatGroupUserService.chatGroupUserCreate(chatGroup.getId(), response.getTid(), resp.getOwnerImAccount(), ChatGroupStatusEnum.SUCCESS, null, req.getCrowType(), ChatGroupUserTypeEnum.OWNER, req.getWorkspaceId(), req.getOuId(), ChatGroupUserDataSourceEnum.CREATE_GROUP);
|
||||
this.chatGroupUserService.chatGroupUserCreate(chatGroup.getId(), response.getTid(), resp.getOwnerImAccount(), ChatGroupStatusEnum.SUCCESS, null, req.getCrowType(), ChatGroupUserTypeEnum.OWNER, req.getWorkspaceId(), req.getOuId(), ChatGroupUserDataSourceEnum.CREATE_GROUP.getCode());
|
||||
// 群聊创建成功发送MQ
|
||||
this.chatGroupCreateSendMQ(req, response, resp.getOwnerId().toString(), resp.getOwnerImAccount(), chatGroup.getId());
|
||||
// 返回
|
||||
@ -478,7 +472,7 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
|
||||
|
||||
nimChannelService.changeOwner(changeOwnerRequest);
|
||||
this.updateGroupOwner(chatGroupId, newAccIdOwner);
|
||||
chatGroupUserService.changeOwner(chatGroupId, oldAccIdOwner, newAccIdOwner, dataSource);
|
||||
chatGroupUserService.changeOwner(chatGroupId, oldAccIdOwner, newAccIdOwner, dataSource.getCode());
|
||||
operateLogService.create(OperateLogTypeEnum.USER_ENTER_CHAT_GROUP, String.format("changeOwner-success,chatGroupId:%d,oldAccIdOwner:%s,newAccIdOwner:%s", chatGroupId, oldAccIdOwner, newAccIdOwner));
|
||||
} catch (ServiceException serviceException) {
|
||||
operateLogService.create(OperateLogTypeEnum.CHANGE_OWNER, String.format("changeOwner-fail,chatGroupId:%d,oldAccIdOwner:%s,newAccIdOwner:%s", chatGroupId, oldAccIdOwner, newAccIdOwner));
|
||||
@ -537,12 +531,12 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
|
||||
request.setMsg("进入群:" + groupName);
|
||||
try {
|
||||
nimChannelService.userAddChatGroup(request);
|
||||
chatGroupUserService.chatGroupUserBatchCreate(chatGroupId,tid, members, ChatGroupStatusEnum.SUCCESS,null, chatGroup.getCrowType(), chatGroup.getWorkspaceId(), chatGroup.getOuId(),dataSource);
|
||||
chatGroupUserService.chatGroupUserBatchCreate(chatGroupId,tid, members, ChatGroupStatusEnum.SUCCESS,null, chatGroup.getCrowType(), chatGroup.getWorkspaceId(), chatGroup.getOuId(),dataSource.getCode());
|
||||
operateLogService.create(OperateLogTypeEnum.USER_ENTER_CHAT_GROUP, String.format("user:%s,enter chatGroup:%s,owner:%s", JSON.toJSONString(members), tid, owner));
|
||||
return true;
|
||||
} catch (ServiceException serviceException) {
|
||||
String error = String.format("errorCode: %s;msg:%s" ,serviceException.getErrorCode(), serviceException.getMessage());
|
||||
chatGroupUserService.chatGroupUserBatchCreate(chatGroupId,tid, members, ChatGroupStatusEnum.FAIL,error, chatGroup.getCrowType(), chatGroup.getWorkspaceId(), chatGroup.getOuId(),dataSource);
|
||||
chatGroupUserService.chatGroupUserBatchCreate(chatGroupId,tid, members, ChatGroupStatusEnum.FAIL,error, chatGroup.getCrowType(), chatGroup.getWorkspaceId(), chatGroup.getOuId(),dataSource.getCode());
|
||||
operateLogService.create(OperateLogTypeEnum.USER_ENTER_CHAT_GROUP, String.format("user:%s,enter-error chatGroup:%s,owner:%s", JSON.toJSONString(members), tid, owner));
|
||||
this.sendDingRobot(error);
|
||||
return false;
|
||||
|
||||
@ -40,7 +40,7 @@ public class ChatGroupUserServiceImpl extends ServiceImpl<ChatGroupUserMapper,
|
||||
|
||||
@Override
|
||||
public Boolean chatGroupUserCreate(Long chatGroupId, String tid, String accId, ChatGroupStatusEnum status, String remark
|
||||
, ChatGroupCreateReq.CrowTypeEnum crowType, ChatGroupUserTypeEnum type, Long workspaceId,Long ouId, ChatGroupUserDataSourceEnum dataSource) {
|
||||
, ChatGroupCreateReq.CrowTypeEnum crowType, ChatGroupUserTypeEnum type, Long workspaceId,Long ouId, String dataSource) {
|
||||
return this.saveOrUpdate(ChatGroupUser.builder()
|
||||
.chatGroupId(chatGroupId)
|
||||
.tid(tid)
|
||||
@ -61,7 +61,7 @@ public class ChatGroupUserServiceImpl extends ServiceImpl<ChatGroupUserMapper,
|
||||
* @param newAccId 新账号
|
||||
*/
|
||||
@Override
|
||||
public void changeOwner(Long chatGroupId, String oldAccId, String newAccId, ChatGroupUserDataSourceEnum dataSource ) {
|
||||
public void changeOwner(Long chatGroupId, String oldAccId, String newAccId, String dataSource ) {
|
||||
|
||||
this.chatGroupUserDelete(chatGroupId, oldAccId);
|
||||
ChatGroup chatGroup = chatGroupService.getById(chatGroupId);
|
||||
@ -96,7 +96,7 @@ public class ChatGroupUserServiceImpl extends ServiceImpl<ChatGroupUserMapper,
|
||||
|
||||
@Override
|
||||
public Boolean chatGroupUserBatchCreate(Long chatGroupId, String tid, Set<String> members, ChatGroupStatusEnum status
|
||||
, String remark, ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, ChatGroupUserDataSourceEnum dataSource) {
|
||||
, String remark, ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, String dataSource) {
|
||||
if (CollectionUtils.isEmpty(members)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user