公聊房-改造sendSysMsgService里发送全服房间消息的公共方法
This commit is contained in:
@@ -15,9 +15,20 @@ public class Attach {
|
|||||||
private String message;
|
private String message;
|
||||||
private Object data;
|
private Object data;
|
||||||
|
|
||||||
|
//用于携带给客户端,用于区分同一组first和second的消息,是单房间消息,还是轮询全服房间遍历发送的单房间消息
|
||||||
|
//已使用公聊房机制,解决轮询全服房间发送消息的云信im限频问题
|
||||||
|
private Integer allRoomMsg;
|
||||||
|
|
||||||
public Attach(int first, int second, Object data) {
|
public Attach(int first, int second, Object data) {
|
||||||
this.first = first;
|
this.first = first;
|
||||||
this.second = second;
|
this.second = second;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Attach(int first, int second, Object data, int allRoomMsg) {
|
||||||
|
this.first = first;
|
||||||
|
this.second = second;
|
||||||
|
this.data = data;
|
||||||
|
this.allRoomMsg = allRoomMsg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,10 +18,12 @@ import com.accompany.common.utils.ReplaceAppDomainUtils;
|
|||||||
import com.accompany.common.utils.UUIDUtil;
|
import com.accompany.common.utils.UUIDUtil;
|
||||||
import com.accompany.core.base.SpringContextHolder;
|
import com.accompany.core.base.SpringContextHolder;
|
||||||
import com.accompany.core.enumeration.I18nAlertEnum;
|
import com.accompany.core.enumeration.I18nAlertEnum;
|
||||||
|
import com.accompany.core.model.PartitionInfo;
|
||||||
import com.accompany.core.model.Room;
|
import com.accompany.core.model.Room;
|
||||||
import com.accompany.core.model.Users;
|
import com.accompany.core.model.Users;
|
||||||
import com.accompany.core.mybatismapper.RoomMapperExpand;
|
import com.accompany.core.mybatismapper.RoomMapperExpand;
|
||||||
import com.accompany.core.service.base.BaseService;
|
import com.accompany.core.service.base.BaseService;
|
||||||
|
import com.accompany.core.service.partition.PartitionInfoService;
|
||||||
import com.accompany.core.util.I18NMessageSourceUtil;
|
import com.accompany.core.util.I18NMessageSourceUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@@ -61,6 +63,8 @@ public class SendSysMsgService extends BaseService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RoomMapperExpand roomMapperExpand;
|
private RoomMapperExpand roomMapperExpand;
|
||||||
|
@Autowired
|
||||||
|
private PartitionInfoService partitionInfoService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送系统通知,捕获异常不抛出。
|
* 发送系统通知,捕获异常不抛出。
|
||||||
@@ -546,13 +550,33 @@ public class SendSysMsgService extends BaseService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageToPartition(Integer partitionId, int first, int second, Object data) {
|
public void sendSingleRoomMessage(long roomId, String fromAccId, BaseChatRoomMsg msg) {
|
||||||
|
try {
|
||||||
|
String msgId = UUIDUtil.get();
|
||||||
|
this.erBanNetEaseService.sendChatRoomMsg(roomId, msgId, fromAccId,
|
||||||
|
msg.getMsgType(), msg.getAttach(), msg.getExt());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("发送房间消息失败[roomId : {}, fromAccId : {}, message : {}]",
|
||||||
|
roomId, fromAccId, msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessageToPartition(int partitionId, int first, int second, Object data) {
|
||||||
Attach attach = new Attach(first, second, data);
|
Attach attach = new Attach(first, second, data);
|
||||||
sendMessageToPartition(partitionId, attach);
|
sendMessageToPartition(partitionId, attach);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageToPartition(Integer partitionId, Attach attach) {
|
public void sendMessageToPartition(int partitionId, Attach attach) {
|
||||||
|
attach.setAllRoomMsg(Constant.Yes1No0.YES);
|
||||||
BaseChatRoomMsg msg = BaseChatRoomMsg.buildBaseChatRoomMsg(attach);
|
BaseChatRoomMsg msg = BaseChatRoomMsg.buildBaseChatRoomMsg(attach);
|
||||||
|
|
||||||
|
PartitionInfo partitionInfo = partitionInfoService.getById(partitionId);
|
||||||
|
if (partitionInfo == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendSingleRoomMessage(partitionInfo.getPublicChatRoomId(), SystemConfig.secretaryUid, attach);
|
||||||
|
|
||||||
sendMessageToPartition(partitionId, msg);
|
sendMessageToPartition(partitionId, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,7 +586,16 @@ public class SendSysMsgService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageToPartition(Room curRoom, Attach attach) {
|
public void sendMessageToPartition(Room curRoom, Attach attach) {
|
||||||
|
attach.setAllRoomMsg(Constant.Yes1No0.YES);
|
||||||
BaseChatRoomMsg msg = BaseChatRoomMsg.buildBaseChatRoomMsg(attach);
|
BaseChatRoomMsg msg = BaseChatRoomMsg.buildBaseChatRoomMsg(attach);
|
||||||
|
|
||||||
|
PartitionInfo partitionInfo = partitionInfoService.getById(curRoom.getPartitionId());
|
||||||
|
if (partitionInfo == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendSingleRoomMessage(partitionInfo.getPublicChatRoomId(), SystemConfig.secretaryUid, attach);
|
||||||
|
|
||||||
sendMessageToPartition(curRoom, msg);
|
sendMessageToPartition(curRoom, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,6 +641,15 @@ public class SendSysMsgService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendFloatingMessageForRoom(FloatingMessageTemplate message) {
|
public void sendFloatingMessageForRoom(FloatingMessageTemplate message) {
|
||||||
|
int partitionId = message.getPartitionId();
|
||||||
|
|
||||||
|
PartitionInfo partitionInfo = partitionInfoService.getById(partitionId);
|
||||||
|
if (partitionInfo == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendFloatingMessageForRoom(partitionInfo.getPublicChatRoomId(), Long.parseLong(SystemConfig.secretaryUid), message);
|
||||||
|
|
||||||
List<Room> validRooms = this.roomMapperExpand.listValidRoomsByPartitionId(null, message.getPartitionId());
|
List<Room> validRooms = this.roomMapperExpand.listValidRoomsByPartitionId(null, message.getPartitionId());
|
||||||
if (CollectionUtils.isEmpty(validRooms)){
|
if (CollectionUtils.isEmpty(validRooms)){
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user