Browse Source

fix:修复工艺结束没有从task map 中remove的问题

master
白凤吉 6 months ago
parent
commit
21545a7bbb
  1. 24
      src/main/java/com/qyft/gd/service/CraftsStepService.java

24
src/main/java/com/qyft/gd/service/CraftsStepService.java

@ -86,12 +86,13 @@ public class CraftsStepService {
public void run() { public void run() {
currentStatus = CraftsStepStatus.IN_PROGRESS; currentStatus = CraftsStepStatus.IN_PROGRESS;
Crafts crafts = craftsService.findCraftsById(craftId); Crafts crafts = craftsService.findCraftsById(craftId);
log.info("开始执行工艺,加热区 {},工艺 {}", heatId, crafts.getName());
log.info("开始执行工艺,加热区: {}, 工艺: {}", heatId, crafts.getName());
String steps = crafts.getSteps(); String steps = crafts.getSteps();
JSONArray stepsJsonArray = JSONUtil.parseArray(steps); JSONArray stepsJsonArray = JSONUtil.parseArray(steps);
for (Object stepsJsonObject : stepsJsonArray) { for (Object stepsJsonObject : stepsJsonArray) {
if (!Thread.currentThread().isInterrupted()) { if (!Thread.currentThread().isInterrupted()) {
JSONObject stepsJson = (JSONObject) stepsJsonObject; JSONObject stepsJson = (JSONObject) stepsJsonObject;
log.info("执行工艺步骤,加热区: {}, 执行步骤: {}", heatId, stepsJson.toString());
String method = stepsJson.get("method").toString(); String method = stepsJson.get("method").toString();
JSONObject params = (JSONObject) stepsJson.get("params"); JSONObject params = (JSONObject) stepsJson.get("params");
boolean result = switch (method) { boolean result = switch (method) {
@ -108,15 +109,20 @@ public class CraftsStepService {
default -> false; default -> false;
}; };
if (!result) { if (!result) {
taskMap.remove(heatId);
log.info("执行工艺错误,加热区: {}, 当前执行步骤: {}", heatId, currentMethod);
pushMsg(heatId, CraftsStepStatus.ERROR); pushMsg(heatId, CraftsStepStatus.ERROR);
return; return;
} }
pushMsg(heatId, currentStatus, currentMethod);
} else { } else {
taskMap.remove(heatId);
log.info("停止执行工艺,加热区: {}", heatId);
pushMsg(heatId, CraftsStepStatus.STOPPED); pushMsg(heatId, CraftsStepStatus.STOPPED);
return; return;
} }
} }
taskMap.remove(heatId);
log.info("执行工艺完毕,加热区: {}", heatId);
pushMsg(heatId, CraftsStepStatus.FINISH); pushMsg(heatId, CraftsStepStatus.FINISH);
} }
@ -126,6 +132,7 @@ public class CraftsStepService {
*/ */
private boolean upTray() { private boolean upTray() {
currentMethod = CraftsStepMethod.UP_TRAY; currentMethod = CraftsStepMethod.UP_TRAY;
pushMsg(heatId, currentStatus, currentMethod);
try { try {
Thread.sleep(2000); Thread.sleep(2000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -140,6 +147,7 @@ public class CraftsStepService {
*/ */
private boolean downTray() { private boolean downTray() {
currentMethod = CraftsStepMethod.DOWN_TRAY; currentMethod = CraftsStepMethod.DOWN_TRAY;
pushMsg(heatId, currentStatus, currentMethod);
try { try {
Thread.sleep(2000); Thread.sleep(2000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -154,6 +162,7 @@ public class CraftsStepService {
*/ */
private boolean addLiquid(JSONObject params) { private boolean addLiquid(JSONObject params) {
currentMethod = CraftsStepMethod.ADD_LIQUID; currentMethod = CraftsStepMethod.ADD_LIQUID;
pushMsg(heatId, currentStatus, currentMethod);
JSONArray tubeSolJSONArray = params.getJSONArray("tubeSolList"); JSONArray tubeSolJSONArray = params.getJSONArray("tubeSolList");
List<TubeSol> tubeSolList = JSONUtil.toList(tubeSolJSONArray.toString(), TubeSol.class); List<TubeSol> tubeSolList = JSONUtil.toList(tubeSolJSONArray.toString(), TubeSol.class);
@ -171,6 +180,8 @@ public class CraftsStepService {
*/ */
private boolean moveToSol() { private boolean moveToSol() {
currentMethod = CraftsStepMethod.MOVE_TO_SOL; currentMethod = CraftsStepMethod.MOVE_TO_SOL;
pushMsg(heatId, currentStatus, currentMethod);
try { try {
Thread.sleep(5000); Thread.sleep(5000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -185,6 +196,8 @@ public class CraftsStepService {
*/ */
private boolean moveToHeater() { private boolean moveToHeater() {
currentMethod = CraftsStepMethod.MOVE_TO_HEATER; currentMethod = CraftsStepMethod.MOVE_TO_HEATER;
pushMsg(heatId, currentStatus, currentMethod);
try { try {
Thread.sleep(5000); Thread.sleep(5000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -199,6 +212,7 @@ public class CraftsStepService {
*/ */
private boolean shaking(JSONObject params) { private boolean shaking(JSONObject params) {
currentMethod = CraftsStepMethod.SHAKING; currentMethod = CraftsStepMethod.SHAKING;
pushMsg(heatId, currentStatus, currentMethod);
Integer second = params.getInt("second"); Integer second = params.getInt("second");
try { try {
@ -215,6 +229,7 @@ public class CraftsStepService {
*/ */
private boolean startHeating(JSONObject params) { private boolean startHeating(JSONObject params) {
currentMethod = CraftsStepMethod.START_HEATING; currentMethod = CraftsStepMethod.START_HEATING;
pushMsg(heatId, currentStatus, currentMethod);
Double temperature = params.getDouble("temperature"); Double temperature = params.getDouble("temperature");
try { try {
@ -231,6 +246,8 @@ public class CraftsStepService {
*/ */
private boolean stopHeating() { private boolean stopHeating() {
currentMethod = CraftsStepMethod.STOP_HEATING; currentMethod = CraftsStepMethod.STOP_HEATING;
pushMsg(heatId, currentStatus, currentMethod);
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -245,6 +262,8 @@ public class CraftsStepService {
*/ */
private boolean takePhoto() { private boolean takePhoto() {
currentMethod = CraftsStepMethod.TAKE_PHOTO; currentMethod = CraftsStepMethod.TAKE_PHOTO;
pushMsg(heatId, currentStatus, currentMethod);
try { try {
Thread.sleep(1000); Thread.sleep(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -273,6 +292,7 @@ public class CraftsStepService {
*/ */
private boolean delay(JSONObject params) { private boolean delay(JSONObject params) {
currentMethod = CraftsStepMethod.DELAY; currentMethod = CraftsStepMethod.DELAY;
pushMsg(heatId, currentStatus, currentMethod);
Integer second = params.getInt("second"); Integer second = params.getInt("second");
return deviceStepService.delay(second); return deviceStepService.delay(second);

Loading…
Cancel
Save