Commit e2cf6616 by 罗长华

离开/踢出群组下发消息

parent ac443330
......@@ -85,7 +85,7 @@ public class ImGroupController {
public ApiResult<Integer> leaveGroup(@RequestBody LeaveGroupParam param) {
log.info("离开群组请求 参数: {}", JSON.toJSONString(param));
List<String> memberIds = Arrays.asList(param.getUserIds().split(","));
return ApiResult.ok(groupService.leaveGroup(param.getGroupId(), memberIds));
return ApiResult.ok(groupService.leaveGroup(param.getOperatorUserId(), param.getGroupId(), memberIds));
}
/**
......
......@@ -2,6 +2,8 @@ package com.wecloud.im.param.group;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* 离开(踢出)群
* @Author luozh
......@@ -12,12 +14,20 @@ import lombok.Data;
public class LeaveGroupParam {
/**
* 操作人用户id
*/
@NotBlank(message = "operatorUserId 不能为空")
private String operatorUserId;
/**
* 用户Id
*/
@NotBlank(message = "userIds 不能为空")
private String userIds;
/**
* 群组id
*/
@NotBlank(message = "groupId 不能为空")
private String groupId;
}
......@@ -51,7 +51,7 @@ public interface ImGroupService {
* @param memberClientIds
* @Return
*/
Integer leaveGroup(String groupId, List<String> memberClientIds);
Integer leaveGroup(String operatorUserId, String groupId, List<String> memberClientIds);
/**
* 获取群成员列表
......
......@@ -246,8 +246,11 @@ public class ImGroupServiceImpl implements ImGroupService {
}
@Override
public Integer leaveGroup(String groupId, List<String> memberClientIds) {
public Integer leaveGroup(String operatorUserId, String groupId, List<String> memberClientIds) {
Long appId = SecurityUtils.getCurrentAppId();
ImClient operator = clientService.getCacheImClient(appId, operatorUserId);
ImApplication imApplication = applicationService.getCacheById(appId);
// 查询会话
ImConversation conversation =
......@@ -257,6 +260,11 @@ public class ImGroupServiceImpl implements ImGroupService {
throw new BusinessException("群组不存在");
}
// 查询该会话所有成员
List<ImConversationMembers> membersList =
conversationMembersService.list(new QueryWrapper<ImConversationMembers>().lambda().eq(ImConversationMembers::getFkAppid,
imApplication.getId()).eq(ImConversationMembers::getFkConversationId, conversation.getId()));
// 查找在群组里的客户端
List<ImConversationMembers> existMemberList =
conversationMembersService.list(Wrappers.<ImConversationMembers>lambdaQuery()
......@@ -269,6 +277,20 @@ public class ImGroupServiceImpl implements ImGroupService {
// 将群成员数量减
imConversationMapper.addMemberCount(imApplication.getId(), conversation.getId(), -existMemberList.size());
}
for (ImConversationMembers members : existMemberList) {
// 操作的client ID
Map<String, Object> content = new HashMap<>();
content.put("operator", operator.getClientId());
// 被操作的client ID
content.put("passivityOperator", members.getClientId());
ImMessage imMessage = MessageBuilder.buildEventMessage(MsgTypeEnum.REMOVE_CLIENT_CONVERSATION, imApplication, operator, conversation, JsonUtils.encodeJson(content));
imMessageService.save(imMessage);
// 发送给在群内的成员
conversationService.sendMsgToMembers(conversation, membersList, operator, imMessage, content);
}
return existMemberList.size();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment