From 9783363dba44f8606e88d2f28349759e3914ea27 Mon Sep 17 00:00:00 2001
From: zhoushihao <zsh19950802@163.com>
Date: 星期三, 16 十月 2024 09:25:57 +0800
Subject: [PATCH] 1、版本部分整合

---
 hangzhoumesParent/common/servicebase/src/main/java/com/mes/tools/WebSocketServer.java |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/hangzhoumesParent/common/servicebase/src/main/java/com/mes/tools/WebSocketServer.java b/hangzhoumesParent/common/servicebase/src/main/java/com/mes/tools/WebSocketServer.java
index 75f66fe..480921c 100644
--- a/hangzhoumesParent/common/servicebase/src/main/java/com/mes/tools/WebSocketServer.java
+++ b/hangzhoumesParent/common/servicebase/src/main/java/com/mes/tools/WebSocketServer.java
@@ -22,12 +22,6 @@
 
     public static ConfigurableApplicationContext applicationContext;
 
-    // 瑙e喅鏃犳硶娉ㄥ叆mapper闂 //浣跨敤鏂规硶
-    // homeMapper=WebSocketServer.applicationContext.getBean(HomeMapper.class);
-    public static void setApplicationContext(ConfigurableApplicationContext configurableApplicationContext) {
-        WebSocketServer.applicationContext = configurableApplicationContext;
-    }
-
     private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);
     private List<String> messages;
     /**
@@ -111,8 +105,6 @@
         JSONObject jsonObject = new JSONObject();
         jsonObject.set("message", text);
         this.messages.add(text);
-        this.sendMessage(jsonObject.toString()); // JSONUtil.toJsonStr(jsonObject)
-
     }
 
     @OnError
@@ -127,9 +119,32 @@
     public void sendMessage(String message) {
         try {
             // log.info("鏈嶅姟绔粰瀹㈡埛绔痆{}]鍙戦�佹秷鎭瘂}", this.session.getId(), message);
-            this.session.getBasicRemote().sendText(message);
+            if(this.session.isOpen()){
+                int maxChunkSize = 50000; // 瀹氫箟鏈�澶х殑鍒嗗潡澶у皬
+                int length = message.length();
+                if(length>50000){
+                    int chunks = (int) Math.ceil((double) length / maxChunkSize);
+                    //鍒嗗潡鍙戦�佹秷鎭�
+                    for (int i = 0; i < chunks; i++) {
+                        int startIndex = i * maxChunkSize;
+                        int endIndex = Math.min(startIndex + maxChunkSize, length);
+                        String chunk = message.substring(startIndex, endIndex);
+
+                        // 鍒ゆ柇鏄惁鏄渶鍚庝竴鍧楁秷鎭�
+                        boolean isLastChunk = (i == chunks - 1);
+                        if(isLastChunk==true){
+                            chunk+="<END>";
+                        }
+                        // 鍙戦�佸垎鍧楁秷鎭紝骞朵紶閫掓槸鍚︽槸鏈�鍚庝竴鍧楁秷鎭殑鏍囪瘑
+                        this.session.getBasicRemote().sendText(chunk);
+                    }
+                }else{
+                    this.session.getBasicRemote().sendText(message);
+                }
+
+            }
         } catch (Exception e) {
-            log.error("鏈嶅姟绔彂閫佹秷鎭粰瀹㈡埛绔け璐�", e);
+            log.error("鍙戦�佹秷鎭粰瀹㈡埛绔け璐ワ細{}", e.getMessage(), e);
         }
     }
 

--
Gitblit v1.8.0