From eb2d3ef0e4fa144d5a76823709a1ab2bc27a2ae9 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期二, 22 七月 2025 17:42:34 +0800
Subject: [PATCH] 1、通信中间件去除上报消息测试类(去除注解) ; 2、remote模块,webSocket模块修改完善,增加机构orgTag控制; 3、从SSO模块获取当前用户信息部分进行集成完善,以供其他部分共享应用。

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java |   86 ++++++++++++++++++++++++++----------------
 1 files changed, 53 insertions(+), 33 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java
index f2c0041..03b1c12 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java
@@ -1,6 +1,9 @@
 package com.dy.pipIrrRemote.largeScreen;
 
+import com.dy.common.aop.SsoCheck;
+import com.dy.common.aop.SsoVo;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
@@ -18,7 +21,7 @@
  * 绠$悊浜嗭紙鍦ㄥ祵鍏ュ紡web Servlet鐜涓級
  */
 @Slf4j
-@ServerEndpoint("/websocket/ls/{id}")
+@ServerEndpoint("/websocket/ls/{token}")
 @Component
 @Scope("prototype") // 闈炲崟渚嬶紝姣忔璇锋眰閮戒細鍒涘缓鏂扮殑瀹炰緥
 public class WebSocketServer {
@@ -31,32 +34,43 @@
 
     // 瀹㈡埛绔繛鎺ヤ細璇濓紝閫氳繃瀹冪粰瀹㈡埛绔彂閫佹暟鎹�
     private Session session;
+
+    private String orgTag;
+
     // 瀹㈡埛绔笂绾挎椂鍒�
     //private String onLineDt ;
-    // 瀹㈡埛绔痠d
-    private String id = "";
+    // 瀹㈡埛绔�
+    private String token = "";
+
+    @Autowired
+    private SsoCheck ssoCheck ;
 
     /**
      * 杩炴帴寤虹珛鎴愬姛璋冪敤鐨勬柟娉�
      * @param session websocket浼氳瘽瀵硅薄
-     * @param id 瀹㈡埛绔痠d
+     * @param token 瀹㈡埛绔痠d
      */
     @OnOpen
-    public void onOpen(Session session, @PathParam("id") String id) {
-        this.session = session;
-        //this.onLineDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
-        this.id = id;
-        if(this.id == null || this.id.length() == 0){
-            this.id = "" + System.nanoTime() ;
-        }
-        this.sendMessage(WebSocketHeartBeat.getHeartBeatMessage());
+    public void onOpen(Session session, @PathParam("token") String token) {
+        if(this.token == null || this.token.length() == 0){
+            this.session = session;
+            //this.onLineDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;
+            this.token = token;
+            this.sendMessage(WebSocketHeartBeat.getHeartBeatMessage());
 
-        if (webSocketMap.containsKey(id)) {
-            webSocketMap.remove(id);
-            webSocketMap.put(id, this);
-        } else {
-            webSocketMap.put(id, this);
-            WebSocketServer.addOnlineCount();
+            if (webSocketMap.containsKey(token)) {
+                webSocketMap.remove(token);
+                webSocketMap.put(token, this);
+            } else {
+                webSocketMap.put(token, this);
+                WebSocketServer.addOnlineCount();
+            }
+            Object rObj = this.ssoCheck.check(token);
+            if(rObj != null) {
+                if (rObj instanceof SsoVo ssoVo) {
+                    this.orgTag = ssoVo.dataSourceName ;
+                }
+            }
         }
     }
 
@@ -65,12 +79,12 @@
      */
     @OnClose
     public void onClose() {
-        if (webSocketMap.containsKey(id)) {
-            webSocketMap.remove(id);
+        if (webSocketMap.containsKey(token)) {
+            webSocketMap.remove(token);
             //浠巗et涓垹闄�
             WebSocketServer.subOnlineCount();
         }
-        log.info("瀹㈡埛绔�:" + id + "锛屽叧闂簡websocket");
+        log.info("瀹㈡埛绔�:" + token + "锛屽叧闂簡websocket");
     }
 
     /**
@@ -80,7 +94,7 @@
      */
     @OnMessage
     public void onMessage(String message, Session session) {
-        log.info("瀹㈡埛绔�:" + id + "锛寃ebsocket鎶ユ枃:" + message);
+        log.info("瀹㈡埛绔�:" + token + "锛寃ebsocket鎶ユ枃:" + message);
     }
 
     /**
@@ -90,7 +104,7 @@
      */
     @OnError
     public void onError(Session session, Throwable error) {
-        log.error("瀹㈡埛绔�:" + this.id + "锛寃ebsocket浼氳瘽寮傚父锛屽師鍥�:" + error.getMessage());
+        log.error("瀹㈡埛绔�:" + this.token + "锛寃ebsocket浼氳瘽寮傚父锛屽師鍥�:" + error.getMessage());
     }
 
     /**
@@ -100,29 +114,35 @@
         try{
             this.session.getBasicRemote().sendText(message);
         }catch (Exception e){
-            log.error("瀹㈡埛绔�:" + id + "锛寃ebsocket缃戠粶鍙戦�佹暟鎹紓甯�", e);
+            log.error("瀹㈡埛绔�:" + token + "锛寃ebsocket缃戠粶鍙戦�佹暟鎹紓甯�", e);
         }
     }
 
     /**
      * 鏈嶅姟鍣ㄤ富鍔ㄧ兢鎺ㄩ�佹秷鎭�
      */
-    public static void sendMessage2AllClient(String message) throws IOException {
-        ConcurrentHashMap.KeySetView<String, WebSocketServer> ids = webSocketMap.keySet();
-        for (String id : ids) {
-            WebSocketServer webSocketServer = webSocketMap.get(id);
-            webSocketServer.sendMessage(message);
+    public static void sendMessage2AllClient(String orgTag, String message) throws IOException {
+        ConcurrentHashMap.KeySetView<String, WebSocketServer> tokens = webSocketMap.keySet();
+        for (String token : tokens) {
+            WebSocketServer webSocketServer = webSocketMap.get(token);
+            if(orgTag == null){
+                webSocketServer.sendMessage(message);
+            }else{
+                if(webSocketServer.orgTag != null && webSocketServer.orgTag.equals(orgTag)){
+                    webSocketServer.sendMessage(message);
+                }
+            }
         }
     }
 
     /**
      * 鏈嶅姟鍣ㄦ寚瀹氬鎴风鎺ㄩ�佹秷鎭�
      */
-    public static void sendMessage2OneClient(String message, String id) throws IOException {
-        if (message != null && message.length() != 0 && webSocketMap.containsKey(id)) {
-            webSocketMap.get(id).sendMessage(message);
+    public static void sendMessage2OneClient(String message, String token) throws IOException {
+        if (message != null && message.length() != 0 && webSocketMap.containsKey(token)) {
+            webSocketMap.get(token).sendMessage(message);
         } else {
-            log.error("瀹㈡埛绔�" + id + "锛屼笉鍦ㄧ嚎锛�");
+            log.error("瀹㈡埛绔�" + token + "锛屼笉鍦ㄧ嚎锛�");
         }
     }
 

--
Gitblit v1.8.0