From 103ca74d9b67ce4f766b5f77451741a76fa696b9 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期日, 22 三月 2026 09:50:10 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java |   85 ++++++++++++++++++++++++++++++++----------
 1 files changed, 64 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java b/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
index 55db83b..bcbe804 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
@@ -3,7 +3,7 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.core.common.Cools;
 import com.core.common.DateUtils;
 import com.core.common.SpringUtils;
@@ -30,6 +30,7 @@
 import com.zy.core.network.DeviceConnectPool;
 import com.zy.core.network.ZyStationConnectDriver;
 import com.zy.core.network.entity.ZyStationStatusEntity;
+import com.zy.core.utils.DeviceLogRedisKeyBuilder;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 
@@ -115,7 +116,7 @@
             }
 
             BasDevp basDevp = basDevpService
-                    .selectOne(new EntityWrapper<BasDevp>().eq("devp_no", deviceConfig.getDeviceNo()));
+                    .getOne(new QueryWrapper<BasDevp>().eq("devp_no", deviceConfig.getDeviceNo()));
             if (basDevp == null) {
                 return;
             }
@@ -169,7 +170,7 @@
             deviceDataLog.setDeviceNo(deviceConfig.getDeviceNo());
             deviceDataLog.setCreateTime(new Date());
 
-            redisUtil.set(RedisKeyType.DEVICE_LOG_KEY.key + System.currentTimeMillis(), deviceDataLog, 60 * 60 * 24);
+            redisUtil.set(DeviceLogRedisKeyBuilder.build(deviceDataLog), deviceDataLog, 60 * 60 * 24);
             deviceDataLogTime = System.currentTimeMillis();
         }
     }
@@ -208,6 +209,16 @@
 
     @Override
     public StationCommand getCommand(StationCommandType commandType, Integer taskNo, Integer stationId, Integer targetStationId, Integer palletSize) {
+        return getCommand(commandType, taskNo, stationId, targetStationId, palletSize, null);
+    }
+
+    @Override
+    public StationCommand getCommand(StationCommandType commandType,
+                                     Integer taskNo,
+                                     Integer stationId,
+                                     Integer targetStationId,
+                                     Integer palletSize,
+                                     Double pathLenFactor) {
         StationCommand stationCommand = new StationCommand();
         stationCommand.setTaskNo(taskNo);
         stationCommand.setStationId(stationId);
@@ -217,7 +228,12 @@
 
         if (commandType == StationCommandType.MOVE) {
             if (!stationId.equals(targetStationId)) {
-                List<Integer> path = calcPathStationIds(stationId, targetStationId);
+                List<Integer> path = calcPathStationIds(taskNo, stationId, targetStationId, pathLenFactor);
+                if (path == null || path.isEmpty()) {
+                    log.warn("杈撻�佺嚎鍛戒护鐢熸垚澶辫触锛岃矾寰勪负绌猴紝taskNo={}, stationId={}, targetStationId={}",
+                            taskNo, stationId, targetStationId);
+                    return null;
+                }
                 stationCommand.setNavigatePath(path);
             }
         }
@@ -259,7 +275,7 @@
                     JSON.toJSONString(commandResponse)
             );
             if (optService != null) {
-                optService.insert(basStationOpt);
+                optService.save(basStationOpt);
             }
         }
         return commandResponse;
@@ -275,12 +291,15 @@
         return zyStationConnectDriver.readOriginCommand(address, length);
     }
 
-    private List<Integer> calcPathStationIds(Integer startStationId, Integer targetStationId) {
+    private List<Integer> calcPathStationIds(Integer taskNo,
+                                             Integer startStationId,
+                                             Integer targetStationId,
+                                             Double pathLenFactor) {
         NavigateUtils navigateUtils = SpringUtils.getBean(NavigateUtils.class);
         if (navigateUtils == null) {
             return new ArrayList<>();
         }
-        List<NavigateNode> nodes = navigateUtils.calcByStationId(startStationId, targetStationId);
+        List<NavigateNode> nodes = navigateUtils.calcByStationId(startStationId, targetStationId, taskNo, pathLenFactor);
         List<Integer> ids = new ArrayList<>();
         for (NavigateNode n : nodes) {
             JSONObject v = JSONObject.parseObject(n.getNodeValue());
@@ -333,7 +352,9 @@
             segCmd.setCommandType(original.getCommandType());
             segCmd.setPalletSize(original.getPalletSize());
             segCmd.setNavigatePath(new ArrayList<>(path.subList(0, currentEndIdx + 1)));
-            sendCommand(segCmd);
+            if (!sendSegmentWithRetry(segCmd, original.getTaskNo())) {
+                return;
+            }
 
             long runTime = System.currentTimeMillis();
             boolean firstRun = true;
@@ -384,18 +405,8 @@
                         nextCmd.setPalletSize(original.getPalletSize());
                         nextCmd.setNavigatePath(new ArrayList<>(path.subList(currentStartIdx, currentEndIdx + 1)));
                         nextCmd.setOriginalNavigatePath(path);
-                        while (true) {
-                            CommandResponse commandResponse = sendCommand(nextCmd);
-                            if (commandResponse == null) {
-                                Thread.sleep(200);
-                                continue;
-                            }
-
-                            if (commandResponse.getResult()) {
-                                break;
-                            }
-
-                            Thread.sleep(200);
+                        if (!sendSegmentWithRetry(nextCmd, original.getTaskNo())) {
+                            break;
                         }
                     }
                     Thread.sleep(500);
@@ -415,7 +426,7 @@
             if (deviceConfigService == null) {
                 return null;
             }
-            List<DeviceConfig> devpList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
+            List<DeviceConfig> devpList = deviceConfigService.list(new QueryWrapper<DeviceConfig>()
                     .eq("device_type", String.valueOf(SlaveType.Devp)));
             for (DeviceConfig dc : devpList) {
                 com.zy.core.thread.StationThread t = (com.zy.core.thread.StationThread) SlaveConnection.get(SlaveType.Devp, dc.getDeviceNo());
@@ -437,4 +448,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