| package com.zy.asrs.utils; | 
|   | 
| import com.baomidou.mybatisplus.mapper.EntityWrapper; | 
| import com.core.common.SpringUtils; | 
| import com.zy.asrs.entity.BasDevpPosition; | 
| import com.zy.asrs.entity.TaskWrk; | 
| import com.zy.asrs.entity.WrkMast; | 
| import com.zy.core.enums.RouteCollectCountType; | 
| import com.zy.core.model.RgvSlave; | 
| import com.zy.system.service.UserService; | 
|   | 
| import java.util.ArrayList; | 
| import java.util.Collections; | 
| import java.util.List; | 
|   | 
| import static java.util.stream.Collectors.toList; | 
|   | 
| /** | 
|  * Created by Monkey D. Luffy on 2023/7/18 | 
|  */ | 
| public class RouteUtils { | 
|     //排序  执行方向(面朝轨道 定位值左小右大)  0:左 小   1:右 大 | 
|     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[] 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) { | 
|         List<Integer> siteList = new ArrayList<>(); | 
|         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> 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); | 
|                     basDevpPositions.remove(basDevpPosition); | 
|                     break; | 
|                 } | 
|             } | 
|         } | 
|         return basDevpPositionSort; | 
|     } | 
|   | 
|     //检测是否在范围 | 
|     public static boolean CheckIfItIsWithinTheRange(List<Integer> staNoList, Long staNoNowPos, List<BasDevpPosition> basDevpPositionList, boolean itSmall) { | 
|         List<Integer> siteList = new ArrayList<>(); | 
|         Long maxOrMin = 0L; | 
|   | 
|   | 
|         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; | 
|                 } | 
|             } | 
|         } | 
|         if (itSmall) { | 
|             for (BasDevpPosition basDevpPosition : basDevpPositionList) { | 
|                 if (basDevpPosition.getDevNo().equals(rangeList[rangeList.length - 1])) { | 
|                     maxOrMin = basDevpPosition.getPlcPosition(); | 
|                     break; | 
|                 } | 
|             } | 
|             if (maxOrMin == 0){ | 
|                 return false; | 
|             } | 
|             return staNoNowPos <= maxOrMin+50; | 
|         } | 
|         for (BasDevpPosition basDevpPosition : basDevpPositionList) { | 
|             if (basDevpPosition.getDevNo().equals(rangeList[0])) { | 
|                 maxOrMin = basDevpPosition.getPlcPosition(); | 
|                 break; | 
|             } | 
|         } | 
|         if (maxOrMin == 0){ | 
|             return false; | 
|         } | 
|         return staNoNowPos >= maxOrMin-50; | 
|     } | 
|   | 
|     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); | 
|     } | 
|   | 
| } |