删除多余的仿真销毁消息

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;
/** /**
* 仿真主线程 * 仿真主线程
*/ */
@ -39,322 +60,342 @@ import java.util.Set;
@Slf4j @Slf4j
public class SimulationMainThread { public class SimulationMainThread {
@Autowired @Autowired
private GroupSimulationCache groupSimulationCache; private GroupSimulationCache groupSimulationCache;
@Autowired @Autowired
private StompMessageService stompMessageService; private StompMessageService stompMessageService;
@Autowired @Autowired
private SimulationRealDeviceConnectManager simulationRealDeviceConnectManager; private SimulationRealDeviceConnectManager simulationRealDeviceConnectManager;
@Scheduled(fixedRate = 1000) @Scheduled(fixedRate = 1000)
public void updatePlcGatewayOnlineStatus() { public void updatePlcGatewayOnlineStatus() {
Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap(); Map<String, Simulation> groupSimulationMap = this.groupSimulationCache.getGroupSimulationMap();
for (Simulation simulation : groupSimulationMap.values()) { for (Simulation simulation : groupSimulationMap.values()) {
this.simulationRealDeviceConnectManager.updatePlcGatewayOnlineStatus(simulation); this.simulationRealDeviceConnectManager.updatePlcGatewayOnlineStatus(simulation);
}
} }
}
@EventListener @EventListener
public void userPlayChangeNotify(SimulationUserPlayChangeEvent event) { public void userPlayChangeNotify(SimulationUserPlayChangeEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SimulationUser simulationUser = event.getSimulationUser(); SimulationUser simulationUser = event.getSimulationUser();
log.info(String.format("仿真[%s]用户[%s]扮演角色变更事件通知,当前扮演[%s]", log.info(String.format("仿真[%s]用户[%s]扮演角色变更事件通知,当前扮演[%s]",
simulationUser.getUser().getId(), simulation.getId(), simulationUser.getUser().getId(), simulation.getId(),
simulationUser.getPlayedMember())); simulationUser.getPlayedMember()));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<SimulationUserMessageVO> playChangeMessage = SocketMessageFactory SocketMessageVO<SimulationUserMessageVO> playChangeMessage = SocketMessageFactory
.buildSimulationUserPlayChangeMessage(simulation, simulationUser); .buildSimulationUserPlayChangeMessage(simulation, simulationUser);
this.stompMessageService.sendToUser(userIds, playChangeMessage); this.stompMessageService.sendToUser(userIds, playChangeMessage);
} }
@EventListener @EventListener
public void userEnterNotify(SimulationUserEnterEvent event) { public void userEnterNotify(SimulationUserEnterEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SimulationUser simulationUser = event.getSimulationUser(); SimulationUser simulationUser = event.getSimulationUser();
log.info(String.format("用户[%s]进入综合演练仿真[%s]成为仿真成员事件通知", log.info(String.format("用户[%s]进入综合演练仿真[%s]成为仿真成员事件通知",
simulationUser.getUser().getId(), simulation.getId())); simulationUser.getUser().getId(), simulation.getId()));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
// SocketMessageVO<SimulationVO> inviteMessage = SocketMessageFactory.buildSimulationInviteMessage(simulation); // SocketMessageVO<SimulationVO> inviteMessage = SocketMessageFactory.buildSimulationInviteMessage(simulation);
// this.stompMessageService.sendToUser(simulationUser.getUser().getId().toString(), inviteMessage); // this.stompMessageService.sendToUser(simulationUser.getUser().getId().toString(), inviteMessage);
SocketMessageVO<SimulationUserMessageVO> message = SocketMessageFactory SocketMessageVO<SimulationUserMessageVO> message = SocketMessageFactory
.buildSimulationUserEnterMessage(simulation, simulationUser); .buildSimulationUserEnterMessage(simulation, simulationUser);
this.stompMessageService.sendToUser(userIds, message); this.stompMessageService.sendToUser(userIds, message);
} }
@EventListener @EventListener
public void kickOutUserNotify(SimulationUserKickOutEvent event) { public void kickOutUserNotify(SimulationUserKickOutEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
log.info(String.format("综合演练仿真[%s]踢出用户[%s]事件通知", log.info(String.format("综合演练仿真[%s]踢出用户[%s]事件通知",
simulation.getId(), event.getSimulationUser().getUser().getId())); simulation.getId(), event.getSimulationUser().getUser().getId()));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
userIds.add(event.getSimulationUser().getUser().getId().toString()); userIds.add(event.getSimulationUser().getUser().getId().toString());
SocketMessageVO<SimulationUserMessageVO> message = SocketMessageFactory SocketMessageVO<SimulationUserMessageVO> message = SocketMessageFactory
.buildSimulationUserKickOutMessage(simulation, event.getSimulationUser()); .buildSimulationUserKickOutMessage(simulation, event.getSimulationUser());
this.stompMessageService.sendToUser(userIds, message); this.stompMessageService.sendToUser(userIds, message);
} }
@EventListener @EventListener
public void simulationMemberAdd(SimulationMemberAddEvent event) { public void simulationMemberAdd(SimulationMemberAddEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SimulationMember member = event.getMember(); SimulationMember member = event.getMember();
log.info(String.format("仿真[%s]添加仿真成员[%s]消息通知", log.info(String.format("仿真[%s]添加仿真成员[%s]消息通知",
simulation.getId(), member)); simulation.getId(), member));
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
SocketMessageVO<SimulationMemberMessageVO> message = SocketMessageFactory SocketMessageVO<SimulationMemberMessageVO> message = SocketMessageFactory
.buildSimulationMemberAddMessage(simulation, member); .buildSimulationMemberAddMessage(simulation, member);
this.stompMessageService.sendToUser(userIds, message); this.stompMessageService.sendToUser(userIds, message);
} }
@EventListener @EventListener
public void conversationCreate(SimulationConversationCreateEvent event) { public void conversationCreate(SimulationConversationCreateEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
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(
this.stompMessageService.sendToUser(userIds, createMessage); simulation, conversation);
} this.stompMessageService.sendToUser(userIds, createMessage);
}
@EventListener @EventListener
public void conversationInvite(SimulationConversationInviteEvent event) { public void conversationInvite(SimulationConversationInviteEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
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(
this.stompMessageService.sendToUser(member.getUserId(), message); simulation, conversation, member);
} this.stompMessageService.sendToUser(member.getUserId(), message);
}
@EventListener @EventListener
public void memberConnectConversation(SimulationConversationMemberConnectEvent event) { public void memberConnectConversation(SimulationConversationMemberConnectEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
SimulationMember member = event.getMember(); SimulationMember member = event.getMember();
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
log.info(String.format("仿真[%s]会话[%s]成员[%s]接受邀请进入会话消息发送", log.info(String.format("仿真[%s]会话[%s]成员[%s]接受邀请进入会话消息发送",
simulation.getId(), conversation.getId(), member.toString())); simulation.getId(), conversation.getId(), member.toString()));
SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory
.buildSimulationMemberConnectConversationMessage(simulation, conversation, member); .buildSimulationMemberConnectConversationMessage(simulation, conversation, member);
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
this.stompMessageService.sendToUser(userIds, message); this.stompMessageService.sendToUser(userIds, message);
} }
@EventListener(SimulationConversationChatEvent.class) @EventListener(SimulationConversationChatEvent.class)
public void conversationChat(SimulationConversationChatEvent event) { public void conversationChat(SimulationConversationChatEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
ConversationMessage conversationMessage = event.getConversationMessage(); ConversationMessage conversationMessage = event.getConversationMessage();
log.info(String.format("仿真[%s]会话[%s]会话消息发送", log.info(String.format("仿真[%s]会话[%s]会话消息发送",
simulation.getId(), conversation.getId())); simulation.getId(), conversation.getId()));
SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory
.buildSimulationConversationChatMessage(simulation, conversation, conversationMessage); .buildSimulationConversationChatMessage(simulation, conversation, conversationMessage);
if (conversation.hasOtherMemberConnect()) { if (conversation.hasOtherMemberConnect()) {
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
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
public void conversationExit(SimulationConversationExitEvent event) { public void conversationExit(SimulationConversationExitEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
Conversation conversation = event.getConversation(); Conversation conversation = event.getConversation();
SimulationMember member = event.getMember(); SimulationMember member = event.getMember();
log.info(String.format("仿真[%s]会话[%s]成员[%s]退出消息发送", log.info(String.format("仿真[%s]会话[%s]成员[%s]退出消息发送",
simulation.getId(), conversation.getId(), member.getId())); simulation.getId(), conversation.getId(), member.getId()));
SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory SocketMessageVO<ConversationSocketMessageVO> message = SocketMessageFactory
.buildSimulationConversationExitMessage(simulation, conversation, member); .buildSimulationConversationExitMessage(simulation, conversation, member);
Set<String> userIds = simulation.getSimulationUserIds(); Set<String> userIds = simulation.getSimulationUserIds();
this.stompMessageService.sendToUser(userIds, message); this.stompMessageService.sendToUser(userIds, message);
} }
/** /**
* 仿真暂停消息通知 * 仿真暂停消息通知
*/ */
@EventListener @EventListener
public void simulationPause(SimulationPauseEvent event) { public void simulationPause(SimulationPauseEvent 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<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Pause, SocketMessageVO<Boolean> message = SocketMessageFactory.build(
simulation.getId(), true); WebSocketMessageType.Simulation_Control_Pause,
this.stompMessageService.sendToUser(users, message); simulation.getId(), true);
} this.stompMessageService.sendToUser(users, message);
}
/** /**
* 仿真恢复运行消息通知 * 仿真恢复运行消息通知
* *
* @param event * @param event
*/ */
@EventListener @EventListener
public void simulationResume(SimulationResumeEvent event) { public void simulationResume(SimulationResumeEvent 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<Boolean> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Pause, SocketMessageVO<Boolean> message = SocketMessageFactory.build(
simulation.getId(), false); WebSocketMessageType.Simulation_Control_Pause,
this.stompMessageService.sendToUser(users, message); simulation.getId(), false);
} this.stompMessageService.sendToUser(users, message);
}
/** /**
* 仿真重置消息通知 * 仿真重置消息通知
* *
* @param event * @param event
*/ */
@EventListener @EventListener
public void simulationReset(SimulationResetEvent event) { public void simulationReset(SimulationResetEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
Set<String> users = simulation.getSimulationUserIds(); Set<String> users = simulation.getSimulationUserIds();
SocketMessageVO<Boolean> message = SocketMessageFactory.build( SocketMessageVO<Boolean> message = SocketMessageFactory.build(
WebSocketMessageType.Simulation_Reset, WebSocketMessageType.Simulation_Reset,
simulation.getId(), true); simulation.getId(), true);
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
/** /**
* 仿真运行计划重置消息通知 * 仿真运行计划重置消息通知
*/ */
@EventListener @EventListener
public void simulationRunPlanReload(SimulationRunPlanReloadEvent event) { public void simulationRunPlanReload(SimulationRunPlanReloadEvent 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_Run_Plan_Reload, WebSocketMessageType.Simulation_Run_Plan_Reload,
simulation.getId(), "1"); simulation.getId(), "1");
this.stompMessageService.sendToUser(users, message); this.stompMessageService.sendToUser(users, message);
} }
/** /**
* 仿真背景重新加载 * 仿真背景重新加载
*/ */
@EventListener @EventListener
public void simulationScenesReload(SimulationScenesReloadEvent event) { public void simulationScenesReload(SimulationScenesReloadEvent 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<Boolean> message = SocketMessageFactory.buildSimulationScenesReload(simulation.getId(), simulation.isPlanRunning()); SocketMessageVO<Boolean> message = SocketMessageFactory.buildSimulationScenesReload(
this.stompMessageService.sendToUser(users, message); simulation.getId(), simulation.isPlanRunning());
} this.stompMessageService.sendToUser(users, message);
}
/** /**
* 仿真运行异常消息通知 * 仿真运行异常消息通知
* *
* @param event * @param event
*/ */
@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(),
Set<String> users = simulation.getSimulationUserIds(); simulation.getCorrectSystemTime()
SocketMessageVO<String> message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Error, .format(DateTimeFormatter.ofPattern("yyyy-mm-dd hh:mm:ss"))));
simulation.getId(), ""); Set<String> users = simulation.getSimulationUserIds();
this.stompMessageService.sendToUser(users, message); SocketMessageVO<String> message = SocketMessageFactory.build(
} WebSocketMessageType.Simulation_Error,
simulation.getId(), "");
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);
} // }
/** /**
* 仿真剧本提示 * 仿真剧本提示
*/ */
@EventListener @EventListener
public void simulationScriptTip(SimulationScriptTipEvent event) { public void simulationScriptTip(SimulationScriptTipEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
ScriptActionBO action = event.getAction(); ScriptActionBO action = event.getAction();
ScriptActionVO actionVO = ScriptActionVO.buildScriptTipVO(action); ScriptActionVO actionVO = ScriptActionVO.buildScriptTipVO(action);
if (actionVO.getType().equals(ScriptActionBO.ActionType.Conversation)) { if (actionVO.getType().equals(ScriptActionBO.ActionType.Conversation)) {
LocalDateTime correctSystemTime = simulation.getCorrectSystemTime(); LocalDateTime correctSystemTime = simulation.getCorrectSystemTime();
String currentTime = correctSystemTime.getHour() + "" + correctSystemTime.getMinute() + ""; String currentTime = correctSystemTime.getHour() + "" + correctSystemTime.getMinute() + "";
actionVO.setContent(String.format(actionVO.getContent(), currentTime)); actionVO.setContent(String.format(actionVO.getContent(), currentTime));
}
SocketMessageVO<ScriptActionVO> message =
SocketMessageFactory.buildScriptTipMessage(simulation.getId(), actionVO);
stompMessageService.sendToUser(action.getMember().getUserId(), message);
log.info(String.format("仿真[%s]剧本提示成员[%s]执行动作[%s]", simulation.getId(), action.getMember().getId(), action.getId()));
} }
SocketMessageVO<ScriptActionVO> message =
SocketMessageFactory.buildScriptTipMessage(simulation.getId(), actionVO);
stompMessageService.sendToUser(action.getMember().getUserId(), message);
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(
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); simulation.getId());
log.info(String.format("仿真[%s]竞赛实操[%s]演出完成", simulation.getId(), simulation.getScript().getId())); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} log.info(
String.format("仿真[%s]竞赛实操[%s]演出完成", simulation.getId(), simulation.getScript().getId()));
}
@EventListener @EventListener
public void simulationScriptActionFinish(SimulationScriptActionFinishEvent event) { public void simulationScriptActionFinish(SimulationScriptActionFinishEvent event) {
Simulation simulation = event.getSimulation(); Simulation simulation = event.getSimulation();
ScriptActionBO action = event.getScriptActionBO(); ScriptActionBO action = event.getScriptActionBO();
ScriptActionVO vo = ScriptActionVO.buildFinishTipVO(action); ScriptActionVO vo = ScriptActionVO.buildFinishTipVO(action);
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
public void simulationTrainIsAboutArrive(SimulationTrainIsAbout2ArriveEvent event) { public void simulationTrainIsAboutArrive(SimulationTrainIsAbout2ArriveEvent event) {
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(),
SocketMessageVO<TrainIsAbout2ArriveVO> message = train.getNextStation().getCode());
SocketMessageFactory.buildTrainIsAbout2ArriveMessage(simulation.getId(), arriveVO); SocketMessageVO<TrainIsAbout2ArriveVO> message =
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); SocketMessageFactory.buildTrainIsAbout2ArriveMessage(simulation.getId(), arriveVO);
log.info("列车[{}]即将进站", train.getGroupNumber()); stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
} log.info("列车[{}]即将进站", train.getGroupNumber());
} }
}
@EventListener @EventListener
public void simulationScriptActionError(SimulationScriptActionErrorEvent event) { public void simulationScriptActionError(SimulationScriptActionErrorEvent event) {
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(),
stompMessageService.sendToUser(action.getMember().getUserId(), message); action.getId());
} stompMessageService.sendToUser(action.getMember().getUserId(), message);
}
@EventListener @EventListener
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(),
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); event.getStatusMap());
} stompMessageService.sendToUser(simulation.getSimulationUserIds(), message);
}
@EventListener @EventListener
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(),
stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); event.getStatusMap());
} 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(
this.stompMessageService.sendToUser(event.getUserId(), message); event.getOrderCode());
} 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(
this.stompMessageService.sendToUser(event.getSimulation().getSimulationUserIds(), message); event.getSimulation().getId(), event.getChangeTrips());
} this.stompMessageService.sendToUser(event.getSimulation().getSimulationUserIds(), message);
}
} }