@ -8,11 +8,14 @@ import club.joylink.rtss.vo.client.runplan.RunPlanTripTimeVO;
import club.joylink.rtss.vo.client.runplan.RunPlanTripVO ;
import club.joylink.rtss.vo.client.runplan.user.* ;
import club.joylink.rtss.vo.runplan.RunPlanInputData ;
import lombok.AllArgsConstructor ;
import lombok.Getter ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Component ;
import org.springframework.util.CollectionUtils ;
import java.time.LocalTime ;
import java.time.temporal.ChronoUnit ;
import java.util.* ;
import java.util.stream.Collectors ;
@ -35,16 +38,10 @@ public class RunPlanGenerator {
public List < RunPlanTripVO > generatorTrips ( Long userId , RunPlanInputData inputData , MapVO mapVO ) {
/ / 校验时间
BusinessExceptionAssertEnum . DATA_ERROR . assertTrue ( inputData . getOverTime ( ) . isAfter ( inputData . getBeginTime ( ) ) , " 输入参数错误:发车时间应早于结束时间 " ) ;
LocalTime beginTimeOffset = inputData . getBeginTime ( ) . minusHours ( OFFSET_TIME_HOURS ) ;
/ / 向前推两小时 , 如果到前一天 , 则时间不合理
BusinessExceptionAssertEnum . DATA_ERROR . assertTrue ( inputData . getBeginTime ( ) . isAfter ( beginTimeOffset ) , " 发车时间过早,建议晚于上午两点 " ) ;
inputData . setBeginTime ( beginTimeOffset ) ;
inputData . setOverTime ( inputData . getOverTime ( ) . minusHours ( OFFSET_TIME_HOURS ) ) ;
checkInputTime ( inputData ) ;
RunPlanRoutingVO running1Routing = runPlanRoutingService . queryUserRoutingByCode ( userId , mapVO . getId ( ) , inputData . getRunningRouting1 ( ) ) ;
RunPlanRoutingVO running2Routing = runPlanRoutingService . queryUserRoutingByCode ( userId , mapVO . getId ( ) , inputData . getRunningRouting2 ( ) ) ;
RunPlanRoutingVO running1Routing = runPlanRoutingService . queryUserRoutingById ( userId , mapVO . getId ( ) , inputData . getRunningRouting1 ( ) ) ;
RunPlanRoutingVO running2Routing = runPlanRoutingService . queryUserRoutingById ( userId , mapVO . getId ( ) , inputData . getRunningRouting2 ( ) ) ;
BusinessExceptionAssertEnum . OPERATION_NOT_SUPPORTED . assertTrue ( running1Routing . isLoopRoute ( ) & & running2Routing . isLoopRoute ( ) , " 交路类型错误 " ) ;
/ / 验证环路是否闭环
boolean isLoop = running1Routing . getParkSectionCodeList ( ) . get ( 0 ) . getSectionCode ( ) . equals ( running2Routing . getParkSectionCodeList ( ) . get ( running2Routing . getParkSectionCodeList ( ) . size ( ) - 1 ) . getSectionCode ( ) )
@ -54,7 +51,7 @@ public class RunPlanGenerator {
List < RunPlanRoutingVO > inboundRoutings = new ArrayList < > ( ) ;
RunPlanRoutingVO outboundRouting1 = null ;
RunPlanRoutingVO outboundRouting2 = null ;
if ( inputData . isOutAndIn ( ) ) {
if ( inputData . hasOutAndInBound ( ) ) {
/ / 确定出库
List < RunPlanRoutingVO > outboundRoutings = runPlanRoutingService . getUserRoutingByType ( userId , mapVO . getId ( ) , RunPlanRoutingVO . UserRoutingType . OUTBOUND ) ;
inboundRoutings = runPlanRoutingService . getUserRoutingByType ( userId , mapVO . getId ( ) , RunPlanRoutingVO . UserRoutingType . INBOUND ) ;
@ -64,12 +61,12 @@ public class RunPlanGenerator {
. findFirst ( ) . orElse ( null ) ;
outboundRouting2 = outboundRoutings . stream ( ) . filter ( outRouting - >
Objects . equals ( outRouting . getEndSectionCode ( ) , running2Routing . getStartSectionCode ( ) ) & & ! Objects . equals ( outRouting . getRight ( ) , running2Routing . getRight ( ) ) )
Objects . equals ( outRouting . getEndSectionCode ( ) , running2Routing . getStartSectionCode ( ) ) & & ! Objects . equals ( outRouting . getRight ( ) , running2Routing . getRight ( ) ) )
. sorted ( Comparator . comparingInt ( o - > o . getParkSectionCodeList ( ) . indexOf ( running2Routing . getParkSectionCodeList ( ) . get ( 0 ) ) ) )
. findFirst ( ) . orElse ( null ) ;
BusinessExceptionAssertEnum . DATA_NOT_EXIST . assertNotTrue ( Objects . isNull ( outboundRouting1 ) & & Objects . isNull ( outboundRouting2 ) , " 没有找到对应的出库交路 " ) ;
if ( ( Objects . nonNull ( outboundRouting1 ) & & Objects . nonNull ( outboundRouting2 ) ) & & Objects . equals ( outboundRouting1 . getRight ( ) , outboundRouting2 . getRight ( ) ) & & Objects . equals ( outboundRouting1 . getStartStationCode ( ) , outboundRouting2 . getStartStationCode ( ) ) ) {
outboundRouting2 = null ;
if ( ( Objects . nonNull ( outboundRouting1 ) & & Objects . nonNull ( outboundRouting2 ) ) & & Objects . equals ( outboundRouting1 . getRight ( ) , outboundRouting2 . getRight ( ) ) & & Objects . equals ( outboundRouting1 . getStartStationCode ( ) , outboundRouting2 . getStartStationCode ( ) ) ) {
outboundRouting2 = null ;
}
}
@ -80,60 +77,25 @@ public class RunPlanGenerator {
RunPlanUserConfigVO config = runPlanUserConfigService . getConfig ( userId , mapVO . getId ( ) ) ;
Map < String , RunPlanUserConfigVO . ReentryTime > reentryData = checkStationReentry ( mapVO , running1Routing , config ) ;
List < RunPlanTripVO > tripList = new ArrayList < > ( 100 ) ;
/ / 单个服务号还是多服务铺画
if ( Objects . nonNull ( inputData . getDepartureInterval ( ) ) ) {
if ( ! inputData . isOutAndIn ( ) | | ( Objects . nonNull ( outboundRouting1 ) & & Objects . nonNull ( outboundRouting2 ) ) ) {
/ / 相向发车
LinkedList < RunPlanTripVO > serviceTripList = generateService ( inputData , mapVO , outboundRouting1 , inboundRoutings , running1Routing , running2Routing , runLevelMap , parkTimeMap , reentryData ) ;
tripList . addAll ( serviceTripList ) ;
int startServiceNumber = Integer . parseInt ( inputData . getServiceNumber ( ) ) ;
LocalTime beginTime = inputData . getBeginTime ( ) ;
if ( inputData . multiService ( ) & & ( ! inputData . hasOutAndInBound ( ) | | ( Objects . nonNull ( outboundRouting1 ) & & Objects . nonNull ( outboundRouting2 ) ) ) ) {
/ / 相向发车
LinkedList < RunPlanTripVO > serviceTripList1 = generateService ( inputData , mapVO , outboundRouting1 , inboundRoutings , running1Routing , running2Routing , runLevelMap , parkTimeMap , reentryData ) ;
tripList . addAll ( serviceTripList1 ) ;
int startServiceNumber = Integer . parseInt ( inputData . getServiceNumber ( ) ) ;
LocalTime initBeginTime = inputData . getBeginTime ( ) ;
inputData . setServiceNumber ( String . format ( " %03d " , startServiceNumber + 1 ) ) ;
LinkedList < RunPlanTripVO > serviceTripList2 = generateService ( inputData , mapVO , outboundRouting2 , inboundRoutings , running2Routing , running1Routing , runLevelMap , parkTimeMap , reentryData ) ;
tripList . addAll ( serviceTripList2 ) ;
LocalTime firstRoundTripTime1 = getLastDepartTime ( inputData , mapVO , runLevelMap , parkTimeMap , reentryData , outboundRouting1 , outboundRouting2 , running1Routing , running2Routing , serviceTripList , true ) ;
DepartEndTime departEndTime = getDepartEndTime ( inputData , serviceTripList1 , serviceTripList2 ) ;
inputData . setServiceNumber ( String . format ( " %03d " , startServiceNumber + 1 ) ) ;
serviceTripList = generateService ( inputData , mapVO , outboundRouting2 , inboundRoutings , running2Routing , running1Routing , runLevelMap , parkTimeMap , reentryData ) ;
tripList . addAll ( serviceTripList ) ;
LocalTime firstRoundTripTime2 = getLastDepartTime ( inputData , mapVO , runLevelMap , parkTimeMap , reentryData , outboundRouting2 , outboundRouting1 , running2Routing , running1Routing , serviceTripList , true ) ;
inputData . setServiceNumber ( String . format ( " %03d " , startServiceNumber + 2 ) ) ;
generateServices ( inputData , mapVO , running1Routing , running2Routing , inboundRoutings , outboundRouting1 , runLevelMap , parkTimeMap , reentryData , tripList , beginTime , firstRoundTripTime2 ) ;
inputData . setServiceNumber ( String . format ( " %03d " , startServiceNumber + 3 ) ) ;
generateServices ( inputData , mapVO , running2Routing , running1Routing , inboundRoutings , outboundRouting2 , runLevelMap , parkTimeMap , reentryData , tripList , beginTime , firstRoundTripTime1 ) ;
} else {
LocalTime firstRoundTripTime = null ;
LocalTime preServiceDepartTime ;
RunPlanRoutingVO outboundRouting ;
/ / 出库的衔接环路
RunPlanRoutingVO outRefLoop ;
/ / 另一个交路
RunPlanRoutingVO otherLoop ;
if ( Objects . nonNull ( outboundRouting1 ) ) {
outboundRouting = outboundRouting1 ;
outRefLoop = running1Routing ;
otherLoop = running2Routing ;
} else {
outboundRouting = outboundRouting2 ;
outRefLoop = running2Routing ;
otherLoop = running1Routing ;
}
do {
LinkedList < RunPlanTripVO > serviceTripList = generateService ( inputData , mapVO , outboundRouting , inboundRoutings , outRefLoop , otherLoop , runLevelMap , parkTimeMap , reentryData ) ;
inputData . setServiceNumber ( String . format ( " %03d " , Integer . parseInt ( inputData . getServiceNumber ( ) ) + 2 ) ) ;
inputData . setBeginTime ( inputData . getBeginTime ( ) . plusSeconds ( inputData . getDepartureInterval ( ) ) ) ;
if ( Objects . isNull ( firstRoundTripTime ) ) {
firstRoundTripTime = getLastDepartTime ( inputData , mapVO , runLevelMap , parkTimeMap , reentryData , outboundRouting , null , outRefLoop , otherLoop , serviceTripList , false ) ;
}
preServiceDepartTime = serviceTripList . getFirst ( ) . getStartTime ( ) ;
tripList . addAll ( serviceTripList ) ;
} while ( preServiceDepartTime . plusSeconds ( inputData . getDepartureInterval ( ) * 2 ) . compareTo ( firstRoundTripTime ) < = 0 ) ;
}
inputData . setServiceNumber ( String . format ( " %03d " , startServiceNumber + 2 ) ) ;
generateServices ( inputData , mapVO , running1Routing , running2Routing , inboundRoutings , outboundRouting1 , runLevelMap , parkTimeMap , reentryData , tripList , initBeginTime , departEndTime . departEndTime1 ) ;
inputData . setServiceNumber ( String . format ( " %03d " , startServiceNumber + 3 ) ) ;
generateServices ( inputData , mapVO , running2Routing , running1Routing , inboundRoutings , outboundRouting2 , runLevelMap , parkTimeMap , reentryData , tripList , initBeginTime , departEndTime . departEndTime2 ) ;
} else {
RunPlanRoutingVO outboundRouting ;
/ / 出库的衔接环路
RunPlanRoutingVO outRefLoop ;
@ -148,66 +110,190 @@ public class RunPlanGenerator {
outRefLoop = running2Routing ;
otherLoop = running1Routing ;
}
tripList . addAll ( generateService ( inputData , mapVO , outboundRouting , inboundRoutings , outRefLoop , otherLoop , runLevelMap , parkTimeMap , reentryData ) ) ;
if ( inputData . multiService ( ) ) {
LocalTime departEndTime = null ;
LocalTime preServiceDepartTime ;
do {
LinkedList < RunPlanTripVO > serviceTripList = generateService ( inputData , mapVO , outboundRouting , inboundRoutings , outRefLoop , otherLoop , runLevelMap , parkTimeMap , reentryData ) ;
if ( Objects . isNull ( departEndTime ) ) {
departEndTime = getDepartEndTime ( inputData , serviceTripList ) ;
}
preServiceDepartTime = serviceTripList . getFirst ( ) . getStartTime ( ) ;
tripList . addAll ( serviceTripList ) ;
inputData . setServiceNumber ( String . format ( " %03d " , Integer . parseInt ( inputData . getServiceNumber ( ) ) + 2 ) ) ;
inputData . setBeginTime ( inputData . getBeginTime ( ) . plusSeconds ( inputData . getDepartureInterval ( ) ) ) ;
} while ( preServiceDepartTime . plusSeconds ( inputData . getDepartureInterval ( ) * 2 ) . compareTo ( departEndTime ) < = 0 ) ;
} else {
tripList . addAll ( generateService ( inputData , mapVO , outboundRouting , inboundRoutings , outRefLoop , otherLoop , runLevelMap , parkTimeMap , reentryData ) ) ;
}
}
return tripList ;
}
private void generateServices ( RunPlanInputData inputData , MapVO mapVO , RunPlanRoutingVO running1Routing , RunPlanRoutingVO running2Routing , List < RunPlanRoutingVO > inboundRoutings , RunPlanRoutingVO outboundRouting1 , Map < String , Integer > runLevelMap , Map < String , Integer > parkTimeMap , Map < String , RunPlanUserConfigVO . ReentryTime > reentryData , List < RunPlanTripVO > tripList , LocalTime beginTime , LocalTime firstRoundTripTime2 ) {
LinkedList < RunPlanTripVO > serviceTripList ;
inputData . setBeginTime ( beginTime . plusSeconds ( inputData . getDepartureInterval ( ) ) ) ;
LocalTime preServiceDepartTime1 ;
do {
serviceTripList = generateService ( inputData , mapVO , outboundRouting1 , inboundRoutings , running1Routing , running2Routing , runLevelMap , parkTimeMap , reentryData ) ;
inputData . setServiceNumber ( String . format ( " %03d " , Integer . parseInt ( inputData . getServiceNumber ( ) ) + 2 ) ) ;
inputData . setBeginTime ( inputData . getBeginTime ( ) . plusSeconds ( inputData . getDepartureInterval ( ) ) ) ;
preServiceDepartTime1 = serviceTripList . getFirst ( ) . getStartTime ( ) ;
tripList . addAll ( serviceTripList ) ;
} while ( preServiceDepartTime1 . plusSeconds ( inputData . getDepartureInterval ( ) * 2 ) . compareTo ( firstRoundTripTime2 ) < = 0 ) ;
private LocalTime getDepartEndTime ( RunPlanInputData inputData , LinkedList < RunPlanTripVO > serviceTripList ) {
LocalTime departEndTime ;
List < RunPlanTripTimeVO > outBoundTimeList = serviceTripList . getFirst ( ) . getTimeList ( ) ;
RunPlanTripTimeVO tripTime = null ;
LocalTime overTime = null ;
k :
for ( int f = 1 ; f < outBoundTimeList . size ( ) ; f + + ) {
tripTime = outBoundTimeList . get ( f ) ;
for ( int i = 0 ; i < serviceTripList . size ( ) ; i + = 2 ) {
List < RunPlanTripTimeVO > secondTimeList = serviceTripList . get ( i ) . getTimeList ( ) ;
for ( RunPlanTripTimeVO runPlanTripTimeVO : secondTimeList ) {
if ( Objects . equals ( runPlanTripTimeVO . getStationCode ( ) , tripTime . getStationCode ( ) ) ) {
if ( runPlanTripTimeVO . getArrivalTime ( ) . isAfter ( tripTime . getArrivalTime ( ) ) ) {
overTime = runPlanTripTimeVO . getArrivalTime ( ) ;
break k ;
}
break ;
}
}
}
}
departEndTime = Objects . nonNull ( overTime ) ? overTime . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , tripTime . getArrivalTime ( ) ) ) : LocalTime . of ( 12 , 0 ) ;
return departEndTime ;
}
private LocalTime getLastDepartTime ( RunPlanInputData inputData , MapVO mapVO ,
Map < String , Integer > runLevelMap , Map < String , Integer > parkTimeMap , Map < String , RunPlanUserConfigVO . ReentryTime > reentryData ,
RunPlanRoutingVO outboundRouting , RunPlanRoutingVO otherOutboundRouting , RunPlanRoutingVO outRefLoop , RunPlanRoutingVO otherLoop ,
LinkedList < RunPlanTripVO > serviceTripList , boolean opposite ) {
if ( inputData . isOutAndIn ( ) ) {
if ( Objects . equals ( outboundRouting . getRight ( ) , outRefLoop . getRight ( ) ) ) {
LocalTime firstRoundTripTime ;
if ( serviceTripList . size ( ) = = 2 ) {
firstRoundTripTime = serviceTripList . get ( 1 ) . getEndTime ( ) ;
} else if ( Objects . equals ( outboundRouting . getParkSectionCodeList ( ) . get ( 1 ) . getStationCode ( ) , outRefLoop . getStartStationCode ( ) ) ) {
firstRoundTripTime = serviceTripList . get ( opposite ? 1 : 2 ) . getEndTime ( ) ;
} else {
int outTripRunTime = getOutTripRunTime ( mapVO , opposite ? otherOutboundRouting : outboundRouting , runLevelMap , parkTimeMap , reentryData ) ;
if ( serviceTripList . size ( ) = = 3 ) {
int inTripRunTime = getInTripRunTime ( mapVO , inputData . getInboundRouting ( ) , runLevelMap , parkTimeMap , reentryData ) ;
int outRefTripRunTime = getLoopTripRunTime ( mapVO , outRefLoop , runLevelMap , parkTimeMap , reentryData ) ;
firstRoundTripTime = serviceTripList . get ( 2 ) . getEndTime ( ) . minusSeconds ( inTripRunTime - outRefTripRunTime + outTripRunTime ) ;
} else {
firstRoundTripTime = serviceTripList . get ( opposite ? 2 : 3 ) . getEndTime ( ) . minusSeconds ( outTripRunTime ) ;
}
}
return firstRoundTripTime ;
}
if ( Objects . equals ( outboundRouting . getRight ( ) , otherLoop . getRight ( ) ) ) {
LocalTime firstRoundTripTime ;
if ( Objects . equals ( outboundRouting . getParkSectionCodeList ( ) . get ( 1 ) . getStationCode ( ) , otherLoop . getStartStationCode ( ) ) | | serviceTripList . size ( ) = = 2 ) {
firstRoundTripTime = serviceTripList . get ( opposite ? 0 : 1 ) . getEndTime ( ) ;
} else {
int outTripRunTime = getOutTripRunTime ( mapVO , opposite ? otherOutboundRouting : outboundRouting , runLevelMap , parkTimeMap , reentryData ) ;
if ( serviceTripList . size ( ) = = 3 ) {
int inTripRunTime = getInTripRunTime ( mapVO , inputData . getInboundRouting ( ) , runLevelMap , parkTimeMap , reentryData ) ;
int outRefTripRunTime = getLoopTripRunTime ( mapVO , otherLoop , runLevelMap , parkTimeMap , reentryData ) ;
firstRoundTripTime = serviceTripList . get ( opposite ? 1 : 2 ) . getEndTime ( ) . minusSeconds ( inTripRunTime - outRefTripRunTime + outTripRunTime ) ;
} else {
firstRoundTripTime = serviceTripList . get ( opposite ? 1 : 2 ) . getEndTime ( ) . minusSeconds ( outTripRunTime ) ;
}
}
return firstRoundTripTime ;
}
return null ;
private void checkInputTime ( RunPlanInputData inputData ) {
BusinessExceptionAssertEnum . DATA_ERROR . assertTrue ( inputData . getOverTime ( ) . isAfter ( inputData . getBeginTime ( ) ) , " 输入参数错误:发车时间应早于结束时间 " ) ;
LocalTime beginTimeOffset = inputData . getBeginTime ( ) . minusHours ( OFFSET_TIME_HOURS ) ;
BusinessExceptionAssertEnum . DATA_ERROR . assertTrue ( inputData . getBeginTime ( ) . isAfter ( beginTimeOffset ) , " 发车时间过早,建议晚于上午两点 " ) ;
inputData . setBeginTime ( beginTimeOffset ) ;
inputData . setOverTime ( inputData . getOverTime ( ) . minusHours ( OFFSET_TIME_HOURS ) ) ;
}
private void generateServices ( RunPlanInputData inputData , MapVO mapVO , RunPlanRoutingVO running1Routing , RunPlanRoutingVO running2Routing , List < RunPlanRoutingVO > inboundRoutings , RunPlanRoutingVO outboundRouting1 , Map < String , Integer > runLevelMap , Map < String , Integer > parkTimeMap , Map < String , RunPlanUserConfigVO . ReentryTime > reentryData , List < RunPlanTripVO > tripList , LocalTime initBeginTime , LocalTime departEndTime ) {
LinkedList < RunPlanTripVO > serviceTripList ;
inputData . setBeginTime ( initBeginTime ) ;
LocalTime preServiceDepartTime = inputData . getBeginTime ( ) ;
while ( preServiceDepartTime . plusSeconds ( inputData . getDepartureInterval ( ) * 2 ) . compareTo ( Objects . nonNull ( departEndTime ) ? departEndTime : LocalTime . of ( 12 , 0 ) ) < = 0 ) {
inputData . setBeginTime ( inputData . getBeginTime ( ) . plusSeconds ( inputData . getDepartureInterval ( ) ) ) ;
serviceTripList = generateService ( inputData , mapVO , outboundRouting1 , inboundRoutings , running1Routing , running2Routing , runLevelMap , parkTimeMap , reentryData ) ;
inputData . setServiceNumber ( String . format ( " %03d " , Integer . parseInt ( inputData . getServiceNumber ( ) ) + 2 ) ) ;
preServiceDepartTime = serviceTripList . getFirst ( ) . getStartTime ( ) ;
tripList . addAll ( serviceTripList ) ;
}
return serviceTripList . get ( 0 ) . getEndTime ( ) ;
}
private DepartEndTime getDepartEndTime ( RunPlanInputData inputData , LinkedList < RunPlanTripVO > serviceTripList1 , LinkedList < RunPlanTripVO > serviceTripList2 ) {
Long interval1 = null ;
LocalTime time11 = null ;
LocalTime time12 = null ;
RunPlanTripTimeVO collisionTripTime1 = null ;
List < RunPlanTripTimeVO > firstTimeListOf1 = serviceTripList1 . getFirst ( ) . getTimeList ( ) ;
List < RunPlanTripTimeVO > secondTimeListOf2 = serviceTripList2 . get ( 1 ) . getTimeList ( ) ;
k :
for ( int i = 1 ; i < firstTimeListOf1 . size ( ) ; i + + ) {
for ( int y = 0 ; y < secondTimeListOf2 . size ( ) ; y + + ) {
if ( Objects . equals ( firstTimeListOf1 . get ( i ) . getStationCode ( ) , secondTimeListOf2 . get ( y ) . getStationCode ( ) ) ) {
time11 = firstTimeListOf1 . get ( i ) . getArrivalTime ( ) ;
time12 = secondTimeListOf2 . get ( y ) . getArrivalTime ( ) ;
interval1 = ChronoUnit . SECONDS . between ( time11 , time12 ) ;
collisionTripTime1 = firstTimeListOf1 . get ( i ) ;
break k ;
}
}
}
Long interval2 = null ;
LocalTime time22 = null ;
LocalTime time21 = null ;
RunPlanTripTimeVO collisionTripTime2 = null ;
List < RunPlanTripTimeVO > firstTimeListOf2 = serviceTripList2 . getFirst ( ) . getTimeList ( ) ;
List < RunPlanTripTimeVO > secondTimeListOf1 = serviceTripList1 . get ( 1 ) . getTimeList ( ) ;
k :
for ( int i = 1 ; i < firstTimeListOf2 . size ( ) ; i + + ) {
for ( int y = 0 ; y < secondTimeListOf1 . size ( ) ; y + + ) {
if ( Objects . equals ( firstTimeListOf2 . get ( i ) . getStationCode ( ) , secondTimeListOf1 . get ( y ) . getStationCode ( ) ) ) {
time22 = firstTimeListOf2 . get ( i ) . getArrivalTime ( ) ;
time21 = secondTimeListOf1 . get ( y ) . getArrivalTime ( ) ;
interval2 = ChronoUnit . SECONDS . between ( time22 , time21 ) ;
collisionTripTime2 = firstTimeListOf2 . get ( i ) ;
break k ;
}
}
}
if ( ( Objects . isNull ( interval1 ) & & Objects . isNull ( interval2 ) ) ) {
return new DepartEndTime ( null , null ) ;
}
LocalTime departEndTime1 = null ;
LocalTime departEndTime2 = null ;
LocalTime overTime = null ;
if ( Objects . isNull ( interval2 ) | | ( Objects . nonNull ( interval1 ) & & Math . abs ( interval1 ) < = Math . abs ( interval2 ) ) ) {
if ( time11 . isBefore ( time12 ) ) {
if ( Objects . nonNull ( interval2 ) & & time22 . isBefore ( time21 ) ) {
departEndTime1 = time12 . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , time11 ) ) ;
departEndTime2 = time21 . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , time22 ) ) ;
} else {
departEndTime1 = time12 . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , time11 ) ) ;
departEndTime2 = inputData . getBeginTime ( ) . plusSeconds ( Math . abs ( interval1 ) ) ;
}
} else {
departEndTime2 = inputData . getBeginTime ( ) . plusSeconds ( Math . abs ( interval1 ) ) ;
k :
for ( int i = 1 ; i < serviceTripList2 . size ( ) ; i + = 2 ) {
List < RunPlanTripTimeVO > secondTimeList = serviceTripList2 . get ( i ) . getTimeList ( ) ;
for ( RunPlanTripTimeVO runPlanTripTimeVO : secondTimeList ) {
if ( Objects . equals ( runPlanTripTimeVO . getStationCode ( ) , collisionTripTime1 . getStationCode ( ) ) ) {
if ( runPlanTripTimeVO . getArrivalTime ( ) . isAfter ( collisionTripTime1 . getArrivalTime ( ) ) ) {
overTime = runPlanTripTimeVO . getArrivalTime ( ) ;
break k ;
}
break ;
}
}
}
if ( Objects . nonNull ( overTime ) ) {
departEndTime1 = overTime . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , time11 ) ) ;
}
}
} else {
if ( time22 . isBefore ( time21 ) ) {
if ( Objects . nonNull ( interval1 ) & & time11 . isBefore ( time12 ) ) {
departEndTime2 = time21 . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , time22 ) ) ;
departEndTime1 = time12 . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , time11 ) ) ;
} else {
departEndTime2 = time21 . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , time22 ) ) ;
departEndTime1 = inputData . getBeginTime ( ) . plusSeconds ( Math . abs ( interval2 ) ) ;
}
} else {
departEndTime1 = inputData . getBeginTime ( ) . plusSeconds ( Math . abs ( interval2 ) ) ;
k :
for ( int i = 1 ; i < serviceTripList1 . size ( ) ; i + = 2 ) {
List < RunPlanTripTimeVO > secondTimeList = serviceTripList1 . get ( i ) . getTimeList ( ) ;
for ( RunPlanTripTimeVO runPlanTripTimeVO : secondTimeList ) {
if ( Objects . equals ( runPlanTripTimeVO . getStationCode ( ) , collisionTripTime2 . getStationCode ( ) ) ) {
if ( runPlanTripTimeVO . getArrivalTime ( ) . isAfter ( collisionTripTime2 . getArrivalTime ( ) ) ) {
overTime = runPlanTripTimeVO . getArrivalTime ( ) ;
break k ;
}
break ;
}
}
}
if ( Objects . nonNull ( overTime ) ) {
departEndTime2 = overTime . minusSeconds ( ChronoUnit . SECONDS . between ( inputData . getBeginTime ( ) , time22 ) ) ;
}
}
}
return new DepartEndTime ( departEndTime1 , departEndTime2 ) ;
}
@AllArgsConstructor
@Getter
class DepartEndTime {
LocalTime departEndTime1 ;
LocalTime departEndTime2 ;
}
private Map < String , RunPlanUserConfigVO . ReentryTime > checkStationReentry ( MapVO mapVO , RunPlanRoutingVO running1Routing , RunPlanUserConfigVO config ) {
@ -247,7 +333,7 @@ public class RunPlanGenerator {
LinkedList < RunPlanTripVO > serviceTripList = new LinkedList < > ( ) ;
int nextTripNumber = 1 ;
if ( inputData . isOutAndIn ( ) ) {
if ( inputData . hasOutAndInBound ( ) ) {
/ / 构建出库车次
nextTripNumber = buildServiceTrip ( inputData , mapVO , outboundRouting , runLevelMap , parkTimeMap , reentryData , serviceTripList , nextTripNumber ) ;
}
@ -271,17 +357,17 @@ public class RunPlanGenerator {
}
}
if ( inputData . isOutAndIn ( ) ) {
if ( inputData . hasOutAndInBound ( ) ) {
/ / 找最快回库交路
RunPlanRoutingVO inboundRouting ;
if ( loop ) {
inboundRouting = inboundRoutings . stream ( ) . filter ( inRouting - >
Objects . equals ( inRouting . getStartS ectionCode( ) , otherLoop . getStartSectionCode ( ) ) & & Objects . equals ( inRouting . getRight ( ) , otherLoop . getRight ( ) ) )
Objects . equals ( inRouting . getStartS tationCode( ) , otherLoop . getStartStationCode ( ) ) /*&& Objects.equals(inRouting.getRight(), otherLoop.getRight())*/ )
. sorted ( Comparator . comparingInt ( o - > o . getParkSectionCodeList ( ) . size ( ) ) )
. findFirst ( ) . orElse ( null ) ;
} else {
inboundRouting = inboundRoutings . stream ( ) . filter ( inRouting - >
Objects . equals ( inRouting . getStartS ectionCode( ) , outRefLoop . getStartSectionCode ( ) ) & & Objects . equals ( inRouting . getRight ( ) , outRefLoop . getRight ( ) ) )
Objects . equals ( inRouting . getStartS tationCode( ) , outRefLoop . getStartStationCode ( ) ) /*&& Objects.equals(inRouting.getRight(), outRefLoop.getRight())*/ )
. sorted ( Comparator . comparingInt ( o - > o . getParkSectionCodeList ( ) . size ( ) ) )
. findFirst ( ) . orElse ( null ) ;
}