每次开始触发办理进路时设置开放信号显示

This commit is contained in:
xiazengbin 2022-08-11 17:56:34 +08:00
parent 4073382b85
commit 112ab6cbab
7 changed files with 3254 additions and 3221 deletions

View File

@ -1,318 +1,319 @@
package club.joylink.rtss.simulation.cbtc.ATS.service; package club.joylink.rtss.simulation.cbtc.ATS.service;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm; import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm;
import club.joylink.rtss.simulation.cbtc.CI.CiApiService; import club.joylink.rtss.simulation.cbtc.CI.CiApiService;
import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService; import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Cycle; import club.joylink.rtss.simulation.cbtc.data.map.Cycle;
import club.joylink.rtss.simulation.cbtc.data.map.Route; import club.joylink.rtss.simulation.cbtc.data.map.Route;
import club.joylink.rtss.simulation.cbtc.data.map.Signal; import club.joylink.rtss.simulation.cbtc.data.map.Signal;
import club.joylink.rtss.simulation.cbtc.data.status.RouteStatus; import club.joylink.rtss.simulation.cbtc.data.status.RouteStatus;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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 org.springframework.util.StringUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Slf4j @Slf4j
@Component @Component
public class AtsRouteService { public class AtsRouteService {
@Autowired @Autowired
private CiRouteService routeService; private CiRouteService routeService;
@Autowired @Autowired
private CiApiService ciApiService; private CiApiService ciApiService;
/** /**
* 进路收人工控 * 进路收人工控
* *
* @param simulation * @param simulation
* @param signalCode * @param signalCode
* @param routeCodeList * @param routeCodeList
*/ */
public void setRouteHumanControl(Simulation simulation, String signalCode, List<String> routeCodeList) { public void setRouteHumanControl(Simulation simulation, String signalCode, List<String> routeCodeList) {
if (!CollectionUtils.isEmpty(routeCodeList)) { if (!CollectionUtils.isEmpty(routeCodeList)) {
routeCodeList.forEach(routeCode -> { routeCodeList.forEach(routeCode -> {
Route route = simulation.getRepository().getByCode(routeCode, Route.class); Route route = simulation.getRepository().getByCode(routeCode, Route.class);
route.setAtsControl(false); route.setAtsControl(false);
}); });
} else if (StringUtils.hasText(signalCode)) { } else if (StringUtils.hasText(signalCode)) {
Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class); Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class);
List<Route> routeList = signal.getRouteList(); List<Route> routeList = signal.getRouteList();
if (!CollectionUtils.isEmpty(routeList)) { if (!CollectionUtils.isEmpty(routeList)) {
routeList.forEach(route -> route.setAtsControl(false)); routeList.forEach(route -> route.setAtsControl(false));
} }
} }
} }
/** /**
* 进路交自动控 * 进路交自动控
*/ */
public void setRouteAtsControl(Simulation simulation, String signalCode, public void setRouteAtsControl(Simulation simulation, String signalCode,
List<String> routeCodeList, List<Boolean> checkConflictList) { List<String> routeCodeList, List<Boolean> checkConflictList) {
SimulationDataRepository repository = simulation.getRepository(); SimulationDataRepository repository = simulation.getRepository();
if (!CollectionUtils.isEmpty(routeCodeList)) { if (!CollectionUtils.isEmpty(routeCodeList)) {
if (!CollectionUtils.isEmpty(checkConflictList)) { if (!CollectionUtils.isEmpty(checkConflictList)) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(routeCodeList.size() == checkConflictList.size(), BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(routeCodeList.size() == checkConflictList.size(),
String.format("进路数和是否检查冲突数量不一致:[%s], [%s]", String.format("进路数和是否检查冲突数量不一致:[%s], [%s]",
String.join(",", routeCodeList), String.join(",", routeCodeList),
String.join(",", checkConflictList.stream().map(String::valueOf).collect(Collectors.toList())))); String.join(",", checkConflictList.stream().map(String::valueOf).collect(Collectors.toList()))));
} }
List<Route> routes = routeCodeList.stream().map(routeCode -> repository.getByCode(routeCode, Route.class)).collect(Collectors.toList()); List<Route> routes = routeCodeList.stream().map(routeCode -> repository.getByCode(routeCode, Route.class)).collect(Collectors.toList());
if (repository.getConfig().isSignalHumanControlBeforeSetAtsControlOrCIAutoTrigger()) { if (repository.getConfig().isSignalHumanControlBeforeSetAtsControlOrCIAutoTrigger()) {
routes.stream() routes.stream()
.map(Route::getStart) .map(Route::getStart)
.distinct() .distinct()
.forEach(signal -> .forEach(signal ->
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED
.assertNotTrue(signal.isCiControl(), .assertNotTrue(signal.isCiControl(),
String.format("信号机[%s]需处于人工控状态", signal.getCode()))); String.format("信号机[%s]需处于人工控状态", signal.getCode())));
} }
if (CollectionUtils.isEmpty(checkConflictList)) { if (CollectionUtils.isEmpty(checkConflictList)) {
routes.forEach(route -> route.setAtsControl(true)); routes.forEach(route -> route.setAtsControl(true));
} else { } else {
for (int i = 0; i < routeCodeList.size(); i++) { for (int i = 0; i < routeCodeList.size(); i++) {
Route route = repository.getByCode(routeCodeList.get(i), Route.class); Route route = repository.getByCode(routeCodeList.get(i), Route.class);
boolean checkConflict = checkConflictList.get(i); boolean checkConflict = checkConflictList.get(i);
route.setAtsControl(true); route.setAtsControl(true);
route.setCheckConflict(checkConflict); route.setCheckConflict(checkConflict);
} }
} }
} else if (StringUtils.hasText(signalCode)) { } else if (StringUtils.hasText(signalCode)) {
Signal signal = repository.getByCode(signalCode, Signal.class); Signal signal = repository.getByCode(signalCode, Signal.class);
if (repository.getConfig().isSignalHumanControlBeforeSetAtsControlOrCIAutoTrigger()) { if (repository.getConfig().isSignalHumanControlBeforeSetAtsControlOrCIAutoTrigger()) {
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(signal.isCiControl(), String.format("信号机[%s]需处于人工控状态", signal.getCode())); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(signal.isCiControl(), String.format("信号机[%s]需处于人工控状态", signal.getCode()));
} }
List<Route> routeList = signal.getRouteList(); List<Route> routeList = signal.getRouteList();
if (!CollectionUtils.isEmpty(routeList)) { if (!CollectionUtils.isEmpty(routeList)) {
routeList.forEach(route -> route.setAtsControl(true)); routeList.forEach(route -> route.setAtsControl(true));
} }
} }
} }
/** /**
* 查询进路状态/模式 * 查询进路状态/模式
*/ */
public List<RouteStatus> findRoutesStatus(Simulation simulation, String signalCode) { public List<RouteStatus> findRoutesStatus(Simulation simulation, String signalCode) {
Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class); Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class);
List<Route> routeList = signal.getRouteList(); List<Route> routeList = signal.getRouteList();
return routeList.stream().map(RouteStatus::new).collect(Collectors.toList()); return routeList.stream().map(RouteStatus::new).collect(Collectors.toList());
} }
/** /**
* 设置联锁自动进路 * 设置联锁自动进路
*/ */
public void setCiAuto(Simulation simulation, String signalCode) { public void setCiAuto(Simulation simulation, String signalCode) {
Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class); Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class);
if (simulation.getRepository().getConfig().isSetRouteBeforeSetFlt()) { if (simulation.getRepository().getConfig().isSetRouteBeforeSetFlt()) {
Route lockedRoute = signal.getLockedRoute(); Route lockedRoute = signal.getLockedRoute();
if (lockedRoute == null) { if (lockedRoute == null) {
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL,
String.format("信号机[%s(%s)]没有已锁闭进路,不能设置联锁自动进路", signal.getName(), signal.getCode())); String.format("信号机[%s(%s)]没有已锁闭进路,不能设置联锁自动进路", signal.getName(), signal.getCode()));
} }
if (!lockedRoute.isFlt()) { if (!lockedRoute.isFlt()) {
throw new SimulationException(SimulationExceptionType.Unsupported_Operation, throw new SimulationException(SimulationExceptionType.Unsupported_Operation,
String.format("进路[%s]不能设置车队进路", lockedRoute.getCode())); String.format("进路[%s]不能设置车队进路", lockedRoute.getCode()));
} }
if (lockedRoute.isCiControl()) { if (lockedRoute.isCiControl()) {
throw new SimulationException(SimulationExceptionType.Operation_Conflict, throw new SimulationException(SimulationExceptionType.Operation_Conflict,
String.format("进路[%s(%s)]自动追踪已开启,不能设置联锁自动进路", lockedRoute.getName(), lockedRoute.getCode())); String.format("进路[%s(%s)]自动追踪已开启,不能设置联锁自动进路", lockedRoute.getName(), lockedRoute.getCode()));
} }
lockedRoute.setFleetMode(true); lockedRoute.setFleetMode(true);
} else { } else {
List<Route> routeList = signal.getRouteList(); List<Route> routeList = signal.getRouteList();
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertCollectionNotEmpty(routeList, signal.debugStr() + "不是进路始端信号机"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertCollectionNotEmpty(routeList, signal.debugStr() + "不是进路始端信号机");
// 筛选最适合的进路筛选逻辑与办理引导时筛选逻辑类似 // 筛选最适合的进路筛选逻辑与办理引导时筛选逻辑类似
List<Route> fltRoutes = routeList.stream().filter(Route::isFlt).collect(Collectors.toList()); List<Route> fltRoutes = routeList.stream().filter(Route::isFlt).collect(Collectors.toList());
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertCollectionNotEmpty(fltRoutes, signal.debugStr() + "下没有可设置的车队进路"); BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertCollectionNotEmpty(fltRoutes, signal.debugStr() + "下没有可设置的车队进路");
List<Route> collect = fltRoutes.stream() List<Route> collect = fltRoutes.stream()
.filter(r -> !r.isTurnBack() && CollectionUtils.isEmpty(r.getSwitchList())) .filter(r -> !r.isTurnBack() && CollectionUtils.isEmpty(r.getSwitchList()))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)) { if (CollectionUtils.isEmpty(collect)) {
collect = fltRoutes.stream().filter(r -> !r.isTurnBack()).collect(Collectors.toList()); collect = fltRoutes.stream().filter(r -> !r.isTurnBack()).collect(Collectors.toList());
} }
if (CollectionUtils.isEmpty(collect)) { if (CollectionUtils.isEmpty(collect)) {
collect = fltRoutes; collect = fltRoutes;
} }
Route route = collect.get(0); Route route = collect.get(0);
Route.CheckFailMessage message = routeService.setRoute(simulation, route); route.setSettedAspect(route.getAspect());
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNull(message, route.debugStr() + "无法办理"); Route.CheckFailMessage message = routeService.setRoute(simulation, route);
route.setFleetMode(true); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNull(message, route.debugStr() + "无法办理");
} route.setFleetMode(true);
} }
}
/**
* 取消联锁自动进路 /**
*/ * 取消联锁自动进路
public void cancelCiAuto(Simulation simulation, String signalCode) { */
Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class); public void cancelCiAuto(Simulation simulation, String signalCode) {
Route lockedRoute = signal.getLockedRoute(); Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class);
if (Objects.isNull(lockedRoute)) { Route lockedRoute = signal.getLockedRoute();
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, if (Objects.isNull(lockedRoute)) {
String.format("信号机[%s(%s)]没有已锁闭进路,不能执行取消联锁自动进路", signal.getName(), signal.getCode())); throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL,
} String.format("信号机[%s(%s)]没有已锁闭进路,不能执行取消联锁自动进路", signal.getName(), signal.getCode()));
if (!lockedRoute.isFleetMode()) { }
throw new SimulationException(SimulationExceptionType.Operation_Repetition, String.format("信号机[%s(%s)]没有打开连锁自动进路,不能取消联锁自动进路", signal.getName(), signal.getCode())); if (!lockedRoute.isFleetMode()) {
} throw new SimulationException(SimulationExceptionType.Operation_Repetition, String.format("信号机[%s(%s)]没有打开连锁自动进路,不能取消联锁自动进路", signal.getName(), signal.getCode()));
lockedRoute.setFleetMode(false); }
if (simulation.getRepository().getConfig().isCancelRouteWhenCancelFlt()) { lockedRoute.setFleetMode(false);
routeService.unlockRoute(simulation, lockedRoute); if (simulation.getRepository().getConfig().isCancelRouteWhenCancelFlt()) {
} routeService.unlockRoute(simulation, lockedRoute);
} }
}
/**
* 设置联锁自动触发 /**
*/ * 设置联锁自动触发
public void setCiAutoTrigger(Simulation simulation, String signalCode, List<String> routeCodeList) { */
SimulationDataRepository repository = simulation.getRepository(); public void setCiAutoTrigger(Simulation simulation, String signalCode, List<String> routeCodeList) {
List<Route> routeList; SimulationDataRepository repository = simulation.getRepository();
if (StringUtils.hasText(signalCode)) { List<Route> routeList;
Signal signal = repository.getByCode(signalCode, Signal.class); if (StringUtils.hasText(signalCode)) {
if (repository.getConfig().isSignalHumanControlBeforeSetAtsControlOrCIAutoTrigger()) { Signal signal = repository.getByCode(signalCode, Signal.class);
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(signal.isAtsControl(), String.format("信号机[%s]需处于人工控", signal.getCode())); if (repository.getConfig().isSignalHumanControlBeforeSetAtsControlOrCIAutoTrigger()) {
} BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(signal.isAtsControl(), String.format("信号机[%s]需处于人工控", signal.getCode()));
routeList = signal.getRouteList(); }
} else { routeList = signal.getRouteList();
routeList = routeCodeList.stream() } else {
.map(code -> repository.getByCode(code, Route.class)) routeList = routeCodeList.stream()
.collect(Collectors.toList()); .map(code -> repository.getByCode(code, Route.class))
if (repository.getConfig().isSignalHumanControlBeforeSetAtsControlOrCIAutoTrigger()) { .collect(Collectors.toList());
routeList.stream() if (repository.getConfig().isSignalHumanControlBeforeSetAtsControlOrCIAutoTrigger()) {
.map(Route::getStart) routeList.stream()
.distinct() .map(Route::getStart)
.forEach(signal -> .distinct()
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED .forEach(signal ->
.assertNotTrue(signal.isAtsControl(), BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED
String.format("信号机[%s]需处于人工控", signal.getCode()))); .assertNotTrue(signal.isAtsControl(),
} String.format("信号机[%s]需处于人工控", signal.getCode())));
} }
if (!CollectionUtils.isEmpty(routeList)) { }
routeList.stream().filter(Route::isArs).forEach(route -> { if (!CollectionUtils.isEmpty(routeList)) {
if (route.isFleetMode()) { routeList.stream().filter(Route::isArs).forEach(route -> {
throw new SimulationException(SimulationExceptionType.Operation_Conflict, if (route.isFleetMode()) {
String.format("进路[%s(%s)]自动通过已开启,不能设置自动追踪", route.getName(), route.getCode())); throw new SimulationException(SimulationExceptionType.Operation_Conflict,
} String.format("进路[%s(%s)]自动通过已开启,不能设置自动追踪", route.getName(), route.getCode()));
// if (route.isCiControl()) { }
// throw new SimulationException(SimulationExceptionType.Operation_Repetition, String.format("进路[%s(%s)]自动追踪/连锁自动触发已开启,无需重复设置", route.getName(), route.getCode())); // if (route.isCiControl()) {
// } // throw new SimulationException(SimulationExceptionType.Operation_Repetition, String.format("进路[%s(%s)]自动追踪/连锁自动触发已开启,无需重复设置", route.getName(), route.getCode()));
}); // }
for (Route route : routeList) { });
// route.setAtsControl(false); for (Route route : routeList) {
if (route.isArs()) // route.setAtsControl(false);
route.setCiControl(true); if (route.isArs())
} route.setCiControl(true);
} }
} }
}
/**
* 取消联锁自动触发 /**
*/ * 取消联锁自动触发
public void cancelCiAutoTrigger(Simulation simulation, String signalCode, List<String> routeCodes) { */
List<Route> routeList; public void cancelCiAutoTrigger(Simulation simulation, String signalCode, List<String> routeCodes) {
SimulationDataRepository repository = simulation.getRepository(); List<Route> routeList;
if (StringUtils.hasText(signalCode)) { SimulationDataRepository repository = simulation.getRepository();
Signal signal = repository.getByCode(signalCode, Signal.class); if (StringUtils.hasText(signalCode)) {
routeList = signal.getRouteList(); Signal signal = repository.getByCode(signalCode, Signal.class);
} else { routeList = signal.getRouteList();
routeList = routeCodes.stream() } else {
.map(code -> repository.getByCode(code, Route.class)) routeList = routeCodes.stream()
.collect(Collectors.toList()); .map(code -> repository.getByCode(code, Route.class))
} .collect(Collectors.toList());
if (!CollectionUtils.isEmpty(routeList)) { }
for (Route route : routeList) { if (!CollectionUtils.isEmpty(routeList)) {
if (route.isCiControl()) { for (Route route : routeList) {
route.setCiControl(false); if (route.isCiControl()) {
route.setAtsControl(false); route.setCiControl(false);
} route.setAtsControl(false);
} }
} }
} }
}
/**
* 设置自动折返进路 /**
* * 设置自动折返进路
* @param simulation *
* @param cycleCode * @param simulation
*/ * @param cycleCode
public void setAutoTurnBack(Simulation simulation, String cycleCode) { */
Cycle cycle = simulation.getRepository().getByCode(cycleCode, Cycle.class); public void setAutoTurnBack(Simulation simulation, String cycleCode) {
cycle.setSetUp(true); Cycle cycle = simulation.getRepository().getByCode(cycleCode, Cycle.class);
} cycle.setSetUp(true);
}
/**
* 取消自动折返进路 /**
*/ * 取消自动折返进路
public void cancelAutoTurnBack(Simulation simulation, String cycleCode) { */
Cycle cycle = simulation.getRepository().getByCode(cycleCode, Cycle.class); public void cancelAutoTurnBack(Simulation simulation, String cycleCode) {
cycle.setSetUp(false); Cycle cycle = simulation.getRepository().getByCode(cycleCode, Cycle.class);
} cycle.setSetUp(false);
}
/**
* 总取消 /**
*/ * 总取消
public void totalCancel(Simulation simulation, String signalCode) { */
// todo 总取消操作有很多种操作方式对应不同的按钮此处都用信号机编号可能不妥 public void totalCancel(Simulation simulation, String signalCode) {
Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class); // todo 总取消操作有很多种操作方式对应不同的按钮此处都用信号机编号可能不妥
Route lockedRoute = signal.getLockedRoute(); Signal signal = simulation.getRepository().getByCode(signalCode, Signal.class);
if (lockedRoute == null) { Route lockedRoute = signal.getLockedRoute();
throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL, if (lockedRoute == null) {
String.format("信号机[%s(%s)]没有已锁闭进路,无需取消进路", signal.getName(), signal.getCode())); throw new SimulationException(SimulationExceptionType.Operation_Handle_FAIL,
} String.format("信号机[%s(%s)]没有已锁闭进路,无需取消进路", signal.getName(), signal.getCode()));
if (!signal.isApproachLock()) { //当接近区段未被占用 }
this.cancelRoute(simulation, signalCode); if (!signal.isApproachLock()) { //当接近区段未被占用
} else { this.cancelRoute(simulation, signalCode);
this.routeService.unlockRoute(simulation, lockedRoute); } else {
this.ciApiService.cancelFleetRoute(simulation, lockedRoute.getCode()); this.routeService.unlockRoute(simulation, lockedRoute);
// if (signal.isGuideAspect()) { //如果引导信号开启中 this.ciApiService.cancelFleetRoute(simulation, lockedRoute.getCode());
// this.ciApiService.closeGuideSignal(simulation, signalCode); // if (signal.isGuideAspect()) { //如果引导信号开启中
// } else if (signal.isClose()) { //如果信号灯关了 // this.ciApiService.closeGuideSignal(simulation, signalCode);
// } else { // } else if (signal.isClose()) { //如果信号灯关了
// this.ciApiService.closeSignal(simulation, signalCode); // } else {
// } // this.ciApiService.closeSignal(simulation, signalCode);
} // }
} }
}
public void cancelRoute(Simulation simulation, String signalCode) {
Route route = this.ciApiService.findLockedRouteByStartSignal(simulation, signalCode); public void cancelRoute(Simulation simulation, String signalCode) {
if (Objects.nonNull(route)) { Route route = this.ciApiService.findLockedRouteByStartSignal(simulation, signalCode);
BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotTrue( if (Objects.nonNull(route)) {
route.isApproachLock(), "进路接近锁闭,无法取消"); BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotTrue(
BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotTrue( route.isApproachLock(), "进路接近锁闭,无法取消");
route.getStart().isGuideAspect(), "引导进路,需要人解进路"); BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotTrue(
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(route.isFleetMode(), route.getStart().isGuideAspect(), "引导进路,需要人解进路");
String.format("进路[%s]已开启自动通过进路,无法取消", route.debugStr())); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(route.isFleetMode(),
this.ciApiService.unlockRoute(simulation, route.getCode()); String.format("进路[%s]已开启自动通过进路,无法取消", route.debugStr()));
} this.ciApiService.unlockRoute(simulation, route.getCode());
} }
}
public void setOverlap(Simulation simulation, String signalCode, String overlapCode) {
if (signalCode == null || overlapCode == null) { public void setOverlap(Simulation simulation, String signalCode, String overlapCode) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument); if (signalCode == null || overlapCode == null) {
} throw new SimulationException(SimulationExceptionType.Illegal_Argument);
this.ciApiService.setOverlap(simulation, signalCode, overlapCode); }
} this.ciApiService.setOverlap(simulation, signalCode, overlapCode);
}
public void conflictRouteSetConfirm(Simulation simulation, SimulationMember member, String routeCode, int way) {
BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue( public void conflictRouteSetConfirm(Simulation simulation, SimulationMember member, String routeCode, int way) {
Route.Conflict_Handle_Way_1 == way || Route.Conflict_Handle_Way_2 == way BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertTrue(
); Route.Conflict_Handle_Way_1 == way || Route.Conflict_Handle_Way_2 == way
Route route = simulation.getRepository().getByCode(routeCode, Route.class); );
AtsAlarm conflictAlarm = route.getConflictAlarm(); Route route = simulation.getRepository().getByCode(routeCode, Route.class);
if (conflictAlarm != null) { AtsAlarm conflictAlarm = route.getConflictAlarm();
LocalDateTime systemTime = simulation.getCorrectSystemTime(); if (conflictAlarm != null) {
conflictAlarm.confirm(systemTime, member, way); LocalDateTime systemTime = simulation.getCorrectSystemTime();
conflictAlarm.recover(systemTime); conflictAlarm.confirm(systemTime, member, way);
} conflictAlarm.recover(systemTime);
} }
} }
}

