diff --git a/src/main/java/com/iflytop/sgs/app/core/CraftsContext.java b/src/main/java/com/iflytop/sgs/app/core/CraftsContext.java index bb5336b..cde1edf 100644 --- a/src/main/java/com/iflytop/sgs/app/core/CraftsContext.java +++ b/src/main/java/com/iflytop/sgs/app/core/CraftsContext.java @@ -91,7 +91,7 @@ public class CraftsContext implements Runnable { CraftsStep step = craftsStepList.get(currentIndex); craftMonitor.setCurrentStepId(currentIndex); craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); - craftMonitorService.saveOrUpdate(craftMonitor); + craftMonitorService.saveMonitor(craftMonitor); boolean ok = executeStep(step, craftMonitor); if (!ok) { Message errMsg = MessageBuilder.withPayload(CraftEvents.ERROR_OCCUR).build(); diff --git a/src/main/java/com/iflytop/sgs/app/service/crafts/CraftsStepService.java b/src/main/java/com/iflytop/sgs/app/service/crafts/CraftsStepService.java index 3352f26..a0cb9d1 100644 --- a/src/main/java/com/iflytop/sgs/app/service/crafts/CraftsStepService.java +++ b/src/main/java/com/iflytop/sgs/app/service/crafts/CraftsStepService.java @@ -31,6 +31,7 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -100,11 +101,9 @@ public class CraftsStepService { log.info("工艺{},-------------------------------------加稀硝酸-------------------------------------", heatModuleCode); /*工艺监控*/ log.info("工艺{},工艺监控", heatModuleCode); - JSONObject result = new JSONObject(); List finishColumns = new ArrayList<>(); - result.set(ResultCode.SUCCESS.getCode(), finishColumns); - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor); + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.add_liquid_column.getDescription() + Arrays.toString(finishColumns.toArray())); + craftMonitorService.saveMonitor(craftMonitor); /*工艺监控结束*/ /*获取配置信息*/ @@ -213,10 +212,9 @@ public class CraftsStepService { solutionModuleService.solutionMotorMoveZero();//加液机械臂上升 /*工艺监控开始*/ finishColumns.add(i); - result.set("columns", finishColumns);//添加到结果 - craftMonitor.setCurrentStepResult(String.valueOf(result)); + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.add_liquid_column.getDescription() + Arrays.toString(finishColumns.toArray())); craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); - craftMonitorService.saveOrUpdate(craftMonitor); + craftMonitorService.saveMonitor(craftMonitor); /*工艺监控结束*/ } solutionModuleService.liquidPumpMove(-backFlowDistance);//预充 @@ -256,11 +254,9 @@ public class CraftsStepService { log.info("工艺{},------------------------------加浓硝酸---------------------------", heatModuleCode); /*工艺监控*/ log.info("工艺{},工艺监控", heatModuleCode); - JSONObject result = new JSONObject(); List finishColumns = new ArrayList<>(); - result.set(ResultCode.SUCCESS.getCode(), finishColumns); - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor); + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.add_liquid_column.getDescription() + Arrays.toString(finishColumns.toArray())); + craftMonitorService.saveMonitor(craftMonitor); /*工艺监控结束*/ /*获取配置信息*/ @@ -411,10 +407,9 @@ public class CraftsStepService { solutionModuleService.solutionMotorMoveZero();//加液机械臂上升 /*工艺监控开始*/ finishColumns.add(i); - result.set("columns", finishColumns);//添加到结果 - craftMonitor.setCurrentStepResult(String.valueOf(result)); + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.add_liquid_column.getDescription() + Arrays.toString(finishColumns.toArray())); craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); - craftMonitorService.saveOrUpdate(craftMonitor); + craftMonitorService.saveMonitor(craftMonitor); /*工艺监控结束*/ } solutionModuleService.liquidPumpMove(-backFlowDistance);//预充 @@ -453,9 +448,9 @@ public class CraftsStepService { * */ public boolean heat(HeatModuleCode heatModuleCode, JSONObject params, CraftMonitor craftMonitor) throws Exception { /*工艺监控清理上步的记录*/ - JSONObject result = new JSONObject(); - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor); + craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.heat_time.getDescription() + ":0"); + craftMonitorService.saveMonitor(craftMonitor); /*工艺监控清理上步的记录*/ Double temperature = params.getDouble("temperature");//温度 Integer time = params.getInt("time");//秒 @@ -485,10 +480,9 @@ public class CraftsStepService { cycle--; clock = clock + 60; /*保存到工艺监控*/ - result.set("time", clock);//添加到结果 - craftMonitor.setCurrentStepResult(String.valueOf(result)); craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); - craftMonitorService.saveOrUpdate(craftMonitor);//保存到监控 + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.heat_time.getDescription() + ":" + clock / 60); + craftMonitorService.saveMonitor(craftMonitor); /*保存到工艺监控*/ } delay(seconds); @@ -497,9 +491,6 @@ public class CraftsStepService { deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(null);//加热器目标加热时间 deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setHeatingType(HeatingType.finish); //加热完成 log.info("工艺{},加热结束", heatModuleCode); - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); - craftMonitorService.saveOrUpdate(craftMonitor);//保存到监控 webSocketService.pushCraftsDebug(CraftsDebugGenerator.generateJson(heatModuleCode.toString(), "加热结束,持续时间", time)); return true; } @@ -511,9 +502,9 @@ public class CraftsStepService { try { log.info("工艺{},----------------------------------清洗---------------------------------------------", heatModuleCode); /*保存到监控开始*/ - JSONObject result = new JSONObject(); - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor);//保存到监控 + craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.clean_cycle.getDescription() + ":0"); + craftMonitorService.saveMonitor(craftMonitor); /*保存到监控结束*/ /*获取参数开始*/ @@ -651,10 +642,9 @@ public class CraftsStepService { log.info("工艺{},加液模块上升至最高,移出试管", heatModuleCode); solutionModuleService.solutionMotorMoveZero();//加液模块上升至最高,移出试管 } - result.set("cycle", i + 1);//添加到结果 - craftMonitor.setCurrentStepResult(String.valueOf(result)); craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); - craftMonitorService.saveOrUpdate(craftMonitor);//保存到监控 + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.clean_cycle.getDescription() + ":" + (i + 1)); + craftMonitorService.saveMonitor(craftMonitor); } /*清洗结束*/ @@ -685,9 +675,9 @@ public class CraftsStepService { * */ public boolean dry(HeatModuleCode heatModuleCode, JSONObject params, CraftMonitor craftMonitor) throws Exception { /*工艺监控清理上步的记录*/ - JSONObject result = new JSONObject(); - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor); + craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.heat_time.getDescription() + ":0"); + craftMonitorService.saveMonitor(craftMonitor); /*工艺监控清理上步的记录*/ @@ -707,19 +697,15 @@ public class CraftsStepService { deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setStartHeatTime(LocalDateTime.now());//开始加热时间 deviceStateService.getDeviceState().getHeatModuleByCode(heatModuleCode).setTargetTime(time);//加热器目标加热时间 int clock = 0; - result.set("time", clock);//添加到结果 - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor);//保存到监控 int cycle = time / 60; int seconds = time % 60; while (cycle > 0) { delay(60); cycle--; clock = clock + 60; - result.set("time", clock);//添加到结果 - craftMonitor.setCurrentStepResult(String.valueOf(result)); craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); - craftMonitorService.saveOrUpdate(craftMonitor);//保存到监控 + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.heat_time.getDescription() + ":" + clock / 60); + craftMonitorService.saveMonitor(craftMonitor); } log.info("工艺{},恒温中", heatModuleCode); delay(seconds); @@ -739,9 +725,9 @@ public class CraftsStepService { * */ public synchronized boolean anneal(HeatModuleCode heatModuleCode, JSONObject params, CraftMonitor craftMonitor) throws Exception { try { - JSONObject result = new JSONObject(); - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor); + craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.heat_time.getDescription() + ":0"); + craftMonitorService.saveMonitor(craftMonitor); Double temperature = params.getDouble("temperature");//退火温度 Integer time = params.getInt("time");//秒 boolean heatModuleTrayExist = deviceSensorService.getTrayStateByHeatModuleCode(heatModuleCode); @@ -796,19 +782,15 @@ public class CraftsStepService { deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_04).setStartHeatTime(LocalDateTime.now());//开始加热时间 deviceStateService.getDeviceState().getHeatModuleByCode(HeatModuleCode.heat_module_04).setTargetTime(time);//加热器目标加热时间 int clock = 0; - result.set("time", clock);//添加到结果 - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor);//保存到监控 int cycle = time / 60; int seconds = time % 60; while (cycle > 0) { delay(60); cycle--; clock = clock + 60; - result.set("time", clock);//添加到结果 craftMonitor.setDeviceState(JSONUtil.toJsonStr(deviceStateService.getDeviceState())); - craftMonitor.setCurrentStepResult(String.valueOf(result)); - craftMonitorService.saveOrUpdate(craftMonitor);//保存到监控 + craftMonitor.setCurrentStepResult(CraftsMonitorResultCode.heat_time.getDescription() + ":" + clock / 60); + craftMonitorService.saveMonitor(craftMonitor); } log.info("工艺{},恒温中", HeatModuleCode.heat_module_04); delay(seconds); diff --git a/src/main/java/com/iflytop/sgs/common/enums/CraftsMonitorResultCode.java b/src/main/java/com/iflytop/sgs/common/enums/CraftsMonitorResultCode.java new file mode 100644 index 0000000..ae9b27f --- /dev/null +++ b/src/main/java/com/iflytop/sgs/common/enums/CraftsMonitorResultCode.java @@ -0,0 +1,18 @@ +package com.iflytop.sgs.common.enums; + +import lombok.Getter; + +/** + * 容器 + */ +@Getter +public enum CraftsMonitorResultCode { + add_liquid_column("已加液列数"), + heat_time("已加热分钟"), + clean_cycle("已清洗次数"); + private final String description; + + CraftsMonitorResultCode(String description) { + this.description = description; + } +}