From a7d5e6c4a45ca1f7bb1560ef4e76f4c1680c41db Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期六, 18 五月 2024 10:43:29 +0800
Subject: [PATCH] #

---
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java |  127 ++++++++++++++++++++++++++++++------------
 1 files changed, 90 insertions(+), 37 deletions(-)

diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java
index 1934fc0..9fc734c 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/core/utils/NavigateSolution.java
@@ -1,6 +1,10 @@
 package com.zy.asrs.wcs.core.utils;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.zy.asrs.framework.common.SpringUtils;
 import com.zy.asrs.wcs.core.model.NavigateNode;
+import com.zy.asrs.wcs.system.entity.Dict;
+import com.zy.asrs.wcs.system.service.DictService;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -12,20 +16,22 @@
  */
 public class NavigateSolution {
 
-    // -1 -> 澧欏锛� 1 -> 璧风偣  2 -> 缁堢偣  3-> 姣嶈建  4->绔欑偣
+    // -1 -> 澧欏锛� 0 -> 璐т綅锛� 1 -> 璧风偣  2 -> 缁堢偣  3-> 姣嶈建  4->绔欑偣
 
     int[][] map = {{}};
 
     public NavigateSolution() {
         //杞藉叆鍦板浘
-        NavigateMapData mapData = new NavigateMapData();
+        NavigateMapData mapData = SpringUtils.getBean(NavigateMapData.class);
+        mapData.setLev(1);
         int[][] data = mapData.getData();
         this.map = data;
     }
 
     public NavigateSolution(Integer mapType, Integer lev, List<int[]> whitePoints, List<int[]> shuttlePoints) {
         //杞藉叆鍦板浘鎸囧畾灞傞珮鍦板浘
-        NavigateMapData mapData = new NavigateMapData(lev);
+        NavigateMapData mapData = SpringUtils.getBean(NavigateMapData.class);
+        mapData.setLev(lev);
         int[][] data = mapData.getDataFromRedis(mapType, whitePoints, shuttlePoints);
         if (data == null) {
             data = mapData.getData(mapType, whitePoints, shuttlePoints);
@@ -94,6 +100,18 @@
 
 
     public ArrayList<NavigateNode> extend_current_node(NavigateNode current_node) {
+        //榛樿鍦板浘姣嶈建鏂瑰悜x
+        String mapDirection = "x";
+        DictService dictService = SpringUtils.getBean(DictService.class);
+        if (dictService != null) {
+            Dict dict = dictService.getOne(new LambdaQueryWrapper<Dict>()
+                    .eq(Dict::getFlag, "direction_map")
+                    .eq(Dict::getStatus, 1));
+            if (dict != null) {
+                mapDirection = dict.getValue();
+            }
+        }
+
         //鑾峰彇褰撳墠缁撶偣鐨剎, y
         int x = current_node.getX();
         int y = current_node.getY();
@@ -126,31 +144,62 @@
 //                neighbour_node.add(node);
 //            }
 //        }
-        if (map[x][y] == 3) {
-            //姣嶈建鎵嶈兘杩涜宸﹀彸绉诲姩
-            if (is_valid(x, y + 1))
-            {
-                NavigateNode node = new NavigateNode(x, y + 1);
-                neighbour_node.add(node);
-            }
-            if (is_valid(x, y - 1))
-            {
-                NavigateNode node = new NavigateNode(x, y - 1);
-                neighbour_node.add(node);
-            }
-        }
 
-        if (map[x][y] == 0 || map[x][y] == 3 || map[x][y] == 4 || map[x][y] == 5) {
-            //瀛愯建鍜屾瘝杞ㄣ�佽緭閫佺嚎銆佸厖鐢垫々鎵嶈兘杩涜涓婁笅绉诲姩
-            if (is_valid(x + 1, y))
-            {
-                NavigateNode node = new NavigateNode(x + 1, y);
-                neighbour_node.add(node);
+        if (mapDirection.equals("x")) {//姣嶈建x鏂瑰悜
+            if (map[x][y] == 3) {
+                //姣嶈建鎵嶈兘杩涜涓婁笅绉诲姩
+                if (is_valid(x + 1, y))
+                {
+                    NavigateNode node = new NavigateNode(x + 1, y);
+                    neighbour_node.add(node);
+                }
+                if (is_valid(x - 1, y))
+                {
+                    NavigateNode node = new NavigateNode(x -1, y);
+                    neighbour_node.add(node);
+                }
             }
-            if (is_valid(x - 1, y))
-            {
-                NavigateNode node = new NavigateNode(x -1, y);
-                neighbour_node.add(node);
+
+            if (map[x][y] == 0 || map[x][y] == 3 || map[x][y] == 4 || map[x][y] == 5) {
+                //瀛愯建鍜屾瘝杞ㄣ�佽緭閫佺嚎銆佸厖鐢垫々鎵嶈兘杩涜宸﹀彸绉诲姩
+                if (is_valid(x, y + 1))
+                {
+                    NavigateNode node = new NavigateNode(x, y + 1);
+                    neighbour_node.add(node);
+                }
+                if (is_valid(x, y - 1))
+                {
+                    NavigateNode node = new NavigateNode(x, y - 1);
+                    neighbour_node.add(node);
+                }
+            }
+        }else if (mapDirection.equals("y")) {//姣嶈建y鏂瑰悜
+            if (map[x][y] == 3) {
+                //姣嶈建鎵嶈兘杩涜宸﹀彸绉诲姩
+                if (is_valid(x, y + 1))
+                {
+                    NavigateNode node = new NavigateNode(x, y + 1);
+                    neighbour_node.add(node);
+                }
+                if (is_valid(x, y - 1))
+                {
+                    NavigateNode node = new NavigateNode(x, y - 1);
+                    neighbour_node.add(node);
+                }
+            }
+
+            if (map[x][y] == 0 || map[x][y] == 3 || map[x][y] == 4 || map[x][y] == 5) {
+                //瀛愯建鍜屾瘝杞ㄣ�佽緭閫佺嚎銆佸厖鐢垫々鎵嶈兘杩涜涓婁笅绉诲姩
+                if (is_valid(x + 1, y))
+                {
+                    NavigateNode node = new NavigateNode(x + 1, y);
+                    neighbour_node.add(node);
+                }
+                if (is_valid(x - 1, y))
+                {
+                    NavigateNode node = new NavigateNode(x -1, y);
+                    neighbour_node.add(node);
+                }
             }
         }
 
@@ -158,19 +207,23 @@
     }
 
     public boolean is_valid(int x, int y) {
-        // 濡傛灉缁撶偣鐨勪綅缃皬浜�0锛屽垯涓嶅悎娉�
-        if (map[x][y] < 0) return false;
-        for (NavigateNode node : Exist) {
-            //濡傛灉缁撶偣鍑虹幇杩囷紝涓嶅悎娉�
-            if (node.getX() == x && node.getY() == y) {
-                return false;
+        try {
+            // 濡傛灉缁撶偣鐨勪綅缃皬浜�0锛屽垯涓嶅悎娉�
+            if (map[x][y] < 0) return false;
+            for (NavigateNode node : Exist) {
+                //濡傛灉缁撶偣鍑虹幇杩囷紝涓嶅悎娉�
+                if (node.getX() == x && node.getY() == y) {
+                    return false;
+                }
+                if (is_exist(new NavigateNode(x, y))) {
+                    return false;
+                }
             }
-            if (is_exist(new NavigateNode(x, y))) {
-                return false;
-            }
+            //浠ヤ笂鎯呭喌閮芥病鏈夊垯鍚堟硶
+            return true;
+        } catch (Exception e) {
+            return false;
         }
-        //浠ヤ笂鎯呭喌閮芥病鏈夊垯鍚堟硶
-        return true;
     }
 
     public boolean is_exist(NavigateNode node)

--
Gitblit v1.9.1