From c34f9c17fde14f78b3663803e9776d438e8481b9 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 21 三月 2026 22:30:14 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java |   62 ++++++++++++++++++-------------
 1 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java b/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
index 86f57a8..19b3642 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
@@ -383,20 +383,8 @@
             }
 
             int segCursor = 0;
-            while (true) {
-                CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor));
-                if (commandResponse == null) {
-                    try {
-                        Thread.sleep(200);
-                    } catch (Exception ignore) {}
-                    continue;
-                }
-                if (commandResponse.getResult()) {
-                    break;
-                }
-                try {
-                    Thread.sleep(200);
-                } catch (Exception ignore) {}
+            if (!sendSegmentWithRetry(segmentCommands.get(segCursor), original.getTaskNo())) {
+                return;
             }
 
             long runTime = System.currentTimeMillis();
@@ -437,18 +425,8 @@
                     int thresholdSegment = (int) Math.ceil(segLen * segmentAdvanceRatio);
                     if (remainingSegment <= thresholdSegment && segCursor < segmentCommands.size() - 1) {
                         segCursor++;
-                        while (true) {
-                            CommandResponse commandResponse = sendCommand(segmentCommands.get(segCursor));
-                            if (commandResponse == null) {
-                                Thread.sleep(200);
-                                continue;
-                            }
-
-                            if (commandResponse.getResult()) {
-                                break;
-                            }
-
-                            Thread.sleep(200);
+                        if (!sendSegmentWithRetry(segmentCommands.get(segCursor), original.getTaskNo())) {
+                            break;
                         }
                     }
                     Thread.sleep(500);
@@ -535,4 +513,36 @@
         }
         return null;
     }
+
+    private boolean sendSegmentWithRetry(StationCommand command, Integer taskNo) {
+        while (true) {
+            if (isTaskMoveReset(taskNo)) {
+                return false;
+            }
+            CommandResponse commandResponse = sendCommand(command);
+            if (commandResponse == null) {
+                sleepQuietly(200L);
+                continue;
+            }
+            if (commandResponse.getResult()) {
+                return true;
+            }
+            sleepQuietly(200L);
+        }
+    }
+
+    private boolean isTaskMoveReset(Integer taskNo) {
+        if (taskNo == null || redisUtil == null) {
+            return false;
+        }
+        Object cancel = redisUtil.get(RedisKeyType.DEVICE_STATION_MOVE_RESET.key + taskNo);
+        return cancel != null;
+    }
+
+    private void sleepQuietly(long millis) {
+        try {
+            Thread.sleep(millis);
+        } catch (Exception ignore) {
+        }
+    }
 }

--
Gitblit v1.9.1