From d193355c76cfbec572408f9a256c970699c9a542 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期三, 18 三月 2026 15:12:55 +0800
Subject: [PATCH] #

---
 src/main/resources/sql/20260318_add_station_command_segment_advance_ratio.sql |   15 +++++++
 src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java                  |   52 +++++++++++++++++++++++++
 2 files changed, 66 insertions(+), 1 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 8f63434..2cfd566 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV4Thread.java
@@ -31,6 +31,8 @@
 import com.zy.core.network.ZyStationConnectDriver;
 import com.zy.core.network.entity.ZyStationStatusEntity;
 import com.zy.core.utils.DeviceLogRedisKeyBuilder;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
@@ -42,6 +44,8 @@
 @Data
 @Slf4j
 public class ZyStationV4Thread implements Runnable, com.zy.core.thread.StationThread {
+    private static final String CFG_STATION_COMMAND_SEGMENT_ADVANCE_RATIO = "stationCommandSegmentAdvanceRatio";
+    private static final double DEFAULT_STATION_COMMAND_SEGMENT_ADVANCE_RATIO = 0.3d;
 
     private List<StationProtocol> statusList = new ArrayList<>();
     private DeviceConfig deviceConfig;
@@ -303,6 +307,7 @@
     }
 
     private void executeMoveWithSeg(StationCommand original) {
+        double segmentAdvanceRatio = loadSegmentAdvanceRatio();
         if(original.getCommandType() == StationCommandType.MOVE){
             List<Integer> path = JSON.parseArray(JSON.toJSONString(original.getNavigatePath(), SerializerFeature.DisableCircularReferenceDetect), Integer.class);
             List<Integer> liftTransferPath = JSON.parseArray(JSON.toJSONString(original.getLiftTransferPath(), SerializerFeature.DisableCircularReferenceDetect), Integer.class);
@@ -424,7 +429,7 @@
                     int currentSegStartIndex = segCursor == 0 ? 0 : segmentEndIndices.get(segCursor - 1);
                     int segLen = currentSegEndIndex - currentSegStartIndex + 1;
                     int remainingSegment = Math.max(0, currentSegEndIndex - currentIndex);
-                    int thresholdSegment = (int) Math.ceil(segLen * 0.3);
+                    int thresholdSegment = (int) Math.ceil(segLen * segmentAdvanceRatio);
                     if (remainingSegment <= thresholdSegment && segCursor < segmentCommands.size() - 1) {
                         segCursor++;
                         while (true) {
@@ -452,6 +457,51 @@
         }
     }
 
+    private double loadSegmentAdvanceRatio() {
+        try {
+            ConfigService configService = SpringUtils.getBean(ConfigService.class);
+            if (configService == null) {
+                return DEFAULT_STATION_COMMAND_SEGMENT_ADVANCE_RATIO;
+            }
+            Config config = configService.getOne(new QueryWrapper<Config>()
+                    .eq("code", CFG_STATION_COMMAND_SEGMENT_ADVANCE_RATIO));
+            if (config == null || Cools.isEmpty(config.getValue())) {
+                return DEFAULT_STATION_COMMAND_SEGMENT_ADVANCE_RATIO;
+            }
+            return normalizeSegmentAdvanceRatio(config.getValue());
+        } catch (Exception ignore) {
+            return DEFAULT_STATION_COMMAND_SEGMENT_ADVANCE_RATIO;
+        }
+    }
+
+    private double normalizeSegmentAdvanceRatio(String valueText) {
+        if (valueText == null) {
+            return DEFAULT_STATION_COMMAND_SEGMENT_ADVANCE_RATIO;
+        }
+        String text = valueText.trim();
+        if (text.isEmpty()) {
+            return DEFAULT_STATION_COMMAND_SEGMENT_ADVANCE_RATIO;
+        }
+        if (text.endsWith("%")) {
+            text = text.substring(0, text.length() - 1).trim();
+        }
+        try {
+            double ratio = Double.parseDouble(text);
+            if (ratio > 1d && ratio <= 100d) {
+                ratio = ratio / 100d;
+            }
+            if (ratio < 0d) {
+                return 0d;
+            }
+            if (ratio > 1d) {
+                return 1d;
+            }
+            return ratio;
+        } catch (Exception ignore) {
+            return DEFAULT_STATION_COMMAND_SEGMENT_ADVANCE_RATIO;
+        }
+    }
+
     private StationProtocol findCurrentStationByTask(Integer taskNo) {
         try {
             com.zy.asrs.service.DeviceConfigService deviceConfigService = SpringUtils.getBean(com.zy.asrs.service.DeviceConfigService.class);
diff --git a/src/main/resources/sql/20260318_add_station_command_segment_advance_ratio.sql b/src/main/resources/sql/20260318_add_station_command_segment_advance_ratio.sql
new file mode 100644
index 0000000..7285179
--- /dev/null
+++ b/src/main/resources/sql/20260318_add_station_command_segment_advance_ratio.sql
@@ -0,0 +1,15 @@
+-- 杈撻�佺珯鐐瑰垎娈靛懡浠ゆ彁鍓嶄笅鍙戞瘮渚�
+-- 鏀寔 0.3 / 30 / 30% 涓夌鍐欐硶锛屼唬鐮佷晶浼氱粺涓�杞崲涓� 0~1 鍖洪棿姣斾緥
+
+INSERT INTO sys_config(name, code, value, type, status, select_type)
+SELECT '杈撻�佺珯鐐瑰垎娈垫彁鍓嶄笅鍙戞瘮渚�', 'stationCommandSegmentAdvanceRatio', '0.3', 1, 1, 'system'
+FROM dual
+WHERE NOT EXISTS (
+    SELECT 1
+    FROM sys_config
+    WHERE code = 'stationCommandSegmentAdvanceRatio'
+);
+
+SELECT id, name, code, value, type, status, select_type
+FROM sys_config
+WHERE code = 'stationCommandSegmentAdvanceRatio';

--
Gitblit v1.9.1