From 4c9b54b3b55e93e4d57685c036165bfce95c9c74 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期五, 18 四月 2025 08:41:53 +0800 Subject: [PATCH] 告警实时推送 --- src/main/java/com/whyc/webSocket/LockAlmRtSocket.java | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/whyc/webSocket/LockAlmRtSocket.java b/src/main/java/com/whyc/webSocket/LockAlmRtSocket.java index acd5134..9c489a2 100644 --- a/src/main/java/com/whyc/webSocket/LockAlmRtSocket.java +++ b/src/main/java/com/whyc/webSocket/LockAlmRtSocket.java @@ -3,11 +3,13 @@ import com.whyc.config.WebSocketConfig; import com.whyc.dto.LockAlmDto; import com.whyc.dto.Response; +import com.whyc.pojo.plus_user.UserInf; import com.whyc.service.LockAlarmService; import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import javax.servlet.http.HttpSession; import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.util.HashMap; @@ -25,6 +27,8 @@ private volatile boolean runFlag = true; + private static HttpSession httpSession; + private volatile Map<String, Thread> threadMap = new HashMap<>(); private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); @@ -36,12 +40,19 @@ @OnOpen - public void onOpen(Session session) { + public void onOpen(Session session, EndpointConfig config) { this.session = session; + this.httpSession = (HttpSession) config.getUserProperties().get("httpSession"); } @OnMessage public void onMessage(Session session, String message) { LockAlmDto almDto= ActionUtil.getGson().fromJson(message,LockAlmDto.class); + if(httpSession!=null){ + UserInf user = (UserInf) httpSession.getAttribute("user"); + almDto.setUid(user.getUid()); + }else{ + almDto.setUid(10001); + } thread = new Thread("Thread_areaLockStateSocket") { @Override public void run() { -- Gitblit v1.9.1