diff --git a/src/main/java/club/joylink/rtss/simulation/Simulation.java b/src/main/java/club/joylink/rtss/simulation/Simulation.java index 17a3bb2a3..8d9488cf0 100644 --- a/src/main/java/club/joylink/rtss/simulation/Simulation.java +++ b/src/main/java/club/joylink/rtss/simulation/Simulation.java @@ -336,7 +336,6 @@ public abstract class Simulation routes = commonRepository.getRoutesByStartSignal(cilSignal.getId()); + Optional routeOptional = routes.stream().filter(cr -> { + List spList = cr.getPathElement().getSpList(); + if (CollectionUtils.isEmpty(spList)) + return true; + return spList.stream().allMatch(sp -> cilRepository.getSwitchById(sp.getCommonSwitch().getId()).getPosition() == sp.getPosition()); + }).limit(1).findAny(); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(routeOptional.isPresent(), "无能够办理的进路"); + CommonRoute route = routeOptional.get(); + //2021-04-26 17:55:55 引导进路的办理先放在这里,后面有需要再迁移 + setGuideRouteProgress(cilRepository, route); + } + + public void humanCancel(RtSimulation simulation, String signalId) { + //检查 + CilRepository cilRepository = simulation.getRepository(CilRepository.NAME, CilRepository.class); + CilSignal cilSignal = cilRepository.getSignalById(signalId); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertHasText(cilSignal.getLrId(), "信号机无已办理进路"); + CilRoute cilRoute = cilRepository.getRouteById(cilSignal.getLrId()); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(cilRoute.isDelayUnlocking(), "进路已在延时解锁中"); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(cilRoute.isTrainIn(), "进路非空闲状态"); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(cilSignalLogicService.isApproachOccupied(simulation, signalId), + "进路未接近锁闭"); + //关闭信号 + cilSignalLogicService.UpdateSignalDisplay(simulation, cilSignal, CilSignal.RED, false); + //设置延时解锁 + cilSignal.initDelayTime(); + cilRoute.setDelayUnlocking(true); + } + + void cancelDelayUnlock(CilRepository cilRepository, CilSignal cilSignal) { + BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(cilSignal.getLrId()); + CilRoute cilRoute = cilRepository.getRouteById(cilSignal.getLrId()); + cilRoute.setDelayUnlocking(false); + cilSignal.clearDelayTime(); + } + public void routeLogic(RtSimulation rtSimulation, CilRepository cilRepository) { List supervisedRouteList = cilRepository.getSupervisedRouteList(); for (CilRoute cilRoute : supervisedRouteList) { @@ -27,14 +103,6 @@ public class CilRouteLogicService { if (cilRoute.isDelayUnlocking()) { this.delayUnlockingProgress(rtSimulation, cilRoute, cilRepository.getConfig()); } -// switch (cilRoute.getStage()) { -// case CilRoute.STAGE_SETTING: -// this.settingProgress(rtSimulation, cilRoute, cilRepository.getConfig()); -// break; -// case CilRoute.STAGE_WATCH: -// this.watchRoute(cilRoute); -// break; -// } } } @@ -149,6 +217,14 @@ public class CilRouteLogicService { return true; } + private void routeUse(CilRepository cilRepository, List switchPositions) { + if (!CollectionUtils.isEmpty(switchPositions)) { + for (SwitchPosition sp : switchPositions) { + routeUse(cilRepository, sp); + } + } + } + private void routeUse(CilRepository cilRepository, SwitchPosition switchPosition) { CilSwitch cilSwitch = cilRepository.getSwitchById(switchPosition.getCommonSwitch().getId()); cilSwitch.routeUse(switchPosition.getPosition()); @@ -210,7 +286,7 @@ public class CilRouteLogicService { // 进路内的设备转动、锁闭 if (!cilRoute.isLock()) { cilSwitchLogicService.tryTurn(rtSimulation, pathElement.getSpList()); // 转动道岔 - boolean allLock = try2RouteLockSwitches(cilRepository, cilRoute, pathElement.getSpList()); // 锁闭道岔 + boolean allLock = try2RouteLockSwitches(cilRepository, cilRoute.getId(), pathElement.getSpList()); // 锁闭道岔 if (allLock) { // if (!config.isLockFirst()) { routeLockSections(cilRepository, commonRoute); @@ -412,7 +488,7 @@ public class CilRouteLogicService { * * @return 全部锁闭时为true */ - private boolean try2RouteLockSwitches(CilRepository cilRepository, CilRoute route, List switchPositionList) { + private boolean try2RouteLockSwitches(CilRepository cilRepository, String routeId, List switchPositionList) { boolean flag = true; if (!CollectionUtils.isEmpty(switchPositionList)) { for (SwitchPosition switchPosition : switchPositionList) { @@ -420,7 +496,7 @@ public class CilRouteLogicService { if (cilSwitch.getPosition() != switchPosition.getPosition()) { flag = false; } else { - cilSwitch.lockByRoute(route); + cilSwitch.lockByRoute(routeId); } } } @@ -522,4 +598,17 @@ public class CilRouteLogicService { } } + /** + * 办理引导进路逻辑 + */ + private void setGuideRouteProgress(CilRepository cilRepository, CommonRoute route) { + this.routeUse(cilRepository, route.getPathElement().getSpList()); //道岔征用 + this.try2RouteLockSwitches(cilRepository, route.getId(), route.getPathElement().getSpList()); //道岔锁闭(应该不会失败) + route.getPathElement().getAllSectionList().forEach(cs->{ + CilSection cilSection = cilRepository.getSectionById(cs.getId()); +// if (!cilSection.isAxcOccupy()) { + cilSection.lockByRoute(route); +// } + }); + } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilSignalLogicService.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilSignalLogicService.java index 8dcc623b6..22877c85e 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilSignalLogicService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilSignalLogicService.java @@ -5,7 +5,6 @@ import club.joylink.rtss.simulation.rt.CIL.bo.CilRepository; import club.joylink.rtss.simulation.rt.CIL.bo.CilSignal; import club.joylink.rtss.simulation.rt.RtSimulation; import club.joylink.rtss.simulation.rt.SRD.SrdApiService; -import club.joylink.rtss.simulation.rt.SRD.bo.SrSignal; import club.joylink.rtss.simulation.rt.repo.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -46,6 +45,7 @@ public class CilSignalLogicService { } public void reopen(RtSimulation rtSimulation, String signalId) { + //检查 CilRepository cilRepository = rtSimulation.getRepository(CilRepository.NAME, CilRepository.class); CommonRepository commonRepository = rtSimulation.getRepository(CommonRepository.NAME, CommonRepository.class); CilSignal cilSignal = cilRepository.getSignalById(signalId); @@ -55,7 +55,9 @@ public class CilSignalLogicService { CommonRoute commonRoute = commonRepository.getRouteById(cilSignal.getLrId()); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(cilRouteLogicService.canOpenSignal(rtSimulation, commonRoute.getId()), "联锁条件不满足,无法重开"); - UpdateSignalDisplay(rtSimulation, cilSignal, commonRoute.getSignalAspect(), false); + //执行 + cilRouteLogicService.cancelDelayUnlock(cilRepository, cilSignal);//取消延时解锁 + UpdateSignalDisplay(rtSimulation, cilSignal, commonRoute.getSignalAspect(), false); //信号机开放 } public boolean try2UpdateSignalDisplay(RtSimulation rtSimulation, CilSignal signal, int aspect, boolean ctcMode) { diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilRoute.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilRoute.java index 1bad8a9cf..749cfd6f1 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilRoute.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilRoute.java @@ -58,8 +58,8 @@ public class CilRoute extends CilDevice { private boolean trainIn; //列车进入进路 @Setter private boolean delayUnlocking; //延时解锁中 - - + @Setter + boolean gl; public CilRoute(String id, String name) { super(id, name); diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java index ff9cdda96..3e3b5d5a8 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java @@ -7,7 +7,8 @@ import lombok.Setter; @Getter public class CilSignal extends CilDevice { - public static final int DEFAULT_DELAY_TIME = 30 * 1000; + public static final int DEFAULT_DELAY_TIME = 30 * 1000; //进路延时解锁默认时长 + public static final int DEFAULT_GUIDE_TIME = 15 * 1000; //引导信号有效时长 int signalAspect = RED; //当前显示的信号 public static final int RED = 1; // 红灯信号(禁止信号) @@ -39,7 +40,8 @@ public class CilSignal extends CilDevice { boolean fl; //侧防锁闭(侧防锁闭后信号机不能开放) @Setter String lrId; //锁闭进路的id - int delayTime; //信号机延时解锁倒计时/ms + int delayTime; //进路延时解锁倒计时/ms + int guideTime; //引导信号剩余时间 Fault fault; @@ -114,6 +116,22 @@ public class CilSignal extends CilDevice { this.delayTime = Math.max(this.delayTime - CilLogicService.CilMainLogicRate, 0); } + public void clearDelayTime() { + this.delayTime = 0; + } + + public void initGuideTime() { + this.guideTime = DEFAULT_GUIDE_TIME; + } + + public void updateGuideTime() { + this.guideTime = Math.max(this.delayTime - CilLogicService.CilMainLogicRate, 0); + } + + public void clearGuideTime() { + this.guideTime = 0; + } + public void setFault(Fault fault) { this.fault = fault; } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSwitch.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSwitch.java index ac54fd01c..9b98c65a5 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSwitch.java @@ -83,9 +83,9 @@ public class CilSwitch extends CilDevice { this.routeUseToPosition = 0; } - public void lockByRoute(CilRoute cilRoute) { - if (!Objects.equals(cilRoute.getId(), this.routeId)) { - this.routeId = cilRoute.getId(); + public void lockByRoute(String routeId) { + if (!Objects.equals(routeId, this.routeId)) { + this.routeId = routeId; this.rl = true; } } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/operation/SignalOperationHandler.java b/src/main/java/club/joylink/rtss/simulation/rt/operation/SignalOperationHandler.java index 3ae43e2d3..4aed4181b 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/operation/SignalOperationHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/operation/SignalOperationHandler.java @@ -38,8 +38,8 @@ public class SignalOperationHandler { } @SimulationOperationMapping("Signal_Set_Guide") - public boolean setGuide(RtSimulation simulation, String signalId, String routeId) { - return this.cilApiService.setGuide(simulation, signalId, routeId); + public void setGuide(RtSimulation simulation, String signalId, String routeId) { + this.cilApiService.setGuide(simulation, signalId, routeId); } @SimulationOperationMapping("Signal_Block") diff --git a/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonRepository.java b/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonRepository.java index 035135242..fae852d6c 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/repo/CommonRepository.java @@ -5,7 +5,9 @@ import club.joylink.rtss.simulation.SimulationRepository; import lombok.Getter; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Getter public class CommonRepository extends SimulationRepository { @@ -63,4 +65,8 @@ public class CommonRepository extends SimulationRepository { BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(commonSwitch, String.format("不存在id为[%s]的道岔", id)); return commonSwitch; } + + public List getRoutesByStartSignal(String signalId) { + return this.routeMap.values().stream().filter(commonRoute -> commonRoute.getStart().getId().equals(signalId)).collect(Collectors.toList()); + } }