|
|
@ -34,7 +34,8 @@ public class CraftsStepService { |
|
|
|
|
|
|
|
private final ExecutorService executorService = Executors.newCachedThreadPool(); |
|
|
|
private final ConcurrentHashMap<String, Future<?>> taskMap = new ConcurrentHashMap<>(); |
|
|
|
|
|
|
|
private final ConcurrentHashMap<String, Boolean> pausedMap = new ConcurrentHashMap<>(); |
|
|
|
private final ConcurrentHashMap<String, Object> taskLocks = new ConcurrentHashMap<>(); |
|
|
|
/** |
|
|
|
* 启动工艺 |
|
|
|
* |
|
|
@ -49,6 +50,7 @@ public class CraftsStepService { |
|
|
|
CraftsTask task = new CraftsTask(craftId, heatId); |
|
|
|
taskFuture = executorService.submit(task); |
|
|
|
taskMap.put(heatId, taskFuture); |
|
|
|
taskLocks.put(heatId, new Object()); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@ -63,19 +65,40 @@ public class CraftsStepService { |
|
|
|
boolean cancelled = taskFuture.cancel(true); |
|
|
|
if (cancelled) { |
|
|
|
taskMap.remove(heatId); |
|
|
|
pausedMap.remove(heatId); |
|
|
|
taskLocks.remove(heatId); |
|
|
|
} |
|
|
|
|
|
|
|
return cancelled; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 暂停工艺 |
|
|
|
* |
|
|
|
* @param heatId 加热区id |
|
|
|
*/ |
|
|
|
public synchronized void pauseCrafts(String heatId) { |
|
|
|
pausedMap.put(heatId, true); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 恢复工艺继续执行 |
|
|
|
* |
|
|
|
* @param heatId 加热区id |
|
|
|
*/ |
|
|
|
public synchronized void resumeCrafts(String heatId) { |
|
|
|
pausedMap.put(heatId, false); |
|
|
|
synchronized (taskLocks.get(heatId)) { |
|
|
|
taskLocks.get(heatId).notify(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class CraftsTask implements Runnable { |
|
|
|
private final String heatId; |
|
|
|
private final Long craftId; |
|
|
|
|
|
|
|
private static String currentMethod = null; |
|
|
|
private static int currentStatus = CraftsStepStatus.NOT_EXECUTED; |
|
|
|
|
|
|
|
public CraftsTask(Long craftId, String heatId) { |
|
|
|
this.heatId = heatId; |
|
|
@ -84,7 +107,6 @@ public class CraftsStepService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
currentStatus = CraftsStepStatus.IN_PROGRESS; |
|
|
|
Crafts crafts = craftsService.findCraftsById(craftId); |
|
|
|
log.info("开始执行工艺,加热区: {}, 工艺: {}", heatId, crafts.getName()); |
|
|
|
String steps = crafts.getSteps(); |
|
|
@ -114,6 +136,20 @@ public class CraftsStepService { |
|
|
|
pushMsg(heatId, CraftsStepStatus.ERROR); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
synchronized (taskLocks.get(heatId)) { |
|
|
|
while (pausedMap.getOrDefault(heatId, false)) { |
|
|
|
try { |
|
|
|
log.info("暂停执行工艺,加热区: {}", heatId); |
|
|
|
pushMsg(heatId, CraftsStepStatus.PAUSED); |
|
|
|
taskLocks.get(heatId).wait(); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
Thread.currentThread().interrupt(); |
|
|
|
return; |
|
|
|
} |
|
|
|
log.info("恢复执行工艺,加热区: {}", heatId); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
taskMap.remove(heatId); |
|
|
|
log.info("停止执行工艺,加热区: {}", heatId); |
|
|
@ -132,7 +168,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean upTray() { |
|
|
|
currentMethod = CraftsStepMethod.UP_TRAY; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
try { |
|
|
|
Thread.sleep(2000); |
|
|
|
} catch (InterruptedException e) { |
|
|
@ -147,7 +183,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean downTray() { |
|
|
|
currentMethod = CraftsStepMethod.DOWN_TRAY; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
try { |
|
|
|
Thread.sleep(2000); |
|
|
|
} catch (InterruptedException e) { |
|
|
@ -162,7 +198,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean addLiquid(JSONObject params) { |
|
|
|
currentMethod = CraftsStepMethod.ADD_LIQUID; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
|
|
|
|
JSONArray tubeSolJSONArray = params.getJSONArray("tubeSolList"); |
|
|
|
List<TubeSol> tubeSolList = JSONUtil.toList(tubeSolJSONArray.toString(), TubeSol.class); |
|
|
@ -180,7 +216,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean moveToSol() { |
|
|
|
currentMethod = CraftsStepMethod.MOVE_TO_SOL; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
|
|
|
|
try { |
|
|
|
Thread.sleep(5000); |
|
|
@ -196,7 +232,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean moveToHeater() { |
|
|
|
currentMethod = CraftsStepMethod.MOVE_TO_HEATER; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
|
|
|
|
try { |
|
|
|
Thread.sleep(5000); |
|
|
@ -212,7 +248,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean shaking(JSONObject params) { |
|
|
|
currentMethod = CraftsStepMethod.SHAKING; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
|
|
|
|
Integer second = params.getInt("second"); |
|
|
|
try { |
|
|
@ -229,7 +265,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean startHeating(JSONObject params) { |
|
|
|
currentMethod = CraftsStepMethod.START_HEATING; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
|
|
|
|
Double temperature = params.getDouble("temperature"); |
|
|
|
try { |
|
|
@ -246,7 +282,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean stopHeating() { |
|
|
|
currentMethod = CraftsStepMethod.STOP_HEATING; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
|
|
|
|
try { |
|
|
|
Thread.sleep(1000); |
|
|
@ -262,7 +298,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean takePhoto() { |
|
|
|
currentMethod = CraftsStepMethod.TAKE_PHOTO; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
|
|
|
|
try { |
|
|
|
Thread.sleep(1000); |
|
|
@ -292,7 +328,7 @@ public class CraftsStepService { |
|
|
|
*/ |
|
|
|
private boolean delay(JSONObject params) { |
|
|
|
currentMethod = CraftsStepMethod.DELAY; |
|
|
|
pushMsg(heatId, currentStatus, currentMethod); |
|
|
|
pushMsg(heatId, CraftsStepStatus.IN_PROGRESS, currentMethod); |
|
|
|
|
|
|
|
Integer second = params.getInt("second"); |
|
|
|
return deviceStepService.delay(second); |
|
|
|