From 802c12dcbc63ee1662c15723d27c8fc1f4fd36e6 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期六, 21 十二月 2024 08:42:56 +0800
Subject: [PATCH] #拐点算法优化

---
 src/main/java/com/zy/common/utils/NyShuttleOperaUtils.java |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/zy/common/utils/NyShuttleOperaUtils.java b/src/main/java/com/zy/common/utils/NyShuttleOperaUtils.java
index d7f5d6a..fc00b05 100644
--- a/src/main/java/com/zy/common/utils/NyShuttleOperaUtils.java
+++ b/src/main/java/com/zy/common/utils/NyShuttleOperaUtils.java
@@ -22,7 +22,7 @@
      * @param startPoint 璧风偣锛堝皬杞﹀綋鍓嶄綅缃級
      * @param targetPoint 鐩爣鐐癸紙璐х墿鐩爣浣嶇疆锛�
      */
-    public static NyShuttleOperaResult getShuttleTransportCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint) {
+    public static synchronized NyShuttleOperaResult getShuttleTransportCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint) {
         //琛岃蛋璺緞
         ArrayList<NavigateNode> nodes = new ArrayList<>();
         //鍛戒护闆嗗悎
@@ -51,7 +51,7 @@
      * @param middlePoint 涓棿鐐癸紙璐х墿浣嶇疆锛�
      * @param targetPoint 鐩爣鐐癸紙璐х墿鐩爣浣嶇疆锛�
      */
-    public static NyShuttleOperaResult getShuttleTransportCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String middlePoint, String targetPoint) {
+    public static synchronized NyShuttleOperaResult getShuttleTransportCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String middlePoint, String targetPoint) {
         //琛岃蛋璺緞
         ArrayList<NavigateNode> nodes = new ArrayList<>();
         //鍛戒护闆嗗悎
@@ -86,7 +86,7 @@
     /**
      * 鑾峰彇璧风偣鍒扮洰鏍囩偣琛岃蛋鍛戒护
      */
-    public static NyShuttleOperaResult getStartToTargetCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint, Integer mapType) {
+    public static synchronized NyShuttleOperaResult getStartToTargetCommands(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint, Integer mapType) {
         NavigateMapUtils navigateMapUtils = SpringUtils.getBean(NavigateMapUtils.class);
         //璁$畻璧风偣鍒扮洰鏍囩偣琛岃蛋鑺傜偣
         List<NavigateNode> calc = NavigateUtils.calc(startPoint, targetPoint, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startPoint)), null);
@@ -114,14 +114,17 @@
             allNode.addAll(nodes);
         }
 
-        navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(startPoint), allNode, true);//閿佸畾璺緞
+        boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(startPoint), shuttleNo, allNode, true);//閿佸畾璺緞
+        if (!result) {
+            return null;//璺緞閿佸畾澶辫触
+        }
         return result(commands, calc);
     }
 
     /**
      * 鑾峰彇璧风偣鍒扮洰鏍囩偣琛岃蛋鍛戒护(鍙紶鐧藉悕鍗�)
      */
-    public static NyShuttleOperaResult getStartToTargetCommandsByWhites(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint, Integer mapType, List<int[]> whites) {
+    public static synchronized NyShuttleOperaResult getStartToTargetCommandsByWhites(Integer shuttleNo, Integer wrkNo, String startPoint, String targetPoint, Integer mapType, List<int[]> whites) {
         NavigateMapUtils navigateMapUtils = SpringUtils.getBean(NavigateMapUtils.class);
         //璁$畻璧风偣鍒扮洰鏍囩偣琛岃蛋鑺傜偣
         List<NavigateNode> calc = NavigateUtils.calc(startPoint, targetPoint, mapType, Utils.getShuttlePoints(shuttleNo, Utils.getLev(startPoint)), whites);
@@ -149,7 +152,25 @@
             allNode.addAll(nodes);
         }
 
-        navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(startPoint), allNode, true);//閿佸畾璺緞
+        //閿佸畾璺緞鏃跺墧闄ょ櫧鍚嶅崟鑺傜偣
+        ArrayList<NavigateNode> nodes = new ArrayList<>();
+        for (NavigateNode node : allNode) {
+            boolean flag = false;
+            for (int[] white : whites) {
+                if (node.getX() == white[0] && node.getY() == white[1]) {
+                    flag = true;//瀛樺湪鐧藉悕鍗曡妭鐐�
+                    break;//璺宠繃鐧藉悕鍗曡妭鐐�
+                }
+            }
+
+            if (!flag) {
+                nodes.add(node);
+            }
+        }
+        boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(startPoint), shuttleNo, nodes, true);//閿佸畾璺緞
+        if (!result) {
+            return null;//璺緞閿佸畾澶辫触
+        }
         return result(commands, calc);
     }
 

--
Gitblit v1.9.1