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) {