From 642f20dd1b068e23146b8ec96c5eac8b63c96b87 Mon Sep 17 00:00:00 2001
From: jianghaiyue <jianghaiyue@zkyt.com>
Date: 星期三, 05 十一月 2025 18:18:25 +0800
Subject: [PATCH] 优化更新

---
 algo-zkd/src/main/java/com/algo/service/PathPlanningService.java |   62 ++++++++++++++++++++++++++++---
 1 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/algo-zkd/src/main/java/com/algo/service/PathPlanningService.java b/algo-zkd/src/main/java/com/algo/service/PathPlanningService.java
index 1d93b85..54b0e54 100644
--- a/algo-zkd/src/main/java/com/algo/service/PathPlanningService.java
+++ b/algo-zkd/src/main/java/com/algo/service/PathPlanningService.java
@@ -170,7 +170,7 @@
 
         System.out.println("姝ラ2: 澶勭悊鏈夊墿浣欒矾寰勭殑CTU");
         for (AGVStatus agv : ctuWithRemainingPaths) {
-            PlannedPath remainingPath = processRemainingPath(agv);
+            PlannedPath remainingPath = processRemainingPath(agv, unifiedTimestamp);
             if (remainingPath != null) {
                 plannedPaths.add(remainingPath);
                 plannedAgvIds.put(agv.getAgvId(), "REMAINING_PATH");
@@ -299,6 +299,9 @@
         // 7.5. 鏈�缁堥伩璁╂鏌�
         performFinalYieldingCheck(agvStatusList, plannedPaths, plannedAgvIds, spaceTimeOccupancyMap, constraints, unifiedTimestamp);
 
+        // 7.6. 閲嶆柊璁$畻鎵�鏈夎矾寰勭殑鏃堕棿鎴�
+        recalculateAllPathTimings(plannedPaths, agvStatusList, unifiedTimestamp);
+
         // 8. 鏈�缁堢鎾炴娴嬪拰瑙e喅
         System.out.println("姝ラ6: 鏈�缁堢鎾炴娴�");
         List<Conflict> conflicts = collisionDetector.detectConflicts(plannedPaths);
@@ -341,9 +344,10 @@
      * 澶勭悊CTU鐨勫墿浣欒矾寰�
      *
      * @param agv CTU鐘舵��
+     * @param unifiedTimestamp 缁熶竴鏃堕棿鎴筹紙绉掞級
      * @return 澶勭悊鍚庣殑璺緞
      */
-    private PlannedPath processRemainingPath(AGVStatus agv) {
+    private PlannedPath processRemainingPath(AGVStatus agv, long unifiedTimestamp) {
         if (!agv.hasRemainingPath()) {
             return null;
         }
@@ -376,8 +380,8 @@
         processedPath.setSegId(segId);
 
         if (timeCalculator != null && !remainingCodes.isEmpty()) {
-            // 鑾峰彇AGV鐨勪笅涓�涓矾寰勭偣鍒拌揪鏃堕棿浣滀负璧峰鏃堕棿
-            long startTime = agv.getNextPointArrivalTime();
+            // 浣跨敤缁熶竴鏃堕棿鎴充綔涓鸿捣濮嬫椂闂达紙杞崲涓烘绉掞級
+            long startTime = unifiedTimestamp * 1000;
             
             CTUPhysicalConfig config = agv.getPhysicalConfig();
             
@@ -619,7 +623,6 @@
             return;
         }
 
-        String actionType = "2"; // 浠诲姟绫诲瀷
         String taskId = task.getTaskId();
         int backpackLevel = task.getBackpackIndex();
 
@@ -627,20 +630,23 @@
             PathCode pathCode = codeList.get(i);
 
             // 璁剧疆鍩烘湰淇℃伅
-            pathCode.setActionType(actionType);
             pathCode.setTaskId(taskId);
             pathCode.setLev(backpackLevel);
 
             // 璁剧疆鐩爣鐐逛俊鎭�
             if (i == codeList.size() - 1) { // 鏈�鍚庝竴涓偣
                 pathCode.setTargetPoint(true);
+                // 鏍规嵁浠诲姟绫诲瀷璁剧疆actionType鍜宲osType锛�
                 if (task.isLoaded()) {
+                    pathCode.setActionType("2"); // 鏀捐揣
                     pathCode.setPosType("2"); // 鏀捐揣
                 } else {
+                    pathCode.setActionType("1"); // 鍙栬揣
                     pathCode.setPosType("1"); // 鍙栬揣
                 }
             } else {
                 pathCode.setTargetPoint(false);
+                pathCode.setActionType(null); 
                 pathCode.setPosType(null);
             }
         }
@@ -796,6 +802,50 @@
         }
     }
 
+    private void recalculateAllPathTimings(List<PlannedPath> plannedPaths, 
+                                           List<AGVStatus> agvStatusList, 
+                                           long unifiedTimestamp) {
+        if (plannedPaths == null || plannedPaths.isEmpty() || timeCalculator == null) {
+            return;
+        }
+
+        Map<String, AGVStatus> agvStatusMap = new HashMap<>();
+        for (AGVStatus agv : agvStatusList) {
+            if (agv.getAgvId() != null) {
+                agvStatusMap.put(agv.getAgvId(), agv);
+            }
+        }
+
+        long startTimeMs = unifiedTimestamp * 1000;
+        int recalculatedCount = 0;
+
+        // 閬嶅巻鎵�鏈夎矾寰勶紝閲嶆柊璁$畻鏃堕棿鎴�
+        for (PlannedPath path : plannedPaths) {
+            if (path == null || path.getCodeList() == null || path.getCodeList().isEmpty()) {
+                continue;
+            }
+
+            String agvId = path.getAgvId();
+            if (agvId == null) {
+                continue;
+            }
+
+            // 鑾峰彇AGV鐨勭墿鐞嗛厤缃�
+            AGVStatus agvStatus = agvStatusMap.get(agvId);
+            CTUPhysicalConfig config = (agvStatus != null && agvStatus.getPhysicalConfig() != null) 
+                    ? agvStatus.getPhysicalConfig() 
+                    : new CTUPhysicalConfig(); 
+
+            double initialSpeed = 0.0;
+
+            // 閲嶆柊璁$畻璺緞鏃堕棿鎴�
+            timeCalculator.calculatePathTiming(path, startTimeMs, config, initialSpeed);
+            recalculatedCount++;
+        }
+
+        System.out.println("  宸查噸鏂拌绠� " + recalculatedCount + " 鏉¤矾寰勭殑鏃堕棿鎴筹紙缁熶竴鏃堕棿鍩哄噯: " + unifiedTimestamp + "绉掞級");
+    }
+
     /**
      * 璇嗗埆闇�瑕佽琛岀殑AGV
      * 妫�鏌ョ┖闂睞GV鏄惁鍗犵敤浜嗗叾浠朅GV鍓╀綑璺緞涓婄殑浣嶇疆

--
Gitblit v1.9.1