|
@@ -51,16 +51,16 @@ public class WebSocketServer {
|
|
|
try {
|
|
|
session.getBasicRemote().sendText("连接成功");
|
|
|
//查询用户是否有未读消息,如果有则使用ws推送,延迟2秒
|
|
|
- Thread.sleep(2000);
|
|
|
ChatMsg unRead = new ChatMsg();
|
|
|
unRead.setToId(uid);
|
|
|
unRead.setIsRead("N");
|
|
|
List<ChatMsg> list = msgService.selectChatMsgList(unRead);
|
|
|
+ Thread.sleep(2000);
|
|
|
for (ChatMsg msg : list) {
|
|
|
msg.setRemark("unRead");
|
|
|
session.getBasicRemote().sendText(JSON.toJSONString(msg));
|
|
|
- msg.setIsRead("Y");
|
|
|
- msgService.updateChatMsg(msg);
|
|
|
+// msg.setIsRead("Y");
|
|
|
+// msgService.updateChatMsg(msg);
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException(e);
|
|
@@ -85,14 +85,17 @@ public class WebSocketServer {
|
|
|
public void onMessage(@PathParam("uid") Long uid, String message) {
|
|
|
try {
|
|
|
//获取客户端发送来的数据 {"toId":2,"message":"你好"}
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- ChatMsg msg = mapper.readValue(message, ChatMsg.class);
|
|
|
- msg.setFromId(uid);
|
|
|
- // 保存到数据库
|
|
|
- msg.setIsRead("N");
|
|
|
- msgService.insertChatMsg(msg);
|
|
|
- //发布集群消息
|
|
|
- this.sendClusterMessage(message);
|
|
|
+ if (!"heartbeat".equals(message)) {
|
|
|
+ //判断如果不是心跳消息再处理
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ ChatMsg msg = mapper.readValue(message, ChatMsg.class);
|
|
|
+ msg.setFromId(uid);
|
|
|
+ // 保存到数据库
|
|
|
+ msg.setIsRead("N");
|
|
|
+ msgService.insertChatMsg(msg);
|
|
|
+ //发布集群消息
|
|
|
+ this.sendClusterMessage(message);
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -119,10 +122,10 @@ public class WebSocketServer {
|
|
|
try {
|
|
|
Session session = currentMap.get(msg.getToId());
|
|
|
if (session != null) {
|
|
|
- ChatMsg readMsg = new ChatMsg();
|
|
|
- readMsg.setMsgId(msg.getMsgId());
|
|
|
- readMsg.setIsRead("Y");
|
|
|
- msgService.updateChatMsg(readMsg);
|
|
|
+// ChatMsg readMsg = new ChatMsg();
|
|
|
+// readMsg.setMsgId(msg.getMsgId());
|
|
|
+// readMsg.setIsRead("Y");
|
|
|
+// msgService.updateChatMsg(readMsg);
|
|
|
session.getBasicRemote().sendText(JSON.toJSONString(msg));
|
|
|
}
|
|
|
} catch (Exception e) {
|