From f94b04aaf37f4deee8ef38254a4a6f5d8c2df701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Sat, 22 Feb 2025 15:49:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=B7=A5=E8=89=BA=E6=AD=A5=E9=AA=A4?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=8F=8D=E9=A6=88=E5=BA=94=E5=BD=93=E5=8F=8D?= =?UTF-8?q?=E9=A6=88=E5=B7=A5=E8=89=BA=E6=89=A7=E8=A1=8C=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E4=B8=8B=E6=A0=87=E8=80=8C=E4=B8=8D=E6=98=AF=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/qyft/gd/model/vo/CraftsStepResult.java | 4 +- .../com/qyft/gd/service/CraftsStepService.java | 46 +++++++++------------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/qyft/gd/model/vo/CraftsStepResult.java b/src/main/java/com/qyft/gd/model/vo/CraftsStepResult.java index 2e311b6..3330eaf 100644 --- a/src/main/java/com/qyft/gd/model/vo/CraftsStepResult.java +++ b/src/main/java/com/qyft/gd/model/vo/CraftsStepResult.java @@ -16,8 +16,8 @@ public class CraftsStepResult { */ private Integer status; /** - * 当前工艺执行的方法 + * 当前工艺执行的方法数组下标 */ - private String method; + private Integer methodIndex; } diff --git a/src/main/java/com/qyft/gd/service/CraftsStepService.java b/src/main/java/com/qyft/gd/service/CraftsStepService.java index d2cf7b5..1810fb9 100644 --- a/src/main/java/com/qyft/gd/service/CraftsStepService.java +++ b/src/main/java/com/qyft/gd/service/CraftsStepService.java @@ -99,20 +99,21 @@ public class CraftsStepService { this.pushMsg(heatId, status, null); } - private void pushMsg(String heatId, Integer status, String method) { + + private void pushMsg(String heatId, Integer status, Integer methodNum) { CraftsStepResult craftsStepResult = new CraftsStepResult(); craftsStepResult.setHeatId(heatId); craftsStepResult.setStatus(status); - craftsStepResult.setMethod(method); + craftsStepResult.setMethodIndex(methodNum); webSocketService.pushMsg(WebSocketMessageType.CRAFTS, craftsStepResult); } class CraftsTask implements Runnable { - private static String currentMethod = null; + private static int currentMethodNum = 0; private final String heatId; - private final Long craftId; + private final long craftId; - public CraftsTask(Long craftId, String heatId) { + public CraftsTask(long craftId, String heatId) { this.heatId = heatId; this.craftId = craftId; } @@ -144,8 +145,8 @@ public class CraftsStepService { }; if (!result) { taskMap.remove(heatId); - log.info("执行工艺错误,加热区: {}, 当前执行步骤: {}", heatId, currentMethod); - pushMsg(heatId, CraftsStepStatus.ERROR); + log.info("执行工艺错误,加热区: {}, 当前执行步骤: {}", heatId, stepsJsonArray.get(currentMethodNum).toString()); + pushMsg(heatId, CraftsStepStatus.ERROR, currentMethodNum); return; } @@ -168,6 +169,7 @@ public class CraftsStepService { pushMsg(heatId, CraftsStepStatus.STOPPED); return; } + currentMethodNum++; } taskMap.remove(heatId); log.info("执行工艺完毕,加热区: {}", heatId); @@ -179,8 +181,7 @@ public class CraftsStepService { * 抬起托盘 */ private boolean upTray() { - currentMethod = CraftsStepMethod.UP_TRAY; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); try { Thread.sleep(2000); } catch (InterruptedException e) { @@ -194,8 +195,7 @@ public class CraftsStepService { * 降下托盘 */ private boolean downTray() { - currentMethod = CraftsStepMethod.DOWN_TRAY; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); try { Thread.sleep(2000); } catch (InterruptedException e) { @@ -209,8 +209,7 @@ public class CraftsStepService { * 添加溶液 */ private boolean addLiquid(JSONObject params) { - currentMethod = CraftsStepMethod.ADD_LIQUID; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); JSONArray tubeSolJSONArray = params.getJSONArray("tubeSolList"); List tubeSolList = JSONUtil.toList(tubeSolJSONArray.toString(), TubeSol.class); @@ -227,8 +226,7 @@ public class CraftsStepService { * 将指定加热区的托盘移至加液区 */ private boolean moveToSol() { - currentMethod = CraftsStepMethod.MOVE_TO_SOL; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); try { Thread.sleep(5000); @@ -243,8 +241,7 @@ public class CraftsStepService { * 移至加热 */ private boolean moveToHeat() { - currentMethod = CraftsStepMethod.MOVE_TO_HEAT; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); try { Thread.sleep(5000); @@ -259,8 +256,7 @@ public class CraftsStepService { * 摇匀 */ private boolean shaking(JSONObject params) { - currentMethod = CraftsStepMethod.SHAKING; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); Integer second = params.getInt("second"); try { @@ -276,8 +272,7 @@ public class CraftsStepService { * 开始加热 */ private boolean startHeating(JSONObject params) { - currentMethod = CraftsStepMethod.START_HEATING; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); Double temperature = params.getDouble("temperature"); try { @@ -293,8 +288,7 @@ public class CraftsStepService { * 停止加热 */ private boolean stopHeating() { - currentMethod = CraftsStepMethod.STOP_HEATING; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); try { Thread.sleep(1000); @@ -309,8 +303,7 @@ public class CraftsStepService { * 拍照 */ private boolean takePhoto() { - currentMethod = CraftsStepMethod.TAKE_PHOTO; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); try { Thread.sleep(1000); @@ -339,8 +332,7 @@ public class CraftsStepService { * 等待 */ private boolean delay(JSONObject params) { - currentMethod = CraftsStepMethod.DELAY; - pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); + pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethodNum); Integer second = params.getInt("second"); return deviceStepService.delay(second);