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 | 140 ++++++++++++++++++++++++++--------------------
1 files changed, 78 insertions(+), 62 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 5a58ada..afdae1d 100644
--- a/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
+++ b/src/main/java/com/zy/core/thread/fake/FakeNyShuttleThread.java
@@ -267,8 +267,13 @@
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);
@@ -276,8 +281,13 @@
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);
@@ -285,16 +295,24 @@
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);
+ startTime = System.currentTimeMillis();
if (batteryPower >= 100) {
break;
}
@@ -306,8 +324,13 @@
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);
@@ -315,8 +338,13 @@
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");
@@ -326,74 +354,62 @@
fakeStatus.put("deviceStatus", 1);//璁惧绌洪棽
fakeStatusMap.put(key, fakeStatus);
} else if (commandType.equals("move")) {
- boolean firstMove = true;
-
String baseCommandKey = RedisKeyType.FAKE_SHUTTLE_MOVE_EXECUTE_COMMAND_LIST.key + deviceConfig.getDeviceNo() + "_";
- Set<String> keys = redisUtil.searchKeys(baseCommandKey);
-
- if (!keys.isEmpty()) {
- firstMove = false;
+ 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);
-
- String finalKey = baseCommandKey + System.currentTimeMillis();
- redisUtil.set(finalKey, list);
-
- if(!firstMove) {
- return;
- }
+ List<JSONObject> executePathList = JSON.parseArray(pathList, JSONObject.class);
fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
fakeStatusMap.put(key, fakeStatus);
- Thread.sleep(2000);
-
+ long startTime = System.currentTimeMillis();
while (true) {
- Set<String> searchKeys = redisUtil.searchKeys(baseCommandKey);
- if(searchKeys.isEmpty()) {
- break;
+ if((System.currentTimeMillis() - startTime) < 1000 * 2) {
+ continue;
}
+ break;
+ }
- TreeSet<String> treeSet = new TreeSet<>();
- for (String tmpKey : searchKeys) {
- treeSet.add(tmpKey);
- }
-
- String first = treeSet.first();
-
- Object object = redisUtil.get(first);
- if(object == null) {
- break;
- }
-
- List<JSONObject> executePathList = (List<JSONObject>) object;
- for (JSONObject path : executePathList) {
- while (true) {
- JSONObject realFakeStatus = fakeStatusMap.get(key);
- Integer errorCode = realFakeStatus.getInteger("errorCode");
- if (errorCode > 0) {
- continue;
- }
- break;
+ for (JSONObject path : executePathList) {
+ while (true) {
+ JSONObject realFakeStatus = fakeStatusMap.get(key);
+ Integer errorCode = realFakeStatus.getInteger("errorCode");
+ if (errorCode > 0) {
+ continue;
}
-
- String currentCode = fakeStatus.getString("currentCode");
- JSONObject point = JSON.parseObject(currentCode);
- point.put("x", path.getInteger("xp"));
- point.put("y", path.getInteger("yp"));
- point.put("z", path.getInteger("z"));
- fakeStatus.put("currentCode", JSON.toJSONString(point));
- fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
- fakeStatusMap.put(key, fakeStatus);
- Thread.sleep(2000);
+ break;
}
- redisUtil.del(first);
+
+ while (true) {
+ if((System.currentTimeMillis() - startTime) < 1000 * 1) {
+ continue;
+ }
+ break;
+ }
+
+ String currentCode = fakeStatus.getString("currentCode");
+ JSONObject point = JSON.parseObject(currentCode);
+ point.put("x", path.getInteger("xp"));
+ point.put("y", path.getInteger("yp"));
+ point.put("z", path.getInteger("z"));
+ fakeStatus.put("currentCode", JSON.toJSONString(point));
+ fakeStatus.put("deviceStatus", 0);//璁惧蹇欑
+ fakeStatusMap.put(key, fakeStatus);
+ startTime = System.currentTimeMillis();
}
fakeStatus.put("deviceStatus", 1);//璁惧绌洪棽
fakeStatusMap.put(key, fakeStatus);
+ redisUtil.del(finalKey);
}
} catch (Exception e) {
e.printStackTrace();
--
Gitblit v1.9.1