From 03c3ae747f82ad22c761c79e7b1c0e0031c57d41 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 06 四月 2026 20:28:35 +0800
Subject: [PATCH] #出库站点命令下发

---
 src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java |   47 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 44 insertions(+), 3 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 af286c8..63d81b4 100644
--- a/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
+++ b/src/main/java/com/zy/core/thread/impl/ZyStationV3Thread.java
@@ -30,6 +30,8 @@
 import com.zy.core.network.DeviceConnectPool;
 import com.zy.core.network.ZyStationConnectDriver;
 import com.zy.core.network.entity.ZyStationStatusEntity;
+import com.zy.core.thread.support.RecentStationArrivalTracker;
+import com.zy.core.thread.support.StationErrLogSupport;
 import com.zy.core.utils.DeviceLogRedisKeyBuilder;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
@@ -40,6 +42,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -48,16 +51,19 @@
 public class ZyStationV3Thread implements Runnable, com.zy.core.thread.StationThread {
 
     private List<StationProtocol> statusList = new ArrayList<>();
+    private volatile List<Integer> taskNoList = new ArrayList<>();
     private DeviceConfig deviceConfig;
     private RedisUtil redisUtil;
     private ZyStationConnectDriver zyStationConnectDriver;
     private int deviceLogCollectTime = 200;
     private long deviceDataLogTime = System.currentTimeMillis();
     private ExecutorService executor = Executors.newFixedThreadPool(9999);
+    private final RecentStationArrivalTracker recentArrivalTracker;
 
     public ZyStationV3Thread(DeviceConfig deviceConfig, RedisUtil redisUtil) {
         this.deviceConfig = deviceConfig;
         this.redisUtil = redisUtil;
+        this.recentArrivalTracker = new RecentStationArrivalTracker(redisUtil);
     }
 
     @Override
@@ -130,6 +136,7 @@
         }
 
         List<ZyStationStatusEntity> zyStationStatusEntities = zyStationConnectDriver.getStatus();
+        LinkedHashSet<Integer> taskNoSet = new LinkedHashSet<>();
         for (ZyStationStatusEntity statusEntity : zyStationStatusEntities) {
             for (StationProtocol stationProtocol : statusList) {
                 if (stationProtocol.getStationId().equals(statusEntity.getStationId())) {
@@ -148,6 +155,10 @@
                     stationProtocol.setRunBlock(statusEntity.isRunBlock());
                     stationProtocol.setEnableIn(statusEntity.isEnableIn());
                     stationProtocol.setWeight(statusEntity.getWeight());
+                    if (statusEntity.getTaskNo() != null && statusEntity.getTaskNo() > 0) {
+                        taskNoSet.add(statusEntity.getTaskNo());
+                    }
+                    recentArrivalTracker.observe(statusEntity.getStationId(), statusEntity.getTaskNo(), statusEntity.isLoading());
                 }
 
                 if (!Cools.isEmpty(stationProtocol.getSystemWarning())) {
@@ -159,8 +170,10 @@
                 }
             }
         }
+        taskNoList = new ArrayList<>(taskNoSet);
 
         OutputQueue.DEVP.offer(MessageFormat.format("銆恵0}銆慬id:{1}] <<<<< 瀹炴椂鏁版嵁鏇存柊鎴愬姛", DateUtils.convert(new Date()), deviceConfig.getDeviceNo()));
+        StationErrLogSupport.sync(deviceConfig, redisUtil, statusList);
 
         if (System.currentTimeMillis() - deviceDataLogTime > deviceLogCollectTime) {
             DeviceDataLog deviceDataLog = new DeviceDataLog();
@@ -208,7 +221,27 @@
     }
 
     @Override
+    public List<Integer> getAllTaskNoList() {
+        return taskNoList;
+    }
+
+    @Override
+    public boolean hasRecentArrival(Integer stationId, Integer taskNo) {
+        return recentArrivalTracker.hasRecentArrival(stationId, taskNo);
+    }
+
+    @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);
@@ -218,7 +251,7 @@
 
         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);
@@ -281,12 +314,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.calcOptimalPathByStationId(startStationId, targetStationId, taskNo, pathLenFactor);
         List<Integer> ids = new ArrayList<>();
         for (NavigateNode n : nodes) {
             JSONObject v = JSONObject.parseObject(n.getNodeValue());
@@ -467,4 +503,9 @@
         } catch (Exception ignore) {
         }
     }
+
+    @Override
+    public boolean clearPath(Integer taskNo) {
+        return false;
+    }
 }

--
Gitblit v1.9.1