From ac09ee9c9f39cb9d452b57504e5c79321e0371eb Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期四, 03 四月 2025 15:34:34 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java |   54 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
index ab95590..e6fa940 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/rcs/thread/impl/NyShuttleThread.java
@@ -62,6 +62,7 @@
 
     private static final boolean DEBUG = false;//璋冭瘯妯″紡
 
+    private List<JSONObject> socketReadResults = new ArrayList<>();
     private List<JSONObject> socketResults = new ArrayList<>();
 
     //鍘熷璁惧鏁版嵁
@@ -82,6 +83,7 @@
             while (true) {
                 try {
                     listenSocketMessage();
+                    listenInit();//鐩戝惉鍒濆鍖栦簨浠�
                 } catch (Exception e) {
                     e.printStackTrace();
                 }
@@ -137,7 +139,6 @@
         Thread otherThread = new Thread(() -> {
             while (true) {
                 try {
-                    listenInit();//鐩戝惉鍒濆鍖栦簨浠�
                     saveLog();//淇濆瓨鏁版嵁
                 } catch (Exception e) {
                     e.printStackTrace();
@@ -223,7 +224,19 @@
             }
 
             JSONObject result = JSON.parseObject(sb.toString());//寰楀埌鍝嶅簲缁撴灉闆�
-            if (!socketResults.isEmpty() && socketResults.size() >= 5) {
+
+            String msgType = result.getString("msgType");
+            if ("responseMsg".equals(msgType)) {
+                JSONObject response = result.getJSONObject("response");
+                JSONObject body = response.getJSONObject("body");
+                if (body.containsKey("workingMode")) {
+                    //read
+                    socketReadResults.add(body);
+                    return;
+                }
+            }
+
+            if (!socketResults.isEmpty() && socketResults.size() >= 20) {
                 socketResults.remove(0);//娓呯悊澶磋妭鐐�
             }
             socketResults.add(result);//娣诲姞鏁版嵁
@@ -307,7 +320,18 @@
 
             //----------璇诲彇鍥涘悜绌挎杞︾姸鎬�-----------
             NyShuttleHttpCommand readStatusCommand = getReadStatusCommand(Integer.parseInt(device.getDeviceNo()));
-            JSONObject data = requestCommand(readStatusCommand);
+            requestCommandAsync(readStatusCommand);//璇锋眰鐘舵��
+
+            if (this.socketReadResults.isEmpty()) {
+                if (System.currentTimeMillis() - shuttleProtocol.getLastOnlineTime() > 1000 * 60) {
+                    //鏈�鍚庝竴娆′笂绾挎椂闂磋秴杩�60s锛岃瀹氱绾�
+                    this.shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.OFFLINE);
+                }
+                return;
+            }
+
+            JSONObject data = this.socketReadResults.get(0);
+            this.socketReadResults.remove(0);
             if (data == null) {
                 if (System.currentTimeMillis() - shuttleProtocol.getLastOnlineTime() > 1000 * 60) {
                     //鏈�鍚庝竴娆′笂绾挎椂闂磋秴杩�60s锛岃瀹氱绾�
@@ -356,13 +380,17 @@
                 ///璇诲彇鍥涘悜绌挎杞︾姸鎬�-end
 
                 //灏忚溅澶勪簬杩愯涓紝灏嗘爣璁扮疆涓簍rue
-                if (shuttleProtocol.getDeviceStatus() == 1) {
+                if (shuttleProtocol.getDeviceStatus() == 0) {
                     shuttleProtocol.setPakMk(true);
                 }
 
-                if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == 0) {
+                if (shuttleProtocol.getProtocolStatusType() == null && shuttleProtocol.getDeviceStatus().intValue() == 1) {
                     //灏忚溅绌洪棽鐘舵�併�佸皬杞︿换鍔$姸鎬佷负鏈煡锛岃瀹氭浘绂荤嚎杩囷紝闇�瑕佸浣嶆垚绌洪棽
                     shuttleProtocol.setProtocolStatusType(ShuttleProtocolStatusType.IDLE);
+                }
+
+                if (shuttleProtocol.getProtocolStatusType().equals(ShuttleProtocolStatusType.OFFLINE) && shuttleProtocol.getDeviceStatus().intValue() == 1) {
+                    this.shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE);
                 }
 
                 this.originDeviceData = data;
@@ -1109,6 +1137,22 @@
         return result;//杩斿洖Body缁撴灉闆�
     }
 
+    private void requestCommandAsync(NyShuttleHttpCommand httpCommand) throws IOException {
+        if (this.socket == null) {
+            return;
+        }
+
+        //鍘嬬缉鏁版嵁鍖�
+        JSONObject data = JSON.parseObject(JSON.toJSONString(httpCommand));
+        data.remove("nodes");
+
+        // 鑾峰彇杈撳嚭娴�
+        OutputStreamWriter writer = new OutputStreamWriter(this.socket.getOutputStream());
+        writer.write(JSON.toJSONString(data) + "\r\n");
+        writer.flush();
+//            System.out.println("Sent message to server: " + JSON.toJSONString(httpCommand));
+    }
+
     private JSONObject filterBodyData(JSONObject data) {
         Object response = data.get("response");
         if (response == null) {

--
Gitblit v1.9.1