调整类名称,新增接收状态消息
This commit is contained in:
parent
381db54988
commit
b6b25142a2
@ -10,7 +10,7 @@ import ink.wgink.module.instantmessage.pojo.pos.NoticePO;
|
|||||||
import ink.wgink.module.instantmessage.pojo.vos.NoticeVO;
|
import ink.wgink.module.instantmessage.pojo.vos.NoticeVO;
|
||||||
import ink.wgink.module.instantmessage.service.IMessageService;
|
import ink.wgink.module.instantmessage.service.IMessageService;
|
||||||
import ink.wgink.module.instantmessage.service.INoticeService;
|
import ink.wgink.module.instantmessage.service.INoticeService;
|
||||||
import ink.wgink.module.instantmessage.websocket.enums.ClientSocketTypeEnum;
|
import ink.wgink.module.instantmessage.websocket.enums.MessageTypeEnum;
|
||||||
import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager;
|
import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager;
|
||||||
import ink.wgink.module.instantmessage.websocket.pojo.WebSocketClientMessage;
|
import ink.wgink.module.instantmessage.websocket.pojo.WebSocketClientMessage;
|
||||||
import ink.wgink.module.instantmessage.websocket.pojo.WebSocketSession;
|
import ink.wgink.module.instantmessage.websocket.pojo.WebSocketSession;
|
||||||
@ -57,7 +57,7 @@ public class MessageServiceImpl extends DefaultBaseService implements IMessageSe
|
|||||||
public void notice(String clientName, NoticeBO noticeBO) {
|
public void notice(String clientName, NoticeBO noticeBO) {
|
||||||
List<WebSocketSession> webSocketSessions = listWebSocketSessions(clientName, noticeBO);
|
List<WebSocketSession> webSocketSessions = listWebSocketSessions(clientName, noticeBO);
|
||||||
NoticeBody noticeBody = new NoticeBody(noticeBO.getTitle(), noticeBO.getContent());
|
NoticeBody noticeBody = new NoticeBody(noticeBO.getTitle(), noticeBO.getContent());
|
||||||
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(ClientSocketTypeEnum.NOTICE.getValue(),
|
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(MessageTypeEnum.NOTICE.getValue(),
|
||||||
true,
|
true,
|
||||||
WebSocketChannelManager.FORM_SYSTEM,
|
WebSocketChannelManager.FORM_SYSTEM,
|
||||||
noticeBO.getTo(),
|
noticeBO.getTo(),
|
||||||
@ -74,7 +74,7 @@ public class MessageServiceImpl extends DefaultBaseService implements IMessageSe
|
|||||||
public void notice(String clientName, NoticeTargetBO noticeTargetBO) {
|
public void notice(String clientName, NoticeTargetBO noticeTargetBO) {
|
||||||
List<WebSocketSession> webSocketSessions = listWebSocketSessions(clientName, noticeTargetBO);
|
List<WebSocketSession> webSocketSessions = listWebSocketSessions(clientName, noticeTargetBO);
|
||||||
NoticeBody noticeBody = new NoticeBody(noticeTargetBO.getTitle(), noticeTargetBO.getContent(), noticeTargetBO.getTarget());
|
NoticeBody noticeBody = new NoticeBody(noticeTargetBO.getTitle(), noticeTargetBO.getContent(), noticeTargetBO.getTarget());
|
||||||
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(ClientSocketTypeEnum.NOTICE_TARGET_MESSAGE.getValue(),
|
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(MessageTypeEnum.NOTICE_TARGET_MESSAGE.getValue(),
|
||||||
true,
|
true,
|
||||||
WebSocketChannelManager.FORM_SYSTEM,
|
WebSocketChannelManager.FORM_SYSTEM,
|
||||||
noticeTargetBO.getTo(),
|
noticeTargetBO.getTo(),
|
||||||
@ -99,7 +99,7 @@ public class MessageServiceImpl extends DefaultBaseService implements IMessageSe
|
|||||||
scheduledExecutorService.schedule(() -> {
|
scheduledExecutorService.schedule(() -> {
|
||||||
for (WebSocketSession webSocketSession : webSocketSessions) {
|
for (WebSocketSession webSocketSession : webSocketSessions) {
|
||||||
NoticeBody noticeBody = new NoticeBody(notice.getTitle(), notice.getMsg(), notice.getTarget());
|
NoticeBody noticeBody = new NoticeBody(notice.getTitle(), notice.getMsg(), notice.getTarget());
|
||||||
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(ClientSocketTypeEnum.NOTICE_TARGET_MESSAGE.getValue(),
|
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(MessageTypeEnum.NOTICE_TARGET_MESSAGE.getValue(),
|
||||||
true,
|
true,
|
||||||
WebSocketChannelManager.FORM_SYSTEM,
|
WebSocketChannelManager.FORM_SYSTEM,
|
||||||
webSocketSession.getUserId(),
|
webSocketSession.getUserId(),
|
||||||
@ -174,7 +174,7 @@ public class MessageServiceImpl extends DefaultBaseService implements IMessageSe
|
|||||||
countNeedToDealWithBody.setSystem(noticePO.getNoticeSystem());
|
countNeedToDealWithBody.setSystem(noticePO.getNoticeSystem());
|
||||||
// 查询待办状态
|
// 查询待办状态
|
||||||
List<CountNeedToDealWithBody> counts = noticeService.listNoticeCount(webSocketSession.getUserId(), countNeedToDealWithBody);
|
List<CountNeedToDealWithBody> counts = noticeService.listNoticeCount(webSocketSession.getUserId(), countNeedToDealWithBody);
|
||||||
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(ClientSocketTypeEnum.SEARCH_COUNT_NEED_TO_DEALT_WITH.getValue(),
|
WebSocketClientMessage webSocketClientMessage = new WebSocketClientMessage(MessageTypeEnum.SEARCH_COUNT_NEED_TO_DEALT_WITH.getValue(),
|
||||||
true,
|
true,
|
||||||
WebSocketChannelManager.FORM_SYSTEM,
|
WebSocketChannelManager.FORM_SYSTEM,
|
||||||
webSocketSession.getUserId(),
|
webSocketSession.getUserId(),
|
||||||
|
@ -10,7 +10,7 @@ package ink.wgink.module.instantmessage.websocket.enums;
|
|||||||
* @Date: 2021/1/13 11:20 下午
|
* @Date: 2021/1/13 11:20 下午
|
||||||
* @Version: 1.0
|
* @Version: 1.0
|
||||||
*/
|
*/
|
||||||
public enum ClientSocketTypeEnum {
|
public enum MessageTypeEnum {
|
||||||
|
|
||||||
REGISTER(1000, "注册消息,body 为 RegisterBody 的 JSON 字符串"),
|
REGISTER(1000, "注册消息,body 为 RegisterBody 的 JSON 字符串"),
|
||||||
|
|
||||||
@ -41,16 +41,16 @@ public enum ClientSocketTypeEnum {
|
|||||||
SEARCH_ONLINE_USER_FRIEND(4002, "查询朋友在线用户,body 为查询用户的 userId"),
|
SEARCH_ONLINE_USER_FRIEND(4002, "查询朋友在线用户,body 为查询用户的 userId"),
|
||||||
SEARCH_COUNT_NEED_TO_DEALT_WITH(4003, "查询全部待办总数"),
|
SEARCH_COUNT_NEED_TO_DEALT_WITH(4003, "查询全部待办总数"),
|
||||||
|
|
||||||
STATUS_SEND(9001, "消息发送状态,body 为 BaseResult 的 JSON 字符串"),
|
STATUS_SEND(9001, "消息发送状态,body 为 StatusBody 的 JSON 字符串"),
|
||||||
STATUS_SEND_ONLINE(9002, "发送在线状态,body 为 在线用户的ID JSONArray 字符串"),
|
STATUS_SEND_ONLINE(9002, "发送在线状态,body 为 在线用户的ID JSONArray 字符串"),
|
||||||
STATUS_SEND_OFFLINE(9003, "发送离线状态,body 为 离线用户的ID JSONArray 字符串"),
|
STATUS_SEND_OFFLINE(9003, "发送离线状态,body 为 离线用户的ID JSONArray 字符串"),
|
||||||
|
|
||||||
STATUS_RECEIVED(9101,"消息接受状态");
|
STATUS_RECEIVE(9101,"消息接受状态,body 为 StatusBody 的 JSON 字符串");
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
private String summary;
|
private String summary;
|
||||||
|
|
||||||
ClientSocketTypeEnum(int value, String summary) {
|
MessageTypeEnum(int value, String summary) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.summary = summary;
|
this.summary = summary;
|
||||||
}
|
}
|
@ -15,12 +15,11 @@ public enum StatusEnum {
|
|||||||
FAILED(400, "失败"),
|
FAILED(400, "失败"),
|
||||||
MESSAGE_ERROR(401, "消息错误"),
|
MESSAGE_ERROR(401, "消息错误"),
|
||||||
SESSION_ERROR(402, "会话错误"),
|
SESSION_ERROR(402, "会话错误"),
|
||||||
CLIENT_SESSION_ERROR(403, "客户端会话错误"),
|
TYPE_ERROR(403, "类型编码错误"),
|
||||||
TYPE_ERROR(404, "类型错误"),
|
BODY_ERROR(404, "消息体错误"),
|
||||||
BODY_ERROR(405, "消息体错误"),
|
FROM_ERROR(405, "来源错误"),
|
||||||
FROM_ERROR(406, "来源错误"),
|
TO_ERROR(406, "接收人错误"),
|
||||||
TO_ERROR(407, "接受用户错误"),
|
RECEIVE_ERROR(407, "接收错误");
|
||||||
RECEIVE_ERROR(408, "接收错误");
|
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
private String summary;
|
private String summary;
|
||||||
|
@ -2,7 +2,7 @@ package ink.wgink.module.instantmessage.websocket.handler.text;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONException;
|
import com.alibaba.fastjson.JSONException;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import ink.wgink.module.instantmessage.websocket.enums.ClientSocketTypeEnum;
|
import ink.wgink.module.instantmessage.websocket.enums.MessageTypeEnum;
|
||||||
import ink.wgink.module.instantmessage.websocket.enums.StatusEnum;
|
import ink.wgink.module.instantmessage.websocket.enums.StatusEnum;
|
||||||
import ink.wgink.module.instantmessage.websocket.exception.*;
|
import ink.wgink.module.instantmessage.websocket.exception.*;
|
||||||
import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager;
|
import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager;
|
||||||
@ -42,20 +42,21 @@ public class WebSocketTextHandler {
|
|||||||
if (StringUtils.isBlank(clientSocketMessage.getBody())) {
|
if (StringUtils.isBlank(clientSocketMessage.getBody())) {
|
||||||
throw new BodyException("Body主体不能为空");
|
throw new BodyException("Body主体不能为空");
|
||||||
}
|
}
|
||||||
if (ClientSocketTypeEnum.REGISTER.getValue() == clientSocketMessage.getType()) {
|
if (MessageTypeEnum.REGISTER.getValue() == clientSocketMessage.getType()) {
|
||||||
// 客户端注册消息
|
// 客户端注册消息
|
||||||
statusBody = clientRegisterSession(ctx.channel(), clientSocketMessage);
|
statusBody = clientRegisterSession(ctx.channel(), clientSocketMessage);
|
||||||
} else if (ClientSocketTypeEnum.MESSAGE.getValue() == clientSocketMessage.getType()) {
|
} else if (MessageTypeEnum.MESSAGE.getValue() == clientSocketMessage.getType()) {
|
||||||
// 文本消息
|
// 文本消息
|
||||||
sendText(ctx.channel(), clientSocketMessage);
|
sendText(ctx.channel(), clientSocketMessage);
|
||||||
} else if (ClientSocketTypeEnum.MESSAGE_GROUP.getValue() == clientSocketMessage.getType()) {
|
} else if (MessageTypeEnum.MESSAGE_GROUP.getValue() == clientSocketMessage.getType()) {
|
||||||
// 群发消息
|
// 群发消息
|
||||||
sendGroupText(ctx.channel(), clientSocketMessage);
|
sendGroupText(ctx.channel(), clientSocketMessage);
|
||||||
} else if (ClientSocketTypeEnum.SEARCH_ONLINE_USER.getValue() == clientSocketMessage.getType()) {
|
} else if (MessageTypeEnum.SEARCH_ONLINE_USER.getValue() == clientSocketMessage.getType()) {
|
||||||
// 用户在线状态
|
// 用户在线状态
|
||||||
listOnlineUser(ctx.channel(), clientSocketMessage);
|
listOnlineUser(ctx.channel(), clientSocketMessage);
|
||||||
} else if (ClientSocketTypeEnum.STATUS_RECEIVED.getValue() == clientSocketMessage.getType()) {
|
} else if (MessageTypeEnum.STATUS_RECEIVE.getValue() == clientSocketMessage.getType()) {
|
||||||
// 消息接收状态
|
// 消息接收状态
|
||||||
|
sendReceiveStatus(clientSocketMessage);
|
||||||
} else {
|
} else {
|
||||||
throw new TypeException("请求类型错误");
|
throw new TypeException("请求类型错误");
|
||||||
}
|
}
|
||||||
@ -74,7 +75,7 @@ public class WebSocketTextHandler {
|
|||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
clientSocketMessage = new WebSocketClientMessage();
|
clientSocketMessage = new WebSocketClientMessage();
|
||||||
clientSocketMessage.setSystem(true);
|
clientSocketMessage.setSystem(true);
|
||||||
clientSocketMessage.setType(ClientSocketTypeEnum.MESSAGE_SYSTEM.getValue());
|
clientSocketMessage.setType(MessageTypeEnum.MESSAGE_SYSTEM.getValue());
|
||||||
clientSocketMessage.setFrom(WebSocketChannelManager.FORM_SYSTEM);
|
clientSocketMessage.setFrom(WebSocketChannelManager.FORM_SYSTEM);
|
||||||
statusBody = new StatusBody(StatusEnum.TO_ERROR.getValue(), StatusEnum.MESSAGE_ERROR, e.getMessage());
|
statusBody = new StatusBody(StatusEnum.TO_ERROR.getValue(), StatusEnum.MESSAGE_ERROR, e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
@ -85,6 +86,19 @@ public class WebSocketTextHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送接收状态
|
||||||
|
*
|
||||||
|
* @param clientSocketMessage 客户端消息
|
||||||
|
*/
|
||||||
|
private void sendReceiveStatus(WebSocketClientMessage webSocketClientMessage) {
|
||||||
|
List<String> toUserIds = new ArrayList<>(Sets.newHashSet(webSocketClientMessage.getTo().split(",")));
|
||||||
|
List<WebSocketSession> webSocketSessions = WebSocketChannelManager.getInstance().listOnlineUser(toUserIds);
|
||||||
|
for (WebSocketSession webSocketSession : webSocketSessions) {
|
||||||
|
WebSocketChannelManager.getInstance().sendText(webSocketSession.getChannel(), webSocketClientMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端会话注册
|
* 客户端会话注册
|
||||||
*
|
*
|
||||||
@ -171,7 +185,7 @@ public class WebSocketTextHandler {
|
|||||||
}
|
}
|
||||||
idsBody = new IdsBody();
|
idsBody = new IdsBody();
|
||||||
idsBody.setIds(new ArrayList<>(idSets));
|
idsBody.setIds(new ArrayList<>(idSets));
|
||||||
webSocketClientMessage.setType(ClientSocketTypeEnum.STATUS_SEND_ONLINE.getValue());
|
webSocketClientMessage.setType(MessageTypeEnum.STATUS_SEND_ONLINE.getValue());
|
||||||
webSocketClientMessage.setBody(JSONObject.toJSONString(idsBody));
|
webSocketClientMessage.setBody(JSONObject.toJSONString(idsBody));
|
||||||
sendText(fromChannel, webSocketClientMessage);
|
sendText(fromChannel, webSocketClientMessage);
|
||||||
}
|
}
|
||||||
@ -184,7 +198,7 @@ public class WebSocketTextHandler {
|
|||||||
* @param msg
|
* @param msg
|
||||||
*/
|
*/
|
||||||
public static void sendTextFailed(Channel fromChannel, WebSocketClientMessage webSocketClientMessage, String msg) {
|
public static void sendTextFailed(Channel fromChannel, WebSocketClientMessage webSocketClientMessage, String msg) {
|
||||||
webSocketClientMessage.setType(ClientSocketTypeEnum.STATUS_SEND.getValue());
|
webSocketClientMessage.setType(MessageTypeEnum.STATUS_SEND.getValue());
|
||||||
webSocketClientMessage.setBody(JSONObject.toJSONString(new StatusBody(StatusEnum.FAILED.getValue(), StatusEnum.FAILED, msg)));
|
webSocketClientMessage.setBody(JSONObject.toJSONString(new StatusBody(StatusEnum.FAILED.getValue(), StatusEnum.FAILED, msg)));
|
||||||
WebSocketChannelManager.getInstance().sendText(fromChannel, webSocketClientMessage);
|
WebSocketChannelManager.getInstance().sendText(fromChannel, webSocketClientMessage);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class WebSocketClientMessage {
|
|||||||
*/
|
*/
|
||||||
private String from;
|
private String from;
|
||||||
/**
|
/**
|
||||||
* 去处,系统消息为 clientName, 非系统消息为 userId
|
* 去处,接收人userId
|
||||||
*/
|
*/
|
||||||
private String to;
|
private String to;
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user