diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java index a39907781..dcd47294f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java @@ -21,6 +21,7 @@ import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService; import club.joylink.rtss.simulation.cbtc.onboard.ATP.OnboardAtpApiService; import club.joylink.rtss.vo.client.map.newmap.MapStationRunLevelVO; import lombok.extern.slf4j.Slf4j; +import org.apache.tomcat.util.threads.StopPooledThreadException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; @@ -303,36 +304,36 @@ public class AtsTrainService { BusinessExceptionAssertEnum.INVALID_OPERATION.assertNotNull(path, String.format("列车[%s]无法到达目的地码[%s]对应区段[%s]", groupNumber, destinationCode, destinationSection.getCode())); supervisedTrain.setHeadPath(path); - //根据找到的路径更新目标区段--- - Section nextTarget = null; - int index = path.indexOf(headSection); - if (index == -1) - break; - for (int i = index; i < path.size(); i++) { - Section section = path.get(i); - if (section.isSpecialSection() - && supervisedTrain.isNotArriveAt(repository, new SectionPosition(section, section.getStopPointByDirection(right)))) { - List routePaths = repository.queryRoutePathsByEnd(section); - if (routePaths.stream().anyMatch(rp -> rp.containsSection(headSection))) { - nextTarget = section; - break; - } - } - } - if (nextTarget == null) { - nextTarget = path.get(path.size() - 1); - } - if (nextTarget.getCode().equals(estimatedArriveStandTrack)) { - break; - } - MapStationRunLevelVO runLevel = simulation.getBuildParams().getMap().getRunLevelByStartAndEndSection(estimatedArriveStandTrack, nextTarget.getCode()); - int runningTime = 0; - if (runLevel != null) { - runningTime = runLevel.getL3(); - } - supervisedTrain.updateEstimatedArriveInfo(nextTarget, simulation.getSystemTime().plusSeconds(runningTime).toLocalTime()); - this.onboardAtpApiService.updateNextStation(simulation, supervisedTrain.getGroupNumber(), - nextTarget.getStation().getCode(), nextTarget.getCode(), runningTime, true); +// //根据找到的路径更新目标区段--- +// Section nextTarget = null; +// int index = path.indexOf(headSection); +// if (index == -1) +// break; +// for (int i = index; i < path.size(); i++) { +// Section section = path.get(i); +// if (section.isSpecialSection() +// && supervisedTrain.isNotArriveAt(repository, new SectionPosition(section, section.getStopPointByDirection(right)))) { +// List routePaths = repository.queryRoutePathsByEnd(section); +// if (routePaths.stream().anyMatch(rp -> rp.containsSection(headSection))) { +// nextTarget = section; +// break; +// } +// } +// } +// if (nextTarget == null) { +// nextTarget = path.get(path.size() - 1); +// } +// if (nextTarget.getCode().equals(estimatedArriveStandTrack)) { +// break; +// } +// MapStationRunLevelVO runLevel = simulation.getBuildParams().getMap().getRunLevelByStartAndEndSection(estimatedArriveStandTrack, nextTarget.getCode()); +// int runningTime = 0; +// if (runLevel != null) { +// runningTime = runLevel.getL3(); +// } +// supervisedTrain.updateEstimatedArriveInfo(nextTarget, simulation.getSystemTime().plusSeconds(runningTime).toLocalTime()); +// this.onboardAtpApiService.updateNextStation(simulation, supervisedTrain.getGroupNumber(), +// nextTarget.getStation().getCode(), nextTarget.getCode(), runningTime, true); break; default: throw new SimulationException(SimulationExceptionType.System_Fault, String.format("无法识别的目的地码类型[%s]", destinationCodeDefinition.getType())); @@ -630,19 +631,19 @@ public class AtsTrainService { } break; } - if (nextTarget != null) { - if (nextTarget.getCode().equals(estimatedArriveStandTrack)) { - return; - } - SectionPosition stopPosition = new SectionPosition(nextTarget, nextTarget.getStopPointByDirection(trainRight)); - Float distance = CalculateService.calculateDistance(headPosition, stopPosition, trainRight); - if (distance != null) { - runningTime = (int) (distance / (45 / 3.6)); - } - train.updateEstimatedArriveInfo(nextTarget, simulation.getSystemTime().plusSeconds(runningTime).toLocalTime()); - this.onboardAtpApiService.updateNextStation(simulation, train.getGroupNumber(), - nextTarget.getStation().getCode(), nextTarget.getCode(), runningTime, true); - } +// if (nextTarget != null) { +// if (nextTarget.getCode().equals(estimatedArriveStandTrack)) { +// return; +// } +// SectionPosition stopPosition = new SectionPosition(nextTarget, nextTarget.getStopPointByDirection(trainRight)); +// Float distance = CalculateService.calculateDistance(headPosition, stopPosition, trainRight); +// if (distance != null) { +// runningTime = (int) (distance / (45 / 3.6)); +// } +// train.updateEstimatedArriveInfo(nextTarget, simulation.getSystemTime().plusSeconds(runningTime).toLocalTime()); +// this.onboardAtpApiService.updateNextStation(simulation, train.getGroupNumber(), +// nextTarget.getStation().getCode(), nextTarget.getCode(), runningTime, true); +// } } else { //没有目的地码定义数据 Section prePassed = null; List routingList = repository.queryRoutingByDestCode(destinationCode); @@ -667,38 +668,63 @@ public class AtsTrainService { break; } } - if (Objects.nonNull(nextTarget)) { - if (Objects.nonNull(prePassed)) { - MapStationRunLevelVO runLevel = simulation.getBuildParams().getMap().getRunLevelByStartAndEndSection(prePassed.getCode(), nextTarget.getCode()); - if (Objects.nonNull(runLevel)) { - runningTime = runLevel.getL3(); - } - } - if (!Objects.equals(estimatedArriveStandTrack, nextTarget.getCode())) { - boolean isPark = true; - if (repository.getConfig().isNoParkingServiceNumber(train.getServiceNumber())) { - isPark = false; - } else if (repository.getConfig().isParkingServiceNumber(train.getServiceNumber())) { - isPark = true; - } - train.updateEstimatedArriveInfo(nextTarget, LocalTime.now().plusSeconds(runningTime)); - //默认 - this.onboardAtpApiService.updateNextStation(simulation, train.getGroupNumber(), - nextTarget.getStation().getCode(), nextTarget.getCode(), runningTime, isPark); - } - } - } else { - nextTarget = this.queryNextTargetByStartSectionAndRoutings(simulation, routingList, headSection); - if (Objects.nonNull(nextTarget) && !Objects.equals(estimatedArriveStandTrack, nextTarget.getCode())) { - if (Objects.equals(train.getActualLeaveStandTrack(), nextTarget.getCode())) { - log.warn(String.format("列车[%s]刚离开的站台,不更新", train.getGroupNumber())); - return; - } - train.updateEstimatedArriveInfo(nextTarget, train.getEstimatedArriveTime()); - this.onboardAtpApiService.updateNextSection(simulation, - train.getGroupNumber(), nextTarget.getCode()); - } +// if (Objects.nonNull(nextTarget)) { +// if (Objects.nonNull(prePassed)) { +// MapStationRunLevelVO runLevel = simulation.getBuildParams().getMap().getRunLevelByStartAndEndSection(prePassed.getCode(), nextTarget.getCode()); +// if (Objects.nonNull(runLevel)) { +// runningTime = runLevel.getL3(); +// } +// } +// if (!Objects.equals(estimatedArriveStandTrack, nextTarget.getCode())) { +// boolean isPark = true; +// if (repository.getConfig().isNoParkingServiceNumber(train.getServiceNumber())) { +// isPark = false; +// } else if (repository.getConfig().isParkingServiceNumber(train.getServiceNumber())) { +// isPark = true; +// } +// train.updateEstimatedArriveInfo(nextTarget, LocalTime.now().plusSeconds(runningTime)); +// //默认 +// this.onboardAtpApiService.updateNextStation(simulation, train.getGroupNumber(), +// nextTarget.getStation().getCode(), nextTarget.getCode(), runningTime, isPark); +// } +// } } +// else { +// nextTarget = this.queryNextTargetByStartSectionAndRoutings(simulation, routingList, headSection); +// if (Objects.nonNull(nextTarget) && !Objects.equals(estimatedArriveStandTrack, nextTarget.getCode())) { +// if (Objects.equals(train.getActualLeaveStandTrack(), nextTarget.getCode())) { +// log.warn(String.format("列车[%s]刚离开的站台,不更新", train.getGroupNumber())); +// return; +// } +// train.updateEstimatedArriveInfo(nextTarget, train.getEstimatedArriveTime()); +// this.onboardAtpApiService.updateNextSection(simulation, +// train.getGroupNumber(), nextTarget.getCode()); +// } +// } + } + if (nextTarget != null) { + if (nextTarget.getCode().equals(estimatedArriveStandTrack)) { + return; + } + boolean isPark = true; + if (repository.getConfig().isNoParkingServiceNumber(train.getServiceNumber())) { + isPark = false; + } + if (!nextTarget.isAheadOf(headSection, trainRight)) { + atpService.turnDirectionImmediately(repository.getOnlineTrainBy(train.getGroupNumber())); + } + SectionPosition stopPosition = new SectionPosition(nextTarget, nextTarget.getStopPointByDirection(trainRight)); + Float distance = CalculateService.calculateDistance(headPosition, stopPosition, trainRight); + if (distance == null) { + distance = CalculateService.calculateDistance(headPosition, stopPosition, !trainRight); + + } + if (distance != null) { + runningTime = (int) (distance / (45 / 3.6)); + } + train.updateEstimatedArriveInfo(nextTarget, simulation.getSystemTime().plusSeconds(runningTime).toLocalTime()); + this.onboardAtpApiService.updateNextStation(simulation, train.getGroupNumber(), + nextTarget.getStation().getCode(), nextTarget.getCode(), runningTime, isPark); } break; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/RouteService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/RouteService.java index e430b1b4a..b0a602c0c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/RouteService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/service/RouteService.java @@ -43,11 +43,11 @@ public class RouteService { if (Objects.nonNull(failMessage)) { return failMessage; } - // 区间运行方向检查 - failMessage = this.directionRodCheck(simulation, route); - if (Objects.nonNull(failMessage)) { - return failMessage; - } +// // 区间运行方向检查 +// failMessage = this.directionRodCheck(simulation, route); +// if (Objects.nonNull(failMessage)) { +// return failMessage; +// } // 共用道岔的冲突进路检查 failMessage = this.switchUseCheck(simulation, route); if (Objects.nonNull(failMessage)) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java index b2f56b4ba..3c6106607 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java @@ -24,6 +24,7 @@ import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher; import club.joylink.rtss.simulation.cbtc.ATS.service.AtsTrainLoadService; import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams; import club.joylink.rtss.simulation.cbtc.command.CommandBO; +import club.joylink.rtss.simulation.cbtc.command.CommandExecuteService; import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO; import club.joylink.rtss.simulation.cbtc.communication.vo.fault.DeviceFaultInfo; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; @@ -138,6 +139,8 @@ public class GroupSimulationServiceImpl implements GroupSimulationService { private IRunPlanRunlevelService iRunPlanRunlevelService; @Autowired private IRunPlanParktimeService iRunPlanParktimeService; + @Autowired + private CommandExecuteService commandExecuteService; // /** // * 创建仿真并进行缓存 // * @@ -931,6 +934,7 @@ public class GroupSimulationServiceImpl implements GroupSimulationService { } CommandBO commandBO = new CommandBO(initiateVO.getCommandType(), member, targetMember, initiateVO.getParams(), steps); targetMember.setCommand(commandBO); + commandExecuteService.addJobs(simulation); } @Override diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java index f90e4aba9..367dcbea1 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/Simulation.java @@ -645,5 +645,6 @@ public class Simulation extends club.joylink.rtss.simulation.Simulation haveCommandMember = simulation.getSimulationMembers().stream().filter(member -> member.getCommand() != null).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(haveCommandMember)) + removeJobs(simulation); for (SimulationMember member : haveCommandMember) { CommandBO command = member.getCommand(); if (!member.isRobot()) { @@ -59,4 +63,12 @@ public class CommandExecuteService { } } } + + public void addJobs(Simulation simulation) { + simulation.addJobIfAbsent(Simulation.JobName.commandExecuteRun, () -> this.run(simulation), SimulationConstants.COMMAND_EXECUTE_RATE); + } + + public void removeJobs(Simulation simulation) { + simulation.removeJob(Simulation.JobName.commandExecuteRun); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java index 6ba332283..aa0778f20 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java @@ -1,5 +1,6 @@ package club.joylink.rtss.simulation.cbtc.data.map; +import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; @@ -998,6 +999,12 @@ public class Section extends MayOutOfOrderDevice { } } + public boolean isAheadOf(Section other, boolean right) { + if (this.equals(other)) + return false; + return CalculateService.isTargetSectionOnDirectionExist(other, right, this); + } + public enum SectionRoadType { /** * 左行线