From 6aee4ce7e920fe0f81c9fbfc497c03c65dd17f50 Mon Sep 17 00:00:00 2001 From: DU Date: Thu, 8 Apr 2021 16:39:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E5=9B=BE=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E5=87=BA=E5=BA=93=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/runplan/RunPlanGenerator.java | 72 ++++++++++++------- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java b/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java index eb69f0d74..7342ae08d 100644 --- a/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java +++ b/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java @@ -69,8 +69,8 @@ public class RunPlanGenerator { Routing2BoundInfo outBoundRouting2 = null; Routing2BoundInfo outBoundRouting1 = null; if (inputData.hasOutAndInBound()) { - outBoundRouting1 = getOutboundRouting(running1Routing, outboundRoutings); - outBoundRouting2 = getOutboundRouting(running2Routing, outboundRoutings); + outBoundRouting1 = getOutboundRouting(running1Routing, outboundRoutings,runLevelMap); + outBoundRouting2 = getOutboundRouting(running2Routing, outboundRoutings,runLevelMap); if (Objects.nonNull(outBoundRouting1) && Objects.nonNull(outBoundRouting2)) { setOutBoundTripTimes(runLevelMap, parkTimeMap, reentryData, serviceTripList1, outBoundRouting1); setOutBoundTripTimes(runLevelMap, parkTimeMap, reentryData, serviceTripList2, outBoundRouting2); @@ -104,11 +104,11 @@ public class RunPlanGenerator { //另一个交路 RunPlanRoutingVO otherLoop = running2Routing; if (inputData.hasOutAndInBound()) { - outBoundRouting = getOutboundRouting(running1Routing, outboundRoutings); + outBoundRouting = getOutboundRouting(running1Routing, outboundRoutings,runLevelMap); outRefLoop = running1Routing; otherLoop = running2Routing; if (Objects.isNull(outBoundRouting)) { - outBoundRouting = getOutboundRouting(running2Routing, outboundRoutings); + outBoundRouting = getOutboundRouting(running2Routing, outboundRoutings,runLevelMap); outRefLoop = running2Routing; otherLoop = running1Routing; } @@ -201,10 +201,10 @@ public class RunPlanGenerator { } if (inputData.hasOutAndInBound()) { - Routing2BoundInfo inboundRouting = getInboundRouting(loop ? outRefLoop : otherLoop, inboundRoutings); + Routing2BoundInfo inboundRouting = getInboundRouting(loop ? outRefLoop : otherLoop, inboundRoutings,runLevelMap); if (Objects.isNull(inboundRouting)) { serviceTripList.removeLast(); - inboundRouting = getInboundRouting(!loop ? outRefLoop : otherLoop, inboundRoutings); + inboundRouting = getInboundRouting(!loop ? outRefLoop : otherLoop, inboundRoutings,runLevelMap); } if (Objects.nonNull(inboundRouting)) { setInBoundTripTimes(runLevelMap, parkTimeMap, reentryData, serviceTripList, inboundRouting); @@ -214,7 +214,7 @@ public class RunPlanGenerator { } - private Routing2BoundInfo getInboundRouting(RunPlanRoutingVO runningRouting, List inboundRoutings) { + private Routing2BoundInfo getInboundRouting(RunPlanRoutingVO runningRouting, List inboundRoutings, Map runLevelMap) { //找入库 RunPlanRoutingVO inboundRouting = null; List parkSectionCodeList = runningRouting.getParkSectionCodeList(); @@ -222,16 +222,28 @@ public class RunPlanGenerator { t: for (int index = runningRouting.getStartTbFront() ? 0 : 1, i = parkSectionCodeList.size() - (runningRouting.getEndTbFront() ? 1 : 2); i > index; i--) { RunPlanRoutingSection parkSection = parkSectionCodeList.get(i); - for (int x = 0, y = inboundRoutings.size(); x < y; x++) { - RunPlanRoutingVO inRouting = inboundRoutings.get(x); + + inboundRouting = inboundRoutings.stream().filter(inRouting -> { + List inSectionList = inRouting.getParkSectionCodeList(); RunPlanRoutingSection inSection = inSectionList.get(inSectionList.size() - 2); - if (Objects.equals(parkSection.getSectionCode(), inSection.getSectionCode())) { - inboundRouting = inRouting; - r = runningRouting.getStartTbFront() ? i + 1 : i; - break t; - } + return Objects.equals(parkSection.getSectionCode(), inSection.getSectionCode()); + }).sorted(Comparator.comparing(routingVO -> runLevelMap.get(parkSection.getSectionCode() + "-" + routingVO.getEndSectionCode()))).findFirst().orElse(null); + if (Objects.nonNull(inboundRouting)) { + r = runningRouting.getStartTbFront() ? i + 1 : i; + break t; } + +// for (int x = 0, y = inboundRoutings.size(); x < y; x++) { +// RunPlanRoutingVO inRouting = inboundRoutings.get(x); +// List inSectionList = inRouting.getParkSectionCodeList(); +// RunPlanRoutingSection inSection = inSectionList.get(inSectionList.size() - 2); +// if (Objects.equals(parkSection.getSectionCode(), inSection.getSectionCode())) { +// inboundRouting = inRouting; +// r = runningRouting.getStartTbFront() ? i + 1 : i; +// break t; +// } +// } } if (Objects.isNull(inboundRouting)) return null; return new Routing2BoundInfo(inboundRouting, r); @@ -309,7 +321,8 @@ public class RunPlanGenerator { continue; } RunPlanUserConfigVO.ReentryTime reentryTime = reentryData.get(routingSection.getStationCode()); - runPlanTripTimeVO.setArrivalTime(CollectionUtils.isEmpty(tripTimeList) ? tripList.getLast().getEndTime().plusSeconds(45) + runPlanTripTimeVO.setArrivalTime(CollectionUtils.isEmpty(tripTimeList) ? + CollectionUtils.isEmpty(tripList) ? inputData.getBeginTime().plusSeconds(reentryData.get(routing.getStartStationCode()).getTbTo()): tripList.getLast().getEndTime().plusSeconds(reentryData.get(routing.getStartStationCode()).getTbBack()-reentryData.get(routing.getStartStationCode()).getTbFrom()) : tripTimeList.getLast().getDepartureTime().plusSeconds(runLevelMap.get(tripTimeList.getLast().getSectionCode() + "-" + runPlanTripTimeVO.getSectionCode()))); runPlanTripTimeVO.setDepartureTime(Objects.isNull(routing.getEndTbFront()) ? runPlanTripTimeVO.getArrivalTime() @@ -373,7 +386,7 @@ public class RunPlanGenerator { } } - private Routing2BoundInfo getOutboundRouting(RunPlanRoutingVO runningRouting, List outboundRoutings) { + private Routing2BoundInfo getOutboundRouting(RunPlanRoutingVO runningRouting, List outboundRoutings,Map runLevelMap) { //找出库 RunPlanRoutingVO outboundRouting = null; List parkSectionCodeList = runningRouting.getParkSectionCodeList(); @@ -381,17 +394,28 @@ public class RunPlanGenerator { t: for (int i = runningRouting.getStartTbFront() ? 0 : 1, index = parkSectionCodeList.size() - (runningRouting.getEndTbFront() ? 1 : 2); i < index; i++) { RunPlanRoutingSection parkSection = parkSectionCodeList.get(i); - for (int x = 0, y = outboundRoutings.size(); x < y; x++) { - RunPlanRoutingVO outRouting = outboundRoutings.get(x); + + outboundRouting = outboundRoutings.stream().filter(outRouting -> { RunPlanRoutingSection outSection = outRouting.getParkSectionCodeList().get(1); - if (Objects.equals(parkSection.getSectionCode(), outSection.getSectionCode())) { - outboundRouting = outRouting; - r = runningRouting.getStartTbFront() ? i : i - 1; - break t; - } + return Objects.equals(parkSection.getSectionCode(), outSection.getSectionCode()); + }).sorted(Comparator.comparing(routingVO -> runLevelMap.get(routingVO.getStartSectionCode() + "-" + parkSection.getSectionCode()))).findFirst().orElse(null); + if (Objects.nonNull(outboundRouting)) { + r = runningRouting.getStartTbFront() ? i : i - 1; + break t; } + + +// for (int x = 0, y = outboundRoutings.size(); x < y; x++) { +// RunPlanRoutingVO outRouting = outboundRoutings.get(x); +// RunPlanRoutingSection outSection = outRouting.getParkSectionCodeList().get(1); +// if (Objects.equals(parkSection.getSectionCode(), outSection.getSectionCode())) { +// outboundRouting = outRouting; +// r = runningRouting.getStartTbFront() ? i : i - 1; +// break t; +// } +// } } - if (Objects.isNull(outboundRouting)) return null; + if (Objects.isNull(outboundRouting)) return null; return new Routing2BoundInfo(outboundRouting, r); }