Commit 452b16ef by Future

方法调整

parent 53e8024b
package com.wecloud.im.service.impl; package com.wecloud.im.service.impl;
import com.wecloud.im.chatroom.cache.ChatRoomCacheManager;
import com.wecloud.im.param.ChatRoomMemberPageParam;
import com.wecloud.im.param.ExitChatRoomParam;
import com.wecloud.im.param.IntoChatRoomParam;
import com.wecloud.im.vo.ChatRoomMemberVo;
import com.wecloud.im.ws.utils.RedisUtils;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.enums.BaseEnum;
import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
...@@ -37,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem; ...@@ -37,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.wecloud.im.chatroom.cache.ChatRoomCacheManager;
import com.wecloud.im.entity.ImApplication; import com.wecloud.im.entity.ImApplication;
import com.wecloud.im.entity.ImClient; import com.wecloud.im.entity.ImClient;
import com.wecloud.im.entity.ImConversation; import com.wecloud.im.entity.ImConversation;
...@@ -44,12 +16,15 @@ import com.wecloud.im.entity.ImConversationMembers; ...@@ -44,12 +16,15 @@ import com.wecloud.im.entity.ImConversationMembers;
import com.wecloud.im.entity.ImMessage; import com.wecloud.im.entity.ImMessage;
import com.wecloud.im.entity.ImMessageOnlineSend; import com.wecloud.im.entity.ImMessageOnlineSend;
import com.wecloud.im.mapper.ImConversationMapper; import com.wecloud.im.mapper.ImConversationMapper;
import com.wecloud.im.param.ChatRoomMemberPageParam;
import com.wecloud.im.param.DisbandConversationParam; import com.wecloud.im.param.DisbandConversationParam;
import com.wecloud.im.param.ExitChatRoomParam;
import com.wecloud.im.param.GroupChatSettingParam; import com.wecloud.im.param.GroupChatSettingParam;
import com.wecloud.im.param.ImClientSimpleDto; import com.wecloud.im.param.ImClientSimpleDto;
import com.wecloud.im.param.ImConversationPageParam; import com.wecloud.im.param.ImConversationPageParam;
import com.wecloud.im.param.ImConversationQueryParam; import com.wecloud.im.param.ImConversationQueryParam;
import com.wecloud.im.param.ImConversationQueryVo; import com.wecloud.im.param.ImConversationQueryVo;
import com.wecloud.im.param.IntoChatRoomParam;
import com.wecloud.im.param.ListConversationMembersParam; import com.wecloud.im.param.ListConversationMembersParam;
import com.wecloud.im.param.MutedGroupMemberParam; import com.wecloud.im.param.MutedGroupMemberParam;
import com.wecloud.im.param.MutedGroupParam; import com.wecloud.im.param.MutedGroupParam;
...@@ -66,11 +41,11 @@ import com.wecloud.im.sdk.enums.GroupChatSettingTypeEnum; ...@@ -66,11 +41,11 @@ import com.wecloud.im.sdk.enums.GroupChatSettingTypeEnum;
import com.wecloud.im.sdk.enums.GroupRoleEnum; import com.wecloud.im.sdk.enums.GroupRoleEnum;
import com.wecloud.im.sdk.enums.MutedEnum; import com.wecloud.im.sdk.enums.MutedEnum;
import com.wecloud.im.service.ContextService; import com.wecloud.im.service.ContextService;
import com.wecloud.im.service.ImApplicationService;
import com.wecloud.im.service.ImClientService; import com.wecloud.im.service.ImClientService;
import com.wecloud.im.service.ImConversationMembersService; import com.wecloud.im.service.ImConversationMembersService;
import com.wecloud.im.service.ImConversationService; import com.wecloud.im.service.ImConversationService;
import com.wecloud.im.service.ImMessageService; import com.wecloud.im.service.ImMessageService;
import com.wecloud.im.vo.ChatRoomMemberVo;
import com.wecloud.im.vo.ConversationMemberVo; import com.wecloud.im.vo.ConversationMemberVo;
import com.wecloud.im.vo.ConversationVo; import com.wecloud.im.vo.ConversationVo;
import com.wecloud.im.vo.ImConversationCreateVo; import com.wecloud.im.vo.ImConversationCreateVo;
...@@ -79,8 +54,30 @@ import com.wecloud.im.ws.enums.MsgTypeEnum; ...@@ -79,8 +54,30 @@ import com.wecloud.im.ws.enums.MsgTypeEnum;
import com.wecloud.im.ws.enums.WsResponseCmdEnum; import com.wecloud.im.ws.enums.WsResponseCmdEnum;
import com.wecloud.im.ws.model.WsResponse; import com.wecloud.im.ws.model.WsResponse;
import com.wecloud.im.ws.sender.ChannelSender; import com.wecloud.im.ws.sender.ChannelSender;
import com.wecloud.im.ws.utils.RedisUtils;
import com.wecloud.utils.JsonUtils; import com.wecloud.utils.JsonUtils;
import com.wecloud.utils.SnowflakeUtil; import com.wecloud.utils.SnowflakeUtil;
import io.geekidea.springbootplus.framework.common.api.ApiCode;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.common.enums.BaseEnum;
import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.wecloud.im.ws.enums.MsgTypeEnum.CONVERSATION_FORBID_ADD_FRIEND; import static com.wecloud.im.ws.enums.MsgTypeEnum.CONVERSATION_FORBID_ADD_FRIEND;
import static com.wecloud.im.ws.enums.MsgTypeEnum.CONVERSATION_FORBID_ADD_FRIEND_CANCEL; import static com.wecloud.im.ws.enums.MsgTypeEnum.CONVERSATION_FORBID_ADD_FRIEND_CANCEL;
...@@ -475,8 +472,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -475,8 +472,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
Long appId = imApplication.getId(); Long appId = imApplication.getId();
String sender = imClientSender.getClientId(); String sender = imClientSender.getClientId();
Integer msgType = imMessage.getMsgType(); Integer msgType = imMessage.getMsgType();
sendMsgToMembers(conversationId, membersList, appId, sender, messageId, msgType, content, Boolean.FALSE, sendMsgToMembers(conversationId, membersList, appId, sender, content, imMessage);
Boolean.TRUE);
} }
// 将群成员数量减 // 将群成员数量减
...@@ -530,11 +526,8 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -530,11 +526,8 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
Long conversationId = param.getConversationId(); Long conversationId = param.getConversationId();
Long appId = currentClient.getFkAppid(); Long appId = currentClient.getFkAppid();
String sender = currentClient.getClientId(); String sender = currentClient.getClientId();
Long messageId = imMessage.getId();
Integer msgType = imMessage.getMsgType();
sendMsgToMembers(conversationId, membersList, appId, sender, messageId, msgType, content, Boolean.FALSE, sendMsgToMembers(conversationId, membersList, appId, sender, content, imMessage);
Boolean.TRUE);
} }
@Override @Override
...@@ -606,8 +599,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -606,8 +599,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
String sender = currentClient.getClientId(); String sender = currentClient.getClientId();
Integer msgType = MsgTypeEnum.LEAVE_CONVERSATION.getUriCode(); Integer msgType = MsgTypeEnum.LEAVE_CONVERSATION.getUriCode();
sendMsgToMembers(conversationId, membersList, appId, sender, messageId, msgType, null, Boolean.FALSE, sendMsgToMembers(conversationId, membersList, appId, sender, null, imMessage);
Boolean.TRUE);
// 群主退出 转移给下一个人 // 群主退出 转移给下一个人
if (GroupRoleEnum.OWNER.getCode().equals(members.getRole())) { if (GroupRoleEnum.OWNER.getCode().equals(members.getRole())) {
ImConversationMembers conversationMember = membersList.get(0); ImConversationMembers conversationMember = membersList.get(0);
...@@ -792,9 +784,13 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -792,9 +784,13 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
HashMap<String, String> content = Maps.newHashMap(); HashMap<String, String> content = Maps.newHashMap();
content.put("name", imConversationById.getName()); content.put("name", imConversationById.getName());
// 发送消息至成员 // 发送消息至成员
ImMessage message = new ImMessage();
message.setWithdraw(Boolean.FALSE);
message.setEvent(Boolean.TRUE);
message.setMsgType(MsgTypeEnum.CONVERSATION_NAME_CHANGE.getUriCode());
sendMsgToMembers(param.getConversationId(), membersList, currentClient.getFkAppid(), sendMsgToMembers(param.getConversationId(), membersList, currentClient.getFkAppid(),
currentClient.getClientId(), null, MsgTypeEnum.CONVERSATION_NAME_CHANGE.getUriCode(), content, currentClient.getClientId(), content, message);
Boolean.FALSE, Boolean.TRUE);
return ApiResult.ok(); return ApiResult.ok();
} else { } else {
...@@ -839,8 +835,11 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -839,8 +835,11 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
Long conversationId = imConversationAttrUpdate.getConversationId(); Long conversationId = imConversationAttrUpdate.getConversationId();
Long appId = currentClient.getFkAppid(); Long appId = currentClient.getFkAppid();
String sender = currentClient.getClientId(); String sender = currentClient.getClientId();
Integer msgType = MsgTypeEnum.CONVERSATION_EXPAND_FIELD_CHANGE.getUriCode(); ImMessage message = new ImMessage();
sendMsgToMembers(conversationId, membersList, appId, sender, null, msgType, content, Boolean.FALSE, Boolean.TRUE); message.setWithdraw(Boolean.FALSE);
message.setEvent(Boolean.TRUE);
message.setMsgType(MsgTypeEnum.CONVERSATION_EXPAND_FIELD_CHANGE.getUriCode());
sendMsgToMembers(conversationId, membersList, appId, sender, content, message);
} else { } else {
throw new BusinessException("修改错误"); throw new BusinessException("修改错误");
} }
...@@ -1079,7 +1078,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1079,7 +1078,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
imMessageService.save(imMessage); imMessageService.save(imMessage);
// 发送消息至群成员 // 发送消息至群成员
sendMsgToMembers(conversationId, membersList, currentClient.getFkAppid(), currentClient.getClientId(), sendMsgToMembers(conversationId, membersList, currentClient.getFkAppid(), currentClient.getClientId(),
imMessage.getId(), imMessage.getMsgType(), content, Boolean.FALSE, Boolean.TRUE); content, imMessage);
} }
} }
...@@ -1092,14 +1091,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1092,14 +1091,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
* @param membersList 成员列表 * @param membersList 成员列表
* @param appId appId * @param appId appId
* @param sender 发送者 * @param sender 发送者
* @param msgId 消息id
* @param msgType 消息类型
* @param content 消息内容 * @param content 消息内容
* @param withdraw 是否撤回
* @param event 是否事件
*/ */
private void sendMsgToMembers(Long conversationId, List<ImConversationMembers> membersList, Long appId, private void sendMsgToMembers(Long conversationId, List<ImConversationMembers> membersList, Long appId,
String sender, Long msgId, Integer msgType, Map content, Boolean withdraw, Boolean event) { String sender, Map content, ImMessage message) {
for (ImConversationMembers member : membersList) { for (ImConversationMembers member : membersList) {
// 不关心事件是否发送成功 // 不关心事件是否发送成功
try { try {
...@@ -1111,10 +1106,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1111,10 +1106,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
continue; continue;
} }
sendConversationEventMsg(conversationId, sender, imClientReceiver.getId(), msgId, msgType, content, withdraw sendConversationEventMsg(conversationId, sender, imClientReceiver.getId(), content, message);
, event);
} catch (Exception e) { } catch (Exception e) {
log.info("下发群会话事件失败,事件类型 {} 接收人 {}", msgType, JSON.toJSONString(member)); log.info("下发群会话事件失败,事件类型 {} 接收人 {}", message.getMsgType(), JSON.toJSONString(member));
} }
} }
} }
...@@ -1127,15 +1121,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1127,15 +1121,10 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
* @param appId appId * @param appId appId
* @param sender 发送者 * @param sender 发送者
* @param receiverClientId 接收者client id * @param receiverClientId 接收者client id
* @param msgId 消息id * @param message
* @param msgType 消息类型
* @param content 消息内容
* @param withdraw 是否撤回
* @param event 是否事件
*/ */
private void sendEventMsgToMember(Long conversationId, Long appId, String sender, private void sendEventMsgToMember(Long conversationId, Long appId, String sender,
Long receiverClientId, Long msgId, Integer msgType, Long receiverClientId, Map<String, Object> content, ImMessage message) {
Map content, Boolean withdraw, Boolean event) {
// 查询接收方 // 查询接收方
ImClient imClientReceiver = imClientService.getOne(new QueryWrapper<ImClient>().lambda() ImClient imClientReceiver = imClientService.getOne(new QueryWrapper<ImClient>().lambda()
.eq(ImClient::getFkAppid, appId) .eq(ImClient::getFkAppid, appId)
...@@ -1143,7 +1132,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1143,7 +1132,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
if (imClientReceiver == null) { if (imClientReceiver == null) {
return; return;
} }
sendConversationEventMsg(conversationId, sender, receiverClientId, msgId, msgType, content, withdraw, event); sendConversationEventMsg(conversationId, sender, receiverClientId, content, message);
} }
...@@ -1154,26 +1143,21 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1154,26 +1143,21 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
* @param conversationId 会话id * @param conversationId 会话id
* @param sender 发送者 * @param sender 发送者
* @param receiverClientId 接收者client id * @param receiverClientId 接收者client id
* @param msgId 消息id
* @param msgType 消息类型
* @param content 消息内容 * @param content 消息内容
* @param withdraw 是否撤回
* @param event 是否事件
*/ */
private void sendConversationEventMsg(Long conversationId, String sender, private void sendConversationEventMsg(Long conversationId, String sender,
Long receiverClientId, Long msgId, Integer msgType, Long receiverClientId, Map<String, Object> content, ImMessage message) {
Map content, Boolean withdraw, Boolean event) {
// 封装响应的实体 // 封装响应的实体
ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend(); ImMessageOnlineSend imMessageOnlineSend = new ImMessageOnlineSend();
imMessageOnlineSend.setMsgId(msgId); imMessageOnlineSend.setMsgId(message.getId());
imMessageOnlineSend.setCreateTime(new Date()); imMessageOnlineSend.setCreateTime(new Date());
imMessageOnlineSend.setType(msgType); imMessageOnlineSend.setType(message.getMsgType());
imMessageOnlineSend.setSender(sender); imMessageOnlineSend.setSender(sender);
imMessageOnlineSend.setContent(content); imMessageOnlineSend.setContent(content);
imMessageOnlineSend.setConversationId(conversationId); imMessageOnlineSend.setConversationId(conversationId);
imMessageOnlineSend.setWithdraw(withdraw); imMessageOnlineSend.setWithdraw(message.getWithdraw());
imMessageOnlineSend.setEvent(event); imMessageOnlineSend.setEvent(message.getEvent());
// 向接收方推送 // 向接收方推送
WsResponse<ImMessageOnlineSend> responseModel = new WsResponse<>(); WsResponse<ImMessageOnlineSend> responseModel = new WsResponse<>();
...@@ -1233,10 +1217,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap ...@@ -1233,10 +1217,9 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
// 遍历发送给已在群内的成员 // 遍历发送给已在群内的成员
for (String key : chatRoomMembers.keySet()) { for (String key : chatRoomMembers.keySet()) {
Long fkClientId = Long.valueOf(key.split(RedisUtils.SPLIT)[0]); Long fkClientId = Long.valueOf(key.split(RedisUtils.SPLIT)[0]);
sendEventMsgToMember(imApplication, fkClientId, imMessage, imClientSender); sendEventMsgToMember(param.getChatRoomId(), imApplication.getId(), imClientSender.getClientId(),fkClientId
content, imMessage);
} }
// 发送给刚被拉入群的成员
sendEventMsgToMember(imApplication, clientToConversation.getId(), imMessage, imClientSender);
imConversationMapper.addMemberCount(imApplication.getId(), param.getChatRoomId(), 1); imConversationMapper.addMemberCount(imApplication.getId(), param.getChatRoomId(), 1);
return true; return true;
......
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