@ -5,26 +5,23 @@ import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStandService;
import club.joylink.rtss.simulation.cbtc.ATS.service.AtsTrainService ;
import club.joylink.rtss.simulation.cbtc.ATS.service.AtsTrainService ;
import club.joylink.rtss.simulation.cbtc.Simulation ;
import club.joylink.rtss.simulation.cbtc.Simulation ;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository ;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository ;
import club.joylink.rtss.simulation.cbtc.data.map.MapConfig ;
import club.joylink.rtss.simulation.cbtc.data.map.* ;
import club.joylink.rtss.simulation.cbtc.data.map.Route ;
import club.joylink.rtss.simulation.cbtc.data.map.Section ;
import club.joylink.rtss.simulation.cbtc.data.map.Signal ;
import club.joylink.rtss.simulation.cbtc.data.map.Stand ;
import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan ;
import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan ;
import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan ;
import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan ;
import club.joylink.rtss.simulation.cbtc.data.support.RoutePath ;
import club.joylink.rtss.simulation.cbtc.data.support.RoutePath ;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo ;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo ;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.OnboardAtpApiService ;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.OnboardAtpApiService ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Component ;
import org.springframework.util.CollectionUtils ;
import java.time.LocalDateTime ;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
import java.time.LocalTime ;
import java.time.temporal.ChronoUnit ;
import java.time.temporal.ChronoUnit ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.List ;
import java.util.Objects ;
import java.util.Objects ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Component ;
import org.springframework.util.CollectionUtils ;
/ * *
/ * *
* 计划车阶段处理服务
* 计划车阶段处理服务
@ -32,7 +29,6 @@ import org.springframework.util.CollectionUtils;
@Slf4j
@Slf4j
@Component
@Component
public class AtsPlanTrainStageService implements AtsStageService {
public class AtsPlanTrainStageService implements AtsStageService {
@Autowired
@Autowired
private AtsRealRunRecordService realRunRecordService ;
private AtsRealRunRecordService realRunRecordService ;
@Autowired
@Autowired
@ -43,11 +39,9 @@ public class AtsPlanTrainStageService implements AtsStageService {
private AtsTrainService atsTrainService ;
private AtsTrainService atsTrainService ;
@Override
@Override
public void handleTransferTrackParking ( Simulation simulation , TrainInfo trainInfo ,
public void handleTransferTrackParking ( Simulation simulation , TrainInfo trainInfo , Section parkSection ) {
Section parkSection ) {
SimulationDataRepository repository = simulation . getRepository ( ) ;
SimulationDataRepository repository = simulation . getRepository ( ) ;
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) ,
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) , trainInfo . getTripNumber ( ) ) ;
trainInfo . getTripNumber ( ) ) ;
/ / List < RoutePath > routePathList = repository . queryRoutePathsByEnd ( parkSection ) ;
/ / List < RoutePath > routePathList = repository . queryRoutePathsByEnd ( parkSection ) ;
/ / if ( routePathList . get ( 0 ) . isRight ( ) = = trainInfo . getRight ( ) ) { / / 准备回库
/ / if ( routePathList . get ( 0 ) . isRight ( ) = = trainInfo . getRight ( ) ) { / / 准备回库
/ / if ( ! parkSection . isTurnBackTrack ( ) ) { / / 针对上饶沙盘
/ / if ( ! parkSection . isTurnBackTrack ( ) ) { / / 针对上饶沙盘
@ -88,18 +82,15 @@ public class AtsPlanTrainStageService implements AtsStageService {
}
}
@Override
@Override
public void handleNormalStandParking ( Simulation simulation , TrainInfo trainInfo ,
public void handleNormalStandParking ( Simulation simulation , TrainInfo trainInfo , Section parkSection ) {
Section parkSection ) {
SimulationDataRepository repository = simulation . getRepository ( ) ;
SimulationDataRepository repository = simulation . getRepository ( ) ;
MapConfig config = repository . getConfig ( ) ;
MapConfig config = repository . getConfig ( ) ;
List < Stand > standList = parkSection . getStandList ( ) ;
List < Stand > standList = parkSection . getStandList ( ) ;
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) ,
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) , trainInfo . getTripNumber ( ) ) ;
trainInfo . getTripNumber ( ) ) ;
TripPlan nextTripPlan = null ;
TripPlan nextTripPlan = null ;
StationPlan stationPlan = tripPlan . queryStationPlan ( parkSection ) ;
StationPlan stationPlan = tripPlan . queryStationPlan ( parkSection ) ;
if ( config . isStandTbStrategyIsInvalid ( ) ) {
if ( config . isStandTbStrategyIsInvalid ( ) ) {
if ( stationPlan ! = null & & tripPlan . isLastPlan ( stationPlan )
if ( stationPlan ! = null & & tripPlan . isLastPlan ( stationPlan ) & & tripPlan . isFrontTurnBack ( ) ) { / / 到达终点站了 , 判断站前折返还是站后折返
& & tripPlan . isFrontTurnBack ( ) ) { / / 到达终点站了 , 判断站前折返还是站后折返
/ / 站前折返 , 查询下一车次计划
/ / 站前折返 , 查询下一车次计划
nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
} else if ( stationPlan = = null & & tripPlan . isLastPlanStation ( parkSection . getStation ( ) ) ) {
} else if ( stationPlan = = null & & tripPlan . isLastPlanStation ( parkSection . getStation ( ) ) ) {
@ -110,12 +101,9 @@ public class AtsPlanTrainStageService implements AtsStageService {
}
}
if ( nextTripPlan ! = null ) { / / 站前折返 , 更新计划
if ( nextTripPlan ! = null ) { / / 站前折返 , 更新计划
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
BusinessExceptionAssertEnum . DATA_ERROR . assertEquals (
BusinessExceptionAssertEnum . DATA_ERROR . assertEquals ( nextTripPlan . getFirstStationPlan ( ) . getSection ( ) , parkSection ,
nextTripPlan . getFirstStationPlan ( ) . getSection ( ) , parkSection ,
String . format ( " 下一车次计划[%s]第一站台轨和停靠站台轨不相同:[%s] " , nextTripPlan . getStNumber ( ) , parkSection . getName ( ) ) ) ;
String . format ( " 下一车次计划[%s]第一站台轨和停靠站台轨不相同:[%s] " ,
this . updateNextPlan ( simulation , trainInfo , nextTripPlan , nextTripPlan . getFirstStationPlan ( ) ) ;
nextTripPlan . getStNumber ( ) , parkSection . getName ( ) ) ) ;
this . updateNextPlan ( simulation , trainInfo , nextTripPlan ,
nextTripPlan . getFirstStationPlan ( ) ) ;
}
}
} else {
} else {
if ( ! CollectionUtils . isEmpty ( standList ) ) {
if ( ! CollectionUtils . isEmpty ( standList ) ) {
@ -126,24 +114,20 @@ public class AtsPlanTrainStageService implements AtsStageService {
case AUTO :
case AUTO :
if ( stationPlan ! = null & & tripPlan . isLastPlan ( stationPlan ) ) { / / 当前计划终点站
if ( stationPlan ! = null & & tripPlan . isLastPlan ( stationPlan ) ) { / / 当前计划终点站
if ( Objects . equals ( stand . isRight ( ) , trainInfo . getRight ( ) ) ) {
if ( Objects . equals ( stand . isRight ( ) , trainInfo . getRight ( ) ) ) {
onboardAtpApiService . startTurnBack ( simulation , trainInfo . getGroupNumber ( ) ,
onboardAtpApiService . startTurnBack ( simulation , trainInfo . getGroupNumber ( ) , parkSection . getCode ( ) ) ;
parkSection . getCode ( ) ) ;
nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
if ( nextTripPlan ! = null ) { / / 站前折返 , 更新计划
if ( nextTripPlan ! = null ) { / / 站前折返 , 更新计划
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
this . updateNextPlan ( simulation , trainInfo , nextTripPlan ,
this . updateNextPlan ( simulation , trainInfo , nextTripPlan , nextTripPlan . getSecondStationPlan ( ) ) ;
nextTripPlan . getSecondStationPlan ( ) ) ;
}
}
}
}
}
}
break ;
break ;
default :
default :
if ( stationPlan ! = null & & tripPlan . isLastPlan ( stationPlan )
if ( stationPlan ! = null & & tripPlan . isLastPlan ( stationPlan ) & & tripPlan . isFrontTurnBack ( ) ) { / / 到达终点站了 , 判断站前折返还是站后折返
& & tripPlan . isFrontTurnBack ( ) ) { / / 到达终点站了 , 判断站前折返还是站后折返
/ / 站前折返 , 查询下一车次计划
/ / 站前折返 , 查询下一车次计划
nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
} else if ( stationPlan = = null & & tripPlan . isLastPlanStation (
} else if ( stationPlan = = null & & tripPlan . isLastPlanStation ( parkSection . getStation ( ) ) ) {
parkSection . getStation ( ) ) ) {
if ( config . isAtsAutoHandleManualFrontTurnBack ( ) ) {
if ( config . isAtsAutoHandleManualFrontTurnBack ( ) ) {
/ / 人工站前折返
/ / 人工站前折返
nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
@ -151,12 +135,9 @@ public class AtsPlanTrainStageService implements AtsStageService {
}
}
if ( nextTripPlan ! = null ) { / / 站前折返 , 更新计划
if ( nextTripPlan ! = null ) { / / 站前折返 , 更新计划
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
BusinessExceptionAssertEnum . DATA_ERROR . assertEquals (
BusinessExceptionAssertEnum . DATA_ERROR . assertEquals ( nextTripPlan . getFirstStationPlan ( ) . getSection ( ) , parkSection ,
nextTripPlan . getFirstStationPlan ( ) . getSection ( ) , parkSection ,
String . format ( " 下一车次计划[%s]第一站台轨和停靠站台轨不相同:[%s] " , nextTripPlan . getStNumber ( ) , parkSection . getName ( ) ) ) ;
String . format ( " 下一车次计划[%s]第一站台轨和停靠站台轨不相同:[%s] " ,
this . updateNextPlan ( simulation , trainInfo , nextTripPlan , nextTripPlan . getFirstStationPlan ( ) ) ;
nextTripPlan . getStNumber ( ) , parkSection . getName ( ) ) ) ;
this . updateNextPlan ( simulation , trainInfo , nextTripPlan ,
nextTripPlan . getFirstStationPlan ( ) ) ;
}
}
break ;
break ;
}
}
@ -165,11 +146,9 @@ public class AtsPlanTrainStageService implements AtsStageService {
}
}
@Override
@Override
public void ready2DepartFromNormalStand ( Simulation simulation , TrainInfo trainInfo ,
public void ready2DepartFromNormalStand ( Simulation simulation , TrainInfo trainInfo , Section parkSection ) {
Section parkSection ) {
SimulationDataRepository repository = simulation . getRepository ( ) ;
SimulationDataRepository repository = simulation . getRepository ( ) ;
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) ,
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) , trainInfo . getTripNumber ( ) ) ;
trainInfo . getTripNumber ( ) ) ;
StationPlan stationPlan = tripPlan . queryStationPlan ( parkSection ) ;
StationPlan stationPlan = tripPlan . queryStationPlan ( parkSection ) ;
if ( stationPlan = = null ) {
if ( stationPlan = = null ) {
/ / 非计划中的停靠站台轨 , 暂不处理
/ / 非计划中的停靠站台轨 , 暂不处理
@ -189,8 +168,7 @@ public class AtsPlanTrainStageService implements AtsStageService {
}
}
/ / 到达终点站 , 准备折返
/ / 到达终点站 , 准备折返
log . debug ( String . format ( " 列车[%s]折返初始化 " , trainInfo . getGroupNumber ( ) ) ) ;
log . debug ( String . format ( " 列车[%s]折返初始化 " , trainInfo . getGroupNumber ( ) ) ) ;
List < RoutePath > routePaths = repository . getRoutePaths ( parkSection ,
List < RoutePath > routePaths = repository . getRoutePaths ( parkSection , tripPlan . getEndSection ( ) ) ;
tripPlan . getEndSection ( ) ) ;
Signal signal = parkSection . getSignalOf ( routePaths . get ( 0 ) . isRight ( ) ) ;
Signal signal = parkSection . getSignalOf ( routePaths . get ( 0 ) . isRight ( ) ) ;
if ( signal . isMainAspect ( ) | | signal . isGuideAspect ( ) ) {
if ( signal . isMainAspect ( ) | | signal . isGuideAspect ( ) ) {
Route lockedRoute = signal . getLockedRoute ( ) ;
Route lockedRoute = signal . getLockedRoute ( ) ;
@ -212,8 +190,7 @@ public class AtsPlanTrainStageService implements AtsStageService {
this . onboardAtpApiService . updateTripPlan ( simulation , trainInfo . getGroupNumber ( ) , nextTripPlan ) ;
this . onboardAtpApiService . updateTripPlan ( simulation , trainInfo . getGroupNumber ( ) , nextTripPlan ) ;
}
}
public void updateNextPlan ( Simulation simulation , TrainInfo trainInfo , TripPlan tripPlan ,
public void updateNextPlan ( Simulation simulation , TrainInfo trainInfo , TripPlan tripPlan , StationPlan nextStationPlan ) {
StationPlan nextStationPlan ) {
if ( nextStationPlan = = null ) {
if ( nextStationPlan = = null ) {
log . warn ( String . format ( " 列车[%s]下一计划到站为null " , trainInfo . debugStr ( ) ) ) ;
log . warn ( String . format ( " 列车[%s]下一计划到站为null " , trainInfo . debugStr ( ) ) ) ;
return ;
return ;
@ -262,8 +239,7 @@ public class AtsPlanTrainStageService implements AtsStageService {
}
}
int planRunTime = ( int ) ChronoUnit . SECONDS . between ( startTime , endTime ) ;
int planRunTime = ( int ) ChronoUnit . SECONDS . between ( startTime , endTime ) ;
int adjustRunTime = planRunTime ;
int adjustRunTime = planRunTime ;
if ( ! turnBack & & ! outbound & & config . isAdjustOperationAutomatically ( )
if ( ! turnBack & & ! outbound & & config . isAdjustOperationAutomatically ( ) & & trainInfo . isAtsAutoAdjust ( ) ) {
& & trainInfo . isAtsAutoAdjust ( ) ) {
startTime = systemTime . toLocalTime ( ) ;
startTime = systemTime . toLocalTime ( ) ;
adjustRunTime = ( int ) ChronoUnit . SECONDS . between ( startTime , endTime ) ;
adjustRunTime = ( int ) ChronoUnit . SECONDS . between ( startTime , endTime ) ;
}
}
@ -277,17 +253,12 @@ public class AtsPlanTrainStageService implements AtsStageService {
}
}
@Override
@Override
public void handleTurnBackTrackParking ( Simulation simulation , TrainInfo trainInfo ,
public void handleTurnBackTrackParking ( Simulation simulation , TrainInfo trainInfo , Section parkSection ) {
Section parkSection ) {
SimulationDataRepository repository = simulation . getRepository ( ) ;
SimulationDataRepository repository = simulation . getRepository ( ) ;
LocalDateTime systemTime = simulation . getSystemTime ( ) ;
LocalDateTime systemTime = simulation . getSystemTime ( ) ;
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) ,
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) , trainInfo . getTripNumber ( ) ) ;
trainInfo . getTripNumber ( ) ) ;
if ( tripPlan . getEndSection ( ) . equals ( parkSection )
/*|| tripPlan.getEndSection().getStation().equals(parkSection.getStation())*/ ) {
/ / 车次计划中的车站计划全部完成 , 并且当前折返轨与计划折返轨属于同一站 , 则认为车次计划完成
boolean completed = tripPlan . getPlanList ( ) . stream ( ) . allMatch ( StationPlan : : isFinished )
& & tripPlan . getEndSection ( ) . getStation ( ) . equals ( parkSection . getStation ( ) ) ;
if ( completed ) {
/ / 计划终端折返轨或和计划终端折返轨同站的折返轨 , 根据车次类型处理
/ / 计划终端折返轨或和计划终端折返轨同站的折返轨 , 根据车次类型处理
TripPlan nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
TripPlan nextTripPlan = repository . queryNextTripPlanOf ( tripPlan ) ;
if ( nextTripPlan = = null ) {
if ( nextTripPlan = = null ) {
@ -297,19 +268,15 @@ public class AtsPlanTrainStageService implements AtsStageService {
/ / 备用车
/ / 备用车
if ( systemTime . toLocalTime ( ) . plusMinutes ( 5 ) . isAfter ( nextTripPlan . getStartTime ( ) ) ) {
if ( systemTime . toLocalTime ( ) . plusMinutes ( 5 ) . isAfter ( nextTripPlan . getStartTime ( ) ) ) {
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
BusinessExceptionAssertEnum . DATA_ERROR . assertNotEquals ( parkSection ,
BusinessExceptionAssertEnum . DATA_ERROR . assertNotEquals ( parkSection , nextTripPlan . getFirstStationPlan ( ) . getSection ( ) ) ;
nextTripPlan . getFirstStationPlan ( ) . getSection ( ) ) ;
this . updateNextPlan ( simulation , trainInfo , nextTripPlan , nextTripPlan . getFirstStationPlan ( ) ) ;
this . updateNextPlan ( simulation , trainInfo , nextTripPlan ,
nextTripPlan . getFirstStationPlan ( ) ) ;
return ;
return ;
}
}
} else if ( tripPlan . isTurnBack ( ) ) {
} else if ( tripPlan . isTurnBack ( ) ) {
/ / 折返计划
/ / 折返计划
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
this . updateTripPlan ( simulation , trainInfo , nextTripPlan ) ;
BusinessExceptionAssertEnum . DATA_ERROR . assertNotEquals ( parkSection ,
BusinessExceptionAssertEnum . DATA_ERROR . assertNotEquals ( parkSection , nextTripPlan . getFirstStationPlan ( ) . getSection ( ) ) ;
nextTripPlan . getFirstStationPlan ( ) . getSection ( ) ) ;
this . updateNextPlan ( simulation , trainInfo , nextTripPlan , nextTripPlan . getFirstStationPlan ( ) ) ;
this . updateNextPlan ( simulation , trainInfo , nextTripPlan ,
nextTripPlan . getFirstStationPlan ( ) ) ;
return ;
return ;
}
}
} else {
} else {
@ -350,8 +317,7 @@ public class AtsPlanTrainStageService implements AtsStageService {
return ;
return ;
}
}
SimulationDataRepository repository = simulation . getRepository ( ) ;
SimulationDataRepository repository = simulation . getRepository ( ) ;
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) ,
TripPlan tripPlan = repository . getTripPlan ( trainInfo . getServiceNumber ( ) , trainInfo . getTripNumber ( ) ) ;
trainInfo . getTripNumber ( ) ) ;
StationPlan stationPlan = tripPlan . queryStationPlan ( planStandTrack ) ;
StationPlan stationPlan = tripPlan . queryStationPlan ( planStandTrack ) ;
Section section = repository . getByCode ( planStandTrack , Section . class ) ;
Section section = repository . getByCode ( planStandTrack , Section . class ) ;
/ / 更新离站信息
/ / 更新离站信息