View File

@ -33,7 +33,6 @@ public class CiLogic {
private StationDirectionService stationDirectionService; private StationDirectionService stationDirectionService;
public void run(Simulation simulation) { public void run(Simulation simulation) {
// 采集真实设备状态 // 采集真实设备状态
deviceStatusCollector.collect(simulation); deviceStatusCollector.collect(simulation);
// 信号机监控控制 // 信号机监控控制
@ -119,6 +118,7 @@ public class CiLogic {
MapConfig config = simulation.getRepository().getConfig(); MapConfig config = simulation.getRepository().getConfig();
if (route.isCiControl()) { // 进路联锁自动触发 if (route.isCiControl()) { // 进路联锁自动触发
if (!route.isLock() && !route.isSetting() && ciService.isCiRouteTrigger(simulation, route)) { if (!route.isLock() && !route.isSetting() && ciService.isCiRouteTrigger(simulation, route)) {
route.setSettedAspect(route.getAspect());
routeService.setRoute(simulation, route); routeService.setRoute(simulation, route);
} }
} else if (route.isFleetMode()) { // 联锁自动进路 } else if (route.isFleetMode()) { // 联锁自动进路

View File

@ -1,177 +1,191 @@
package club.joylink.rtss.simulation.cbtc.data.storage.device; package club.joylink.rtss.simulation.cbtc.data.storage.device;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.data.map.DelayUnlockDevice; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement; import club.joylink.rtss.simulation.cbtc.data.map.DelayUnlockDevice;
import club.joylink.rtss.simulation.cbtc.data.map.Route; import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.simulation.cbtc.data.map.Route;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumDeserializer; import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer; import club.joylink.rtss.util.jsonSerialize.Boolean2NumDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Getter; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.NoArgsConstructor; import lombok.Getter;
import lombok.Setter; import lombok.NoArgsConstructor;
import lombok.Setter;
import java.time.LocalDateTime;
import java.util.Objects; import java.time.LocalDateTime;
import java.util.Objects;
@Getter
@Setter @Getter
@NoArgsConstructor @Setter
public class StorageRoute extends StorageDevice { @NoArgsConstructor
public class StorageRoute extends StorageDevice {
/**
* 是否CBTC模式 /**
*/ * 是否CBTC模式
@JsonSerialize(using = Boolean2NumSerializer.class) */
@JsonDeserialize(using = Boolean2NumDeserializer.class) @JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean cbtcMode; @JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean cbtcMode;
/**
* ats自动控制 /**
*/ * ats自动控制
@JsonSerialize(using = Boolean2NumSerializer.class) */
@JsonDeserialize(using = Boolean2NumDeserializer.class) @JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean atsControl; @JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean atsControl;
/**
* 连续通过进路模式(联锁自动进路)开启 /**
*/ * 连续通过进路模式(联锁自动进路)开启
@JsonSerialize(using = Boolean2NumSerializer.class) */
@JsonDeserialize(using = Boolean2NumDeserializer.class) @JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean fleetMode; @JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean fleetMode;
/**
* 自动追踪/联锁自动触发模式开启 /**
*/ * 自动追踪/联锁自动触发模式开启
@JsonSerialize(using = Boolean2NumSerializer.class) */
@JsonDeserialize(using = Boolean2NumDeserializer.class) @JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean ciControl; @JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean ciControl;
/**
* 进路是否排列中 /**
*/ * 进路是否排列中
@JsonSerialize(using = Boolean2NumSerializer.class) */
@JsonDeserialize(using = Boolean2NumDeserializer.class) @JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean setting; @JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean setting;
private LocalDateTime settingStartTime;
private LocalDateTime settingStartTime;
/**
* 是否引导进路排列 /**
*/ * 是否引导进路排列
@JsonSerialize(using = Boolean2NumSerializer.class) */
@JsonDeserialize(using = Boolean2NumDeserializer.class) @JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean settingGuide; @JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean settingGuide;
/**
* 进路是否锁闭 /**
*/ * 进路是否锁闭
@JsonSerialize(using = Boolean2NumSerializer.class) */
@JsonDeserialize(using = Boolean2NumDeserializer.class) @JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean lock; @JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean lock;
/** 进路延时解锁设备 */
private String delayUnlockDevice; /** 进路延时解锁设备 */
private String delayUnlockDevice;
/**
* 是否正常解锁中 /**
*/ * 是否正常解锁中
@JsonSerialize(using = Boolean2NumSerializer.class) */
@JsonDeserialize(using = Boolean2NumDeserializer.class) @JsonSerialize(using = Boolean2NumSerializer.class)
private Boolean normalUnlock; @JsonDeserialize(using = Boolean2NumDeserializer.class)
private Boolean normalUnlock;
private String unlockedSection;
private String unlockedSection;
// public StorageRoute(Route route) {
// super(route.getCode()); /**
// cbtcMode = route.isCbtcMode(); * 该进路办理成功后要开放的信号
// turnBackMode = route.isTurnBackMode(); * <p>
// atsControl = route.isAtsControl(); * 注意每次开始触发办理进路时设置
// fleetMode = route.isFleetMode(); */
// ciControl = route.isCiControl(); private SignalAspect settedAspect;
// setting = route.isSetting();
// settingGuide = route.isSettingGuide(); // public StorageRoute(Route route) {
// lock = route.isLock(); // super(route.getCode());
// canceling = route.isCanceling(); // cbtcMode = route.isCbtcMode();
// normalUnlock = route.isNormalUnlock(); // turnBackMode = route.isTurnBackMode();
// } // atsControl = route.isAtsControl();
// fleetMode = route.isFleetMode();
public StorageRoute(String code) { // ciControl = route.isCiControl();
super(code); // setting = route.isSetting();
} // settingGuide = route.isSettingGuide();
// lock = route.isLock();
public static StorageRoute convert2Storage(Route route) { // canceling = route.isCanceling();
StorageRoute storageRoute = new StorageRoute(route.getCode()); // normalUnlock = route.isNormalUnlock();
if (storageRoute.convert(route)) { // }
return storageRoute;
} public StorageRoute(String code) {
return null; super(code);
} }
@Override public static StorageRoute convert2Storage(Route route) {
public boolean convert(MapElement element) { StorageRoute storageRoute = new StorageRoute(route.getCode());
boolean change = false; if (storageRoute.convert(route)) {
Route route = (Route) element; return storageRoute;
if (!route.isAtsControl()) { }
change = true; return null;
this.setAtsControl(route.isAtsControl()); }
}
if (route.isFleetMode()) { @Override
change = true; public boolean convert(MapElement element) {
this.setFleetMode(route.isFleetMode()); boolean change = false;
} Route route = (Route) element;
if (route.isCiControl()) { if (!route.isAtsControl()) {
change = true; change = true;
this.setCiControl(route.isCiControl()); this.setAtsControl(route.isAtsControl());
} }
if (route.isSetting()) { if (route.isFleetMode()) {
change = true; change = true;
this.setSetting(route.isSetting()); this.setFleetMode(route.isFleetMode());
this.setSettingStartTime(route.getSettingStartTime()); }
} if (route.isCiControl()) {
if (route.isGuideSetting()) { change = true;
change = true; this.setCiControl(route.isCiControl());
this.setSettingGuide(route.isGuideSetting()); }
} if (route.isSetting()) {
if (route.isLock()) { change = true;
change = true; this.setSetting(route.isSetting());
this.setLock(route.isLock()); this.setSettingStartTime(route.getSettingStartTime());
} }
if (route.getDelayUnlockDevice() != null) { if (route.isGuideSetting()) {
change = true; change = true;
this.setDelayUnlockDevice(route.getDelayUnlockDevice().getCode()); this.setSettingGuide(route.isGuideSetting());
} }
if (route.isNormalUnlock()) { if (route.isLock()) {
change = true; change = true;
this.setNormalUnlock(route.isNormalUnlock()); this.setLock(route.isLock());
} }
if (Objects.nonNull(route.getUnlockedSection())) { if (route.getDelayUnlockDevice() != null) {
change = true; change = true;
this.setUnlockedSection(route.getUnlockedSection().getCode()); this.setDelayUnlockDevice(route.getDelayUnlockDevice().getCode());
} }
return change; if (route.isNormalUnlock()) {
} change = true;
this.setNormalUnlock(route.isNormalUnlock());
@Override }
public void recover2Simulation(MapElement element, Simulation simulation, SimulationDataRepository repository) { if (Objects.nonNull(route.getUnlockedSection())) {
Route route = (Route) element; change = true;
route.setAtsControl(atsControl != null ? atsControl : true); this.setUnlockedSection(route.getUnlockedSection().getCode());
route.setFleetMode(fleetMode != null ? fleetMode : false); }
route.setCiControl(ciControl != null ? ciControl : false); if (Objects.nonNull(route.getSettedAspect())) {
route.setSetting(setting != null? setting : false); change = true;
route.setSettingStartTime(this.settingStartTime); this.setSettedAspect(route.getSettedAspect());
route.setGuideSetting(settingGuide != null? settingGuide : false); }
route.setLock(lock != null ? lock : false);
if (this.delayUnlockDevice != null) { return change;
route.setDelayUnlockDevice((DelayUnlockDevice) repository.getByCode(this.delayUnlockDevice)); }
}
route.setNormalUnlock(normalUnlock != null ? normalUnlock : false); @Override
if (Objects.nonNull(this.unlockedSection)) { public void recover2Simulation(MapElement element, Simulation simulation, SimulationDataRepository repository) {
route.setUnlockedSection(repository.getByCode(this.unlockedSection, Section.class)); Route route = (Route) element;
} route.setAtsControl(atsControl != null ? atsControl : true);
} route.setFleetMode(fleetMode != null ? fleetMode : false);
route.setCiControl(ciControl != null ? ciControl : false);
} route.setSetting(setting != null? setting : false);
route.setSettingStartTime(this.settingStartTime);
route.setGuideSetting(settingGuide != null? settingGuide : false);
route.setLock(lock != null ? lock : false);
if (this.delayUnlockDevice != null) {
route.setDelayUnlockDevice((DelayUnlockDevice) repository.getByCode(this.delayUnlockDevice));
}
route.setNormalUnlock(normalUnlock != null ? normalUnlock : false);
if (Objects.nonNull(this.unlockedSection)) {
route.setUnlockedSection(repository.getByCode(this.unlockedSection, Section.class));
}
route.setSettedAspect(settedAspect);
}
}

View File

@ -1,236 +1,237 @@
package club.joylink.rtss.simulation.cbtc.depot; package club.joylink.rtss.simulation.cbtc.depot;
import club.joylink.rtss.simulation.cbtc.ATS.tools.TrainOutboundLoadTool; import club.joylink.rtss.simulation.cbtc.ATS.tools.TrainOutboundLoadTool;
import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService; import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.command.CommandBO; import club.joylink.rtss.simulation.cbtc.command.CommandBO;
import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO; import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.map.Route; import club.joylink.rtss.simulation.cbtc.data.map.Route;
import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.data.map.Signal; import club.joylink.rtss.simulation.cbtc.data.map.Signal;
import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan;
import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; import club.joylink.rtss.simulation.cbtc.data.support.RoutePath;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService; import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService;
import lombok.Getter; import lombok.Getter;
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 java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
public class DepotService { public class DepotService {
@Autowired @Autowired
private CiRouteService ciRouteService; private CiRouteService ciRouteService;
@Autowired @Autowired
private TrainOutboundLoadTool trainOutboundLoadTool; private TrainOutboundLoadTool trainOutboundLoadTool;
@Autowired @Autowired
private GroupSimulationService groupSimulationService; private GroupSimulationService groupSimulationService;
@Autowired @Autowired
private ATPService atpService; private ATPService atpService;
public void loadDepotTrain(Simulation simulation) { public void loadDepotTrain(Simulation simulation) {
if (!simulation.getRepository().getConfig().isHandleDepot()) { if (!simulation.getRepository().getConfig().isHandleDepot()) {
return; return;
} }
Map<Station, List<Section>> parkingTracksMap = simulation.getRepository().getParkingTracksMap(); Map<Station, List<Section>> parkingTracksMap = simulation.getRepository().getParkingTracksMap();
simulation.getRepository().getAllVrTrain().stream() simulation.getRepository().getAllVrTrain().stream()
.collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation)) .collect(Collectors.groupingBy(VirtualRealityTrain::getDepotStation))
.forEach((station, trainList) -> { .forEach((station, trainList) -> {
List<Section> sections = parkingTracksMap.get(station); List<Section> sections = parkingTracksMap.get(station);
// 先加载内侧的停车轨 // 先加载内侧的停车轨
sections.sort(Comparator.comparing(section -> sections.sort(Comparator.comparing(section ->
Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection()))); Objects.isNull(section.getLeftSection()) || Objects.isNull(section.getRightSection())));
boolean right = sections.get(sections.size() - 1).getLeftSection() == null; boolean right = sections.get(sections.size() - 1).getLeftSection() == null;
for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) { for (int i = 0, trainListSize = trainList.size(); i < trainListSize; i++) {
VirtualRealityTrain train = trainList.get(i); VirtualRealityTrain train = trainList.get(i);
Section section = sections.get(i); Section section = sections.get(i);
train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right); train.initManualTrain(new SectionPosition(section, section.getStopPointByDirection(right)), right);
train.parkingAt(section); train.parkingAt(section);
train.initAsRM(); train.initAsRM();
TrainInfo trainInfo = TrainInfo.constructManualTrain(train); TrainInfo trainInfo = TrainInfo.constructManualTrain(train);
trainInfo.tracking(train); trainInfo.tracking(train);
simulation.getRepository().addOnlineTrain(train); simulation.getRepository().addOnlineTrain(train);
simulation.getRepository().addTrainInfo(trainInfo); simulation.getRepository().addTrainInfo(trainInfo);
} }
}); });
} }
public void addJobs(Simulation simulation) { public void addJobs(Simulation simulation) {
simulation.addJob(SimulationModule.DEPOT.name(), () -> this.run(simulation), SimulationConstants.DEPOT_LOOP_RATE); simulation.addJob(SimulationModule.DEPOT.name(), () -> this.run(simulation), SimulationConstants.DEPOT_LOOP_RATE);
} }
private void run(Simulation simulation) { private void run(Simulation simulation) {
if (!simulation.isPlanRunning()) { if (!simulation.isPlanRunning()) {
return; return;
} }
if (!simulation.getRepository().getConfig().isHandleDepot()) { if (!simulation.getRepository().getConfig().isHandleDepot()) {
trainOutboundLoadTool.loadOutboundTrain(simulation); trainOutboundLoadTool.loadOutboundTrain(simulation);
} else { } else {
timeToDeparture(simulation); timeToDeparture(simulation);
backToParking(simulation); backToParking(simulation);
settingRouteAndMoving(simulation); settingRouteAndMoving(simulation);
arriveDestination(simulation); arriveDestination(simulation);
} }
} }
/** /**
* 根据时间筛选从停车轨自动发车 * 根据时间筛选从停车轨自动发车
*/ */
private void timeToDeparture(Simulation simulation) { private void timeToDeparture(Simulation simulation) {
LocalDateTime systemTime = simulation.getSystemTime(); LocalDateTime systemTime = simulation.getSystemTime();
for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getSchedulingTrainPlanList()) { for (SchedulingTrainPlan schedulingTrainPlan : simulation.getRepository().getSchedulingTrainPlanList()) {
if (schedulingTrainPlan.getOutDepotTrip().isDispatched()) { if (schedulingTrainPlan.getOutDepotTrip().isDispatched()) {
continue; continue;
} }
if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) { if (schedulingTrainPlan.getOutDepotTrip().getStartTime().minusMinutes(10).isBefore(systemTime.toLocalTime())) {
schedulingTrainPlan.getOutDepotTrip().dispatched(); schedulingTrainPlan.getOutDepotTrip().dispatched();
// 保存信息 // 保存信息
VirtualRealityTrain train = simulation.getRepository().getVRByCode(schedulingTrainPlan.getGroupNumber(), VirtualRealityTrain.class); VirtualRealityTrain train = simulation.getRepository().getVRByCode(schedulingTrainPlan.getGroupNumber(), VirtualRealityTrain.class);
Section startSection = train.getHeadPosition().getSection(); Section startSection = train.getHeadPosition().getSection();
Section endSection = schedulingTrainPlan.getOutDepotTrip().getStartSection(); Section endSection = schedulingTrainPlan.getOutDepotTrip().getStartSection();
List<RoutePath> routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection); List<RoutePath> routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection);
RoutePath routePath = routePaths.get(0); RoutePath routePath = routePaths.get(0);
DepotRunningInfo depotRunningInfo = new DepotRunningInfo(endSection, train, routePath, false); DepotRunningInfo depotRunningInfo = new DepotRunningInfo(endSection, train, routePath, false);
simulation.getRepository().getDepotRunningInfoList().add(depotRunningInfo); simulation.getRepository().getDepotRunningInfoList().add(depotRunningInfo);
} }
} }
} }
/** /**
* 筛选入库 * 筛选入库
*/ */
private void backToParking(Simulation simulation) { private void backToParking(Simulation simulation) {
for (TrainInfo trainInfo : simulation.getRepository().getTrainInfoMap().values()) { for (TrainInfo trainInfo : simulation.getRepository().getTrainInfoMap().values()) {
if (trainInfo.isInbound() && trainInfo.isParking()) { if (trainInfo.isInbound() && trainInfo.isParking()) {
VirtualRealityTrain train = simulation.getRepository().getVRByCode(trainInfo.getGroupNumber(), VirtualRealityTrain.class); VirtualRealityTrain train = simulation.getRepository().getVRByCode(trainInfo.getGroupNumber(), VirtualRealityTrain.class);
if (train.getHeadPosition().getSection().isTransferTrack() if (train.getHeadPosition().getSection().isTransferTrack()
&& train.getTailPosition().getSection().isTransferTrack()) { && train.getTailPosition().getSection().isTransferTrack()) {
if (simulation.getRepository().getDepotRunningInfoList().stream() if (simulation.getRepository().getDepotRunningInfoList().stream()
.anyMatch(depotRunningInfo -> depotRunningInfo.getTrain().equals(train))) { .anyMatch(depotRunningInfo -> depotRunningInfo.getTrain().equals(train))) {
continue; continue;
} }
train.initAsRM(); train.initAsRM();
Section startSection = train.getHeadPosition().getSection(); Section startSection = train.getHeadPosition().getSection();
Section endSection = null; Section endSection = null;
for (Section section : simulation.getRepository().getParkingTracksMap().get(startSection.getStation())) { for (Section section : simulation.getRepository().getParkingTracksMap().get(startSection.getStation())) {
if (section.isOccupied()) { if (section.isOccupied()) {
continue; continue;
} }
if (section.getLeftSection() == null || section.getRightSection() == null) { if (section.getLeftSection() == null || section.getRightSection() == null) {
endSection = section; endSection = section;
} else if (section.getLeftSection().isParkingTrack() && !section.getLeftSection().isOccupied()) { } else if (section.getLeftSection().isParkingTrack() && !section.getLeftSection().isOccupied()) {
endSection = section.getLeftSection(); endSection = section.getLeftSection();
} else if (section.getRightSection().isParkingTrack() && !section.getRightSection().isOccupied()) { } else if (section.getRightSection().isParkingTrack() && !section.getRightSection().isOccupied()) {
endSection = section.getRightSection(); endSection = section.getRightSection();
} else { } else {
endSection = section; endSection = section;
} }
break; break;
} }
// train.setTarget(endSection); // train.setTarget(endSection);
List<RoutePath> routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection); List<RoutePath> routePaths = simulation.getRepository().queryRoutePaths(startSection, endSection);
if (routePaths == null || routePaths.isEmpty()) { if (routePaths == null || routePaths.isEmpty()) {
return; return;
} }
RoutePath routePath = routePaths.get(0); RoutePath routePath = routePaths.get(0);
DepotRunningInfo depotRunningInfo = new DepotRunningInfo(endSection, train, routePath, true); DepotRunningInfo depotRunningInfo = new DepotRunningInfo(endSection, train, routePath, true);
simulation.getRepository().getDepotRunningInfoList().add(depotRunningInfo); simulation.getRepository().getDepotRunningInfoList().add(depotRunningInfo);
break; break;
} }
} }
} }
} }
/** /**
* 列车排进路并运行 * 列车排进路并运行
*/ */
private void settingRouteAndMoving(Simulation simulation) { private void settingRouteAndMoving(Simulation simulation) {
for (DepotRunningInfo depotRunningInfo : simulation.getRepository().getDepotRunningInfoList()) { for (DepotRunningInfo depotRunningInfo : simulation.getRepository().getDepotRunningInfoList()) {
Section endSection = depotRunningInfo.getEndSection(); Section endSection = depotRunningInfo.getEndSection();
SectionPosition position = new SectionPosition(endSection, endSection.getStopPointByDirection(depotRunningInfo.getRight())); SectionPosition position = new SectionPosition(endSection, endSection.getStopPointByDirection(depotRunningInfo.getRight()));
depotRunningInfo.getTrain().setRobotTargetPosition(position); depotRunningInfo.getTrain().setRobotTargetPosition(position);
if (!depotRunningInfo.getRouteList().isEmpty()) { if (!depotRunningInfo.getRouteList().isEmpty()) {
Route route = depotRunningInfo.getRouteList().get(0); Route route = depotRunningInfo.getRouteList().get(0);
if (route.isLock()) { if (route.isLock()) {
depotRunningInfo.getRouteList().remove(0); depotRunningInfo.getRouteList().remove(0);
} }
if (!route.isSetting()) { if (!route.isSetting()) {
ciRouteService.setRoute(simulation, route); route.setSettedAspect(route.getAspect());
} ciRouteService.setRoute(simulation, route);
} }
} }
} }
}
/**
* 判断运行列车是否到达转换轨并升级 /**
*/ * 判断运行列车是否到达转换轨并升级
private void arriveDestination(Simulation simulation) { */
for (Iterator<DepotRunningInfo> iterator = simulation.getRepository().getDepotRunningInfoList().iterator(); iterator.hasNext(); ) { private void arriveDestination(Simulation simulation) {
DepotRunningInfo depotRunningInfo = iterator.next(); for (Iterator<DepotRunningInfo> iterator = simulation.getRepository().getDepotRunningInfoList().iterator(); iterator.hasNext(); ) {
VirtualRealityTrain train = depotRunningInfo.getTrain(); DepotRunningInfo depotRunningInfo = iterator.next();
if (depotRunningInfo.isArrival()) { VirtualRealityTrain train = depotRunningInfo.getTrain();
// 到达 if (depotRunningInfo.isArrival()) {
iterator.remove(); // 到达
if (depotRunningInfo.in) { iterator.remove();
atpService.turnDirectionImmediately(train); if (depotRunningInfo.in) {
} else { atpService.turnDirectionImmediately(train);
// 升级 } else {
SimulationMember member = simulation.getSimulationMember(train, SimulationMember.Type.DRIVER); // 升级
Map<String, Object> param = new HashMap<>(); SimulationMember member = simulation.getSimulationMember(train, SimulationMember.Type.DRIVER);
param.put("preselectionMode", "AM_C"); Map<String, Object> param = new HashMap<>();
CommandInitiateVO commandInitiateVO = new CommandInitiateVO(CommandBO.CommandType.Change_Preselection_Mode, param.put("preselectionMode", "AM_C");
member.getId(), param); CommandInitiateVO commandInitiateVO = new CommandInitiateVO(CommandBO.CommandType.Change_Preselection_Mode,
groupSimulationService.command(simulation, commandInitiateVO, member); member.getId(), param);
} groupSimulationService.command(simulation, commandInitiateVO, member);
} }
} }
} }
}
@Getter
public static class DepotRunningInfo { @Getter
public static class DepotRunningInfo {
private final List<Route> routeList = new ArrayList<>();
private final List<Route> routeList = new ArrayList<>();
private final Section endSection;
private final Section endSection;
private final VirtualRealityTrain train;
private final VirtualRealityTrain train;
private final Boolean right;
private final Boolean right;
private final Boolean in;
private final Boolean in;
public DepotRunningInfo(Section endSection, VirtualRealityTrain train, RoutePath routePath, boolean in) {
this.endSection = endSection; public DepotRunningInfo(Section endSection, VirtualRealityTrain train, RoutePath routePath, boolean in) {
this.train = train; this.endSection = endSection;
for (Signal signal : routePath.getSignalList()) { this.train = train;
for (Route route : signal.getRouteList()) { for (Signal signal : routePath.getSignalList()) {
if (routePath.getRouteList().contains(route)) { for (Route route : signal.getRouteList()) {
routeList.add(route); if (routePath.getRouteList().contains(route)) {
} routeList.add(route);
} }
} }
this.right = routePath.isRight(); }
this.in = in; this.right = routePath.isRight();
} this.in = in;
}
// 列车是否到达终点
public boolean isArrival() { // 列车是否到达终点
return train.getSpeed() == 0 && train.getHeadPosition().getSection().equals(endSection) public boolean isArrival() {
&& train.getTailPosition().getSection().equals(endSection); return train.getSpeed() == 0 && train.getHeadPosition().getSection().equals(endSection)
} && train.getTailPosition().getSection().equals(endSection);
} }
} }
}