删除多余的仿真销毁消息

This commit is contained in:
joylink_zhangsai 2023-05-24 17:19:51 +08:00
parent 37e13abe47
commit 4f4377f3b8

View File

@ -8,7 +8,29 @@ import club.joylink.rtss.simulation.cbtc.data.vo.ConversationSocketMessageVO;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainIsAbout2ArriveVO; import club.joylink.rtss.simulation.cbtc.data.vo.TrainIsAbout2ArriveVO;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceConnectManager; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceConnectManager;
import club.joylink.rtss.simulation.cbtc.event.*; import club.joylink.rtss.simulation.cbtc.event.SimulationCompetitionPracticeFinishEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationConversationChatEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationConversationCreateEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationConversationExitEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationConversationInviteEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationConversationMemberConnectEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationErrorEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationIbpStatusEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationMemberAddEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationPauseEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationPslStatusEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationResumeEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationRunPlanReloadEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationScenesReloadEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationScriptActionErrorEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationScriptActionFinishEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationScriptTipEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationTrainIsAbout2ArriveEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationTripPlanChangeEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationUserEnterEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationUserKickOutEvent;
import club.joylink.rtss.simulation.cbtc.event.SimulationUserPlayChangeEvent;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.simulation.cbtc.member.SimulationUser; import club.joylink.rtss.simulation.cbtc.member.SimulationUser;
import club.joylink.rtss.simulation.cbtc.script.ScriptActionBO; import club.joylink.rtss.simulation.cbtc.script.ScriptActionBO;
@ -21,17 +43,16 @@ import club.joylink.rtss.vo.client.script.ScriptActionVO;
import club.joylink.rtss.vo.client.simulationv1.SimulationMemberMessageVO; import club.joylink.rtss.vo.client.simulationv1.SimulationMemberMessageVO;
import club.joylink.rtss.vo.client.simulationv1.SimulationUserMessageVO; import club.joylink.rtss.vo.client.simulationv1.SimulationUserMessageVO;
import club.joylink.rtss.websocket.StompMessageService; import club.joylink.rtss.websocket.StompMessageService;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Set;
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.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Set;
/** /**
* 仿真主线程 * 仿真主线程
*/ */
@ -112,7 +133,8 @@ public class SimulationMainThread {
log.info(String.format("仿真[%s]会话[%s]创建消息发送", log.info(String.format("仿真[%s]会话[%s]创建消息发送",
simulation.getId(), conversation.getId())); simulation.getId(), conversation.getId()));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<ConversationSocketMessageVO> createMessage = SocketMessageFactory.buildSimulationConversationCreateMessage(simulation, conversation); SocketMessageVO<ConversationSocketMessageVO> createMessage = SocketMessageFactory.buildSimulationConversationCreateMessage(
simulation, conversation);
this.stompMessageService.sendToUser(userIds, createMessage); this.stompMessageService.sendToUser(userIds, createMessage);
} }
@ -123,7 +145,8 @@ public class SimulationMainThread {
SimulationMember member = event.getMember(); SimulationMember member = event.getMember();
log.info(String.format("仿真[%s]会话[%s]邀请消息发送", log.info(String.format("仿真[%s]会话[%s]邀请消息发送",
simulation.getId(), conversation.getId())); simulation.getId(), conversation.getId()));
SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory.buildSimulationConversationInviteMessage(simulation, conversation, member); SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory.buildSimulationConversationInviteMessage(
simulation, conversation, member);
this.stompMessageService.sendToUser(member.getUserId(), message); this.stompMessageService.sendToUser(member.getUserId(), message);
} }
@ -154,7 +177,8 @@ public class SimulationMainThread {
this.stompMessageService.sendToUser(userIds, message); this.stompMessageService.sendToUser(userIds, message);
return; return;
} }
this.stompMessageService.sendToUser(String.valueOf(conversationMessage.getMember().getUserId()), message); this.stompMessageService.sendToUser(String.valueOf(conversationMessage.getMember().getUserId()),
message);
} }
@EventListener @EventListener
@ -178,7 +202,8 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]暂停", simulation.getId())); log.info(String.format("仿真[%s]暂停", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Pause, SocketMessageVO<Boolean> message = SocketMessageFactory.build(
WebSocketMessageType.Simulation_Control_Pause,
simulation.getId(), true); simulation.getId(), true);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -193,7 +218,8 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]恢复运行", simulation.getId())); log.info(String.format("仿真[%s]恢复运行", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Pause, SocketMessageVO<Boolean> message = SocketMessageFactory.build(
WebSocketMessageType.Simulation_Control_Pause,
simulation.getId(), false); simulation.getId(), false);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -235,7 +261,8 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]背景重新加载", simulation.getId())); log.info(String.format("仿真[%s]背景重新加载", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<Boolean> message = SocketMessageFactory.buildSimulationScenesReload(simulation.getId(), simulation.isPlanRunning()); SocketMessageVO<Boolean> message = SocketMessageFactory.buildSimulationScenesReload(
simulation.getId(), simulation.isPlanRunning());
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
@ -247,28 +274,31 @@ public class SimulationMainThread {
@EventListener @EventListener
public void simulationError(SimulationErrorEvent event) { public void simulationError(SimulationErrorEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]运行异常, 时间 [%s]", simulation.getId(), simulation.getCorrectSystemTime().format(DateTimeFormatter.ofPattern("yyyy-mm-dd hh:mm:ss")))); log.info(String.format("仿真[%s]运行异常, 时间 [%s]", simulation.getId(),
simulation.getCorrectSystemTime()
.format(DateTimeFormatter.ofPattern("yyyy-mm-dd hh:mm:ss"))));
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<String> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Error, SocketMessageVO<String> message = SocketMessageFactory.build(
WebSocketMessageType.Simulation_Error,
simulation.getId(), ""); simulation.getId(), "");
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
/** // /**
* 仿真销毁消息通知 // * 仿真销毁消息通知
* // *
* @param event // * @param event
*/ // */
@EventListener // @EventListener
public void simulationDestroy(SimulationDestroyEvent event) { // public void simulationDestroy(SimulationDestroyEvent event) {
Simulation simulation = event.getSimulation(); // Simulation simulation = event.getSimulation();
log.info(String.format("仿真[%s]销毁", simulation.getId())); // log.info(String.format("仿真[%s]销毁", simulation.getId()));
Set<String> users = simulation.getSimulationUserIds(); // Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<String> message = SocketMessageFactory.build( // SocketMessageVO<String> message = SocketMessageFactory.build(
WebSocketMessageType.Simulation_Over, // WebSocketMessageType.Simulation_Over,
simulation.getId(), ""); // simulation.getId(), "");
this.stompMessageService.sendToUser(users, message); // this.stompMessageService.sendToUser(users, message);
} // }
/** /**
* 仿真剧本提示 * 仿真剧本提示
@ -286,15 +316,19 @@ public class SimulationMainThread {
SocketMessageVO<ScriptActionVO> message = SocketMessageVO<ScriptActionVO> message =
SocketMessageFactory.buildScriptTipMessage(simulation.getId(), actionVO); SocketMessageFactory.buildScriptTipMessage(simulation.getId(), actionVO);
stompMessageService.sendToUser(action.getMember().getUserId(), message); stompMessageService.sendToUser(action.getMember().getUserId(), message);
log.info(String.format("仿真[%s]剧本提示成员[%s]执行动作[%s]", simulation.getId(), action.getMember().getId(), action.getId())); log.info(
String.format("仿真[%s]剧本提示成员[%s]执行动作[%s]", simulation.getId(), action.getMember().getId(),
action.getId()));
} }
@EventListener @EventListener
public void SimulationScriptFinish(SimulationCompetitionPracticeFinishEvent event) { public void SimulationScriptFinish(SimulationCompetitionPracticeFinishEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SocketMessageVO<Boolean> message = SocketMessageFactory.buildCompetitionPracticeFinishMessage(simulation.getId()); SocketMessageVO<Boolean> message = SocketMessageFactory.buildCompetitionPracticeFinishMessage(
simulation.getId());
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
log.info(String.format("仿真[%s]竞赛实操[%s]演出完成", simulation.getId(), simulation.getScript().getId())); log.info(
String.format("仿真[%s]竞赛实操[%s]演出完成", simulation.getId(), simulation.getScript().getId()));
} }
@EventListener @EventListener
@ -305,7 +339,8 @@ public class SimulationMainThread {
SocketMessageVO<ScriptActionVO> message = SocketMessageVO<ScriptActionVO> message =
SocketMessageFactory.buildSimulationScriptActionFinishMessage(simulation.getId(), vo); SocketMessageFactory.buildSimulationScriptActionFinishMessage(simulation.getId(), vo);
stompMessageService.sendToUser(action.getMember().getUserId(), message); stompMessageService.sendToUser(action.getMember().getUserId(), message);
log.info(String.format("用户[%s]完成仿真[%s]id为[%s]的剧本动作", simulation.getId(), action.getMember().getUserId(), action.getId())); log.info(String.format("用户[%s]完成仿真[%s]id为[%s]的剧本动作", simulation.getId(),
action.getMember().getUserId(), action.getId()));
} }
@EventListener @EventListener
@ -313,7 +348,8 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
VirtualRealityTrain train = event.getTrain(); VirtualRealityTrain train = event.getTrain();
if (train.getNextStation() != null) { if (train.getNextStation() != null) {
TrainIsAbout2ArriveVO arriveVO = new TrainIsAbout2ArriveVO(train.getGroupNumber(), train.getNextStation().getCode()); TrainIsAbout2ArriveVO arriveVO = new TrainIsAbout2ArriveVO(train.getGroupNumber(),
train.getNextStation().getCode());
SocketMessageVO<TrainIsAbout2ArriveVO> message = SocketMessageVO<TrainIsAbout2ArriveVO> message =
SocketMessageFactory.buildTrainIsAbout2ArriveMessage(simulation.getId(), arriveVO); SocketMessageFactory.buildTrainIsAbout2ArriveMessage(simulation.getId(), arriveVO);
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
@ -326,7 +362,8 @@ public class SimulationMainThread {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
ScriptActionBO action = event.getScriptActionBO(); ScriptActionBO action = event.getScriptActionBO();
SocketMessageVO<String> message = SocketMessageVO<String> message =
SocketMessageFactory.buildSimulationScriptActionErrorMessage(simulation.getId(), action.getId()); SocketMessageFactory.buildSimulationScriptActionErrorMessage(simulation.getId(),
action.getId());
stompMessageService.sendToUser(action.getMember().getUserId(), message); stompMessageService.sendToUser(action.getMember().getUserId(), message);
} }
@ -334,7 +371,8 @@ public class SimulationMainThread {
public void simulationIbpStatus(SimulationIbpStatusEvent event) { public void simulationIbpStatus(SimulationIbpStatusEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SocketMessageVO<Map<String, IbpStatus>> message = SocketMessageVO<Map<String, IbpStatus>> message =
SocketMessageFactory.buildSimulationIbpStatusMessage(simulation.getId(), event.getStatusMap()); SocketMessageFactory.buildSimulationIbpStatusMessage(simulation.getId(),
event.getStatusMap());
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@ -342,19 +380,22 @@ public class SimulationMainThread {
public void simulationPslStatus(SimulationPslStatusEvent event) { public void simulationPslStatus(SimulationPslStatusEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SocketMessageVO<Map<String, PslStatus>> message = SocketMessageVO<Map<String, PslStatus>> message =
SocketMessageFactory.buildSimulationPslStatusMessage(simulation.getId(), event.getStatusMap()); SocketMessageFactory.buildSimulationPslStatusMessage(simulation.getId(),
event.getStatusMap());
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} }
@EventListener @EventListener
public void handleDeviceFaultOverEvent(OrderPaySuccessEvent event) { public void handleDeviceFaultOverEvent(OrderPaySuccessEvent event) {
SocketMessageVO<String> message = SocketMessageFactory.buildOrderPaySuccessMessage(event.getOrderCode()); SocketMessageVO<String> message = SocketMessageFactory.buildOrderPaySuccessMessage(
event.getOrderCode());
this.stompMessageService.sendToUser(event.getUserId(), message); this.stompMessageService.sendToUser(event.getUserId(), message);
} }
@EventListener @EventListener
public void handleTripPlanChangeEvent(SimulationTripPlanChangeEvent event) { public void handleTripPlanChangeEvent(SimulationTripPlanChangeEvent event) {
SocketMessageVO<RunPlanEChartsDataVO> message = SocketMessageFactory.buildTripPlanChangeMessage(event.getSimulation().getId(), event.getChangeTrips()); SocketMessageVO<RunPlanEChartsDataVO> message = SocketMessageFactory.buildTripPlanChangeMessage(
event.getSimulation().getId(), event.getChangeTrips());
this.stompMessageService.sendToUser(event.getSimulation().getSimulationUserIds(), message); this.stompMessageService.sendToUser(event.getSimulation().getSimulationUserIds(), message);
} }
} }