From e67870fff62635cd14beb0d5988f08aeef4b22fa Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 07 四月 2025 21:27:06 +0800
Subject: [PATCH] 添加远程关阀式终止灌溉计划,未测试

---
 pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/largeScreen/WebSocketServer.java |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 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 9bcf52c..f2c0041 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,7 @@
 package com.dy.pipIrrRemote.largeScreen;
 
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
 import jakarta.websocket.*;
@@ -13,10 +14,13 @@
  * @Author: liurunyu
  * @Date: 2025/2/10 15:25
  * @Description 瀹㈡埛绔紙娴忚鍣級姣忓缓绔嬩竴涓獁ebsocket杩炴帴锛屾湇鍔$灏变細鍒涘缓涓�涓猈ebSocketServer瀹炰緥
+ * 搴旂敤鍓嶆彁鏄瓨鍦ㄤ竴涓狢onfig绫伙紝濡傛湰妯″潡鐨刉ebSocketConfig锛岃繖鏃禓ServerEndpoint鍙桽pringBoot瀹瑰櫒
+ * 绠$悊浜嗭紙鍦ㄥ祵鍏ュ紡web Servlet鐜涓級
  */
 @Slf4j
 @ServerEndpoint("/websocket/ls/{id}")
 @Component
+@Scope("prototype") // 闈炲崟渚嬶紝姣忔璇锋眰閮戒細鍒涘缓鏂扮殑瀹炰緥
 public class WebSocketServer {
 
     // 闈欐�佸彉閲忥紝璁板綍褰撳墠鍦ㄧ嚎杩炴帴鏁�
@@ -27,7 +31,8 @@
 
     // 瀹㈡埛绔繛鎺ヤ細璇濓紝閫氳繃瀹冪粰瀹㈡埛绔彂閫佹暟鎹�
     private Session session;
-
+    // 瀹㈡埛绔笂绾挎椂鍒�
+    //private String onLineDt ;
     // 瀹㈡埛绔痠d
     private String id = "";
 
@@ -39,7 +44,11 @@
     @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());
 
         if (webSocketMap.containsKey(id)) {
@@ -98,7 +107,7 @@
     /**
      * 鏈嶅姟鍣ㄤ富鍔ㄧ兢鎺ㄩ�佹秷鎭�
      */
-    public static void sendAllMessage(String message) throws IOException {
+    public static void sendMessage2AllClient(String message) throws IOException {
         ConcurrentHashMap.KeySetView<String, WebSocketServer> ids = webSocketMap.keySet();
         for (String id : ids) {
             WebSocketServer webSocketServer = webSocketMap.get(id);
@@ -109,7 +118,7 @@
     /**
      * 鏈嶅姟鍣ㄦ寚瀹氬鎴风鎺ㄩ�佹秷鎭�
      */
-    public static void sendOneMessage(String message, String id) throws IOException {
+    public static void sendMessage2OneClient(String message, String id) throws IOException {
         if (message != null && message.length() != 0 && webSocketMap.containsKey(id)) {
             webSocketMap.get(id).sendMessage(message);
         } else {

--
Gitblit v1.8.0