Merge remote-tracking branch 'origin/test' into test

# Conflicts:
#	src/main/java/club/joylink/rtss/simulation/rt/CIL/bo/CilSignal.java
This commit is contained in:
walker-sheng 2021-04-27 17:10:29 +08:00
commit 04d42aff4f
9 changed files with 142 additions and 53 deletions

View File

@ -336,7 +336,6 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
/** /**
* 仿真状态订阅路径 /queue/simulation/{id}/state * 仿真状态订阅路径 /queue/simulation/{id}/state
* @return
*/ */
private String getSimulationStateSubDestination() { private String getSimulationStateSubDestination() {
return String.format("%s/%s", MESSAGE_SUB_PREFIX, "state"); return String.format("%s/%s", MESSAGE_SUB_PREFIX, "state");

View File

@ -7,6 +7,8 @@ import club.joylink.rtss.simulation.rt.CIL.bo.CilSignal;
import club.joylink.rtss.simulation.rt.CIL.bo.CilSwitch; import club.joylink.rtss.simulation.rt.CIL.bo.CilSwitch;
import club.joylink.rtss.simulation.rt.RtSimulation; import club.joylink.rtss.simulation.rt.RtSimulation;
import club.joylink.rtss.simulation.rt.repo.CommonRepository; import club.joylink.rtss.simulation.rt.repo.CommonRepository;
import club.joylink.rtss.simulation.rt.repo.CommonRoute;
import club.joylink.rtss.simulation.rt.repo.CommonSignal;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -69,22 +71,8 @@ public class CilApiService {
return cilRouteLogicService.cancelRoute(simulation, cilSignal.getLrId()); return cilRouteLogicService.cancelRoute(simulation, cilSignal.getLrId());
} }
public boolean setGuide(RtSimulation simulation, String signalId, String routeId) { public void setGuide(RtSimulation simulation, String signalId, String routeId) {
//2021-04-25 16:09:13 比较复杂延后吧 cilRouteLogicService.setGuide(simulation, signalId, routeId);
CommonRepository commonRepository = simulation.getRepository(CommonRepository.NAME, CommonRepository.class);
CilRepository cilRepository = simulation.getRepository(CilRepository.NAME, CilRepository.class);
CilSignal cilSignal = null;
if (StringUtils.hasText(signalId)) {
cilSignal = cilRepository.getSignalById(signalId);
BusinessExceptionAssertEnum.OPERATION_FAIL.assertHasText(cilSignal.getLrId(), "信号机无已锁闭的进路");
} else if (StringUtils.hasText(routeId)) {
//大铁线路没有暂时不管
} else {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("参数缺失");
}
BusinessExceptionAssertEnum.OPERATION_FAIL.assertTrue(cilSignal.sufficientLevel(CilSignal.GUIDE, false), "引导开放条件不满足");
cilSignalLogicService.UpdateSignalDisplay(simulation, cilSignal, CilSignal.GUIDE, false);
return true;
} }
public void signalReopen(RtSimulation simulation, String signalId) { public void signalReopen(RtSimulation simulation, String signalId) {
@ -92,20 +80,7 @@ public class CilApiService {
} }
public void humanCancel(RtSimulation simulation, String signalId) { public void humanCancel(RtSimulation simulation, String signalId) {
//检查 cilRouteLogicService.humanCancel(simulation, 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);
} }
public void blockadeSwitch(RtSimulation simulation, String id) { public void blockadeSwitch(RtSimulation simulation, String id) {

View File

@ -8,8 +8,10 @@ import club.joylink.rtss.simulation.rt.repo.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.List; import java.util.List;
import java.util.Optional;
@Component @Component
public class CilRouteLogicService { public class CilRouteLogicService {
@ -20,6 +22,80 @@ public class CilRouteLogicService {
@Autowired @Autowired
private CilSignalLogicService cilSignalLogicService; private CilSignalLogicService cilSignalLogicService;
public void setGuide(RtSimulation simulation, String signalId, String routeId) {
//数据构建
CommonRepository commonRepository = simulation.getRepository(CommonRepository.NAME, CommonRepository.class);
CilRepository cilRepository = simulation.getRepository(CilRepository.NAME, CilRepository.class);
CommonRoute commonRoute = null;
CommonSignal commonSignal;
CilRoute cilRoute = null;
CilSignal cilSignal;
if (StringUtils.hasText(signalId)) {
commonSignal = commonRepository.getSignalById(signalId);
cilSignal = cilRepository.getSignalById(signalId);
if (StringUtils.hasText(cilSignal.getLrId())) {
commonRoute = commonRepository.getRouteById(cilSignal.getLrId());
cilRoute = cilRepository.getRouteById(cilSignal.getLrId());
}
} else if (StringUtils.hasText(routeId)) {
//2021-04-26 17:44:28暂时应该不会有这个参数
commonRoute = commonRepository.getRouteById(routeId);
cilRoute = cilRepository.getRouteById(routeId);
commonSignal = commonRoute.getStart();
cilSignal = cilRepository.getSignalById(commonSignal.getId());
} else {
throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception("参数缺失");
}
//执行
/* 进路锁闭,但因为区段占用导致无法开放信号 */
if (cilRoute != null) {
if (cilRoute.isLock() && cilSignal.isForbidAspect()) {
cilSignalLogicService.UpdateSignalDisplay(simulation, cilSignal, CilSignal.GUIDE, false);
if (cilRepository.getSectionById(commonRoute.getPathElement().getStart().getId()).isAxcOccupy()) { //进路首区段占用
cilSignal.initGuideTime();
}
cilRoute.setGl(true);
return;
}
}
/* 进路不能锁闭 */
List<CommonRoute> routes = commonRepository.getRoutesByStartSignal(cilSignal.getId());
Optional<CommonRoute> routeOptional = routes.stream().filter(cr -> {
List<SwitchPosition> 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) { public void routeLogic(RtSimulation rtSimulation, CilRepository cilRepository) {
List<CilRoute> supervisedRouteList = cilRepository.getSupervisedRouteList(); List<CilRoute> supervisedRouteList = cilRepository.getSupervisedRouteList();
for (CilRoute cilRoute : supervisedRouteList) { for (CilRoute cilRoute : supervisedRouteList) {
@ -27,14 +103,6 @@ public class CilRouteLogicService {
if (cilRoute.isDelayUnlocking()) { if (cilRoute.isDelayUnlocking()) {
this.delayUnlockingProgress(rtSimulation, cilRoute, cilRepository.getConfig()); 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; return true;
} }
private void routeUse(CilRepository cilRepository, List<SwitchPosition> switchPositions) {
if (!CollectionUtils.isEmpty(switchPositions)) {
for (SwitchPosition sp : switchPositions) {
routeUse(cilRepository, sp);
}
}
}
private void routeUse(CilRepository cilRepository, SwitchPosition switchPosition) { private void routeUse(CilRepository cilRepository, SwitchPosition switchPosition) {
CilSwitch cilSwitch = cilRepository.getSwitchById(switchPosition.getCommonSwitch().getId()); CilSwitch cilSwitch = cilRepository.getSwitchById(switchPosition.getCommonSwitch().getId());
cilSwitch.routeUse(switchPosition.getPosition()); cilSwitch.routeUse(switchPosition.getPosition());
@ -210,7 +286,7 @@ public class CilRouteLogicService {
// 进路内的设备转动锁闭 // 进路内的设备转动锁闭
if (!cilRoute.isLock()) { if (!cilRoute.isLock()) {
cilSwitchLogicService.tryTurn(rtSimulation, pathElement.getSpList()); // 转动道岔 cilSwitchLogicService.tryTurn(rtSimulation, pathElement.getSpList()); // 转动道岔
boolean allLock = try2RouteLockSwitches(cilRepository, cilRoute, pathElement.getSpList()); // 锁闭道岔 boolean allLock = try2RouteLockSwitches(cilRepository, cilRoute.getId(), pathElement.getSpList()); // 锁闭道岔
if (allLock) { if (allLock) {
// if (!config.isLockFirst()) { // if (!config.isLockFirst()) {
routeLockSections(cilRepository, commonRoute); routeLockSections(cilRepository, commonRoute);
@ -412,7 +488,7 @@ public class CilRouteLogicService {
* *
* @return 全部锁闭时为true * @return 全部锁闭时为true
*/ */
private boolean try2RouteLockSwitches(CilRepository cilRepository, CilRoute route, List<SwitchPosition> switchPositionList) { private boolean try2RouteLockSwitches(CilRepository cilRepository, String routeId, List<SwitchPosition> switchPositionList) {
boolean flag = true; boolean flag = true;
if (!CollectionUtils.isEmpty(switchPositionList)) { if (!CollectionUtils.isEmpty(switchPositionList)) {
for (SwitchPosition switchPosition : switchPositionList) { for (SwitchPosition switchPosition : switchPositionList) {
@ -420,7 +496,7 @@ public class CilRouteLogicService {
if (cilSwitch.getPosition() != switchPosition.getPosition()) { if (cilSwitch.getPosition() != switchPosition.getPosition()) {
flag = false; flag = false;
} else { } 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);
// }
});
}
} }

View File

@ -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.CIL.bo.CilSignal;
import club.joylink.rtss.simulation.rt.RtSimulation; import club.joylink.rtss.simulation.rt.RtSimulation;
import club.joylink.rtss.simulation.rt.SRD.SrdApiService; 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 club.joylink.rtss.simulation.rt.repo.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -46,6 +45,7 @@ public class CilSignalLogicService {
} }
public void reopen(RtSimulation rtSimulation, String signalId) { public void reopen(RtSimulation rtSimulation, String signalId) {
//检查
CilRepository cilRepository = rtSimulation.getRepository(CilRepository.NAME, CilRepository.class); CilRepository cilRepository = rtSimulation.getRepository(CilRepository.NAME, CilRepository.class);
CommonRepository commonRepository = rtSimulation.getRepository(CommonRepository.NAME, CommonRepository.class); CommonRepository commonRepository = rtSimulation.getRepository(CommonRepository.NAME, CommonRepository.class);
CilSignal cilSignal = cilRepository.getSignalById(signalId); CilSignal cilSignal = cilRepository.getSignalById(signalId);
@ -55,7 +55,9 @@ public class CilSignalLogicService {
CommonRoute commonRoute = commonRepository.getRouteById(cilSignal.getLrId()); CommonRoute commonRoute = commonRepository.getRouteById(cilSignal.getLrId());
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(cilRouteLogicService.canOpenSignal(rtSimulation, commonRoute.getId()), 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) { public boolean try2UpdateSignalDisplay(RtSimulation rtSimulation, CilSignal signal, int aspect, boolean ctcMode) {

View File

@ -58,8 +58,8 @@ public class CilRoute extends CilDevice {
private boolean trainIn; //列车进入进路 private boolean trainIn; //列车进入进路
@Setter @Setter
private boolean delayUnlocking; //延时解锁中 private boolean delayUnlocking; //延时解锁中
@Setter
boolean gl;
public CilRoute(String id, String name) { public CilRoute(String id, String name) {
super(id, name); super(id, name);

View File

@ -7,7 +7,8 @@ import lombok.Setter;
@Getter @Getter
public class CilSignal extends CilDevice { 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; //当前显示的信号 int signalAspect = RED; //当前显示的信号
public static final int RED = 1; // 红灯信号(禁止信号) public static final int RED = 1; // 红灯信号(禁止信号)
@ -39,7 +40,8 @@ public class CilSignal extends CilDevice {
boolean fl; //侧防锁闭侧防锁闭后信号机不能开放 boolean fl; //侧防锁闭侧防锁闭后信号机不能开放
@Setter @Setter
String lrId; //锁闭进路的id String lrId; //锁闭进路的id
int delayTime; //信号机延时解锁倒计时/ms int delayTime; //进路延时解锁倒计时/ms
int guideTime; //引导信号剩余时间
Fault fault; Fault fault;
@ -114,6 +116,22 @@ public class CilSignal extends CilDevice {
this.delayTime = Math.max(this.delayTime - CilLogicService.CilMainLogicRate, 0); 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) { public void setFault(Fault fault) {
this.fault = fault; this.fault = fault;
} }

View File

@ -83,9 +83,9 @@ public class CilSwitch extends CilDevice {
this.routeUseToPosition = 0; this.routeUseToPosition = 0;
} }
public void lockByRoute(CilRoute cilRoute) { public void lockByRoute(String routeId) {
if (!Objects.equals(cilRoute.getId(), this.routeId)) { if (!Objects.equals(routeId, this.routeId)) {
this.routeId = cilRoute.getId(); this.routeId = routeId;
this.rl = true; this.rl = true;
} }
} }

View File

@ -38,8 +38,8 @@ public class SignalOperationHandler {
} }
@SimulationOperationMapping("Signal_Set_Guide") @SimulationOperationMapping("Signal_Set_Guide")
public boolean setGuide(RtSimulation simulation, String signalId, String routeId) { public void setGuide(RtSimulation simulation, String signalId, String routeId) {
return this.cilApiService.setGuide(simulation, signalId, routeId); this.cilApiService.setGuide(simulation, signalId, routeId);
} }
@SimulationOperationMapping("Signal_Block") @SimulationOperationMapping("Signal_Block")

View File

@ -5,7 +5,9 @@ import club.joylink.rtss.simulation.SimulationRepository;
import lombok.Getter; import lombok.Getter;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Getter @Getter
public class CommonRepository extends SimulationRepository { public class CommonRepository extends SimulationRepository {
@ -63,4 +65,8 @@ public class CommonRepository extends SimulationRepository {
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(commonSwitch, String.format("不存在id为[%s]的道岔", id)); BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(commonSwitch, String.format("不存在id为[%s]的道岔", id));
return commonSwitch; return commonSwitch;
} }
public List<CommonRoute> getRoutesByStartSignal(String signalId) {
return this.routeMap.values().stream().filter(commonRoute -> commonRoute.getStart().getId().equals(signalId)).collect(Collectors.toList());
}
} }