From ad0afa43ef0ec3001122420df245607e4837da3a Mon Sep 17 00:00:00 2001
From: pjb <pjb123456>
Date: 星期一, 21 七月 2025 11:10:56 +0800
Subject: [PATCH] 1105和罐装出库优先级一样(先出选取)

---
 src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java |  540 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 520 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java b/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
index 8ad735b..d061c3f 100644
--- a/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
+++ b/src/main/java/com/zy/asrs/utils/SortTheExecutionOfTheCarUtil.java
@@ -1,9 +1,12 @@
 package com.zy.asrs.utils;
 
-import com.zy.core.enums.RouteCollectCountType;
+import com.zy.asrs.entity.BasDevpPosition;
+import com.zy.asrs.entity.WrkMast;
 
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 public class SortTheExecutionOfTheCarUtil {
     //鎺掑簭
@@ -27,33 +30,530 @@
         }
         return ints;
     }
-    //鎺掑簭
-    public static int ReorderSteId2(int[][] steList,int steNoStart){
-        int[][] ints = new int[steList.length][2];
-        int Difference = 0;
-        for (int[] steNo : steList){
-            if (steNo[0] == steNoStart){
-                Difference = steNo[1] - 1;
+
+//    //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆1000000===>10000==>0==>1000000
+//    public static Integer LatelyAndLessThan(List<BasDevpPosition> devpPosition, long nowPosition,long perimeter){
+//        Integer result = 0;
+//        long Difference = perimeter;
+//        for (BasDevpPosition positions : devpPosition){
+//            Long position = positions.getPlcPosition();
+//            if (position<=nowPosition){
+//                if ((nowPosition-position) < Difference){
+//                    Difference = nowPosition-position;
+//                    result = positions.getDevNo();
+//                }
+//            } else {
+//                if ((nowPosition-(position - perimeter)) < Difference){
+//                    Difference = nowPosition-(position - perimeter);
+//                    result = positions.getDevNo();
+//                }
+//            }
+//        }
+//        return result;
+//    }
+    //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆 0==>1000===>1000000==>0
+    public static Integer LatelyAndLessThan(List<BasDevpPosition> devpPosition, long nowPosition,long perimeter){
+        Integer result = 0;
+        long Difference = perimeter;
+        for (BasDevpPosition positions : devpPosition){
+            Long position = positions.getPlcPosition();
+            if (position >= nowPosition){
+                if ((position-nowPosition) < Difference){
+                    Difference = position-nowPosition;
+                    result = positions.getDevNo();
+                }
+            } else {
+                if (perimeter - (nowPosition - position) < Difference){
+                    Difference = perimeter - (nowPosition - position);
+                    result = positions.getDevNo();
+                }
+            }
+        }
+        return result;
+    }
+
+//    //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆 1000000===>10000==>0==>1000000
+//    public static Integer LatelyAndLessThanWcs(List<BasDevpPosition> devpPosition, long nowPosition,long perimeter){
+//        Integer result = 0;
+//        Integer integer = LatelyAndLessThan(devpPosition, nowPosition,perimeter);
+//        for (BasDevpPosition basDevpPosition:devpPosition){
+//            if (basDevpPosition.getDevNo().equals(integer)){
+//                if (basDevpPosition.getDevNo() == 101){
+//                    result = 133;
+//                }
+//                break;
+//            }
+//            result = basDevpPosition.getDevNo();
+//        }
+//        return result;
+//    }
+    //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆 0==>1000===>1000000==>0
+    public static Integer LatelyAndLessThanWcs(List<BasDevpPosition> devpPosition, long nowPosition,long perimeter){
+        Integer result = -1;
+        Integer integer = LatelyAndLessThan(devpPosition, nowPosition,perimeter);
+        for (BasDevpPosition basDevpPosition:devpPosition){
+            if (basDevpPosition.getDevNo().equals(integer)){
+                if (basDevpPosition.getDevNo() == 134){
+                    result = 101;
+                }
+                break;
+            }
+            result = basDevpPosition.getDevNo();
+        }
+        return result == -1? 101 : result;
+    }
+//    //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆
+//    public static Long LatelyAndLessThan(long[] devpPosition,long nowPosition){
+//        long result = 0L;
+//        long Difference = 1737000L;
+//        for (long position : devpPosition){
+//            if (position<=nowPosition){
+//                if ((nowPosition-position) < Difference){
+//                    Difference = nowPosition-position;
+//                    result = position;
+//                }
+//            } else {
+//                if ((nowPosition-(position - 1737000L)) < Difference){
+//                    Difference = nowPosition-(position - 1737000L);
+//                    result = position;
+//                }
+//            }
+//        }
+//        return result;
+//    }
+
+//    //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆  1000000===>10000==>0==>1000000
+//    public static Integer LatelyAndGreaterThan(List<List<Long>> sitePosition, long nowPosition ,long perimeter){
+//        int result = 0;
+//        long Difference = perimeter;
+//        for (List<Long> rgvPositions: sitePosition){
+//            Long position = rgvPositions.get(1);
+//            if (position>nowPosition){
+//                if ((position - nowPosition) < Difference){
+//                    Difference = position - nowPosition;
+//                    result = rgvPositions.get(0).intValue();
+//                }
+//            } else {
+//                if ((perimeter - (nowPosition - position)) < Difference){
+//                    Difference = perimeter - (nowPosition - position);
+//                    result = rgvPositions.get(0).intValue();
+//                }
+//            }
+//        }
+//        return result;
+//    }
+
+    //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃悗杈圭殑浣嶇疆   0==>1000===>1000000==>0
+    public static Integer LatelyAndGreaterThan(List<List<Long>> sitePosition, long nowPosition ,long perimeter){
+        int result = -1;
+        long Difference = perimeter;
+        for (List<Long> rgvPositions: sitePosition){
+            Long position = rgvPositions.get(1);
+            if (position <= nowPosition){
+                if ((nowPosition - position) < Difference){
+                    Difference = nowPosition - position;
+                    result = rgvPositions.get(0).intValue();
+                }
+            } else {
+                if ((perimeter - (nowPosition - position)) < Difference){
+                    Difference = perimeter - (nowPosition - position);
+                    result = rgvPositions.get(0).intValue();
+                }
+            }
+        }
+        return result;
+    }
+
+    //id鍒濆鍖�
+    public static List<BasDevpPosition> devpNoInit(List<BasDevpPosition> devpPosition){
+        long i = 0;
+        for (BasDevpPosition basDevpPosition : devpPosition){
+            i++;
+            basDevpPosition.setId(i);
+        }
+        return devpPosition;
+    }
+
+
+    //绔欑偣鎺掑簭
+    public static BasDevpPosition[] devpNoSort(List<BasDevpPosition> devpPosition1,Integer devpNo){
+        List<BasDevpPosition> devpPosition = devpNoInit(devpPosition1);
+        BasDevpPosition[] basDevpPositions = new BasDevpPosition[devpPosition.size()];
+        long Difference = 0L;
+        for (BasDevpPosition basDevpPosition : devpPosition){
+            if (basDevpPosition.getDevNo().equals(devpNo)){
+                Difference = basDevpPosition.getId() - 1L;
                 break;
             }
         }
-        for (int[] steNo : steList){
-            int i = steNo[1];
+        for (BasDevpPosition basDevpPosition : devpPosition){
+            long i = basDevpPosition.getId();
             if (i > Difference){
-                steNo[1] = i - Difference;
+                basDevpPosition.setId(i - Difference);
             } else {
-                steNo[1] = steList.length + i-Difference;
+                basDevpPosition.setId(devpPosition.size() + i - Difference);
             }
-            ints[steNo[0]-1] = steNo;
+            basDevpPositions[basDevpPosition.getId().intValue()-1] = basDevpPosition;
         }
-        return 0;
+        return basDevpPositions;
     }
-    public static void main(String[] args) {
-        int[][] ints = new int[][]{{1,1},{2,2},{3,3},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9},{10,10}};
 
-        int[][] reorderSteId = ReorderSteId(ints, 2);
-        for (int[] ste : reorderSteId){
-            System.out.println(Arrays.toString(ste));
+    //閫嗗簭鎺掑垪
+    public static BasDevpPosition[] devpNoSortUN(BasDevpPosition[] devpPosition){
+        BasDevpPosition[] basDevpPositions = new BasDevpPosition[devpPosition.length];
+        for (BasDevpPosition basDevpPosition : devpPosition){
+            basDevpPositions[devpPosition.length - basDevpPosition.getId().intValue()] = basDevpPosition;
+        }
+        return basDevpPositions;
+    }
+
+    //閫嗗簭鎺掑垪
+    public static boolean devpNoSortbj(BasDevpPosition[] devpPosition,Integer souDevpNo,Integer endDevpNo){
+        int sou = 0;
+        int end = 0;
+        for (int i = 0;i<devpPosition.length;i++){
+            if (devpPosition[i].getDevNo().equals(souDevpNo)){
+                sou = i;
+            }
+            if (devpPosition[i].getDevNo().equals(endDevpNo)){
+                end = i;
+            }
+        }
+
+        return sou>end;
+    }
+
+    //鎻愬彇绔欑偣闆嗗悎
+    public static List<Integer> WrkMastExtractSites(List<WrkMast> wrkMastList){
+        List<Integer> siteList = new ArrayList<>();
+        for (WrkMast wrkMast : wrkMastList){
+            if (!siteList.contains(wrkMast.getSourceStaNo())){
+                siteList.add(wrkMast.getSourceStaNo());
+            }
+        }
+        return siteList;
+    }
+    //鎻愬彇绔欑偣闆嗗悎
+    public static List<Integer> BasDevpPositionExtractSites(List<BasDevpPosition> basDevpPositions){
+        List<Integer> siteList = new ArrayList<>();
+        for (BasDevpPosition basDevpPosition : basDevpPositions){
+            if (!siteList.contains(basDevpPosition.getDevNo())){
+                siteList.add(basDevpPosition.getDevNo());
+            }
+        }
+        return siteList;
+    }
+
+    //鎻愬彇绔欑偣闆嗗悎X2
+    public static List<Integer> ExtractSitesComplex(List<Integer> siteList){
+        siteList.addAll(siteList);
+        return siteList;
+    }
+
+    //闆嗗悎杞暟缁�
+    public static int[] SetToArrayConversion(List<Integer> siteList){
+        int[] nums = new int[siteList.size()];
+        for (int i = 0;i<siteList.size();i++){
+            nums[i] = siteList.get(i);
+        }
+        return nums;
+    }
+
+    //鑾峰彇浠诲姟瀵嗛泦鍖�
+    public static List<Integer> ObtainDenseAreasSite(List<Integer> siteList,List<Integer> devpList){
+
+        List<Integer> siteLists = ExtractSitesComplex(devpList);
+        int[] nums = SetToArrayConversion(siteLists);
+
+        List<Integer> champion = new ArrayList<>();
+        for (int rangeArea = 1; rangeArea<=devpList.size();rangeArea++){
+            List<List<Integer>> subsets = getConsecutiveSubsets(nums, rangeArea);
+            if (subsets != null){
+                int temporaryMaxCount = 0;
+                List<Integer> championTemporary = new ArrayList<>();
+                int championCount = 0;
+
+                for (List<Integer> one : subsets){
+                    int intersectionSize = getIntersectionSize(siteList, one);
+                    if (intersectionSize == temporaryMaxCount){
+                        championCount++;
+                        championTemporary = one;
+                    } else if (intersectionSize > temporaryMaxCount){
+                        championCount = 1 ;
+                        temporaryMaxCount = intersectionSize;
+                        championTemporary = one;
+                    }
+                }
+                if (championCount == 1){
+                    champion = championTemporary;
+                    break;
+                }
+                continue;
+            }
+            break;
+        }
+
+        return champion;
+    }
+
+    public static Integer ObtainDenseAreasFirstPlace(List<Integer> siteList,List<Integer> devpList){
+        List<Integer> integers = ObtainDenseAreasSite(siteList, devpList);
+        if (integers==null){
+            return null;
+        }
+        return integers.get(0);
+    }
+
+//    public static void main(String[] args) {
+////        int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+//        List<Integer> siteList = new ArrayList<Integer>() {{
+//            add(1);add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10);
+//        }};
+//        List<Integer> siteLists = ExtractSitesComplex(siteList);
+//        int[] nums = SetToArrayConversion(siteLists);
+//        int subsetSize = 5;  // 鍙互閫氳繃鐢ㄦ埛杈撳叆鎴栬�呭叾浠栨柟寮忔帶鍒�
+//        List<List<Integer>> subsets = getConsecutiveSubsets(nums, subsetSize);
+//        if (subsets != null){
+//            for (List<Integer> subset : subsets) {
+//                System.out.println(subset);
+//            }
+//        } else {
+//            System.out.println("瀛愰泦澶у皬蹇呴』澶т簬0涓斿皬浜庣瓑浜庢暟缁勯暱搴�");
+//        }
+//    }
+
+    public static List<List<Integer>> getConsecutiveSubsets(int[] nums, int size) {
+        List<List<Integer>> result = new ArrayList<>();
+
+        // 纭繚瀛愰泦鐨勫ぇ灏忓悎娉�
+        if (size > nums.length || size <= 0) {
+//            throw new IllegalArgumentException("瀛愰泦澶у皬蹇呴』澶т簬0涓斿皬浜庣瓑浜庢暟缁勯暱搴�");
+            return null;
+        }
+
+        // 閫氳繃婊戝姩绐楀彛娉曠敓鎴愮浉閭荤殑瀛愰泦
+        for (int i = 0; i <= nums.length - size; i++) {
+            List<Integer> subset = new ArrayList<>();
+            for (int j = 0; j < size; j++) {
+                subset.add(nums[i + j]);
+            }
+            if (!result.contains(subset)){
+                result.add(subset);
+            }
+        }
+
+        return result;
+    }
+
+    public static int getIntersectionSize(List<Integer> listA, List<Integer> listB) {
+        // 浣跨敤闆嗗悎鏉ュ瓨鍌ㄤ氦闆嗗厓绱狅紝閬垮厤閲嶅
+        Set<Integer> intersection = new HashSet<>(listA);
+
+        // 淇濈暀闆嗗悎A鍜岄泦鍚圔涓殑鍏卞悓鍏冪礌
+        intersection.retainAll(listB);
+
+        // 杩斿洖浜ら泦鐨勫ぇ灏�
+        return intersection.size();
+    }
+
+//    public static void main(String[] args) {
+//        int[][] ints = new int[][]{{1,1},{3,3},{2,2},{4,4},{5,5},{6,6},{7,7},{8,8},{9,9},{10,10}};
+//
+//        int[][] reorderSteId = ReorderSteId(ints, 2);
+//        for (int[] ste : reorderSteId){
+//            System.out.println(Arrays.toString(ste));
+//        }
+//
+//        long[] longs = new long[]{1L,1000L,200000L,1100000L,1600000L};
+//        long l = LatelyAndLessThan(longs, 1100000L);
+//        System.out.println("l:"+l);
+//    }
+
+
+//    public static void main(String[] args) {
+//        int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+//        List<List<Integer>> subsets = getSubsets(nums);
+//
+//        for (List<Integer> subset : subsets) {
+//            System.out.println(subset);
+//        }
+//    }
+//
+//    public static List<List<Integer>> getSubsets(int[] nums) {
+//        List<List<Integer>> result = new ArrayList<>();
+//        generateSubsets(0, nums, new ArrayList<>(), result);
+//        return result;
+//    }
+//
+//    private static void generateSubsets(int index, int[] nums, List<Integer> current, List<List<Integer>> result) {
+//        if (index == nums.length) {
+//            result.add(new ArrayList<>(current));
+//            return;
+//        }
+//
+//        // 涓嶅寘鍚綋鍓嶅厓绱犵殑瀛愰泦
+//        generateSubsets(index + 1, nums, current, result);
+//
+//        // 鍖呭惈褰撳墠鍏冪礌鐨勫瓙闆�
+//        current.add(nums[index]);
+//        generateSubsets(index + 1, nums, current, result);
+//
+//        // 鍥炴函
+//        current.remove(current.size() - 1);
+//    }
+
+    /*  濂戒笢瑗匡紝鍋氳褰�
+    public static void main(String[] args) {
+        int[] nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+        int subsetSize = 3;  // 鍙互閫氳繃鐢ㄦ埛杈撳叆鎴栬�呭叾浠栨柟寮忔帶鍒�
+        List<List<Integer>> subsets = getConsecutiveSubsets(nums, subsetSize);
+
+        for (List<Integer> subset : subsets) {
+            System.out.println(subset);
         }
     }
+
+    public static List<List<Integer>> getConsecutiveSubsets(int[] nums, int size) {
+        List<List<Integer>> result = new ArrayList<>();
+
+        // 纭繚瀛愰泦鐨勫ぇ灏忓悎娉�
+        if (size > nums.length || size <= 0) {
+            throw new IllegalArgumentException("瀛愰泦澶у皬蹇呴』澶т簬0涓斿皬浜庣瓑浜庢暟缁勯暱搴�");
+        }
+
+        // 閫氳繃婊戝姩绐楀彛娉曠敓鎴愮浉閭荤殑瀛愰泦
+        for (int i = 0; i <= nums.length - size; i++) {
+            List<Integer> subset = new ArrayList<>();
+            for (int j = 0; j < size; j++) {
+                subset.add(nums[i + j]);
+            }
+            result.add(subset);
+        }
+
+        return result;
+    }
+    * */
+
+
+//    public static void main(String[] args) {
+//        // 绀轰緥鍒楄〃A鍜屽垪琛˙
+//        List<Integer> listA = new ArrayList<>();
+//        List<Integer> listB = new ArrayList<>();
+//
+//        // 鍒濆鍖栧垪琛ˋ
+//        listA.add(1);
+//        listA.add(2);
+//        listA.add(3);
+//        listA.add(4);
+//        listA.add(5);
+//
+//        // 鍒濆鍖栧垪琛˙
+//        listB.add(3);
+//        listB.add(4);
+//        listB.add(5);
+//        listB.add(6);
+//        listB.add(7);
+//
+//        // 璁$畻浜ら泦鏁伴噺
+//        int intersectionSize = getIntersectionSize(listA, listB);
+//        System.out.println("浜ら泦鐨勬暟閲忔槸: " + intersectionSize);
+//    }
+
+
+    //鑾峰彇鏈�杩戝苟鍦ㄥ綋鍓嶄綅缃墠杈圭殑浣嶇疆 0==>1000===>1000000==>0
+    public static Double LatelyAndLessThan(long devPosition,long rgvPosition,long perimeter){
+        long Difference = perimeter;
+        if (devPosition >= rgvPosition){
+//            if ((devPosition-rgvPosition) < Difference){
+                Difference = devPosition-rgvPosition;
+//            }
+        } else {
+//            if (perimeter - (rgvPosition - devPosition) < Difference){
+                Difference = perimeter - (rgvPosition - devPosition);
+//            }
+        }
+        return Double.valueOf(Difference);
+    }
+
+    public static int calculateShortestDistanceDistance(List<Integer> data, int a, int b) {
+        Result result = calculateShortestDistance(data, a, b);
+        return result.distance;
+    }
+
+    public static List<Integer> calculateShortestDistancePassedData(List<Integer> data, int a, int b) {
+        Result result = calculateShortestDistance(data, a, b);
+        return result.passedData;
+    }
+
+//    public static String calculateShortestDistanceDirection(List<Integer> data, int a, int b) {
+//        Result result = calculateShortestDistance(data, a, b);
+//        return result.direction;
+//    }
+
+    public static boolean calculateShortestDistanceDirection(List<Integer> data, int a, int b) {
+        Result result = calculateShortestDistance(data, a, b);
+        return result.direction.equals("鍚戝墠璧帮紙椤烘椂閽堬級");
+    }
+
+
+    public static void main(String[] args) {
+        List<Integer> data = new ArrayList<>();
+        // 鐢� List<Integer> 鍒濆鍖栨暟鎹�
+        for (int i = 1; i <= 9; i++) {
+            data.add(i);
+        }
+
+        int a = 3; // 璧风偣
+        int b = 3; // 缁堢偣
+
+        Result result = calculateShortestDistance(data, a, b);
+        System.out.println("鏈�杩戠殑璺濈鏄�: " + result.distance);
+        System.out.println("缁忚繃鐨勬暟鎹�: " + result.passedData);
+        System.out.println("鏂瑰悜: " + result.direction);
+    }
+
+    public static Result calculateShortestDistance(List<Integer> data, int a, int b) {
+        int length = data.size();
+        int indexA = data.indexOf(a);
+        int indexB = data.indexOf(b);
+
+        if (indexA == -1 || indexB == -1) {
+            throw new IllegalArgumentException("鍒楄〃涓湭鎵惧埌鎸囧畾鐨勫厓绱�");
+        }
+
+        // 椤烘椂閽堟柟鍚戠殑璺濈鍙婄粡杩囩殑鏁版嵁
+        List<Integer> clockwiseData = new ArrayList<>();
+        int clockwiseDistance = (indexB - indexA + length) % length;
+        for (int i = 0; i <= clockwiseDistance; i++) {
+            clockwiseData.add(data.get((indexA + i) % length));
+        }
+
+        // 閫嗘椂閽堟柟鍚戠殑璺濈鍙婄粡杩囩殑鏁版嵁
+        List<Integer> counterClockwiseData = new ArrayList<>();
+        int counterClockwiseDistance = (indexA - indexB + length) % length;
+        for (int i = 0; i <= counterClockwiseDistance; i++) {
+            counterClockwiseData.add(data.get((indexA - i + length) % length));
+        }
+
+        // 姣旇緝璺濈骞惰繑鍥炵粨鏋�
+        if (clockwiseDistance <= counterClockwiseDistance) {
+            return new Result(clockwiseDistance, clockwiseData, "鍚戝墠璧帮紙椤烘椂閽堬級");
+        } else {
+            return new Result(counterClockwiseDistance, counterClockwiseData, "鍚戝悗璧帮紙閫嗘椂閽堬級");
+        }
+    }
+
+    // 鐢ㄤ簬杩斿洖缁撴灉鐨勭被
+    static class Result {
+        public int distance;
+        public List<Integer> passedData;
+        public String direction;
+
+        public Result(int distance, List<Integer> passedData, String direction) {
+            this.distance = distance;
+            this.passedData = passedData;
+            this.direction = direction;
+        }
+    }
+
 }

--
Gitblit v1.9.1