From d3417407db947cf6f10c163d75325fd7df408eab Mon Sep 17 00:00:00 2001
From: zy <zy@123>
Date: 星期日, 03 八月 2025 15:19:12 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java |  112 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 82 insertions(+), 30 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 0c67bd8..afdae1d 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,11 @@
 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.RedisKeyType;
 import com.zy.core.enums.SlaveType;
 import com.zy.core.model.param.UpdateFakeThreadStatusParam;
 import com.zy.core.properties.DeviceConfig;
@@ -19,9 +19,7 @@
 import java.io.*;
 import java.net.ServerSocket;
 import java.net.Socket;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
 @Slf4j
@@ -174,7 +172,7 @@
                     }
                     List<DeviceConfig> deviceConfigs = fakeDeviceUtils.getFakeDeviceConfig();
                     for (DeviceConfig device : deviceConfigs) {
-                        excuteFakeCommand(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo());
+                        excuteFakeCommand(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo(), device);
                     }
                 }catch (Exception e){
                     e.printStackTrace();
@@ -250,7 +248,7 @@
         }
     }
 
-    private void excuteFakeCommand(String key) {
+    private void excuteFakeCommand(String key, DeviceConfig deviceConfig) {
         if (!fakeCommandMap.containsKey(key)) {
             return;
         }
@@ -269,56 +267,84 @@
                     fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
                     fakeStatusMap.put(key, fakeStatus);
 
-                    //delay
-                    Thread.sleep(2000);
+                    long startTime = System.currentTimeMillis();
+                    while (true) {
+                        if((System.currentTimeMillis() - startTime) < 1000 * 2) {
+                            continue;
+                        }
+                        break;
+                    }
                     fakeStatus.put("hasLift", true);
                     fakeStatus.put("deviceStatus", 1);//璁惧绌洪棽
                     fakeStatusMap.put(key, fakeStatus);
-                }else if (commandType.equals("liftDown")) {
+                } else if (commandType.equals("liftDown")) {
                     fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
                     fakeStatusMap.put(key, fakeStatus);
 
-                    //delay
-                    Thread.sleep(2000);
+                    long startTime = System.currentTimeMillis();
+                    while (true) {
+                        if((System.currentTimeMillis() - startTime) < 1000 * 2) {
+                            continue;
+                        }
+                        break;
+                    }
                     fakeStatus.put("hasLift", false);
                     fakeStatus.put("deviceStatus", 1);//璁惧绌洪棽
                     fakeStatusMap.put(key, fakeStatus);
-                }else if (commandType.equals("charge")) {
+                } else if (commandType.equals("charge")) {
                     fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
                     fakeStatusMap.put(key, fakeStatus);
 
-                    //delay
-                    Thread.sleep(2000);
+                    long startTime = System.currentTimeMillis();
+                    while (true) {
+                        if((System.currentTimeMillis() - startTime) < 1000 * 2) {
+                            continue;
+                        }
+                        break;
+                    }
                     fakeStatus.put("hasCharge", true);
 
                     Integer batteryPower = Integer.parseInt(fakeStatus.getString("batteryPower"));
                     while (true) {
-                        Thread.sleep(10000);
+                        if((System.currentTimeMillis() - startTime) < 1000 * 10) {
+                            continue;
+                        }
                         batteryPower = batteryPower + 1;
                         fakeStatus.put("batteryPower", batteryPower);
                         fakeStatusMap.put(key, fakeStatus);
-                        if(batteryPower >= 100) {
+                        startTime = System.currentTimeMillis();
+                        if (batteryPower >= 100) {
                             break;
                         }
                     }
 
                     fakeStatus.put("deviceStatus", 1);//璁惧绌洪棽
                     fakeStatusMap.put(key, fakeStatus);
-                }else if (commandType.equals("stopCharge")) {
+                } else if (commandType.equals("stopCharge")) {
                     fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
                     fakeStatusMap.put(key, fakeStatus);
 
-                    //delay
-                    Thread.sleep(2000);
+                    long startTime = System.currentTimeMillis();
+                    while (true) {
+                        if((System.currentTimeMillis() - startTime) < 1000 * 2) {
+                            continue;
+                        }
+                        break;
+                    }
                     fakeStatus.put("hasCharge", false);
                     fakeStatus.put("deviceStatus", 1);//璁惧绌洪棽
                     fakeStatusMap.put(key, fakeStatus);
-                }else if (commandType.equals("updateFloor")) {
+                } else if (commandType.equals("updateFloor")) {
                     fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
                     fakeStatusMap.put(key, fakeStatus);
 
-                    //delay
-                    Thread.sleep(2000);
+                    long startTime = System.currentTimeMillis();
+                    while (true) {
+                        if((System.currentTimeMillis() - startTime) < 1000 * 2) {
+                            continue;
+                        }
+                        break;
+                    }
 
                     JSONObject body = command.getJSONObject("commandBody");
                     String currentCode = fakeStatus.getString("currentCode");
@@ -327,19 +353,44 @@
                     fakeStatus.put("currentCode", JSON.toJSONString(point));
                     fakeStatus.put("deviceStatus", 1);//璁惧绌洪棽
                     fakeStatusMap.put(key, fakeStatus);
-                }else if (commandType.equals("move")) {
-                    fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
-                    fakeStatusMap.put(key, fakeStatus);
-                    Thread.sleep(2000);
+                } else if (commandType.equals("move")) {
+                    String baseCommandKey = RedisKeyType.FAKE_SHUTTLE_MOVE_EXECUTE_COMMAND_LIST.key + deviceConfig.getDeviceNo() + "_";
+                    while (true) {
+                        Set<String> keys = redisUtil.searchKeys(baseCommandKey);
+                        if (keys.isEmpty()) {
+                            break;
+                        }
+                    }
+
+                    String finalKey = baseCommandKey + System.currentTimeMillis();
+                    redisUtil.set(finalKey, true, 60 * 60);
 
                     JSONObject body = command.getJSONObject("commandBody");
                     String pathList = body.getString("path");
-                    List<JSONObject> list = JSON.parseArray(pathList, JSONObject.class);
-                    for (JSONObject path : list) {
+                    List<JSONObject> executePathList = JSON.parseArray(pathList, JSONObject.class);
+
+                    fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
+                    fakeStatusMap.put(key, fakeStatus);
+                    long startTime = System.currentTimeMillis();
+                    while (true) {
+                        if((System.currentTimeMillis() - startTime) < 1000 * 2) {
+                            continue;
+                        }
+                        break;
+                    }
+
+                    for (JSONObject path : executePathList) {
                         while (true) {
                             JSONObject realFakeStatus = fakeStatusMap.get(key);
                             Integer errorCode = realFakeStatus.getInteger("errorCode");
                             if (errorCode > 0) {
+                                continue;
+                            }
+                            break;
+                        }
+
+                        while (true) {
+                            if((System.currentTimeMillis() - startTime) < 1000 * 1) {
                                 continue;
                             }
                             break;
@@ -353,13 +404,14 @@
                         fakeStatus.put("currentCode", JSON.toJSONString(point));
                         fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
                         fakeStatusMap.put(key, fakeStatus);
-                        Thread.sleep(2000);
+                        startTime = System.currentTimeMillis();
                     }
 
                     fakeStatus.put("deviceStatus", 1);//璁惧绌洪棽
                     fakeStatusMap.put(key, fakeStatus);
+                    redisUtil.del(finalKey);
                 }
-            }catch (Exception e){
+            } catch (Exception e) {
                 e.printStackTrace();
             }
         }).start();

--
Gitblit v1.9.1