From 99678ccc1dcf641a73536229da87f964241a364b Mon Sep 17 00:00:00 2001 From: weizhihong Date: Tue, 14 Jun 2022 10:47:24 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=B0=86CTC=E6=89=80=E6=9C=89?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81=E7=A7=BB=E5=88=B0CTCLogicL?= =?UTF-8?q?oop=E3=80=91=20=E3=80=90=E5=A2=9E=E5=8A=A0=E8=B0=83=E5=BA=A6?= =?UTF-8?q?=E5=8F=B0=E3=80=81=E9=82=BB=E7=AB=99=E6=B6=88=E6=81=AF=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=B1=BB=E5=9E=8B=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../runplan/CtcStationRunPlanLogService.java | 52 ++----- .../simulation/cbtc/CTC/CTCLogicLoop.java | 141 +++++++++++++++++- .../message/SimulationUserWsListener.java | 6 +- .../rtss/vo/client/WebSocketMessageType.java | 10 ++ 4 files changed, 155 insertions(+), 54 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/runplan/CtcStationRunPlanLogService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/runplan/CtcStationRunPlanLogService.java index 709526287..96cf51722 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/runplan/CtcStationRunPlanLogService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/runplan/CtcStationRunPlanLogService.java @@ -10,14 +10,11 @@ import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.util.RandomGenerator; -import club.joylink.rtss.vo.client.WebSocketMessageType; -import club.joylink.rtss.vo.client.ctc.CtcRunPlanVO; import club.joylink.rtss.websocket.StompMessageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.time.LocalTime; @@ -92,7 +89,7 @@ public class CtcStationRunPlanLogService { runPlanLogList.add(changeRunPlanLog); } }); - sendRunPlanChangeMessage(simulation, runPlanLogList); + ctcLogicLoop.sendRunPlanChangeMessage(simulation, runPlanLogList, simulation.getSimulationUserIds()); } /** @@ -120,8 +117,7 @@ public class CtcStationRunPlanLogService { } }); // 发送消息 - ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), runPlanLogList, - WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_CHANGE, simulation.getSimulationUserIds()); + ctcLogicLoop.sendCtcManageChangeMessage(simulation, runPlanLogList, simulation.getSimulationUserIds()); } /** @@ -142,8 +138,7 @@ public class CtcStationRunPlanLogService { }, (p) -> p)); simulation.getCtcRepository().getSimulationRunPlanEditAreaMap().put(stationCode, planParamMap); // 发送消息 - ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), runPlanParamList, - WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_COVER, simulation.getSimulationUserIds()); + ctcLogicLoop.sendCtcManageCoverMessage(simulation, runPlanParamList, simulation.getSimulationUserIds()); } /** @@ -158,8 +153,7 @@ public class CtcStationRunPlanLogService { .getSimulationRunPlanEditAreaMap().getOrDefault(stationCode, new ConcurrentHashMap<>()); tripNumberList.forEach(tripNumber -> stationRunLogTripNumberMap.remove(tripNumber)); // 发送消息 - ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), tripNumberList, - WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_REMOVE, simulation.getSimulationUserIds()); + ctcLogicLoop.sendCtcManageRemoveMessage(simulation, tripNumberList, simulation.getSimulationUserIds()); } /** @@ -180,7 +174,7 @@ public class CtcStationRunPlanLogService { simulation.getCtcRepository().addRunPlanToSimulationMap(runPlanLog); runPlanLogList.add(runPlanLog); }); - coverRunPlanMessage(simulation, runPlanLogList); + ctcLogicLoop.coverRunPlanMessage(simulation, runPlanLogList, simulation.getSimulationUserIds()); } /** @@ -236,7 +230,7 @@ public class CtcStationRunPlanLogService { } } if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { - sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); + ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds()); } } } @@ -273,7 +267,7 @@ public class CtcStationRunPlanLogService { } } if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { - sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); + ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds()); } } @@ -307,7 +301,7 @@ public class CtcStationRunPlanLogService { } } if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { - sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); + ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds()); } } @@ -344,7 +338,7 @@ public class CtcStationRunPlanLogService { } } if (changeRunPlanLog.getArriveRunPlan() != null || changeRunPlanLog.getDepartRunPlan() != null) { - sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); + ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds()); } } @@ -362,7 +356,7 @@ public class CtcStationRunPlanLogService { CtcStationRunPlanLog changeRunPlanLog = new CtcStationRunPlanLog(); changeRunPlanLog.setCode(runPlanCode); changeRunPlanLog.setDelete(Boolean.TRUE); - sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog)); + ctcLogicLoop.sendRunPlanChangeMessage(simulation, Arrays.asList(changeRunPlanLog), simulation.getSimulationUserIds()); } } @@ -567,30 +561,4 @@ public class CtcStationRunPlanLogService { } return runPlanParam; } - - /** - * websocket消息发送事件 - * - * @param simulation 仿真实体 - * @param ctcStationRunPlanLogList 信息变更的实体列表 - */ - private void sendRunPlanChangeMessage(Simulation simulation, List ctcStationRunPlanLogList) { - if (!CollectionUtils.isEmpty(ctcStationRunPlanLogList)) { - // CTC运行日志发消息 - List messageList = ctcStationRunPlanLogList.stream().map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog)) - .collect(Collectors.toList()); - ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), messageList - , WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_CHANGE, simulation.getSimulationUserIds()); - } - } - - private void coverRunPlanMessage(Simulation simulation, List ctcStationRunPlanLogList) { - if (!CollectionUtils.isEmpty(ctcStationRunPlanLogList)) { - // CTC运行日志发消息 - List messageList = ctcStationRunPlanLogList.stream().map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog)) - .collect(Collectors.toList()); - ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), messageList - , WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_COVER, simulation.getSimulationUserIds()); - } - } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/CTCLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/CTCLogicLoop.java index 867bffec8..a322ae127 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/CTCLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/CTCLogicLoop.java @@ -1,11 +1,14 @@ package club.joylink.rtss.simulation.cbtc.CTC; +import club.joylink.rtss.simulation.cbtc.ATS.operation.vo.CtcRunPlanParam; import club.joylink.rtss.simulation.cbtc.ATS.service.ars.AtsRouteSelectService; import club.joylink.rtss.simulation.cbtc.CI.CiApiService; import club.joylink.rtss.simulation.cbtc.CTC.data.CtcRepository; +import club.joylink.rtss.simulation.cbtc.CTC.data.CtcStationRunPlanLog; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.vo.client.SocketMessageVO; import club.joylink.rtss.vo.client.WebSocketMessageType; +import club.joylink.rtss.vo.client.ctc.CtcRunPlanVO; import club.joylink.rtss.vo.client.factory.SocketMessageFactory; import club.joylink.rtss.websocket.StompMessageService; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +18,7 @@ import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; @Component public class CTCLogicLoop { @@ -58,18 +62,139 @@ public class CTCLogicLoop { simulation.addFixedRateJob(MESSAGE_NAME, () -> this.sendMessage(simulation), MESSAGE_RATE); } + /** + * 发送CTC初始变化 + * + * @param simulation 仿真实体 + * @param messageList 消息列表 + * @param userIds 用户ID + */ + public void sendRunPlanInitMessage(Simulation simulation, List messageList, Set userIds) { + if (!CollectionUtils.isEmpty(messageList)) { + sendCtcMessage(simulation.getId(), messageList, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_INIT, userIds); + } + } + + /** + * websocket消息发送变化事件 + * + * @param simulation 仿真实体 + * @param messageInfo 信息变更的实体列表 + */ + public void sendRunPlanChangeMessage(Simulation simulation, List messageInfo, Set userIds) { + if (!CollectionUtils.isEmpty(messageInfo)) { + // CTC运行日志发消息 + List messageList = messageInfo.stream().map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog)) + .collect(Collectors.toList()); + sendCtcMessage(simulation.getId(), messageList, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_CHANGE, userIds); + } + } + + /** + * websocket消息发送覆盖事件 + * + * @param simulation 仿真实体 + * @param messageInfo 信息变更的实体列表 + */ + public void coverRunPlanMessage(Simulation simulation, List messageInfo, Set userIds) { + if (!CollectionUtils.isEmpty(messageInfo)) { + // CTC运行日志发消息 + List messageList = messageInfo.stream().map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog)) + .collect(Collectors.toList()); + sendCtcMessage(simulation.getId(), messageList, WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_COVER, userIds); + } + } + + /** + * @param simulation + * @param messageInfo + * @param userIds + */ + public void initCtcManageMessage(Simulation simulation, List messageInfo, Set userIds) { + if (!CollectionUtils.isEmpty(messageInfo)) { + sendCtcMessage(simulation.getId(), messageInfo, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_INIT, userIds); + } + } + + /** + * 发送管理端信息变更消息 + * + * @param simulation 仿真ID + * @param messageInfo 消息 + * @param userIds 用户ID + */ + public void sendCtcManageChangeMessage(Simulation simulation, List messageInfo, Set userIds) { + if (messageInfo != null && !messageInfo.isEmpty()) { + sendCtcMessage(simulation.getId(), messageInfo, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_CHANGE, userIds); + } + } + + /** + * 发送管理端信息覆盖消息 + * + * @param simulation 仿真ID + * @param messageInfo 消息 + * @param userIds 用户ID + */ + public void sendCtcManageCoverMessage(Simulation simulation, List messageInfo, Set userIds) { + if (messageInfo != null && !messageInfo.isEmpty()) { + sendCtcMessage(simulation.getId(), messageInfo, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_COVER, userIds); + } + } + + /** + * 发送管理端信息删除消息 + * + * @param simulation 仿真ID + * @param messageInfo 消息 + * @param userIds 用户ID + */ + public void sendCtcManageRemoveMessage(Simulation simulation, List messageInfo, Set userIds) { + if (messageInfo != null && !messageInfo.isEmpty()) { + sendCtcMessage(simulation.getId(), messageInfo, WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_REMOVE, userIds); + } + } + + /** + * 发送调度台消息 + * + * @param simulationId 仿真ID + * @param messageInfo 消息 + * @param userIds 用户ID + * @param 消息类型 + */ + public void sendCtcDispatcherMessage(String simulationId, T messageInfo, Set userIds) { + if (messageInfo != null) { + sendCtcMessage(simulationId, messageInfo, WebSocketMessageType.SIMULATION_CTC_DISPATCHER_MESSAGE, userIds); + } + } + + /** + * CTC邻站消息 + * + * @param simulationId 仿真ID + * @param messageInfo 消息 + * @param userIds 用户ID + * @param 消息类型 + */ + public void sendCtcAdjacentStationMessage(String simulationId, T messageInfo, Set userIds) { + if (messageInfo != null) { + sendCtcMessage(simulationId, messageInfo, WebSocketMessageType.SIMULATION_CTC_ADJACENT_STATION_MESSAGE, userIds); + } + } + /** * 发送CTC运行计划消息 * - * @param simulationId 仿真ID - * @param messageInfoList 运行计划列表 - * @param type 消息类型 - * @param userIds 用户ID + * @param simulationId 仿真ID + * @param messageInfo 运行计划列表 + * @param type 消息类型 + * @param userIds 用户ID */ - public void sendCtcRunPlanMessage(String simulationId, List messageInfoList, WebSocketMessageType type, Set userIds) { - if (!CollectionUtils.isEmpty(messageInfoList)) { - SocketMessageVO> message = SocketMessageFactory.build(type, simulationId, messageInfoList); - stompMessageService.sendToUser(userIds, message); + public void sendCtcMessage(String simulationId, T messageInfo, WebSocketMessageType type, Set userIds) { + if (messageInfo != null) { + SocketMessageVO messageVO = SocketMessageFactory.build(type, simulationId, messageInfo); + stompMessageService.sendToUser(userIds, messageVO); } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationUserWsListener.java b/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationUserWsListener.java index f7a1055e0..d21a23eb7 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationUserWsListener.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationUserWsListener.java @@ -115,8 +115,7 @@ public class SimulationUserWsListener { List messageList = simulation.getCtcRepository().getAllRunPlanList().stream() .map(ctcStationRunPlanLog -> new CtcRunPlanVO(ctcStationRunPlanLog)) .collect(Collectors.toList()); - ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), messageList - , WebSocketMessageType.SIMULATION_CTC_RUN_PLAN_INIT, Stream.of(userId).collect(Collectors.toSet())); + ctcLogicLoop.sendRunPlanInitMessage(simulation, messageList, Stream.of(userId).collect(Collectors.toSet())); ctcLogicLoop.sendAllMessage(simulation); break; } @@ -124,8 +123,7 @@ public class SimulationUserWsListener { // CTC管理端编辑区发送消息 List allList = new ArrayList<>(); simulation.getCtcRepository().getSimulationRunPlanEditAreaMap().forEach((k, v) -> allList.addAll(v.values())); - ctcLogicLoop.sendCtcRunPlanMessage(simulation.getId(), allList - , WebSocketMessageType.SIMULATION_CTC_MANAGER_RUN_PLAN_EDIT_INIT, Stream.of(userId).collect(Collectors.toSet())); + ctcLogicLoop.initCtcManageMessage(simulation, allList, Stream.of(userId).collect(Collectors.toSet())); break; } } diff --git a/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java b/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java index 459b93848..df4dade4a 100644 --- a/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java +++ b/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java @@ -367,6 +367,16 @@ public enum WebSocketMessageType { */ SIMULATION_CTC_RUN_PLAN_COVER, + /** + * CTC调度台消息类型 + */ + SIMULATION_CTC_DISPATCHER_MESSAGE, + + /** + * CTC邻站消息 + */ + SIMULATION_CTC_ADJACENT_STATION_MESSAGE, + /** * 仿真CTC管理端 */