diff --git a/src/main/java/club/joylink/rtss/simulation/operation/SimulationOperationHandlerManager.java b/src/main/java/club/joylink/rtss/simulation/operation/SimulationOperationHandlerManager.java index 1b9ee9ee2..ac40e3838 100644 --- a/src/main/java/club/joylink/rtss/simulation/operation/SimulationOperationHandlerManager.java +++ b/src/main/java/club/joylink/rtss/simulation/operation/SimulationOperationHandlerManager.java @@ -27,7 +27,7 @@ public class SimulationOperationHandlerManager implements ApplicationContextAwar if (operationMapping == null) { continue; } - String name = operationMapping.name(); + String name = operationMapping.value(); BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(handlerMap.containsKey(name)); OperationHandlerMethod handlerMethod = new OperationHandlerMethod(handler, method); handlerMap.put(name, handlerMethod); diff --git a/src/main/java/club/joylink/rtss/simulation/operation/SimulationOperationMapping.java b/src/main/java/club/joylink/rtss/simulation/operation/SimulationOperationMapping.java index 1cc21b603..08eb90713 100644 --- a/src/main/java/club/joylink/rtss/simulation/operation/SimulationOperationMapping.java +++ b/src/main/java/club/joylink/rtss/simulation/operation/SimulationOperationMapping.java @@ -8,5 +8,6 @@ import java.lang.annotation.Target; @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface SimulationOperationMapping { - String name(); + + String value() default ""; } diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilApiService.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilApiService.java new file mode 100644 index 000000000..36f7fa134 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilApiService.java @@ -0,0 +1,40 @@ +package club.joylink.rtss.simulation.rt.CIL; + +import club.joylink.rtss.simulation.rt.CIL.bo.CilSwitch; +import club.joylink.rtss.simulation.rt.RtSimulation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CilApiService { + + @Autowired + private CilSwitchLogicService cilSwitchLogicService; + + /** + * 转动道岔 + * @param simulation + * @param id + */ + public void turnSwitch(RtSimulation simulation, String id) { + this.cilSwitchLogicService.turn(simulation, id); + } + + /** + * 定操 + * @param simulation + * @param id + */ + public void turnSwitchToNormal(RtSimulation simulation, String id) { + this.cilSwitchLogicService.turn(simulation, id, CilSwitch.NORMAL); + } + + /** + * 反操 + * @param simulation + * @param id + */ + public void turnSwitchToReverse(RtSimulation simulation, String id) { + this.cilSwitchLogicService.turn(simulation, id, CilSwitch.REVERSE); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilSwitchLogicService.java b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilSwitchLogicService.java index 0fd2ab758..c2e166620 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilSwitchLogicService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/CIL/CilSwitchLogicService.java @@ -1,7 +1,6 @@ package club.joylink.rtss.simulation.rt.CIL; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; -import club.joylink.rtss.simulation.SimulationRepository; import club.joylink.rtss.simulation.rt.CIL.bo.CilRepository; import club.joylink.rtss.simulation.rt.CIL.bo.CilSwitch; import club.joylink.rtss.simulation.rt.CIL.bo.CilSwitchPosition; @@ -18,6 +17,14 @@ public class CilSwitchLogicService { @Autowired private SrdApiService srdApiService; + public void turn(RtSimulation rtSimulation, String id) { + CilRepository repository = rtSimulation.getRepository(CilRepository.NAME, CilRepository.class); + CilSwitch aSwitch = repository.getSwitchById(id); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(aSwitch.isLocked(), "道岔锁闭,无法转动"); + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(aSwitch.isOccupy(), "道岔占用,无法转动"); + srdApiService.turnSwitch(rtSimulation, id); + } + /** * 道岔转动 */ diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdApiService.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdApiService.java index 8bfa4777e..0926fd4ec 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdApiService.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/SrdApiService.java @@ -37,6 +37,16 @@ public class SrdApiService { return repository.getPsdList(); } + public void turnSwitch(RtSimulation rtSimulation, String switchId) { + SrdRepository repository = this.getSrdRepository(rtSimulation); + SrSwitch srSwitch = repository.getSwitchById(switchId); + if (srSwitch.isReversePosition() || srSwitch.isTurningToReverse()) { + srSwitch.turnToNormal(rtSimulation.getSystemTime()); + } else if (srSwitch.isNormalPosition() || srSwitch.isTurningToNormal()) { + srSwitch.turnToReverse(rtSimulation.getSystemTime()); + } + } + public void turnSwitch(RtSimulation rtSimulation, String switchId, int position) { SrdRepository repository = this.getSrdRepository(rtSimulation); SrSwitch srSwitch = repository.getSwitchById(switchId); diff --git a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java index 5d4d3077b..64cd961e8 100644 --- a/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/rt/SRD/bo/SrSwitch.java @@ -70,6 +70,14 @@ public class SrSwitch extends SrDevice { return NONE != this.command.get(); } + public boolean isTurningToNormal() { + return NORMAL == this.command.get(); + } + + public boolean isTurningToReverse() { + return REVERSE == this.command.get(); + } + public boolean turnToNormal(LocalDateTime systemTime) { if (this.isNormalPosition() || this.command.get() == NORMAL) { return false; diff --git a/src/main/java/club/joylink/rtss/simulation/rt/operation/SwitchOperationHandler.java b/src/main/java/club/joylink/rtss/simulation/rt/operation/SwitchOperationHandler.java new file mode 100644 index 000000000..d85971976 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/rt/operation/SwitchOperationHandler.java @@ -0,0 +1,32 @@ +package club.joylink.rtss.simulation.rt.operation; + +import club.joylink.rtss.simulation.operation.SimulationOperationController; +import club.joylink.rtss.simulation.operation.SimulationOperationMapping; +import club.joylink.rtss.simulation.rt.CIL.CilApiService; +import club.joylink.rtss.simulation.rt.RtSimulation; +import org.springframework.beans.factory.annotation.Autowired; + +@SimulationOperationController() +public class SwitchOperationHandler { + @Autowired + private CilApiService cilApiService; + + @SimulationOperationMapping("Switch_Turn") + public boolean turn(RtSimulation simulation, String id) { + this.cilApiService.turnSwitch(simulation, id); + return true; + } + + @SimulationOperationMapping("Switch_Normal_Position") + public boolean turnToNormal(RtSimulation simulation, String id) { + this.cilApiService.turnSwitchToNormal(simulation, id); + return true; + } + + @SimulationOperationMapping("Switch_Reverse_Position") + public boolean turnToReverse(RtSimulation simulation, String id) { + this.cilApiService.turnSwitchToReverse(simulation, id); + return true; + } + +}