From 8e6060eaa258e18a8fb60843891e7c188558f81d Mon Sep 17 00:00:00 2001 From: weizhihong Date: Thu, 1 Sep 2022 18:39:33 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E9=80=9F=E5=BA=A6=EF=BC=8C=E7=BB=93=E6=9D=9F?= =?UTF-8?q?=E5=90=8E=E7=9B=B4=E6=8E=A5=E8=8E=B7=E5=8F=96=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E6=AD=A5=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/training2/Training2Service.java | 70 +++++++++++++++---- 1 file changed, 55 insertions(+), 15 deletions(-) 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 e8b38a246..e8f07ada5 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java @@ -72,23 +72,14 @@ public class Training2Service { return; } // 获取运行步骤 - Step2 step = training2.getCurrentRunStep(); - if (step == null) { // 步骤已经运行完毕 - training2.finish(); - // 发送实训完成消息 - sendTrainingFinish(training2, simulation); + Step2 step = getNextStepAndCheckTrainingStatus(training2, simulation); + if (step == null) { return; } - // 步骤是否已经触发 - // 没有触发则检查触发状态,如果可以触发则继续,不能触发则返回 - if (!Step2.StepStatus.isAlreadyTrigger(step.getStepStatus()) && !step.doTriggerVail()) { + // 尝试触发步骤 + if (!tryTriggerStep(step, simulation)) { return; } - // 发送步骤提示信息 - if (!step.isPrompt()) { - step.setPrompt(true); // 标识已发送过消息 - sendStepTips(step, simulation); - } // 获取步骤中未完成的操作 Operation2 operation2 = step.getCurrentRunOperation(); // 操作全部完成的情况,检查步骤完成条件 @@ -126,7 +117,7 @@ public class Training2Service { sendOperationFinish(operation2, simulation); // 如果是最后一步,直接检查步骤有没有完成 if (step.getOperations().indexOf(operation2) == (step.getOperations().size() - 1) && completion) { - checkTrainStepCompletion(step, simulation); + checkStepCompletionAndSendNext(step, simulation); } } } @@ -283,7 +274,7 @@ public class Training2Service { } } if (result) { - checkTrainStepCompletion(step, simulation); // 直接检查步骤是否完成 + checkStepCompletionAndSendNext(step, simulation); // 直接检查步骤是否完成 } // 恢复前端运行 pauseOrStartSimulation(simulation, false); @@ -492,6 +483,55 @@ public class Training2Service { sendStepFinish(step, simulation); } + /** + * 获取实训下一步未执行的步骤,如果实训已结束则返回null + */ + private Step2 getNextStepAndCheckTrainingStatus(Training2 training2, Simulation simulation) { + // 获取运行步骤 + Step2 nextStep = training2.getCurrentRunStep(); + if (nextStep == null) { // 步骤已经运行完毕 + training2.finish(); + // 发送实训完成消息 + sendTrainingFinish(training2, simulation); + return null; + } + return nextStep; + } + + /** + * 尝试触发步骤,如果触发返回true,可以继续,未触发返回false + */ + private boolean tryTriggerStep(Step2 step, Simulation simulation) { + // 步骤是否已经触发 + // 没有触发则检查触发状态,如果可以触发则继续,不能触发则返回 + if (!Step2.StepStatus.isAlreadyTrigger(step.getStepStatus()) && !step.doTriggerVail()) { + return false; + } + // 发送步骤提示信息 + if (!step.isPrompt()) { + step.setPrompt(true); // 标识已发送过消息 + sendStepTips(step, simulation); + } + return true; + } + + /** + * 直接完成并尝试触发下一步 + */ + private void checkStepCompletionAndSendNext(Step2 step, Simulation simulation) { + boolean result = step.doCompletionVail(); + if (result) { + // 发送步骤完成信息 + sendStepFinish(step, simulation); + // 获取运行步骤 + Step2 nextStep = getNextStepAndCheckTrainingStatus(simulation.getTraining2(), simulation); + if (nextStep == null) { + return; + } + tryTriggerStep(nextStep, simulation); + } + } + /** * 暂停、恢复实训 */