From b3814333d786324bb81cca7d1bcf5ac8f2f1a7cf Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期三, 23 七月 2025 08:35:33 +0800
Subject: [PATCH] 保存一个版本

---
 zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java |   63 +++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java
index 0a2285c..b1323c5 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/core/service/astart/MapDataDispatcher.java
@@ -6,6 +6,7 @@
 import com.zy.acs.common.utils.RedisSupport;
 import com.zy.acs.framework.common.Cools;
 import com.zy.acs.framework.exception.CoolException;
+import com.zy.acs.manager.common.utils.MapDataUtils;
 import com.zy.acs.manager.core.service.astart.domain.DynamicNode;
 import com.zy.acs.manager.core.utils.RouteGenerator;
 import com.zy.acs.manager.manager.entity.Code;
@@ -14,13 +15,17 @@
 import com.zy.acs.manager.manager.service.CodeService;
 import com.zy.acs.manager.manager.service.RouteService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import java.util.*;
 
 /**
  * Created by vincent on 6/6/2024
  */
 @Slf4j
+@Service
 public class MapDataDispatcher {
 
     public static final Integer MAP_DEFAULT_LEV = 1;
@@ -36,17 +41,26 @@
 
     private int[][] turnMatrix;
 
-    private String[][] cdaMatrix;
+    private Double[][][] cdaMatrix;
 
     public Map<String, Boolean> routeCdaMap = new HashMap<>();
 
-    private final CodeService codeService;
+    @Autowired
+    private CodeService codeService;
 
-    private final RouteService routeService;
+    @Autowired
+    private RouteService routeService;
 
-    public MapDataDispatcher(CodeService codeService, RouteService routeService) {
-        this.codeService = codeService;
-        this.routeService = routeService;
+    @PostConstruct
+    public void init() {
+        String[][] codeMatrix = this.getCodeMatrix(null);
+        this.initRouteMap(null);
+        if (codeMatrix.length > 0) {
+            this.getMapMatrix(null, null);
+            this.getTurnMatrix(null);
+            this.getCdaMatrix(null);
+            this.getDynamicMatrix(null);
+        }
     }
 
     public String[][] getWaveMatrix(Integer lev) {
@@ -89,13 +103,14 @@
         redis.setValue(RedisConstant.AGV_MAP_ASTAR_DYNAMIC_FLAG, String.valueOf(lev), JSON.toJSONString(dynamicMatrix));
     }
 
-    public String[][] getCdaMatrix(Integer lev) {
+    public Double[][][] getCdaMatrix(Integer lev) {
         lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV);
         // redis
         if (null == this.cdaMatrix) {
             String cdaMatrixStr = redis.getValue(RedisConstant.AGV_MAP_ASTAR_CDA_FLAG, String.valueOf(lev));
             if (!Cools.isEmpty(cdaMatrixStr)) {
-                this.cdaMatrix = JSON.parseObject(cdaMatrixStr, String[][].class);
+                String[][] cdaStrMatrix = JSON.parseObject(cdaMatrixStr, String[][].class);
+                this.cdaMatrix = MapDataUtils.preComputeCdaMatrix(cdaStrMatrix);
             }
         }
         // init
@@ -110,9 +125,9 @@
         return this.cdaMatrix;
     }
 
-    public void setCdaMatrix(Integer lev, String[][] cdaMatrix) {
-        redis.setValue(RedisConstant.AGV_MAP_ASTAR_CDA_FLAG, String.valueOf(lev), JSON.toJSONString(cdaMatrix));
-        this.cdaMatrix = cdaMatrix;
+    public void setCdaMatrix(Integer lev, String[][] cdaStrMatrix) {
+        redis.setValue(RedisConstant.AGV_MAP_ASTAR_CDA_FLAG, String.valueOf(lev), JSON.toJSONString(cdaStrMatrix));
+        this.cdaMatrix = MapDataUtils.preComputeCdaMatrix(cdaStrMatrix);
     }
 
     public int[][] getTurnMatrix(Integer lev) {
@@ -217,6 +232,9 @@
         lev = Optional.ofNullable(lev).orElse(MAP_DEFAULT_LEV);
 
         String[][] codeMatrix = getCodeMatrix(lev);
+        if (null == codeMatrix || codeMatrix.length == 0) {
+            return new DynamicNode[0][0];
+        }
         DynamicNode[][] dynamicMatrix = new DynamicNode[codeMatrix.length][codeMatrix[0].length];
 
         for (int i = 0; i < codeMatrix.length; i++) {
@@ -289,11 +307,20 @@
                             turnMatrix[i][j] = TurnNodeType.STRAIGHT.val;
                             break;
                         case 2:
-                            String firstCode = neighborCodeList.get(0); assert !Cools.isEmpty(firstCode);
-                            String secondCode = neighborCodeList.get(1); assert !Cools.isEmpty(secondCode);
+                            String firstCode = neighborCodeList.get(0);
+                            assert !Cools.isEmpty(firstCode);
+                            String secondCode = neighborCodeList.get(1);
+                            assert !Cools.isEmpty(secondCode);
 
                             int[] firstIdx = this.getCodeMatrixIdx(lev, firstCode);
                             int[] secondIdx = this.getCodeMatrixIdx(lev, secondCode);
+
+                            if (firstIdx == null) {
+                                throw new CoolException("涓嶅瓨鍦ㄧ偣浣�:" + firstCode);
+                            }
+                            if (secondIdx == null) {
+                                throw new CoolException("涓嶅瓨鍦ㄧ偣浣�:" + secondCode);
+                            }
 
                             if (firstIdx[0] != secondIdx[0] && firstIdx[1] != secondIdx[1]) {
                                 turnMatrix[i][j] = TurnNodeType.TURN.val;
@@ -315,7 +342,7 @@
 
         return turnMatrix;
     }
-    
+
 
     public synchronized int[][] initMapMatrix(Integer lev) {
         log.info("There is initializing Map Matrix......");
@@ -364,9 +391,9 @@
             return;
         }
         for (Route route : routeList) {
-            Code startCode = codeService.getById(route.getStartCode());
+            Code startCode = codeService.getCacheById(route.getStartCode());
             int[] startCodeIdx = getCodeMatrixIdx(lev, startCode.getData());
-            Code endCode = codeService.getById(route.getEndCode());
+            Code endCode = codeService.getCacheById(route.getEndCode());
             int[] codeMatrixIdx = getCodeMatrixIdx(lev, endCode.getData());
 
             String routeKey = RouteGenerator.generateRouteKey(startCode.getData(), endCode.getData());
@@ -398,7 +425,9 @@
         for (Code code : codeList) {
             Double x = code.getX();
             Double y = code.getY();
-            if (null == x || null == y) { continue; }
+            if (null == x || null == y) {
+                continue;
+            }
             if (!xIdxList.contains(x)) {
                 xIdxList.add(x);
             }

--
Gitblit v1.9.1