feat: (REQ-3057) 人群列表接口优化

This commit is contained in:
xudawei 2024-11-18 17:46:38 +08:00
parent 0b7e559490
commit 8a8c0b1f58
13 changed files with 116 additions and 62 deletions

View File

@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
/**
* 群聊创建请求
* 人群列表
* @author xudawei
* @date 2024/11/14
*/

View File

@ -0,0 +1,36 @@
package cn.axzo.im.center.common.enums;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 数据来源
*
* @author xudawei
* @date 2024/11/12
*/
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum ChatGroupUserDataSourceEnum {
/**
* 创建群组
*/
CREATE_GROUP("create_group", "创建群组"),
/**
* 人员变更
*/
USER_CHANGE("user_change", "人员变更"),
/**
* API操作
*/
API_HANDLE("api_handle", "API操作"),
;
private final String code;
private final String message;
}

View File

@ -13,11 +13,11 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
@Slf4j
//@SpringBootApplication(scanBasePackages = "cn.axzo", exclude = MybatisPlusAutoConfiguration.class)
//@EnableFeignClients(basePackages = {"cn.axzo"})
//@MapperScan(value = {"cn.axzo.im.dao.mapper"})
//@EnableDiscoveryClient
//@Import(RocketMQEventConfiguration.class)
@SpringBootApplication(scanBasePackages = "cn.axzo", exclude = MybatisPlusAutoConfiguration.class)
@EnableFeignClients(basePackages = {"cn.axzo"})
@MapperScan(value = {"cn.axzo.im.dao.mapper"})
@EnableDiscoveryClient
@Import(RocketMQEventConfiguration.class)
public class ImCenterTestApplication {
public static void main(String[] args) {
System.setProperty("spring.profiles.active", "test");

View File

@ -418,6 +418,7 @@ public class NimChannelService implements IMChannelProvider {
paramMap.put("upcustommode", 1);
paramMap.put("isNotifyCloseOnline", 0);
paramMap.put("isNotifyClosePersistent", 0);
paramMap.put("attach", request.getAttach());
return paramMap;
}
@ -494,7 +495,7 @@ public class NimChannelService implements IMChannelProvider {
HashMap<String, Object> paramMap = Maps.newHashMap();
paramMap.put("tid", request.getTid());
paramMap.put("owner", request.getOwner());
paramMap.put("members", request.getMembers());
paramMap.put("member", request.getMember());
paramMap.put("attach",request.getAttach());
return paramMap;
}

View File

@ -131,7 +131,7 @@ public class RocketMQEventConfiguration {
@Slf4j
@Component
@RocketMQMessageListener(topic = "topic_organizational_${spring.profiles.active}",
consumerGroup = "GID_chat_group_create_${spring.application.name}_${spring.profiles.active}",
consumerGroup = "GID_chat_group_create1_${spring.application.name}_${spring.profiles.active}",
consumeMode = ConsumeMode.ORDERLY,
nameServer = "${rocketmq.name-server}"
)

View File

@ -2,6 +2,7 @@ package cn.axzo.im.entity;
import cn.axzo.im.center.api.vo.req.chatgroup.ChatGroupCreateReq;
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 com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
@ -82,6 +83,12 @@ public class ChatGroupUser implements Serializable {
@TableField("crow_type")
private ChatGroupCreateReq.CrowTypeEnum crowType;
/**
* 数据来源,create_group:创建群组;user_change:人员变更
*/
@TableField("data_source")
private ChatGroupUserDataSourceEnum dataSource;
/**
* 备注目前记录群成员失败加入群原因
*/

View File

@ -10,6 +10,7 @@ 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.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;
@ -156,7 +157,7 @@ public class ChatGroupChangeOwnerEventHandler implements EventHandler, Initializ
continue;
}
// 2 更换群主
this.chatGroupService.changeOwner(chatGroupUser.getChatGroupId(), chatGroupUser.getAccId(), newImAccountOwner);
this.chatGroupService.changeOwner(chatGroupUser.getChatGroupId(), chatGroupUser.getAccId(), newImAccountOwner, ChatGroupUserDataSourceEnum.USER_CHANGE);
break;
case OU:
if (!checkChangeOwnerWhenOu(newValues, chatGroupUser.getAccId(), newImAccountOwner, userRelation.getOuId(), chatGroupUser.getOuId())) {
@ -164,7 +165,7 @@ public class ChatGroupChangeOwnerEventHandler implements EventHandler, Initializ
continue;
}
//2 更换群主
this.chatGroupService.changeOwner(chatGroupUser.getChatGroupId(), chatGroupUser.getAccId(), newImAccountOwner);
this.chatGroupService.changeOwner(chatGroupUser.getChatGroupId(), chatGroupUser.getAccId(), newImAccountOwner, ChatGroupUserDataSourceEnum.USER_CHANGE);
break;
case TEAM:
break;

View File

@ -8,12 +8,14 @@ import cn.axzo.im.center.api.vo.req.chatgroup.ChatGroupCreateReq;
import cn.axzo.im.center.api.vo.req.UserAccountReq;
import cn.axzo.im.center.api.vo.resp.UserAccountResp;
import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.im.center.common.enums.ChatGroupUserDataSourceEnum;
import cn.axzo.im.channel.netease.INotifyService;
import cn.axzo.im.event.inner.EventTypeEnum;
import cn.axzo.im.event.payload.ChatGroupCreatePayload;
import cn.axzo.im.gateway.ProfilesApiGateway;
import cn.axzo.im.service.AccountService;
import cn.axzo.im.service.ChatGroupService;
import cn.axzo.maokai.api.vo.response.OrganizationalNodeUserVO;
import cn.hutool.core.lang.Pair;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
@ -88,7 +90,7 @@ public class ChatGroupEventHandler implements EventHandler, InitializingBean {
String imAccountOwner = payload.getImAccountOwner();
Set<String> members = this.chatGroupOfMembers(req);
this.chatGroupService.userAddChatGroup(payload.getChatGroupId(), tid,imAccountOwner, members, req.getGroupName());
this.chatGroupService.userAddChatGroup(payload.getChatGroupId(), tid,imAccountOwner, members, req.getGroupName(), ChatGroupUserDataSourceEnum.CREATE_GROUP);
}
/**
@ -96,40 +98,40 @@ public class ChatGroupEventHandler implements EventHandler, InitializingBean {
*/
public Set<String> chatGroupOfMembers(ChatGroupCreateReq req) {
//Pair,key:管理人员集合;value:工人集合
Pair<Set<Long>, Set<Long>> adminWorkerSet = chatGroupService.fetchUsersByWorkspaceOuId(req.getCrowType(), req.getWorkspaceId(), req.getOuId(), this.chatGroupService.buildJobCodesByCrowType(req.getCrowType()), req.getCreator());
Set<Long> adminSet = adminWorkerSet.getKey();
Set<Long> workerSet = adminWorkerSet.getValue();
Pair<List<OrganizationalNodeUserVO>, List<OrganizationalNodeUserVO>> adminWorkerPair = chatGroupService.fetchUsersByWorkspaceOuId(req.getCrowType(), req.getWorkspaceId(), req.getOuId(), this.chatGroupService.buildJobCodesByCrowType(req.getCrowType()), req.getCreator());
List<OrganizationalNodeUserVO> adminSet = adminWorkerPair.getKey();
List<OrganizationalNodeUserVO> workerSet = adminWorkerPair.getValue();
Map<Long, PersonProfileDto> personProfileMap = this.buildPersonProfileMap(adminWorkerSet);
Map<Long, PersonProfileDto> personProfileMap = this.buildPersonProfileMap(adminWorkerPair);
List<UserAccountResp> userAccountRespList = Lists.newArrayList();
for (Long item : adminSet) {
PersonProfileDto personProfileDto = personProfileMap.get(item);
for (OrganizationalNodeUserVO item : adminSet) {
PersonProfileDto personProfileDto = personProfileMap.get(item.getPersonId());
if (Objects.isNull(personProfileDto) || Objects.isNull(personProfileDto.getId())) {
log.info("admin-personProfileDto is null");
continue;
}
UserAccountReq userAccountReq = UserAccountReq.builder()
.appType(AppTypeEnum.CMP.getCode())//管理端:AppTypeEnum.CMP.getCode();工人端:AppTypeEnum.CM.getCode()
.userId(item.toString()).nickName(personProfileDto.getRealName())
.userId(item.getPersonId().toString()).nickName(personProfileDto.getRealName())
.headImageUrl(personProfileDto.getAvatarUrl())
.organizationalUnitId(req.getOuId())
.organizationalUnitId(item.getOrganizationalUnitId())
.build();
userAccountRespList.add(accountService.generateAccount(userAccountReq, iNotifyService));
}
for (Long worker : workerSet) {
PersonProfileDto personProfileDto = personProfileMap.get(worker);
for (OrganizationalNodeUserVO worker : workerSet) {
PersonProfileDto personProfileDto = personProfileMap.get(worker.getPersonId());
if (Objects.isNull(personProfileDto) || Objects.isNull(personProfileDto.getId())) {
log.info("worker-personProfileDto is null");
continue;
}
UserAccountReq userAccountReq = UserAccountReq.builder()
.appType(AppTypeEnum.CM.getCode())//管理端:AppTypeEnum.CMP.getCode();工人端:AppTypeEnum.CM.getCode()
.userId(worker.toString()).nickName(personProfileDto.getRealName())
.userId(worker.getPersonId().toString()).nickName(personProfileDto.getRealName())
.headImageUrl(personProfileDto.getAvatarUrl())
.organizationalUnitId(req.getOuId())
.organizationalUnitId(worker.getOrganizationalUnitId())
.build();
userAccountRespList.add(accountService.generateAccount(userAccountReq, iNotifyService));
}
@ -141,14 +143,14 @@ public class ChatGroupEventHandler implements EventHandler, InitializingBean {
* 构建personProfile的Map
* key:id,value:personProfile
*/
private Map<Long, PersonProfileDto> buildPersonProfileMap(Pair<Set<Long>, Set<Long>> adminWorkerSet) {
private Map<Long, PersonProfileDto> buildPersonProfileMap(Pair<List<OrganizationalNodeUserVO>, List<OrganizationalNodeUserVO>> adminWorkerPair) {
Set<Long> adminSet = CollectionUtils.isNotEmpty(adminWorkerSet.getKey()) ? adminWorkerSet.getKey() : Sets.newHashSet();
Set<Long> workerSet = CollectionUtils.isNotEmpty(adminWorkerSet.getValue()) ? adminWorkerSet.getValue() : Sets.newHashSet();
List<OrganizationalNodeUserVO> adminSet = CollectionUtils.isNotEmpty(adminWorkerPair.getKey()) ? adminWorkerPair.getKey() : Lists.newArrayList();
List<OrganizationalNodeUserVO> workerSet = CollectionUtils.isNotEmpty(adminWorkerPair.getValue()) ? adminWorkerPair.getValue() : Lists.newArrayList();
List<Long> adminWorkerList = Lists.newArrayList();
adminWorkerList.addAll(Lists.newArrayList(adminSet));
adminWorkerList.addAll(Lists.newArrayList(workerSet));
adminWorkerList.addAll(Lists.newArrayList(adminSet.stream().map(OrganizationalNodeUserVO::getPersonId).collect(Collectors.toList())));
adminWorkerList.addAll(Lists.newArrayList(workerSet.stream().map(OrganizationalNodeUserVO::getPersonId).collect(Collectors.toList())));
List<PersonProfileDto> personProfileDtoList = profilesApiGateway.getPersonProfilesByIds(adminWorkerList);
return personProfileDtoList.stream().collect(Collectors.toMap(PersonProfileDto::getId, Function.identity(), (x, y) -> x));

View File

@ -7,6 +7,7 @@ import cn.axzo.framework.rocketmq.EventHandler;
import cn.axzo.im.center.api.vo.req.chatgroup.ChatGroupCreateReq;
import cn.axzo.im.center.api.vo.req.chatgroup.ChatGroupGenericSearchReq;
import cn.axzo.im.center.common.enums.AppTypeEnum;
import cn.axzo.im.center.common.enums.ChatGroupUserDataSourceEnum;
import cn.axzo.im.channel.netease.NimChannelService;
import cn.axzo.im.channel.netease.dto.ChatGroupQueryResponse;
import cn.axzo.im.entity.ChatGroup;
@ -184,7 +185,7 @@ public class OrganizationalNodeUserChangeEventHandler implements EventHandler, I
log.info("班组长并未变更,不执行更改群主逻辑,currentImAccount:{},chatGroupId:{}", currentImAccount, chatGroup.getId());
return;
}
this.chatGroupService.changeOwner(chatGroup.getId(), chatGroup.getGroupOwner(), currentImAccount);
this.chatGroupService.changeOwner(chatGroup.getId(), chatGroup.getGroupOwner(), currentImAccount, ChatGroupUserDataSourceEnum.USER_CHANGE);
}
/**
@ -201,7 +202,7 @@ public class OrganizationalNodeUserChangeEventHandler implements EventHandler, I
//orgNodeUser新增人,并且当前群不包含人
if (tag.equals(EventTypeEnum.NODE_USER_CREATE.getName()) && containJobCode &&!members.contains(currentImAccount)) {
//拉人进群
this.chatGroupService.userAddChatGroup(chatGroup.getId(), chatGroup.getTid(), owner, Sets.newHashSet(currentImAccount), chatGroup.getName());
this.chatGroupService.userAddChatGroup(chatGroup.getId(), chatGroup.getTid(), owner, Sets.newHashSet(currentImAccount), chatGroup.getName(), ChatGroupUserDataSourceEnum.USER_CHANGE);
return;
}
//orgNodeUser删除人 并且当前成员不包含人
@ -217,7 +218,7 @@ public class OrganizationalNodeUserChangeEventHandler implements EventHandler, I
if (containJobCode && !members.contains(currentImAccount)) {
//拉人进群
this.chatGroupService.userAddChatGroup(chatGroup.getId(), chatGroup.getTid(), owner, Sets.newHashSet(currentImAccount), chatGroup.getName());
this.chatGroupService.userAddChatGroup(chatGroup.getId(), chatGroup.getTid(), owner, Sets.newHashSet(currentImAccount), chatGroup.getName(), ChatGroupUserDataSourceEnum.USER_CHANGE);
return;
}
if (!containJobCode && members.contains(currentImAccount)) {

View File

@ -10,7 +10,9 @@ import cn.axzo.im.center.api.vo.req.chatgroup.UserAddChatGroupReq;
import cn.axzo.im.center.api.vo.resp.ChatGroupCreateResp;
import cn.axzo.im.center.api.vo.resp.ChatGroupJoinTeamsResp;
import cn.axzo.im.center.api.vo.resp.ChatGroupQueryResp;
import cn.axzo.im.center.common.enums.ChatGroupUserDataSourceEnum;
import cn.axzo.im.entity.ChatGroup;
import cn.axzo.maokai.api.vo.response.OrganizationalNodeUserVO;
import cn.hutool.core.lang.Pair;
import com.baomidou.mybatisplus.extension.service.IService;
@ -32,7 +34,7 @@ public interface ChatGroupService extends IService<ChatGroup> {
/**
* 获取IM账号
*/
Pair<Set<Long>, Set<Long>> fetchUsersByWorkspaceOuId(ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, Set<String> jobCodes, Long personId);
Pair<List<OrganizationalNodeUserVO>, List<OrganizationalNodeUserVO>> fetchUsersByWorkspaceOuId(ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, Set<String> jobCodes, Long personId);
/**
* 通用查询-少条件后期在补
@ -72,7 +74,7 @@ public interface ChatGroupService extends IService<ChatGroup> {
* @param members im账号集合
* @param groupName 群名称
*/
void userAddChatGroup(Long chatGroupId, String tid, String owner, Set<String> members, String groupName);
void userAddChatGroup(Long chatGroupId, String tid, String owner, Set<String> members, String groupName, ChatGroupUserDataSourceEnum dataSource);
/**
* 踢出群
@ -93,7 +95,7 @@ public interface ChatGroupService extends IService<ChatGroup> {
* @param oldAccIdOwner 原群主账号
* @param newAccIdOwner 新群主账号
*/
void changeOwner(Long chatGroupId, String oldAccIdOwner, String newAccIdOwner);
void changeOwner(Long chatGroupId, String oldAccIdOwner, String newAccIdOwner, ChatGroupUserDataSourceEnum dataSource);
/**
* 更改群主

View File

@ -3,6 +3,7 @@ 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;
@ -21,13 +22,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);
, ChatGroupCreateReq.CrowTypeEnum crowType, ChatGroupUserTypeEnum type, Long workspaceId, Long ouId, ChatGroupUserDataSourceEnum dataSource);
/**
* 批量创建群聊成员
*/
Boolean chatGroupUserBatchCreate(Long chatGroupId, String tid, Set<String> members, ChatGroupStatusEnum status, String remark
, ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId);
, ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, ChatGroupUserDataSourceEnum dataSource);
/**
* 删除群聊成员
@ -51,6 +52,6 @@ public interface ChatGroupUserService extends IService<ChatGroupUser> {
* @param oldAccId 原有账号
* @param newAccId 新账号
*/
void changeOwner(Long chatGroupId, String oldAccId, String newAccId);
void changeOwner(Long chatGroupId, String oldAccId, String newAccId, ChatGroupUserDataSourceEnum dataSource);
}

View File

@ -19,6 +19,7 @@ import cn.axzo.im.center.api.vo.resp.ChatGroupQueryResp;
import cn.axzo.im.center.api.vo.resp.UserAccountResp;
import cn.axzo.im.center.common.enums.AppTypeEnum;
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.center.common.enums.OperateLogTypeEnum;
import cn.axzo.im.channel.IMChannelProvider;
@ -63,6 +64,7 @@ import com.google.common.collect.Sets;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -157,7 +159,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());
this.chatGroupUserService.chatGroupUserCreate(chatGroup.getId(), response.getTid(), resp.getOwnerImAccount(), ChatGroupStatusEnum.SUCCESS, null, req.getCrowType(), ChatGroupUserTypeEnum.OWNER, req.getWorkspaceId(), req.getOuId(), ChatGroupUserDataSourceEnum.CREATE_GROUP);
// 群聊创建成功发送MQ
this.chatGroupCreateSendMQ(req, response, resp.getOwnerId().toString(), resp.getOwnerImAccount(), chatGroup.getId());
// 返回
@ -202,11 +204,11 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
//2 人数超限校验
//Pair,key:管理人员集合;value:工人集合
Pair<Set<Long>, Set<Long>> adminWorkerSet = this.fetchUsersByWorkspaceOuId(req.getCrowType(), req.getWorkspaceId(), req.getOuId(), this.buildJobCodesByCrowType(req.getCrowType()), req.getCreator());
Set<Long> adminSet = adminWorkerSet.getKey();
Set<Long> workerSet = adminWorkerSet.getValue();
Pair<List<OrganizationalNodeUserVO>, List<OrganizationalNodeUserVO>> adminWorkerPair = this.fetchUsersByWorkspaceOuId(req.getCrowType(), req.getWorkspaceId(), req.getOuId(), this.buildJobCodesByCrowType(req.getCrowType()), req.getCreator());
List<OrganizationalNodeUserVO> adminSet = adminWorkerPair.getKey();
List<OrganizationalNodeUserVO> workerSet = adminWorkerPair.getValue();
Integer chatGroupAdminMemberCount = CollectionUtils.isEmpty(adminSet) ? 0 : adminSet.contains(ownerId) ? adminSet.size() : adminSet.size() + 1;
Integer chatGroupAdminMemberCount = CollectionUtils.isEmpty(adminSet) ? 0 : adminSet.stream().map(OrganizationalNodeUserVO::getPersonId).collect(Collectors.toSet()).contains(ownerId) ? adminSet.size() : adminSet.size() + 1;
Integer chatGroupWorkerMemberCount = CollectionUtils.isNotEmpty(workerSet) ? workerSet.size() : 0;
if ((chatGroupAdminMemberCount + chatGroupWorkerMemberCount) < 2) {
@ -345,25 +347,23 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
/**
* 获取IM账号
*/
public Pair<Set<Long>, Set<Long>> fetchUsersByWorkspaceOuId(ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, Set<String> jobCodes,Long personId) {
public Pair<List<OrganizationalNodeUserVO>, List<OrganizationalNodeUserVO>> fetchUsersByWorkspaceOuId(ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, Set<String> jobCodes,Long personId) {
switch (crowType) {
case WORKSPACE:
List<OrganizationalNodeUserVO> userListWhenWorkspace = organizationalNodeUserApiGateway.fetchNodeUsersByWorkspaceIdJobCodes(workspaceId, jobCodes);
BizAssertions.assertNotEmpty(userListWhenWorkspace, "人群是项目时,管理员为空,workspaceId:{},ouId:{}", workspaceId, ouId);
Set<Long> personListWhenWorkspace = userListWhenWorkspace.stream().map(OrganizationalNodeUserVO::getPersonId).collect(Collectors.toSet());
return Pair.of(personListWhenWorkspace, Sets.newHashSet());
return Pair.of(userListWhenWorkspace, Lists.newArrayList());
case OU:
List<OrganizationalNodeUserVO> userListWhenOuId = organizationalNodeUserApiGateway.fetchNodeUsersByWorkspaceOuIdJobCodes(workspaceId,ouId,jobCodes);
BizAssertions.assertNotEmpty(userListWhenOuId, "人群是单位时,管理员为空,workspaceId:{},ouId:{}", workspaceId, ouId);
Set<Long> personIdListWhenOuId = userListWhenOuId.stream().map(OrganizationalNodeUserVO::getPersonId).collect(Collectors.toSet());
return Pair.of(personIdListWhenOuId, Sets.newHashSet());
return Pair.of(userListWhenOuId, Lists.newArrayList());
case TEAM:
//获取personId在workspaceId下项目班组对象(角色列表班组长/带班长/小组长/工人)
OrganizationalNodeUserVO projectTeamUser = this.fetchProjectTeamLeaderWorkspacePersonId(workspaceId, personId);
//班组长/带班长
Set<Long> teamerList = this.fetchUsersByWorkspaceIdJobCodes(workspaceId, ouId,projectTeamUser.getOrganizationalNodeId(), Sets.newHashSet("projTeamLeader", "projectTeamManager"), true);
Set<Long> workerList = this.fetchUsersByWorkspaceIdJobCodes(workspaceId, ouId,projectTeamUser.getOrganizationalNodeId(), Sets.newHashSet("projWorker","projectTeamGPLeader"), false);
List<OrganizationalNodeUserVO> teamerList = this.fetchUsersByWorkspaceIdJobCodes(workspaceId, ouId,projectTeamUser.getOrganizationalNodeId(), Sets.newHashSet("projTeamLeader", "projectTeamManager"), true);
List<OrganizationalNodeUserVO> workerList = this.fetchUsersByWorkspaceIdJobCodes(workspaceId, ouId,projectTeamUser.getOrganizationalNodeId(), Sets.newHashSet("projWorker","projectTeamGPLeader"), false);
return Pair.of(teamerList,workerList);
default:
throw new ServiceException("人群不存在");
@ -383,10 +383,10 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
return projectTeamUserList.get(0);
}
private Set<Long> fetchUsersByWorkspaceIdJobCodes(Long workspaceId, Long ouId, Long nodeId,Set<String> jobCodes, boolean isAdmin) {
private List<OrganizationalNodeUserVO> fetchUsersByWorkspaceIdJobCodes(Long workspaceId, Long ouId, Long nodeId,Set<String> jobCodes, boolean isAdmin) {
List<OrganizationalNodeUserVO> userListWhenTeamer = organizationalNodeUserApiGateway.fetchNodeUsersByWorkspaceNodeIdJobCodes(workspaceId, nodeId, jobCodes);
BizAssertions.assertNotEmpty(userListWhenTeamer, "人群是班组时,{}为空,workspaceId:{},ouId:{}", isAdmin ? "班组长/带班长" : "工人", workspaceId, ouId);
return userListWhenTeamer.stream().map(OrganizationalNodeUserVO::getPersonId).collect(Collectors.toSet());
return userListWhenTeamer;
}
/**
@ -454,7 +454,7 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
@Override
public void changeOwner(ChatGroupChangeOwnerReq req) {
ChatGroup chatGroup = this.getById(req.getChatGroupId());
this.changeOwner(chatGroup.getId(), chatGroup.getGroupOwner(), req.getNewAccIdOwner());
this.changeOwner(chatGroup.getId(), chatGroup.getGroupOwner(), req.getNewAccIdOwner(), ChatGroupUserDataSourceEnum.API_HANDLE);
}
/**
@ -464,7 +464,7 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
* @param newAccIdOwner 新群主账号
*/
@Override
public void changeOwner(Long chatGroupId, String oldAccIdOwner, String newAccIdOwner) {
public void changeOwner(Long chatGroupId, String oldAccIdOwner, String newAccIdOwner, ChatGroupUserDataSourceEnum dataSource) {
//新老账号群主相同则进行更换群主
if (Objects.equals(oldAccIdOwner, newAccIdOwner)) {
return;
@ -480,7 +480,7 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
nimChannelService.changeOwner(changeOwnerRequest);
this.updateGroupOwner(chatGroupId, newAccIdOwner);
chatGroupUserService.changeOwner(chatGroupId, oldAccIdOwner, newAccIdOwner);
chatGroupUserService.changeOwner(chatGroupId, oldAccIdOwner, newAccIdOwner, dataSource);
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));
@ -505,7 +505,7 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
@Override
public void userAddChatGroup(UserAddChatGroupReq req) {
ChatGroup chatGroup = this.getById(req.getChatGroupId());
this.userAddChatGroup(chatGroup.getId(), chatGroup.getTid(), chatGroup.getGroupOwner(), req.getMembers(), chatGroup.getName());
this.userAddChatGroup(chatGroup.getId(), chatGroup.getTid(), chatGroup.getGroupOwner(), req.getMembers(), chatGroup.getName(), ChatGroupUserDataSourceEnum.API_HANDLE);
}
/**
@ -517,7 +517,7 @@ public class ChatGroupServiceImpl extends ServiceImpl<ChatGroupMapper, ChatGrou
* @param groupName 群名称
*/
@Override
public void userAddChatGroup(Long chatGroupId, String tid, String owner, Set<String> members, String groupName) {
public void userAddChatGroup(Long chatGroupId, String tid, String owner, Set<String> members, String groupName, ChatGroupUserDataSourceEnum dataSource) {
ChatGroupUserGenericSearchReq req = new ChatGroupUserGenericSearchReq();
req.setChatGroupId(chatGroupId);
@ -539,11 +539,11 @@ 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());
chatGroupUserService.chatGroupUserBatchCreate(chatGroupId,tid, members, ChatGroupStatusEnum.SUCCESS,null, chatGroup.getCrowType(), chatGroup.getWorkspaceId(), chatGroup.getOuId(),dataSource);
operateLogService.create(OperateLogTypeEnum.USER_ENTER_CHAT_GROUP, String.format("user:%s,enter chatGroup:%s,owner:%s", JSON.toJSONString(members), tid, owner));
} 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());
chatGroupUserService.chatGroupUserBatchCreate(chatGroupId,tid, members, ChatGroupStatusEnum.FAIL,error, chatGroup.getCrowType(), chatGroup.getWorkspaceId(), chatGroup.getOuId(),dataSource);
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);
}

View File

@ -3,6 +3,7 @@ package cn.axzo.im.service.impl;
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.dao.mapper.ChatGroupUserMapper;
import cn.axzo.im.entity.ChatGroup;
@ -39,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) {
, ChatGroupCreateReq.CrowTypeEnum crowType, ChatGroupUserTypeEnum type, Long workspaceId,Long ouId, ChatGroupUserDataSourceEnum dataSource) {
return this.saveOrUpdate(ChatGroupUser.builder()
.chatGroupId(chatGroupId)
.tid(tid)
@ -48,6 +49,7 @@ public class ChatGroupUserServiceImpl extends ServiceImpl<ChatGroupUserMapper,
.ouId(ouId)
.status(status)
.crowType(crowType)
.dataSource(dataSource)
.type(type)
.remark(remark).build());
}
@ -59,18 +61,18 @@ public class ChatGroupUserServiceImpl extends ServiceImpl<ChatGroupUserMapper,
* @param newAccId 新账号
*/
@Override
public void changeOwner(Long chatGroupId, String oldAccId, String newAccId) {
public void changeOwner(Long chatGroupId, String oldAccId, String newAccId, ChatGroupUserDataSourceEnum dataSource ) {
this.chatGroupUserDelete(chatGroupId, oldAccId);
ChatGroup chatGroup = chatGroupService.getById(chatGroupId);
this.chatGroupUserCreate(chatGroupId, chatGroup.getTid(), newAccId, ChatGroupStatusEnum.SUCCESS, null, chatGroup.getCrowType(), ChatGroupUserTypeEnum.OWNER, chatGroup.getWorkspaceId(), chatGroup.getOuId());
this.chatGroupUserCreate(chatGroupId, chatGroup.getTid(), newAccId, ChatGroupStatusEnum.SUCCESS, null, chatGroup.getCrowType(), ChatGroupUserTypeEnum.OWNER, chatGroup.getWorkspaceId(), chatGroup.getOuId(), dataSource);
}
@Override
public Boolean chatGroupUserBatchCreate(Long chatGroupId, String tid, Set<String> members, ChatGroupStatusEnum status
, String remark, ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId) {
, String remark, ChatGroupCreateReq.CrowTypeEnum crowType, Long workspaceId, Long ouId, ChatGroupUserDataSourceEnum dataSource) {
if (CollectionUtils.isEmpty(members)) {
return true;
}
@ -97,6 +99,7 @@ public class ChatGroupUserServiceImpl extends ServiceImpl<ChatGroupUserMapper,
.ouId(ouId)
.status(status)
.crowType(crowType)
.dataSource(dataSource)
.remark(remark).build()).collect(Collectors.toList());
return this.saveBatch(chatGroupUsers);
}