From 98f1c4c9ffbbb3347ad752821505bc3c70ea4efc Mon Sep 17 00:00:00 2001
From: lsh <lsh@163.com>
Date: 星期日, 27 四月 2025 10:52:50 +0800
Subject: [PATCH] *

---
 src/main/java/com/zy/asrs/utils/RouteUtils.java |  132 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 116 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/RouteUtils.java b/src/main/java/com/zy/asrs/utils/RouteUtils.java
index 899c8d1..905be8d 100644
--- a/src/main/java/com/zy/asrs/utils/RouteUtils.java
+++ b/src/main/java/com/zy/asrs/utils/RouteUtils.java
@@ -7,6 +7,7 @@
 import com.zy.core.model.RgvSlave;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import static java.util.stream.Collectors.toList;
@@ -16,55 +17,154 @@
  */
 public class RouteUtils {
     //鎺掑簭  鎵ц鏂瑰悜锛堥潰鏈濊建閬� 瀹氫綅鍊煎乏灏忓彸澶э級  0:宸� 灏�   1:鍙� 澶�
-    public static List<Integer>[] gradeRange(List<Integer> staNoList,List<BasDevpPosition> basDevpPositions) {
+    public static List<Integer>[] gradeRange(List<Integer> staNoList, List<BasDevpPosition> basDevpPositionList, boolean itSmall) {
         List<Integer>[] avoidRangeArray = new ArrayList[2];
 
+        Integer[] rangeList = new Integer[staNoList.size()];
+        List<Integer> rangeList1 = new ArrayList<>();
+        List<Integer> rangeList2 = new ArrayList<>();
 
+        int i = 0;
+        for (BasDevpPosition basDevpPosition : basDevpPositionList) {
+            for (Integer staNo : staNoList) {
+                if (basDevpPosition.getDevNo().equals(staNo)) {
+                    rangeList[i] = staNo;
+                    i = i + 1;
+                    break;
+                }
+            }
+        }
+        boolean sign = true;
+        for (int j = 0; j < rangeList.length; j++) {
+            if (itSmall) {
+                if (sign) {
+                    rangeList1.add(rangeList[j]);
+                } else {
+                    rangeList2.add(rangeList[j]);
+                }
+                if (sign && j >= rangeList.length / 2) {
+                    sign = false;
+                }
+            } else {
+                if (sign && j >= rangeList.length / 2) {
+                    sign = false;
+                }
+                if (sign) {
+                    rangeList1.add(rangeList[j]);
+                } else {
+                    rangeList2.add(rangeList[j]);
+                }
+            }
+        }
 
-
-
-
+        avoidRangeArray[0] = rangeList1;
+        avoidRangeArray[1] = rangeList2;
         return avoidRangeArray;
     }
 
 
-
-
     //鑾峰彇鍦ㄨ寖鍥寸殑绔欑偣
-    public static List<Integer> belongToRange(List<Integer> staNoList,Long position,List<BasDevpPosition> basDevpPositions){
+    public static List<Integer> belongToRange(List<Integer> staNoList, Long[] avoid, List<BasDevpPosition> basDevpPositions) {
         List<Integer> siteList = new ArrayList<>();
+
+        for (BasDevpPosition basDevpPosition : basDevpPositions) {
+            if (new TrackRangeUtils().avoidRange(basDevpPosition.getPlcPosition(), avoid)) {
+                for (Integer staNo : staNoList) {
+                    if (basDevpPosition.getDevNo().equals(staNo)) {
+                        siteList.add(staNo);
+                        break;
+                    }
+                }
+            }
+        }
 
         return siteList;
     }
 
     //鎻愬彇绔欑偣闆嗗悎
-    public static List<Integer> BasDevpPositionExtractSites(List<BasDevpPosition> basDevpPositions){
+    public static List<Integer> BasDevpPositionExtractSites(List<BasDevpPosition> basDevpPositions) {
         List<Integer> siteList = new ArrayList<>();
-        for (BasDevpPosition basDevpPosition : basDevpPositions){
-            if (!siteList.contains(basDevpPosition.getDevNo())){
+        for (BasDevpPosition basDevpPosition : basDevpPositions) {
+            if (!siteList.contains(basDevpPosition.getDevNo())) {
                 siteList.add(basDevpPosition.getDevNo());
             }
         }
         return siteList;
     }
 
-    //鎻愬彇绔欑偣闆嗗悎
-    public static List<Integer> SortNearby(List<Integer> staNoList,Long rgvNowPos,List<BasDevpPosition> basDevpPositions){
+    //鎻愬彇绔欑偣闆嗗悎//灏辫繎鎺掑簭
+    public static List<Integer> SortNearby(List<Integer> staNoList, Long rgvNowPos, List<BasDevpPosition> basDevpPositionList) {
         List<Integer> siteList = new ArrayList<>();
+
+        List<BasDevpPosition> basDevpPositions = devpNoSort(basDevpPositionList, rgvNowPos);
+        for (BasDevpPosition basDevpPosition : basDevpPositions) {
+            for (Integer staNo : staNoList) {
+                if (basDevpPosition.getDevNo().equals(staNo)) {
+                    siteList.add(staNo);
+                    break;
+                }
+            }
+        }
+
 
         return siteList;
     }
 
+    //绔欑偣杩囨护
+    public static List<BasDevpPosition> devpNoSort(List<BasDevpPosition> devpPositionList, Long rgvNowPos) {
 
+        List<BasDevpPosition> basDevpPositions = new ArrayList<>();
+        List<BasDevpPosition> basDevpPositionSort = new ArrayList<>();
+        ArrayList<Long> arrayList = new ArrayList<>();
+        for (BasDevpPosition basDevpPosition : devpPositionList) {
+            long position = Math.abs(basDevpPosition.getPlcPosition() - rgvNowPos);
+            BasDevpPosition devpPosition = new BasDevpPosition(basDevpPosition, position);
+            basDevpPositions.add(devpPosition);
+            arrayList.add(position);
+        }
+        Collections.sort(arrayList); // 鍗囧簭鎺掑簭
+        for (Long position : arrayList) {
+            for (BasDevpPosition basDevpPosition : basDevpPositions) {
+                if (basDevpPosition.getPlcPosition().equals(position)) {
+                    basDevpPositionSort.add(basDevpPosition);
+                    break;
+                }
+            }
+        }
+        return basDevpPositionSort;
+    }
 
     //妫�娴嬫槸鍚﹀湪鑼冨洿
-    public static boolean CheckIfItIsWithinTheRange(List<Integer> staNoList,Integer staNo,List<BasDevpPosition> basDevpPositions){
+    public static boolean CheckIfItIsWithinTheRange(List<Integer> staNoList, Long staNoNowPos, List<BasDevpPosition> basDevpPositionList, boolean itSmall) {
         List<Integer> siteList = new ArrayList<>();
-        if (staNoList.isEmpty()){
-            return true;
+
+
+        Integer[] rangeList = new Integer[staNoList.size()];
+        int i = 0;
+        for (BasDevpPosition basDevpPosition : basDevpPositionList) {
+            for (Integer staNo : staNoList) {
+                if (basDevpPosition.getDevNo().equals(staNo)) {
+                    rangeList[i] = staNo;
+                    i = i + 1;
+                    break;
+                }
+            }
         }
 
-        return false;
+        if (itSmall) {
+            return staNoNowPos <= rangeList[rangeList.length - 1];
+        }
+        return staNoNowPos >= rangeList[0];
+    }
+
+    public static long absoluteDifference(Long a, Long b) {
+        if (a == null || b == null) {
+            a = 0L;
+            b = 0L;
+//            throw new IllegalArgumentException("");
+            System.out.println("a or b is null");
+        }
+        return Math.abs(a - b);
     }
 
 }

--
Gitblit v1.9.1