|
|
|
@ -180,20 +180,26 @@ public class MesWorkOrderQueueAcceptStepService extends BaseStepService {
|
|
|
|
|
//加工单验证工步 【排序】
|
|
|
|
|
stepResult = ((IStepService) SpringContextsUtil.getBean("mesWorkOrderCheckSortStepService")).executeInState(reqBean);
|
|
|
|
|
|
|
|
|
|
if (!stepResult.isCompleted()) {
|
|
|
|
|
stepThreadSleepAndSendTaskCompleteAndThrowEx(reqBean, stepResult, MesPcnEnumUtil.STATION_DATA_TYPE.EXP_TEXT,
|
|
|
|
|
getStepParams(reqBean), MesPcnExtConstWords.READ_FAILURE_SLEEP, MesPcnExtConstWords.READ_FAILURE_SLEEP_DEFAULT_TIME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//保存上下文推单信息
|
|
|
|
|
if (stepResult.isCompleted()) productionDispatchContextStepService.dispatchSortQueuePushContext(reqBean, curPushList);
|
|
|
|
|
productionDispatchContextStepService.dispatchSortQueuePushContext(reqBean, curPushList);
|
|
|
|
|
|
|
|
|
|
return stepResult;
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
//当需要加锁且满足腔数的情况下, 保存排序线工单队列推送锁数据【保存LOCK信息:item=id,value=工位】【保存当前工位锁定的信息:item=工位,value=idList】
|
|
|
|
|
List<String> queuePushIdList = CollectionUtils.isEmpty(curPushList) ? null :
|
|
|
|
|
curPushList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getIsNeedLock()))).map(o -> o.getId().toString()).collect(Collectors.toList());
|
|
|
|
|
if (!CollectionUtils.isEmpty(queuePushIdList) && curPushList.size() >= cellEquipContext.getCavity()) {
|
|
|
|
|
productionCustomContextStepService.dispatchSortQueuePushLockContext(reqBean, queuePushIdList);
|
|
|
|
|
//当需要加锁且满足腔数的情况下, 保存排序线工单队列推送锁数据
|
|
|
|
|
Map<String, String> queuePushMap2Locked = CollectionUtils.isEmpty(curPushList) ? null :
|
|
|
|
|
curPushList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getIsNeedLock()))).collect(Collectors.toMap(o -> o.getId().toString(), MesQueueOrderPush::getPushSourceCode));
|
|
|
|
|
if (!CollectionUtils.isEmpty(queuePushMap2Locked) && curPushList.size() >= cellEquipContext.getCavity()) {
|
|
|
|
|
//保存排序线工单队列推送锁数据【保存LOCK信息:item=id,value=工位】【保存当前工位锁定的信息:item=工位,value=idList】
|
|
|
|
|
productionCustomContextStepService.dispatchSortQueuePushLockContext(reqBean, new ArrayList<>(queuePushMap2Locked.keySet()));
|
|
|
|
|
}
|
|
|
|
|
//解锁
|
|
|
|
|
if (!CollectionUtils.isEmpty(queuePushIdList)) queuePushIdList.forEach(o -> unLock(reqBean, o));
|
|
|
|
|
if (!CollectionUtils.isEmpty(queuePushMap2Locked)) queuePushMap2Locked.values().forEach(o -> unLock(reqBean, o));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -204,21 +210,15 @@ public class MesWorkOrderQueueAcceptStepService extends BaseStepService {
|
|
|
|
|
String key = new StringJoiner(MesPcnExtConstWords.AND).add(reqBean.getWorkCenterCode()).add(pushSourceCode).toString();
|
|
|
|
|
ReentrantLock lock = lockMap.computeIfAbsent(key, item -> new ReentrantLock(true));
|
|
|
|
|
//500ms内拿不到锁的情况下监控锁是否已经超时
|
|
|
|
|
if (!lock.tryLock(MesPcnExtConstWords.FIVE_HUNDRED, TimeUnit.MILLISECONDS)) {
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- tryLock [{}] false",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode);
|
|
|
|
|
if (checkTimeOut(reqBean, pushSourceCode, key, lock)) {
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- tryLock [{}] timeOut",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- tryLock [{}] true",
|
|
|
|
|
if (!lock.tryLock(MesPcnExtConstWords.FIVE_HUNDRED, TimeUnit.MILLISECONDS) && checkTimeOut(reqBean, pushSourceCode, key, lock)) return false;
|
|
|
|
|
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- TRY_LOCK [{}] SUCCESS",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode);
|
|
|
|
|
|
|
|
|
|
lockTimeMap.put(key, TimeTool.getNowTime(true));
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- tryLock [{}] EXCEPTION: {}",
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- TRY_LOCK [{}] EXCEPTION: {}",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode, e.toString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -229,13 +229,18 @@ public class MesWorkOrderQueueAcceptStepService extends BaseStepService {
|
|
|
|
|
try {
|
|
|
|
|
String lockTime = lockTimeMap.get(key);
|
|
|
|
|
if ((StringUtils.isEmpty(lockTime) || TimeTool.getSecoundsBetweenTime(1, lockTime, TimeTool.getNowTime(true)) >= MesPcnExtConstWords.TEN) && lock.isLocked()) {
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- checkTimeOut [{}] unlock",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode);
|
|
|
|
|
lock.unlock();
|
|
|
|
|
if (lock.isHeldByCurrentThread()) {
|
|
|
|
|
lock.unlock();
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- CHECK_TIME_OUT [{}] UNLOCK SUCCESS",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode);
|
|
|
|
|
} else {
|
|
|
|
|
lockMap.remove(key);
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- CHECK_TIME_OUT [{}] UNLOCK REMOVE",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (lock.isLocked()) lock.unlock();
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- checkTimeOut [{}] EXCEPTION: {}",
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- CHECK_TIME_OUT [{}] EXCEPTION: {}",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode, e.toString());
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
@ -248,12 +253,12 @@ public class MesWorkOrderQueueAcceptStepService extends BaseStepService {
|
|
|
|
|
lockMap.computeIfPresent(key, (k, v) -> {
|
|
|
|
|
if (!v.isHeldByCurrentThread() || !v.isLocked()) return v;
|
|
|
|
|
v.unlock();
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- unLock [{}] true",
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- UNLOCK [{}] SUCCESS",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode);
|
|
|
|
|
return v;
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- unLock [{}] EXCEPTION: {}",
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- UNLOCK [{}] EXCEPTION: {}",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), pushSourceCode, e.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|