From 45bd2f246f084d5fbaf3bf6034ce6de9d25ef4e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E5=87=A4=E5=90=89?= Date: Fri, 13 Jun 2025 13:31:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=81=9C=E6=AD=A2=E5=B7=A5=E8=89=BA?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=EF=BC=8C=E5=85=B3=E9=97=AD=E9=A3=8E?= =?UTF-8?q?=E6=89=87=E5=92=8C=E5=8A=A0=E7=83=AD=E6=A3=92=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=86=B7=E5=8D=B4=E6=97=B6=E9=97=B4=E4=B8=BAnull?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=EF=BC=8C=E5=B7=A5=E8=89=BA=E5=A2=9E=E5=8A=A0=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E6=AD=A5=E9=AA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iflytop/gd/app/service/api/CraftsService.java | 20 +++++++++++--- .../gd/app/service/crafts/CraftsStepService.java | 31 +++++++++++++++------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/iflytop/gd/app/service/api/CraftsService.java b/src/main/java/com/iflytop/gd/app/service/api/CraftsService.java index 19c0cfe..241e79f 100644 --- a/src/main/java/com/iflytop/gd/app/service/api/CraftsService.java +++ b/src/main/java/com/iflytop/gd/app/service/api/CraftsService.java @@ -15,6 +15,7 @@ import com.iflytop.gd.app.service.device.DeviceStateService; import com.iflytop.gd.app.service.device.module.HeatModuleService; import com.iflytop.gd.app.ws.server.WebSocketSender; import com.iflytop.gd.common.enums.HeatModuleCode; +import com.iflytop.gd.common.enums.HeatingType; import com.iflytop.gd.common.enums.automaton.CraftEvents; import com.iflytop.gd.common.enums.automaton.CraftStates; import com.iflytop.gd.common.exception.AppException; @@ -103,7 +104,7 @@ public class CraftsService extends ServiceImpl { throw new AppException(ResultCode.SOLUTION_MODULE_NO_TRAY); } TrayState trayState = deviceStateService.getDeviceState().getTrayInSolutionModule(); - if(trayState.getCrafts() != null){ + if (trayState.getCrafts() != null) { throw new AppException(ResultCode.SOLUTION_MODULE_OCCUPIED); } HeatModuleState heatModuleState = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode); @@ -215,8 +216,21 @@ public class CraftsService extends ServiceImpl { * 停止执行工艺,不清除上下文 */ public synchronized void stopCrafts(HeatModuleCode heatModuleCode) { - TrayState trayState = deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode); - trayState.setCrafts(null); + try { + heatModuleService.heatRodClose(heatModuleCode); + heatModuleService.fanClose(heatModuleCode); + + TrayState trayState = deviceStateService.getDeviceState().getTrayStateByHeatModuleCode(heatModuleCode); + trayState.setCrafts(null); + HeatModuleState heatModuleState = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode); + heatModuleState.setTargetTime(null); + heatModuleState.setStartHeatTime(null); + heatModuleState.setHeatingType(HeatingType.stop); + heatModuleState.setFanOpen(false); + } catch (Exception e) { + log.error("停止执行工艺错误:", e); + } + CraftsContext ctx = contextMap.get(heatModuleCode); Future future = futureMap.remove(heatModuleCode); if (ctx == null || future == null) { diff --git a/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java b/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java index 2837caa..736e745 100644 --- a/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java +++ b/src/main/java/com/iflytop/gd/app/service/crafts/CraftsStepService.java @@ -67,6 +67,7 @@ public class CraftsStepService { case "shaking" -> shaking(heatModuleCode, params); case "startHeating" -> heating(heatModuleCode, params); case "takePhoto" -> takePhoto(heatModuleCode); + case "delay" -> delay(params); default -> true; }; } @@ -138,7 +139,7 @@ public class CraftsStepService { Long solutionId = addLiquid.getLong("solutionId"); Double volume = addLiquid.getDouble("volume"); Double offset = addLiquid.getDouble("offset"); - if(offset != null){ + if (offset != null) { volume += offset; } Container container = containerService.getContainerBySolutionId(solutionId); @@ -168,7 +169,7 @@ public class CraftsStepService { Integer second = params.getInt("second"); log.info("工艺{},开始摇匀", heatModuleCode); solutionModuleService.shakeStart();//开始摇匀 - delay(second); + sleep(second); log.info("工艺{},停止摇匀", heatModuleCode); solutionModuleService.shakeStop();//停止摇匀 return true; @@ -200,13 +201,13 @@ public class CraftsStepService { deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setFanOpen(true); log.info("工艺{},等待降温", heatModuleCode); while (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature() - 1 > targetTemperature) { - delay(1); + sleep(1); } heatModuleService.fanClose(heatModuleCode); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setFanOpen(false); heatModuleService.heatRodOpen(heatModuleCode, targetTemperature); } else { - if( deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).isFanOpen()){ + if (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).isFanOpen()) { heatModuleService.fanClose(heatModuleCode);//工艺加热前,尝试关闭风扇 deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setFanOpen(false); } @@ -216,7 +217,7 @@ public class CraftsStepService { log.info("工艺{},等待升温", heatModuleCode); if (inTemperature != null) { while (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature() + 1 < inTemperature) { - delay(1); + sleep(1); } log.info("工艺{},温度达到可以放入的温度,下降加热模块托盘", heatModuleCode); heatModuleService.heaterMotorMove(heatModuleCode, trayLower);//下降加热模块托盘 @@ -224,7 +225,7 @@ public class CraftsStepService { deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setStartHeatTime(LocalDateTime.now()); } while (deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getTemperature() + 1 < targetTemperature) { - delay(1); + sleep(1); } } log.info("工艺{},恒温中", heatModuleCode); @@ -239,7 +240,7 @@ public class CraftsStepService { LocalDateTime startHeatTime = deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).getStartHeatTime(); LocalDateTime endHeatTime = startHeatTime.plusSeconds(second); while (LocalDateTime.now().isBefore(endHeatTime)) { - delay(1); + sleep(1); } deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setStartHeatTime(null); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(null); @@ -251,7 +252,7 @@ public class CraftsStepService { deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setStartHeatTime(LocalDateTime.now()); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(coolingSecond); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.trayCooling); - delay(coolingSecond); + sleep(coolingSecond); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setStartHeatTime(null); deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(null); return true; @@ -276,7 +277,19 @@ public class CraftsStepService { /** * 延时等待 */ - private boolean delay(int seconds) { + private boolean delay(JSONObject params) { + Integer seconds = params.getInt("seconds", 0); + sleep(seconds); + return true; + } + + /** + * 延时等待 + */ + private boolean sleep(Integer seconds) { + if (seconds == null) { + return true; + } try { Thread.sleep(seconds * 1000L); } catch (InterruptedException e) {