diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java index 411a304b5..cd514d146 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/GroupSimulationServiceImpl.java @@ -1,14 +1,10 @@ package club.joylink.rtss.simulation.cbtc; -import club.joylink.rtss.configuration.configProp.OtherConfig; -import club.joylink.rtss.configuration.configProp.WeChatConfig; import club.joylink.rtss.constants.MapPrdTypeEnum; import club.joylink.rtss.constants.ProjectDeviceType; import club.joylink.rtss.entity.project.Project; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.*; -import club.joylink.rtss.services.org.IOrgService; -import club.joylink.rtss.services.org.IOrgUserService; import club.joylink.rtss.services.project.ProjectService; import club.joylink.rtss.services.runplan.IRunPlanParktimeService; import club.joylink.rtss.services.runplan.IRunPlanRunlevelService; @@ -28,7 +24,6 @@ import club.joylink.rtss.simulation.cbtc.command.CommandExecuteService; import club.joylink.rtss.simulation.cbtc.command.CommandInitiateVO; import club.joylink.rtss.simulation.cbtc.communication.vo.fault.DeviceFaultInfo; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; -import club.joylink.rtss.simulation.cbtc.conversation.ConversationManagerService; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationIscsDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.DestinationCodeDefinition; @@ -121,28 +116,18 @@ public class GroupSimulationServiceImpl implements GroupSimulationService { @Autowired private IExamService iExamService; @Autowired - private ILessonService iLessonService; - @Autowired private StompMessageService stompMessageService; @Autowired private IScriptService iScriptService; @Autowired - private OtherConfig otherConfig; - @Autowired - private WeChatConfig weChatConfig; - @Autowired private IScriptSimulationService iScriptSimulationService; @Autowired private SimulationRealDeviceConnectManager simulationRealDeviceConnectManager; @Autowired private PassengerFlowSimulateService passengerFlowSimulateService; @Autowired - private IOrgUserService iOrgUserService; - @Autowired private IUserPermissionService iUserPermissionService; @Autowired - private IOrgService iOrgService; - @Autowired private SimulationManager simulationManager; @Autowired private LoginSessionManager loginSessionManager; @@ -155,13 +140,9 @@ public class GroupSimulationServiceImpl implements GroupSimulationService { @Autowired private QRCodeManager qrCodeManager; @Autowired - private ConversationManagerService conversationManagerService; - @Autowired private ProjectService projectService; @Autowired private SimulationService simulationService; - @Autowired - private RunPlanDraftService runPlanDraftService; /** @@ -844,6 +825,9 @@ public class GroupSimulationServiceImpl implements GroupSimulationService { this.memberManager.cancelPlay(simulation, simulationUser); // 移除仿真用户 simulation.removeSimulationUser(simulationUser); + Set userIds = simulation.getSimulationUserIds(); + SocketMessageVO message = SocketMessageFactory.buildSimulationUserExitMessage(simulation, simulationUser); + stompMessageService.sendToUser(userIds, message); } @Override diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationMainThread.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationMainThread.java index 5e4cf8612..fe4c192e0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationMainThread.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationMainThread.java @@ -1,11 +1,8 @@ package club.joylink.rtss.simulation.cbtc; import club.joylink.rtss.event.OrderPaySuccessEvent; -import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm; import club.joylink.rtss.simulation.cbtc.conversation.Conversation; import club.joylink.rtss.simulation.cbtc.conversation.ConversationMessage; -import club.joylink.rtss.simulation.cbtc.data.plan.RealRun; -import club.joylink.rtss.simulation.cbtc.data.status.DeviceStatus; import club.joylink.rtss.simulation.cbtc.data.status.IbpStatus; import club.joylink.rtss.simulation.cbtc.data.vo.ConversationSocketMessageVO; import club.joylink.rtss.simulation.cbtc.data.vo.TrainIsAbout2ArriveVO; @@ -20,7 +17,6 @@ import club.joylink.rtss.vo.client.WebSocketMessageType; import club.joylink.rtss.vo.client.factory.SocketMessageFactory; import club.joylink.rtss.vo.client.psl.PslStatus; import club.joylink.rtss.vo.client.runplan.RunPlanEChartsDataVO; -import club.joylink.rtss.vo.client.runplan.RunPlanTripVO; import club.joylink.rtss.vo.client.script.ScriptActionVO; import club.joylink.rtss.vo.client.simulationv1.SimulationMemberMessageVO; import club.joylink.rtss.vo.client.simulationv1.SimulationUserMessageVO; @@ -28,14 +24,13 @@ import club.joylink.rtss.websocket.StompMessageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.Map; +import java.util.Set; /** * 仿真主线程 @@ -59,73 +54,6 @@ public class SimulationMainThread { } } - @Async("nsExecutor") - @EventListener - public void userClientOnline(SimulationUserConnectEvent event) { - log.info(String.format("收到用户[%s]连接仿真[%s]事件", event.getUserId(), event.getGroup())); - String group = event.getGroup(); - Simulation simulation = this.groupSimulationCache.findSimulationByGroup(group); - if (Objects.isNull(simulation)) { - return; - } - SimulationUser simulationUser = simulation.getSimulationUserById(event.getUserId()); - - if (Objects.nonNull(simulationUser)) { - log.info(String.format("仿真[%s]用户[%s]上线,并同步相关仿真状态", group, event.getUserId())); - // 用户上线状态更新并通知其他在线成员 - simulationUser.online(); - Set userIds = simulation.getSimulationUserIds(); - SocketMessageVO message = SocketMessageFactory - .buildSimulationUserOnlineMessage(simulation, simulationUser); - this.stompMessageService.sendToUser(userIds, message); - // 将当前所有设备状态同步给用户 - List statusList = simulation.getRepository().getAllStatusList(); - if (!CollectionUtils.isEmpty(statusList)) { - SocketMessageVO allStatusMessage = - SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus, - group, statusList); - this.stompMessageService.sendToUser(String.valueOf(event.getUserId()), allStatusMessage); - } - // 将当前所有列车实际运行数据同步给用户 - List realRunRecordList = simulation.getRepository().getRealRunRecordList(); - if (!CollectionUtils.isEmpty(realRunRecordList)) { - SocketMessageVO allTrainRealRunRecord = - SocketMessageFactory.build(WebSocketMessageType.Simulation_RunFact, - group, realRunRecordList); - this.stompMessageService.sendToUser(String.valueOf(event.getUserId()), allTrainRealRunRecord); - } - // 将车次计划变化信息同步给用户 - List changeTrips = simulation.getRepository().getChangeTrips(); - if (!CollectionUtils.isEmpty(changeTrips)) { - SocketMessageVO tripPlanChangeMessage = SocketMessageFactory.buildTripPlanChangeMessage(event.getGroup(), changeTrips); - this.stompMessageService.sendToUser(String.valueOf(event.getUserId()), tripPlanChangeMessage); - } - // ats告警信息同步 - List alarmList = simulation.getRepository().getAlarmList(); - if (!CollectionUtils.isEmpty(alarmList)) { - SocketMessageVO> alarmMessageVO = SocketMessageFactory - .buildAtsAlarmMessage(simulation.getId(), alarmList); - this.stompMessageService.sendToUser(String.valueOf(event.getUserId()), alarmMessageVO); - } - } - } - - @EventListener - public void userClientOffline(SimulationUserDisconnectEvent event) { - log.info(String.format("收到用户[%s]断开仿真[%s]连接事件", event.getUserId(), event.getGroup())); - String group = event.getGroup(); - Simulation simulation = this.groupSimulationCache.findSimulationByGroup(group); - if (Objects.isNull(simulation)) { - return; - } - SimulationUser simulationUser = simulation.getSimulationUserById(event.getUserId()); - simulationUser.offline(); - Set userIds = simulation.getSimulationUserIds(); - SocketMessageVO message = SocketMessageFactory - .buildSimulationUserOfflineMessage(simulation, simulationUser); - this.stompMessageService.sendToUser(userIds, message); - } - @EventListener public void userPlayChangeNotify(SimulationUserPlayChangeEvent event) { Simulation simulation = event.getSimulation(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/event/SimulationUserConnectEvent.java b/src/main/java/club/joylink/rtss/simulation/cbtc/event/SimulationUserConnectEvent.java deleted file mode 100644 index d15f272c3..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/event/SimulationUserConnectEvent.java +++ /dev/null @@ -1,21 +0,0 @@ -package club.joylink.rtss.simulation.cbtc.event; - -import lombok.Getter; -import org.springframework.context.ApplicationEvent; - -/** - * 仿真进入事件 - */ -@Getter -public class SimulationUserConnectEvent extends ApplicationEvent { - - private String group; - - private Long userId; - - public SimulationUserConnectEvent(Long userId, String group, Object source) { - super(source); - this.group = group; - this.userId = userId; - } -} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/event/SimulationUserDisconnectEvent.java b/src/main/java/club/joylink/rtss/simulation/cbtc/event/SimulationUserDisconnectEvent.java deleted file mode 100644 index 21a4a0ae0..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/event/SimulationUserDisconnectEvent.java +++ /dev/null @@ -1,21 +0,0 @@ -package club.joylink.rtss.simulation.cbtc.event; - -import lombok.Getter; -import org.springframework.context.ApplicationEvent; - -/** - * 仿真进入事件 - */ -@Getter -public class SimulationUserDisconnectEvent extends ApplicationEvent { - - private String group; - - private Long userId; - - public SimulationUserDisconnectEvent(Long userId, String group, Object source) { - super(source); - this.group = group; - this.userId = userId; - } -} 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 30ae8f6ba..e1cba37fe 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 @@ -61,6 +61,35 @@ public class SimulationUserWsListener { } } + @Async("nsExecutor") + @EventListener + public void handle(SimulationUserUnsubscribeEvent event) { + Simulation sim = event.getSimulation(); + if (sim instanceof club.joylink.rtss.simulation.cbtc.Simulation) { + club.joylink.rtss.simulation.cbtc.Simulation simulation = (club.joylink.rtss.simulation.cbtc.Simulation) sim; + SimulationUser simulationUser = simulation.querySimulationUserById(event.getUserId()); + if (simulationUser == null) + return; + updateOnlineStatus(simulation, simulationUser); + if (simulationUser.isNoSubscription()) { + applicationContext.publishEvent(new SimulationUserUnsubscribeAllEvent(this, simulation, Long.valueOf(simulationUser.getId()))); + } + } + } + + @Async("nsExecutor") + @EventListener + public void handle(SimulationUserDisconnectEvent event) { + Simulation sim = event.getSimulation(); + if (sim instanceof club.joylink.rtss.simulation.cbtc.Simulation) { + club.joylink.rtss.simulation.cbtc.Simulation simulation = (club.joylink.rtss.simulation.cbtc.Simulation) sim; + SimulationUser simulationUser = simulation.querySimulationUserById(event.getUserId()); + if (simulationUser == null) + return; + updateOnlineStatus(simulation, simulationUser); + } + } + /** * 更新用户在线状态,如果是刚上/下线,发送消息通知其他人 */ diff --git a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java index 3c68e91cf..4410b690a 100644 --- a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java +++ b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java @@ -255,6 +255,11 @@ public class SocketMessageFactory { new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.PLAY_CHANGE)); } + public static SocketMessageVO buildSimulationUserExitMessage(Simulation simulation, SimulationUser simulationUser) { + return build(WebSocketMessageType.Simulation_User, simulation.getId(), + new SimulationUserMessageVO(simulationUser, SimulationUserMessageVO.Type.EXIT)); + } + public static SocketMessageVO buildSimulationMemberAddMessage(Simulation simulation, SimulationMember simulationMember) { return build(WebSocketMessageType.Simulation_Member, simulation.getId(), SimulationMemberMessageVO.buildAddMemberMessage(simulationMember)); diff --git a/src/main/java/club/joylink/rtss/vo/client/simulationv1/SimulationUserMessageVO.java b/src/main/java/club/joylink/rtss/vo/client/simulationv1/SimulationUserMessageVO.java index fb4322bad..699c341f9 100644 --- a/src/main/java/club/joylink/rtss/vo/client/simulationv1/SimulationUserMessageVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/simulationv1/SimulationUserMessageVO.java @@ -23,6 +23,7 @@ public class SimulationUserMessageVO extends SimulationUserVO { OFFLINE, ENTER, PLAY_CHANGE, - KICK_OUT + KICK_OUT, + EXIT } }