| src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| src/main/java/com/zy/asrs/utils/TrackUtils.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2043,6 +2043,16 @@ } return null; } public TaskWrk deviceDetectionGetWrkNo(RgvSlave.RgvStn inSta) { DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, inSta.getDevpPlcId()); StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo()); if (staProtocol == null || Cools.isEmpty(staProtocol.getWorkNo())) { return null; } TaskWrk taskWrk = taskWrkService.selectByWrkNo(staProtocol.getWorkNo()); return taskWrk; } public boolean deviceDetection(RgvSlave.RgvStn inSta,Integer rgvNo) { ArrayList<Integer> arrayList = new ArrayList<Integer>() {{ add(1009); @@ -2122,10 +2132,12 @@ } List<TaskWrk> taskWrkList = new ArrayList<>(); List<Integer> staList = new ArrayList<>(); List<String> taskNoList = taskStartRepel(); for (RgvSlave.RgvStn inSta : rgvSlave.getRgvInSta()) { TaskWrk taskWrk = deviceDetection(inSta); if (taskWrk != null) { if (taskWrk.getWrkNo().toString().equals(taskNoNow)) continue; if (!taskNoList.contains(taskWrk.getWrkNo().toString())) continue; taskWrkList.add(taskWrk); staList.add(inSta.getStaNo()); } @@ -2157,9 +2169,10 @@ if (rgvOtherIDLEOther(rgvSlave)){ if (!rgvOtherIDLE(rgvSlave,staList.get(0))){ System.out.println("空闲就近跳过==="+rgvSlave.getId()+"==="); if (itSmall){ RgvErrCache.updateRgvErr(rgvSlave.getId(),staList.get(0)+"空闲就近跳过"); sign=true; } } } if (sign){ @@ -2238,9 +2251,10 @@ if (rgvOtherIDLEOther2(rgvSlave)){ if (!rgvOtherIDLE2(rgvSlave,staList.get(0))){ System.out.println("运行就近跳过==="+rgvSlave.getId()+"==="); if (itSmall){ RgvErrCache.updateRgvErr(rgvSlave.getId(),staList.get(0)+"运行就近跳过"); sign=true; } } } if (sign){ @@ -2443,6 +2457,60 @@ } } public List<String> taskStartRepel() { ArrayList<String> arrayListOld = new ArrayList<>(); ArrayList<String> arrayListNew = new ArrayList<>(); ArrayList<Integer> arrayListAllP = new ArrayList<>(); ArrayList<Long[]> arrayListAll = new ArrayList<>(); for (RgvSlave rgvSlave : slaveProperties.getRgv()) { try{ String taskNoNow = rgvOtherTaskWrk(rgvSlave); if (!arrayListOld.contains(taskNoNow)){ arrayListOld.add(taskNoNow); } } catch (Exception e) { } } for (RgvSlave rgvSlave : slaveProperties.getRgv()) { if (rgvDetection(rgvSlave)) { for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()) { TaskWrk taskWrk = deviceDetectionGetWrkNo(rgvStn); if (taskWrk != null) { if (!arrayListAllP.contains(taskWrk.getWrkNo())) { arrayListAllP.add(taskWrk.getWrkNo()); BasDevpPosition basDevpPositionSta = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", rgvStn.getStaNo())); BasDevpPosition basDevpPositionEnd = basDevpPositionService.selectOne(new EntityWrapper<BasDevpPosition>().eq("DEV_NO", BarcodeUtils.getOutStaNo(taskWrk.getOriginTargetPoint()))); Long[] longList = {taskWrk.getWrkNo().longValue(),basDevpPositionSta.getPlcPosition(),basDevpPositionEnd.getPlcPosition()}; arrayListAll.add(longList); } } } } } List<Long[]> crossingPathsW = TrackUtils.findCrossingPathsW(arrayListAll); List<Long> wrkNoList = new ArrayList<>(); List<Long> signWrk = new ArrayList<>(); for (Long[] longList : crossingPathsW) { if (!wrkNoList.contains(longList[0]) && !signWrk.contains(longList[0])) { if (!wrkNoList.contains(longList[1]) && !signWrk.contains(longList[1])) { wrkNoList.add(longList[0]); } } signWrk.add(longList[0]); signWrk.add(longList[1]); } for (Integer str : arrayListAllP) { if (!signWrk.contains(str.longValue())) { arrayListNew.add(str.toString()); } } for (Long wrk : wrkNoList) { arrayListNew.add(wrk.toString()); } return arrayListNew; } //获取起点与终点对象 public RgvSlave.RgvStn getRgvStnNow(RgvSlave rgvSlave, Integer staNo) { for (RgvSlave.RgvStn rgvStn : rgvSlave.getRgvInSta()) { src/main/java/com/zy/asrs/utils/TrackUtils.java
New file @@ -0,0 +1,127 @@ package com.zy.asrs.utils; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; public class TrackUtils { public static void main(String[] args) { // 模拟数据 ArrayList<Long[]> arrayListAll = new ArrayList<>(); arrayListAll.add(new Long[]{999L, 100L, 500L}); // 方向: 100→500 // arrayListAll.add(new Long[]{998L, 600L, 400L}); // 方向: 600→400 (反向) // arrayListAll.add(new Long[]{1000L, 400L, 700L}); // 方向: 600→400 (反向) // arrayListAll.add(new Long[]{996L, 10L, 50L}); // 方向: 100→500 // arrayListAll.add(new Long[]{995L, 15L, 60L}); // 方向: 150→600 // 找出所有交叉的数据对 List<CrossPair> crossPairs = findCrossingPaths(arrayListAll); // 打印结果 System.out.println("交叉的路径对:"); crossPairs.forEach(pair -> System.out.println(pair.path1[0] + " (" + pair.path1[1] + "→" + pair.path1[2] + ") 与 " + pair.path2[0] + " (" + pair.path2[1] + "→" + pair.path2[2] + ") 交叉")); } /** * 找出所有交叉的路径对 * 交叉条件: * 1. 方向不同 (起点<终点 vs 起点>终点) * 2. 路径有重叠 */ public static List<Long[]> findCrossingPathsW(ArrayList<Long[]> paths) { if (paths == null || paths.size() <2){ return new ArrayList<>(); } List<CrossPair> crossPairs = findCrossingPaths(paths); List<Long[]> arrayListAll = new ArrayList<>(); for (CrossPair crossPair : crossPairs) { arrayListAll.add(new Long[]{crossPair.path1[0], crossPair.path1[1]}); } return arrayListAll; } public static List<CrossPair> findCrossingPaths(ArrayList<Long[]> paths) { List<CrossPair> crossPairs = new ArrayList<>(); // 获取所有路径 List<Long[]> pathList = new ArrayList<>(paths); // 使用Java 8 Stream API比较所有路径对 crossPairs = pathList.stream() .flatMap(path1 -> pathList.stream() .filter(path2 -> !path1[0].equals(path2[0])) // 排除自身 .filter(path2 -> isOppositeDirection(path1, path2)) // 方向不同 .filter(path2 -> isOverlapping(path1, path2)) // 有重叠 .map(path2 -> new CrossPair(path1, path2)) ) .distinct() // 去重 (A-B 和 B-A 视为同一对) .collect(Collectors.toList()); return crossPairs; } /** * 判断两条路径方向是否相反 */ private static boolean isOppositeDirection(Long[] path1, Long[] path2) { long start1 = path1[1]; long end1 = path1[2]; long start2 = path2[1]; long end2 = path2[2]; // 判断方向:true表示正向(start<end),false表示反向(start>end) boolean direction1 = start1 < end1; boolean direction2 = start2 < end2; return direction1 != direction2; } /** * 判断两条路径是否有重叠 */ private static boolean isOverlapping(Long[] path1, Long[] path2) { long start1 = Math.min(path1[1], path1[2]); // 实际起点(较小值) long end1 = Math.max(path1[1], path1[2]); // 实际终点(较大值) long start2 = Math.min(path2[1], path2[2]); long end2 = Math.max(path2[1], path2[2]); // 检查区间是否有重叠 return !(end1 <= start2 || end2 <= start1); } /** * 辅助类,用于表示交叉的路径对 */ static class CrossPair { Long[] path1; Long[] path2; CrossPair(Long[] path1, Long[] path2) { // 保证存储顺序一致,便于去重 if (path1[0] < path2[0]) { this.path1 = path1; this.path2 = path2; } else { this.path1 = path2; this.path2 = path1; } } @Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof CrossPair)) return false; CrossPair other = (CrossPair) obj; return this.path1[0].equals(other.path1[0]) && this.path2[0].equals(other.path2[0]); } @Override public int hashCode() { return 31 * path1[0].hashCode() + path2[0].hashCode(); } } }