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 a4ded4ce5..3504a82a4 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 @@ -666,32 +666,48 @@ public class AtsStationService { /** * 发送申请转换操作模式申请 * @param simulation - * @param station */ - public void replyOperationMode(Simulation simulation, Station station) { - Station.OperationModeApplication modeApplication = station.getOperationModeApplication(); - if (modeApplication == null) { - return; - } - // 申请超过两分钟 - if (simulation.getCorrectSystemTime().isAfter(modeApplication.getApplyDateTime().plusMinutes(2))) { - station.setOperationModeApplication(null); - return; - } - if (CollectionUtils.isEmpty(modeApplication.getApprovalMember())) { - return; - } - 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); + public void replyOperationMode(Simulation simulation) { + List stationList = simulation.getRepository().getStationList(); + // 需要给用户发送的申请列表 + Map>> userMessageMap = new HashMap<>(stationList.size()); + stationList.stream().filter(station -> { + Station.OperationModeApplication modeApplication = station.getOperationModeApplication(); + if (modeApplication== null) { + return false; + } + if (CollectionUtils.isEmpty(modeApplication.getApprovalMember())) { + return false; + } + // 申请超过两分钟 + if (simulation.getCorrectSystemTime().isAfter(modeApplication.getApplyDateTime().plusMinutes(2))) { + station.setOperationModeApplication(null); + return false; + } + return true; + }).forEach(station -> { + Station.OperationModeApplication modeApplication = station.getOperationModeApplication(); + 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("code", station.getCode()); + messageMap.put("source", modeApplication.getSource()); + messageMap.put("target", modeApplication.getTarget()); + messageMap.put("applyMember", modeApplication.getApplicationMember().getId()); + messageMap.put("applyDateTime", modeApplication.getApplyDateTime()); + for (String userId : userSet) { + if (!userMessageMap.containsKey(userId)) { + userMessageMap.put(userId, new ArrayList<>()); + } + userMessageMap.get(userId).add(messageMap); + } + } + }); + if (!CollectionUtils.isEmpty(userMessageMap)) { + userMessageMap.forEach((k, v) -> + stompMessageService.sendToUser(k, + SocketMessageFactory.build(WebSocketMessageType.Simulation_Operation_Mode_Apply, simulation.getId(), v))); } } 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 dd860f334..cf4e63288 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 @@ -64,10 +64,10 @@ public class CiLogic { // 区间灯点灯逻辑 if (simulation.getRepository().getConfig().isRailway()) { + // 车站站控操作模式转换 + atsStationService.replyOperationMode(simulation); // 车站 simulation.getRepository().getStationList().stream().forEach(station -> { - // 车站站控操作模式转换 - atsStationService.replyOperationMode(simulation, station); // 允许自律状态刷新 station.refreshAllowAutonomyStatus(); // 接、发辅助按钮倒计时刷新