From be8c515eeaeb854e39a97b9793be629f03f5fe36 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 15 Feb 2023 12:55:44 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=BD=A6=E7=AB=99=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E8=BD=AC=E6=8D=A2=E9=80=BB=E8=BE=91=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/StationOperateHandler.java | 4 -- .../cbtc/ATS/service/AtsStationService.java | 42 +++++++++++-------- .../rtss/simulation/cbtc/CI/CiLogic.java | 6 +++ .../simulation/cbtc/data/map/Station.java | 18 ++++++++ .../data/storage/device/StorageStation.java | 10 +++++ .../cbtc/robot/SimulationRobotService.java | 11 ++++- 6 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/StationOperateHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/StationOperateHandler.java index dc57e1b21..5777a95f2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/StationOperateHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/StationOperateHandler.java @@ -323,10 +323,6 @@ public class StationOperateHandler { /** * 车站状态选择切换 - * @param simulation 仿真实体 - * @param stationCode 车站编码 - * @param routeSetMode 排路方式 - * @param planControl 计划控制 */ @OperateHandlerMapping(type = Operation.Type.Station_Switch_Route_Set_Model) public List switchRouteSetModel(Simulation simulation, List routeSetModeParams) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java index 892d2aaa0..a4ded4ce5 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsStationService.java @@ -27,6 +27,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +import java.time.LocalDateTime; import java.time.LocalTime; import java.util.*; import java.util.stream.Collectors; @@ -616,6 +617,15 @@ public class AtsStationService { logList.add(String.format("车站【%s(%s)】 禁止转换", station.getName(), station.getCode())); } else { applyOperation.setApplyDateTime(simulation.getCorrectSystemTime()); + if (applyOperation.isCenterApplication()) { // 如果中心请求,需要车站同意 + applyOperation.setApprovalMember(Arrays.asList(station.getController())); + } else { // 车站同意需要中心同意 + applyOperation.setApprovalMember( + simulation.getSimulationMembers().stream() + .filter(s -> Objects.equals(s.getType(), SimulationMember.Type.DISPATCHER)) + .collect(Collectors.toList()) + ); + } station.setOperationModeApplication(applyOperation); } } else { // 非分散自律抛出异常 @@ -654,7 +664,7 @@ public class AtsStationService { } /** - * + * 发送申请转换操作模式申请 * @param simulation * @param station */ @@ -668,29 +678,27 @@ public class AtsStationService { station.setOperationModeApplication(null); return; } - SimulationMember simulationMember = null; - if (modeApplication.isCenterApplication()) { // 如果中心请求 - simulationMember = station.getController(); - } else { - simulationMember = simulation.getSimulationMembers().stream() - .filter(s -> Objects.equals(s.getType(), SimulationMember.Type.DISPATCHER)) - .findFirst().orElse(null); - } - if (simulationMember == null) { + if (CollectionUtils.isEmpty(modeApplication.getApprovalMember())) { return; - } else if (simulationMember.isRobot()) { - doOperationModeSwitch(station); - } else { - SocketMessageVO socketMessageVO = - SocketMessageFactory.build(WebSocketMessageType.Simulation_Operation_Mode_Apply, simulation.getId(), modeApplication); - stompMessageService.sendToUser(Set.of(simulationMember.getUserId()), socketMessageVO); + } + Set userSet = modeApplication.getApprovalMember().stream() + .filter(m -> !m.isRobot()).map(club.joylink.rtss.simulation.SimulationMember::getUserId).collect(Collectors.toSet()); + if (!CollectionUtils.isEmpty(userSet)) { + Map messageMap = new HashMap<>(); + messageMap.put("source", modeApplication.getSource()); + messageMap.put("target", modeApplication.getTarget()); + messageMap.put("applyMember", modeApplication.getApplicationMember().getId()); + messageMap.put("applyDateTime", modeApplication.getApplyDateTime()); + SocketMessageVO> socketMessageVO = + SocketMessageFactory.build(WebSocketMessageType.Simulation_Operation_Mode_Apply, simulation.getId(), messageMap); + stompMessageService.sendToUser(userSet, socketMessageVO); } } /** * 操作模式直接转换 */ - private void doOperationModeSwitch(Station station) { + public void doOperationModeSwitch(Station station) { Station.OperationModeApplication applyOperation = station.getOperationModeApplication(); station.setOperationMode(applyOperation.getTarget()); station.setOperationModeApplication(null); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiLogic.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiLogic.java index eef107055..dd860f334 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiLogic.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiLogic.java @@ -1,5 +1,6 @@ package club.joylink.rtss.simulation.cbtc.CI; +import club.joylink.rtss.simulation.cbtc.ATS.service.AtsStationService; import club.joylink.rtss.simulation.cbtc.CI.device.CiDeviceStatusCollector; import club.joylink.rtss.simulation.cbtc.CI.device.CiRouteService; import club.joylink.rtss.simulation.cbtc.CI.device.CiService; @@ -36,6 +37,9 @@ public class CiLogic { @Autowired private StationDirectionService stationDirectionService; + @Autowired + private AtsStationService atsStationService; + public void runForTrainPosition(Simulation simulation){ // 采集真实设备状态 deviceStatusCollector.collect(simulation); @@ -62,6 +66,8 @@ public class CiLogic { if (simulation.getRepository().getConfig().isRailway()) { // 车站 simulation.getRepository().getStationList().stream().forEach(station -> { + // 车站站控操作模式转换 + atsStationService.replyOperationMode(simulation, station); // 允许自律状态刷新 station.refreshAllowAutonomyStatus(); // 接、发辅助按钮倒计时刷新 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Station.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Station.java index 53d03fa66..2d8d07d5f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Station.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Station.java @@ -595,8 +595,16 @@ public class Station extends MayOutOfOrderDevice { */ private OperationMode target; + /** + * 申请人 + */ private SimulationMember applicationMember; + /** + * 审批人 + */ + private List approvalMember; + private LocalDateTime applyDateTime; public OperationModeApplication(SimulationMember applicantMember, OperationMode source, OperationMode target) { @@ -642,6 +650,16 @@ public class Station extends MayOutOfOrderDevice { return stationApplication && centerToShunt(); } + /** + * 审批人全部是机器人 + */ + public boolean isRobotApproval() { + if (CollectionUtils.isEmpty(approvalMember)) { + return false; + } + return approvalMember.stream().allMatch(SimulationMember::isRobot); + } + /** * 中心与调车相互转换 */ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageStation.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageStation.java index e87bf5f91..db277d984 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageStation.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageStation.java @@ -15,9 +15,11 @@ import lombok.Setter; import java.time.LocalDateTime; import java.time.LocalTime; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; @Getter @Setter @@ -196,6 +198,11 @@ public class StorageStation extends StorageStatusDevice { */ private String applicationMemberId; + /** + * 审批者ID + */ + private List approvalMemberIds; + private LocalDateTime applyDateTime; public static OperationModeApplicationStorage convert2Storage(Station.OperationModeApplication application) { @@ -207,13 +214,16 @@ public class StorageStation extends StorageStatusDevice { storage.setSource(application.getSource()); storage.setTarget(application.getTarget()); storage.setApplyDateTime(application.getApplyDateTime()); + storage.setApprovalMemberIds(application.getApprovalMember().stream().map(SimulationMember::getId).collect(Collectors.toList())); return storage; } public Station.OperationModeApplication recover2Simulation(Simulation simulation){ SimulationMember simulationMember = simulation.getSimulationMemberById(applicationMemberId); + List approvalMember = approvalMemberIds.stream().map(simulation::getSimulationMemberById).collect(Collectors.toList()); Station.OperationModeApplication application =new Station.OperationModeApplication(simulationMember, source, target); application.setApplyDateTime(applyDateTime); + application.setApprovalMember(approvalMember); return application; } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/robot/SimulationRobotService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/robot/SimulationRobotService.java index ad98e0f06..89f2d30e7 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/robot/SimulationRobotService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/robot/SimulationRobotService.java @@ -570,9 +570,16 @@ public class SimulationRobotService { if (simulation.getScript() != null && simulation.getScript().isBgSet()) { return; } - simulation.getRepository().getStationList().stream().filter(station -> station.getOperationModeApplication() != null) - .forEach(station -> atsStationService.replyOperationMode(simulation, station)); + // 实训场景模式,已设置背景处于编制状态的实训,不做自动转换处理 + Training2 training2 = simulation.getTraining2(); + if (training2 != null && training2.isScene() && StringUtils.hasText(training2.getBgSceneJson()) && !training2.isRunning()) { + return; + } + simulation.getRepository().getStationList().stream() + .filter(station -> station.getOperationModeApplication() != null && station.getOperationModeApplication().isRobotApproval()) + .forEach(station -> atsStationService.doOperationModeSwitch(station)); } + private void doControlBySpeedCurve(Simulation simulation, VirtualRealityTrain train, SpeedCurve speedCurve, float remainDistance) { if (speedCurve.equals(SpeedCurve.ZERO)) { this.doBreakMax(simulation, train);