修改SocketApi消息类型枚举为字符串类型

pull/22/head
rays 2021-06-03 16:34:12 +08:00
parent 0fe4cbcd6b
commit 075fd4606d
3 changed files with 15 additions and 13 deletions

View File

@ -16,28 +16,30 @@ public interface SocketOperatorApi {
/** /**
* *
* *
* @param userId ID * @param msgType {@link cn.stylefeng.roses.kernel.socket.api.enums}
* @param msg * @param userId ID
* @param msg
* @author majianguo * @author majianguo
* @date 2021/6/2 9:35 * @date 2021/6/2 9:35
**/ **/
void sendMsgOfUserSession(ServerMessageTypeEnum msgType, String userId, Object msg); void sendMsgOfUserSession(String msgType, String userId, Object msg);
/** /**
* *
* *
* @param msg * @param msgType {@link cn.stylefeng.roses.kernel.socket.api.enums}
* @param msg
* @author majianguo * @author majianguo
* @date 2021/6/2 9:35 * @date 2021/6/2 9:35
**/ **/
void sendMsgOfAllUserSession(ServerMessageTypeEnum msgType, Object msg); void sendMsgOfAllUserSession(String msgType, Object msg);
/** /**
* *
* <p> * <p>
* 1., * 1.,
* *
* @param msgType * @param msgType {@link cn.stylefeng.roses.kernel.socket.api.enums}
* @param callbackInterface * @param callbackInterface
* @author majianguo * @author majianguo
* @date 2021/6/2 9:54 * @date 2021/6/2 9:54

View File

@ -27,7 +27,7 @@ import java.util.List;
public class WebSocketOperator implements SocketOperatorApi { public class WebSocketOperator implements SocketOperatorApi {
@Override @Override
public void sendMsgOfUserSession(ServerMessageTypeEnum msgType, String userId, Object msg) { public void sendMsgOfUserSession(String msgType, String userId, Object msg) {
// 根据用户ID获取会话 // 根据用户ID获取会话
SocketSession<GettySocketOperator> socketSession = SessionCenter.getSessionByUserId(userId); SocketSession<GettySocketOperator> socketSession = SessionCenter.getSessionByUserId(userId);
if (ObjectUtil.isEmpty(socketSession)) { if (ObjectUtil.isEmpty(socketSession)) {
@ -35,26 +35,26 @@ public class WebSocketOperator implements SocketOperatorApi {
} }
// 判断用户是否监听 // 判断用户是否监听
if (socketSession.getMessageTypes().contains(msgType.getCode())) { if (socketSession.getMessageTypes().contains(msgType)) {
WebSocketMessagePOJO webSocketMessagePOJO = new WebSocketMessagePOJO(); WebSocketMessagePOJO webSocketMessagePOJO = new WebSocketMessagePOJO();
webSocketMessagePOJO.setData(msg); webSocketMessagePOJO.setData(msg);
webSocketMessagePOJO.setType(msgType.getCode()); webSocketMessagePOJO.setType(msgType);
// 发送内容 // 发送内容
socketSession.getSocketOperatorApi().writeAndFlush(webSocketMessagePOJO); socketSession.getSocketOperatorApi().writeAndFlush(webSocketMessagePOJO);
} }
} }
@Override @Override
public void sendMsgOfAllUserSession(ServerMessageTypeEnum msgType, Object msg) { public void sendMsgOfAllUserSession(String msgType, Object msg) {
// 获取监听该消息类型的所有会话 // 获取监听该消息类型的所有会话
List<SocketSession<GettySocketOperator>> socketSessionList = SessionCenter.getSocketSessionByMsgType(msgType.getCode()); List<SocketSession<GettySocketOperator>> socketSessionList = SessionCenter.getSocketSessionByMsgType(msgType);
if (ObjectUtil.isNotEmpty(socketSessionList)) { if (ObjectUtil.isNotEmpty(socketSessionList)) {
// 给所有会话发送消息 // 给所有会话发送消息
for (SocketSession<GettySocketOperator> socketSession : socketSessionList) { for (SocketSession<GettySocketOperator> socketSession : socketSessionList) {
WebSocketMessagePOJO webSocketMessagePOJO = new WebSocketMessagePOJO(); WebSocketMessagePOJO webSocketMessagePOJO = new WebSocketMessagePOJO();
webSocketMessagePOJO.setData(msg); webSocketMessagePOJO.setData(msg);
webSocketMessagePOJO.setType(msgType.getCode()); webSocketMessagePOJO.setType(msgType);
// 发送内容 // 发送内容
socketSession.getSocketOperatorApi().writeAndFlush(webSocketMessagePOJO); socketSession.getSocketOperatorApi().writeAndFlush(webSocketMessagePOJO);
} }

View File

@ -115,7 +115,7 @@ public class MessageDbServiceImpl implements MessageApi {
// 给用户发送通知 // 给用户发送通知
for (Long userId : userIdSet) { for (Long userId : userIdSet) {
socketOperatorApi.sendMsgOfUserSession(ServerMessageTypeEnum.SYS_NOTICE_MSG_TYPE, userId.toString(), messageSendRequest); socketOperatorApi.sendMsgOfUserSession(ServerMessageTypeEnum.SYS_NOTICE_MSG_TYPE.getCode(), userId.toString(), messageSendRequest);
} }
sysMessageService.saveBatch(sendMsgList); sysMessageService.saveBatch(sendMsgList);