diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java index 347e5e8c8..b9ccb4f3a 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java @@ -143,6 +143,7 @@ public class Training2Service { if (training2 == null || !training2.isStarted() || training2.isFinish()) { // 结束并移除运行任务 removeTrainingJob(simulation); + trainingStatusMessage(simulation, 0); return; } // 获取运行步骤 @@ -275,7 +276,6 @@ public class Training2Service { // 创建者退出,则清理实训 if (simulation.getCreator().getId().equals(user.getId())) { training2.finish(); - removeTrainingJob(simulation); } } else { return List.of(); @@ -554,7 +554,6 @@ public class Training2Service { } catch (Exception e) { log.error("loadTrainingToStep is error", e); training2.finish(); - removeTrainingJob(simulation); } } @@ -930,6 +929,8 @@ public class Training2Service { addTrainingJob(simulation, training2); // 启动仿真 simulationLifeCycleService.resume(simulation); + // 发送开始消息 + trainingStatusMessage(simulation, 1); } /** @@ -940,4 +941,14 @@ public class Training2Service { simulation.getTraining2().setJumpToStep(null); simulation.getTraining2().finish(); } + + /** + * 实训状态消息 + * @param simulation 仿真 + * @param status 状态 + */ + private void trainingStatusMessage(Simulation simulation, int status) { + SocketMessageVO message = SocketMessageFactory.build(WebSocketMessageType.Simulation_Training_Status, simulation.getId(), status); + stompMessageService.sendToUser(simulation.getSimulationUserIds(), message); + } } 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 9231d46c9..d541c939d 100644 --- a/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java +++ b/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java @@ -381,6 +381,10 @@ public enum WebSocketMessageType { * 实训准备开始,其他成员加载实训内容消息 */ Simulation_Training_Prepare_Start, + /** + * 实训开始、结束状态 + */ + Simulation_Training_Status, /** * 步骤开始时提示信息 */ @@ -399,7 +403,7 @@ public enum WebSocketMessageType { /** * 实训完成 */ - Simulation_Training_Finish + Simulation_Training_Finish, /** ------------ 新实训消息 ----------- */ ; } 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 b280d66ac..d795ee8e0 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 @@ -161,7 +161,8 @@ public class SocketMessageFactory { case Simulation_Training_Audio_MATCH_RESULT: // case Simulation_Training_Operate_Error: // case Simulation_Training_Operate_Finish: - case Simulation_Training_Finish: { + case Simulation_Training_Finish: + case Simulation_Training_Status: { topicList.add(String.format(WebSocketSubscribeTopic.AssistantSimulation, group)); topicList.add(String.format(WebSocketSubscribeTopic.Simulation, group)); topicList.add(String.format(WebSocketSubscribeTopic.Sandbox3D, group));