[办理进路][道岔转动][道岔强扳]接口阻塞式等待结果

This commit is contained in:
joylink_zhangsai 2023-10-27 15:56:52 +08:00
parent 2f2ec98029
commit b01ac1dc0f
10 changed files with 1098 additions and 1089 deletions

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.simulation.cbtc.ATS.operation.handler;
import club.joylink.rtss.exception.BaseException;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
import club.joylink.rtss.simulation.cbtc.ATS.operation.annotation.OperateHandler;
@ -13,8 +14,10 @@ import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
@Slf4j
@OperateHandler
@ -30,12 +33,40 @@ public class SignalOperateHandler {
* 排列进路
*/
@OperateHandlerMapping(type = Operation.Type.Signal_Set_Route)
public void settingRoute(Simulation simulation, String routeCode) {
public void settingRoute(Simulation simulation, String routeCode) throws InterruptedException {
// Route.CheckFailMessage checkResult = this.ciApiService.routeSettingCheck(simulation, routeCode);
// if (checkResult != null)
// log.info(checkResult.debugStr());
Route.CheckFailMessage checkFailMessage = this.ciApiService.settingRoute(simulation, routeCode);
BusinessExceptionAssertEnum.SIMULATION_EXCEPTION_FOR_SHOW.assertNull(checkFailMessage, "进路排列失败,被联锁逻辑取消");
//等待进路办理完成
LocalDateTime timeoutTime = simulation.getSystemTime().plusSeconds(20);
Route route = simulation.getRepository().getByCode(routeCode, Route.class);
CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(() -> {
while (true) {
if (route.getSettedAspect().equals(route.getStart().getAspect()) ||
(route.isGuideSetting() && route.getStart().isGuideAspect())) {
return true;
}
if (simulation.getSystemTime().isAfter(timeoutTime)) {
return false;
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
try {
Boolean success = future.get();
BusinessExceptionAssertEnum.OPERATION_FAIL.assertTrue(success);
} catch (BaseException be) {
throw be;
} catch (Exception e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception();
}
}
/**

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.simulation.cbtc.ATS.operation.handler;
import club.joylink.rtss.exception.BaseException;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.ATP.ground.GroundAtpApiService;
import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation;
@ -17,10 +18,12 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
@OperateHandler
@Slf4j
@ -46,7 +49,9 @@ public class SwitchOperateHandler {
Switch aSwitch = simulation.getRepository().getByCode(switchCode, Switch.class);
BusinessExceptionAssertEnum.SIMULATION_EXCEPTION_FOR_SHOW.assertTrue(!aSwitch.isLocked(),
String.format("联锁操作被取消,道岔%s被锁定", aSwitch.getName()));
this.ciApiService.turn(simulation, switchCode);
SwitchIndication pos = this.ciApiService.turn(simulation, switchCode);
waitResult(simulation, aSwitch, pos);
}
/**
@ -95,30 +100,6 @@ public class SwitchOperateHandler {
}
}
// /**道岔定操(联动)*/
// @OperateHandlerMapping(type = Operation2.Type.Switch_Turn_NP_Chain)
// public void chainTurn2Normal(Simulation simulation, String switchCode) {
// this.turn2Normal(simulation, switchCode);
// SimulationDataRepository repository = simulation.getRepository();
// Switch aSwitch = repository.getByCode(switchCode, Switch.class);
// Switch linkedSwitch = aSwitch.queryLinkedSwitch();
// if (Objects.nonNull(linkedSwitch)) {
// this.ciApiService.turn2NormalPosition(simulation, linkedSwitch.getCode());
// }
// }
// /**道岔反操(联动)*/
// @OperateHandlerMapping(type = Operation2.Type.Switch_Turn_RP_Chain)
// public void chainTurn2Reverse(Simulation simulation, String switchCode) {
// this.turn2Reverse(simulation, switchCode);
// SimulationDataRepository repository = simulation.getRepository();
// Switch aSwitch = repository.getByCode(switchCode, Switch.class);
// Switch linkedSwitch = aSwitch.queryLinkedSwitch();
// if (Objects.nonNull(linkedSwitch)) {
// this.ciApiService.turn2ReversePosition(simulation, linkedSwitch.getCode());
// }
// }
/**
* 道岔单锁
*/
@ -152,30 +133,6 @@ public class SwitchOperateHandler {
}
}
// /**道岔单锁(联动)*/
// @OperateHandlerMapping(type =Operation2.Type.Switch_Single_Lock_Chain)
// public void chainSingleLockSwitch(Simulation simulation, String switchCode) {
// SimulationDataRepository repository = simulation.getRepository();
// Switch aSwitch = repository.getByCode(switchCode, Switch.class);
// Switch linkedSwitch = aSwitch.queryLinkedSwitch();
// ciApiService.singleLockSwitch(simulation, switchCode);
// if (Objects.nonNull(linkedSwitch)) {
// this.ciApiService.singleLockSwitch(simulation, linkedSwitch.getCode());
// }
// }
// /**道岔单解(联动)*/
// @OperateHandlerMapping(type =Operation2.Type.Switch_Single_Unlock_Chain)
// public void chainSingleUnlockSwitch(Simulation simulation, String switchCode) {
// SimulationDataRepository repository = simulation.getRepository();
// Switch aSwitch = repository.getByCode(switchCode, Switch.class);
// Switch linkedSwitch = aSwitch.queryLinkedSwitch();
// ciApiService.singleUnlockSwitch(simulation, switchCode);
// if (Objects.nonNull(linkedSwitch)) {
// this.ciApiService.singleUnlockSwitch(simulation, linkedSwitch.getCode());
// }
// }
/**
* 道岔初始化封锁
*/
@ -319,7 +276,9 @@ public class SwitchOperateHandler {
*/
@OperateHandlerMapping(type = Operation.Type.Switch_Force_Turn)
public void switchForceTurn(Simulation simulation, String switchCode, Boolean normal) {
ciApiService.switchForceTurn(simulation, switchCode);
SwitchIndication pos = ciApiService.switchForceTurn(simulation, switchCode);
waitResult(simulation, simulation.getRepository().getByCode(switchCode, Switch.class), pos);
}
/**
@ -364,4 +323,33 @@ public class SwitchOperateHandler {
Switch aSwitch = simulation.getRepository().getByCode(switchCode, Switch.class);
atsSectionService.defectiveShunting(simulation, aSwitch.getA().getCode(), new ArrayList<>());
}
private static void waitResult(Simulation simulation, Switch aSwitch, SwitchIndication pos) {
//等待转动完成
LocalDateTime timeoutTime = simulation.getSystemTime().plusSeconds(13);
CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(() -> {
while (true) {
if (Objects.equals(aSwitch.getPos(), pos)) {
return true;
}
if (simulation.getSystemTime().isAfter(timeoutTime)) {
return false;
}
try {
Thread.sleep(100);
} catch (Exception e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception();
}
}
});
try {
Boolean success = future.get();
BusinessExceptionAssertEnum.OPERATION_FAIL.assertTrue(success, "道岔转动失败");
} catch (BaseException be) {
throw be;
} catch (Exception e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(e);
}
}
}

View File

@ -2,6 +2,7 @@ package club.joylink.rtss.simulation.cbtc.CI;
import club.joylink.rtss.simulation.cbtc.CI.device.CiStandService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.map.ESP;
import club.joylink.rtss.simulation.cbtc.data.map.Route;
import club.joylink.rtss.simulation.cbtc.data.map.Stand;
@ -65,8 +66,9 @@ public interface CiApiService {
*
* @param simulation
* @param switchCode
* @return
*/
void turn(Simulation simulation, String switchCode);
SwitchIndication turn(Simulation simulation, String switchCode);
/**
* 转动道岔到定位
@ -338,8 +340,10 @@ public interface CiApiService {
/**
* 强扳道岔
*
* @return
*/
void switchForceTurn(Simulation simulation, String switchCode);
SwitchIndication switchForceTurn(Simulation simulation, String switchCode);
/**
* 计轴预复位

View File

@ -4,6 +4,7 @@ import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.CI.device.*;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.*;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter;
@ -95,15 +96,17 @@ public class CiApiServiceImpl2 implements CiApiService {
}
@Override
public void turn(Simulation simulation, String switchCode) {
public SwitchIndication turn(Simulation simulation, String switchCode) {
Switch aSwitch = simulation.getRepository().getByCode(switchCode, Switch.class);
if (!this.switchService.turn(simulation, aSwitch)) {
SwitchIndication pos = this.switchService.turn(simulation, aSwitch);
if (pos == null) {
log.info(String.format("道岔[%s(%s)]锁闭,不能转动", aSwitch.getName(), aSwitch.getCode()));
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, "道岔锁闭,不能进行定操");
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, "道岔锁闭,不能进行转动");
}
if (Switch.SwitchFault.SPLIT_1.equals(aSwitch.getFault())) {
Switch.SwitchFault.SPLIT_1.fix(aSwitch);
}
return pos;
}
@Override
@ -582,12 +585,12 @@ public class CiApiServiceImpl2 implements CiApiService {
}
@Override
public void switchForceTurn(Simulation simulation, String switchCode) {
public SwitchIndication switchForceTurn(Simulation simulation, String switchCode) {
Switch aSwitch = simulation.getRepository().getByCode(switchCode, Switch.class);
BusinessExceptionAssertEnum.SIMULATION_EXCEPTION_FOR_SHOW.assertTrue(!aSwitch.isLocked() && aSwitch.isSectionOccupied(),
String.format("对%s强行转岔操作被联锁逻辑取消", aSwitch.getName()));
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(!aSwitch.isLocked(), String.format("道岔[%s]锁闭,无法转动", aSwitch.getCode()));
this.switchService.forceTurn(simulation, aSwitch);
return this.switchService.forceTurn(simulation, aSwitch);
}
@Override

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.simulation.cbtc.CI.device;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.map.Switch;
import club.joylink.rtss.simulation.cbtc.data.map.SwitchElement;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
@ -74,19 +75,19 @@ public class CiSwitchControlService {
* @param aSwitch
* @return
*/
public boolean forceTurn(Simulation simulation, Switch aSwitch) {
public SwitchIndication forceTurn(Simulation simulation, Switch aSwitch) {
if (!aSwitch.isSectionOccupied()) {
return false;
return null;
}
if (aSwitch.isLocked()) {
return false;
return null;
}
// 设置强扳授权
aSwitch.setForceTurnRemain(120 * 1000);
this.turn(simulation, aSwitch);
SwitchIndication pos = this.turn(simulation, aSwitch);
// 手动释放强扳
aSwitch.setForceTurnRemain(0);
return true;
return pos;
}
/**
@ -96,7 +97,7 @@ public class CiSwitchControlService {
* @param aSwitch
* @return
*/
public boolean turn(Simulation simulation, Switch aSwitch) {
public SwitchIndication turn(Simulation simulation, Switch aSwitch) {
VirtualRealitySwitch vrSwitch = aSwitch.getVirtualSwitch();
boolean isRP;
if (vrSwitch.getCommand() != null) {
@ -115,10 +116,15 @@ public class CiSwitchControlService {
}
}
if (isRP) {
return this.turn2NormalPosition(simulation, aSwitch);
if (this.turn2NormalPosition(simulation, aSwitch)) {
return SwitchIndication.N;
}
} else {
return this.turn2ReversePosition(simulation, aSwitch);
if (this.turn2ReversePosition(simulation, aSwitch)) {
return SwitchIndication.R;
}
}
return null;
}
/**

View File

@ -166,7 +166,6 @@ public class Switch extends DelayUnlockDevice {
this.interlockReserve = false;
this.blockadeInvalid = false;
this.init = false;
this.lastTurnToNormal = null;
this.forceTurnRemain = 0;
}

View File

@ -68,10 +68,6 @@ public class RouteStatus extends DeviceStatus {
@JsonDeserialize(using = Boolean2NumDeserializer.class)
private boolean checkConflict;
@JsonSerialize(using = Boolean2NumSerializer.class)
@JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean setSuccess;
public RouteStatus(Route route) {
super(route.getCode(), route.getDeviceType());
this.atsControl = route.isAtsControl();
@ -84,7 +80,6 @@ public class RouteStatus extends DeviceStatus {
this.canceling = route.isDelayUnlocking();
this.normalUnlock = route.isNormalUnlock();
this.checkConflict = route.isCheckConflict();
this.setSuccess = route.getSetSuccess();
}
@Override
@ -100,7 +95,6 @@ public class RouteStatus extends DeviceStatus {
statusVO.setCanceling(canceling);
statusVO.setNormalUnlock(normalUnlock);
statusVO.setCheckConflict(checkConflict);
statusVO.setSetSuccess(setSuccess);
return statusVO;
}
@ -159,11 +153,6 @@ public class RouteStatus extends DeviceStatus {
status.setCheckConflict(this.checkConflict);
change = true;
}
if (!Objects.equals(this.setSuccess, route.getSetSuccess())) {
this.setSuccess = route.getSetSuccess();
status.setSetSuccess(this.setSuccess);
change = true;
}
// if (!Objects.equals(this.conflict, route.isConflict())) {
// this.conflict = route.isConflict();
// this.conflictDesc = route.getConflictDesc();

View File

@ -201,6 +201,7 @@ public class SwitchStatus extends DeviceStatus {
}
if (!Objects.equals(this.fault, aSwitch.getFault())) {
this.fault = (Switch.SwitchFault) aSwitch.getFault();
status.setFault(this.fault == null ? null : this.fault.name());
change = true;
}
status.setFault(this.fault != null ? this.fault.name() : null);

View File

@ -53,9 +53,6 @@ public class RouteStatusVO extends DeviceStatusVO {
@JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean checkConflict;
@JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean setSuccess;
public RouteStatusVO(Route route) {
super(route.getCode(), route.getDeviceType());
}