From 09aa49c8d12e74f0cb99b510761f2873afff873b Mon Sep 17 00:00:00 2001
From: zy <zy@123>
Date: 星期一, 21 七月 2025 10:27:27 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java |   33 ++++++++++++++++++++++++++++++---
 1 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java b/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
index b49aaee..0c67bd8 100644
--- a/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
@@ -3,11 +3,13 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.zy.common.Cools;
+import com.zy.common.R;
 import com.zy.common.SpringUtils;
 import com.zy.common.utils.RedisUtil;
 import com.zy.core.News;
 import com.zy.core.cache.SlaveConnection;
 import com.zy.core.enums.SlaveType;
+import com.zy.core.model.param.UpdateFakeThreadStatusParam;
 import com.zy.core.properties.DeviceConfig;
 import com.zy.core.thread.FakeThread;
 import com.zy.core.thread.impl.NyShuttleThread;
@@ -334,6 +336,15 @@
                     String pathList = body.getString("path");
                     List<JSONObject> list = JSON.parseArray(pathList, JSONObject.class);
                     for (JSONObject path : list) {
+                        while (true) {
+                            JSONObject realFakeStatus = fakeStatusMap.get(key);
+                            Integer errorCode = realFakeStatus.getInteger("errorCode");
+                            if (errorCode > 0) {
+                                continue;
+                            }
+                            break;
+                        }
+
                         String currentCode = fakeStatus.getString("currentCode");
                         JSONObject point = JSON.parseObject(currentCode);
                         point.put("x", path.getInteger("xp"));
@@ -355,6 +366,7 @@
     }
 
     private void handleClient(DeviceConfig device) throws IOException {
+        StringBuffer sb = new StringBuffer();
         try {
             Socket socket = fakeServerMap.get(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo());
             if (socket == null) {
@@ -369,13 +381,14 @@
             // 鑾峰彇杈撳叆娴�
             BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
             // 璇诲彇鏈嶅姟鍣ㄧ殑鍝嶅簲
-            StringBuffer sb = new StringBuffer();
             char[] chars = new char[2048];//缂撳啿鍖�
             while (true) {
                 reader.read(chars);
                 String trim = new String(chars);
-                sb.append(trim);
-                if (trim.lastIndexOf("\r\n") != -1) {
+                int lastIndexOf = trim.lastIndexOf("\r\n");
+                if (lastIndexOf != -1) {
+                    trim = trim.substring(0, lastIndexOf);
+                    sb.append(trim);
                     break;
                 }
             }
@@ -384,6 +397,7 @@
 //            log.info("鏀跺埌Client Data: {}", JSON.toJSONString(result));
             processCommand(result, device);
         } catch (Exception e) {
+            log.error("handleClient deviceNo:{},recevie:{}", device.getDeviceNo(), sb);
             e.printStackTrace();
         }
     }
@@ -529,4 +543,17 @@
     public ConcurrentHashMap<String, JSONObject> getFakeCommandMap() {
         return this.fakeCommandMap;
     }
+
+    @Override
+    public boolean updateFakeStatus(UpdateFakeThreadStatusParam param) {
+        String key = param.getDeviceType() + param.getDeviceNo();
+        JSONObject result = fakeStatusMap.get(key);
+        if (result == null) {
+            return false;
+        }
+
+        JSONObject newData = JSON.parseObject(param.getData());
+        this.fakeStatusMap.put(key, newData);
+        return true;
+    }
 }

--
Gitblit v1.9.1