|
|
|
@ -5,10 +5,13 @@ import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepSer
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesQueueOrderPushService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesCellEquipContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesEquipVariableCollectContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
|
|
|
|
import cn.estsh.i3plus.mes.pcn.actor.shipping.dispatch.IFsmCommonService;
|
|
|
|
|
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService;
|
|
|
|
|
import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.IStepService;
|
|
|
|
|
import cn.estsh.i3plus.mes.pcn.util.StringUtil;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesQueueOrderPush;
|
|
|
|
@ -17,6 +20,8 @@ import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.model.StepResult;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
@ -110,51 +115,76 @@ public class MesWorkOrderQueueAcceptStepService extends BaseStepService {
|
|
|
|
|
//搜集需要考虑加锁的推送来源代码
|
|
|
|
|
List<String> pushSourceCodeList = queueOrderPushCellCfgList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getIsNeedLock()))).map(MesQueueOrderPushCellCfg::getPushSourceCode).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
//验证是否执行加锁
|
|
|
|
|
//当前即将执行的接收队列
|
|
|
|
|
List<MesQueueOrderPush> curPushList = null;
|
|
|
|
|
for (MesQueueOrderPush queueOrderPush : queueOrderPushList) {
|
|
|
|
|
if (null == queueOrderPush) continue;
|
|
|
|
|
//当前遍历中的代码不考虑加锁
|
|
|
|
|
if (CollectionUtils.isEmpty(pushSourceCodeList) || !pushSourceCodeList.contains(queueOrderPush.getPushSourceCode())) {
|
|
|
|
|
if (CollectionUtils.isEmpty(curPushList)) curPushList = new ArrayList<>();
|
|
|
|
|
curPushList.add(queueOrderPush);
|
|
|
|
|
//满足腔数的情况下退出循环
|
|
|
|
|
if (curPushList.size() >= cellEquipContext.getCavity()) break;
|
|
|
|
|
} else {
|
|
|
|
|
//当前遍历中的代码考虑加锁; 获取不到锁的情况下退出循环
|
|
|
|
|
if (!tryLock(reqBean.getWorkCenterCode(), queueOrderPush.getPushSourceCode())) break;
|
|
|
|
|
List<String> queuePushIdList = productionCustomContextStepService.getSortQueuePushLockContext(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode());
|
|
|
|
|
if (!CollectionUtils.isEmpty(queuePushIdList) && queuePushIdList.contains(queueOrderPush.getId().toString())) continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
//验证是否执行加锁
|
|
|
|
|
for (MesQueueOrderPush queueOrderPush : queueOrderPushList) {
|
|
|
|
|
if (null == queueOrderPush || StringUtils.isEmpty(queueOrderPush.getWorkOrderNo())) continue;
|
|
|
|
|
//当前遍历中的代码不考虑加锁
|
|
|
|
|
if (CollectionUtils.isEmpty(pushSourceCodeList) || !pushSourceCodeList.contains(queueOrderPush.getPushSourceCode())) {
|
|
|
|
|
if (CollectionUtils.isEmpty(curPushList)) curPushList = new ArrayList<>();
|
|
|
|
|
curPushList.add(queueOrderPush);
|
|
|
|
|
//满足腔数的情况下退出循环
|
|
|
|
|
if (curPushList.size() >= cellEquipContext.getCavity()) break;
|
|
|
|
|
} else {
|
|
|
|
|
//当前遍历中的代码考虑加锁; 获取不到锁的情况下退出循环
|
|
|
|
|
if (!tryLock(reqBean.getWorkCenterCode(), queueOrderPush.getPushSourceCode())) break;
|
|
|
|
|
List<String> queuePushIdList = productionCustomContextStepService.getSortQueuePushLockContext(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode());
|
|
|
|
|
if (!CollectionUtils.isEmpty(queuePushIdList) && queuePushIdList.contains(queueOrderPush.getId().toString())) continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//验证是否执行解锁
|
|
|
|
|
if (!CollectionUtils.isEmpty(curPushList)) {
|
|
|
|
|
for (MesQueueOrderPush queueOrderPush : curPushList) {
|
|
|
|
|
if (null == queueOrderPush) continue;
|
|
|
|
|
if (CollectionUtils.isEmpty(pushSourceCodeList) || !pushSourceCodeList.contains(queueOrderPush.getPushSourceCode())) continue;
|
|
|
|
|
//当需要考虑加锁且满足腔数的情况下, 保存排序线工单队列推送锁数据
|
|
|
|
|
if (curPushList.size() >= cellEquipContext.getCavity()) productionCustomContextStepService.dispatchSortQueuePushLockContext(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), queueOrderPush.getId().toString());
|
|
|
|
|
//解锁
|
|
|
|
|
unLock(reqBean.getWorkCenterCode(), queueOrderPush.getPushSourceCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//验证是否满足腔数
|
|
|
|
|
if (CollectionUtils.isEmpty(curPushList) || curPushList.size() < cellEquipContext.getCavity()) {
|
|
|
|
|
return stepDynamicsCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().checkRepeat(), stepResult,
|
|
|
|
|
false, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT,
|
|
|
|
|
CollectionUtils.isEmpty(queueOrderPushList) ? "当前未接收到工位工单队列,持续监听中..." : String.format("当前接收到到工位工单队列个数[%s]不满足腔数[%s],持续监听中...", queueOrderPushList.size(), cellEquipContext.getCavity()),
|
|
|
|
|
getStepParams(reqBean), MesPcnExtConstWords.READ_FAILURE_SLEEP, MesPcnExtConstWords.READ_FAILURE_SLEEP_DEFAULT_TIME);
|
|
|
|
|
}
|
|
|
|
|
//验证是否满足腔数
|
|
|
|
|
if (CollectionUtils.isEmpty(curPushList) || curPushList.size() < cellEquipContext.getCavity()) {
|
|
|
|
|
return stepDynamicsCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog().checkRepeat(), stepResult,
|
|
|
|
|
false, MesPcnEnumUtil.STATION_BUSI_TYPE.GUIDE, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT,
|
|
|
|
|
CollectionUtils.isEmpty(curPushList) ? "当前未接收到工位工单队列,持续监听中..." : String.format("当前接收到到工位工单队列个数[%s]不满足腔数[%s],持续监听中...", curPushList.size(), cellEquipContext.getCavity()),
|
|
|
|
|
getStepParams(reqBean), MesPcnExtConstWords.READ_FAILURE_SLEEP, MesPcnExtConstWords.READ_FAILURE_SLEEP_DEFAULT_TIME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//搜集工单号
|
|
|
|
|
List<String> workOrderNoList = curPushList.stream().filter(o -> null != o).map(MesQueueOrderPush::getWorkOrderNo).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
//发送工步内容
|
|
|
|
|
productionCustomContextStepService.sendStepContextMessage(reqBean, workOrderNoList.toString(), MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ);
|
|
|
|
|
|
|
|
|
|
List<MesEquipVariableCollectContext> equipVariableCollectContextList = new ArrayList<>();
|
|
|
|
|
workOrderNoList.stream().filter(o -> !StringUtils.isEmpty(o)).forEach(o ->
|
|
|
|
|
equipVariableCollectContextList.add(new MesEquipVariableCollectContext(reqBean.getOrganizeCode(), o, MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue())));
|
|
|
|
|
//保存上下文扫/读信息:加工单
|
|
|
|
|
productionDispatchContextStepService.dispatchScanWorkOrderNoContext(reqBean, equipVariableCollectContextList);
|
|
|
|
|
|
|
|
|
|
this.sendMessage(reqBean, new StationResultBean().writeDbLog(), String.format("获取到工位工单推送队列%s!", workOrderNoList.toString()), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
|
|
|
|
|
|
|
|
|
|
log.info("工厂{}生产线{}工位{}:FSM STATE DISPATCHER --- DO STEP --- {} EXEC --- QUEUE_ORDER_PUSH:{}",
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), StringUtil.toLowerCaseFirst(this.getClass().getSimpleName()), JSONObject.toJSONString(curPushList));
|
|
|
|
|
|
|
|
|
|
//加工单验证工步 【排序】
|
|
|
|
|
stepResult = ((IStepService) SpringContextsUtil.getBean("mesWorkOrderCheckSortStepService")).executeInState(reqBean);
|
|
|
|
|
|
|
|
|
|
//保存上下文推单信息
|
|
|
|
|
if (stepResult.isCompleted()) productionDispatchContextStepService.dispatchSortQueuePushContext(reqBean, curPushList);
|
|
|
|
|
|
|
|
|
|
return stepResult;
|
|
|
|
|
|
|
|
|
|
return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), stepResult, "工位工单接收成功!");
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
|
|
//验证是否执行解锁
|
|
|
|
|
if (!CollectionUtils.isEmpty(curPushList)) {
|
|
|
|
|
for (MesQueueOrderPush queueOrderPush : curPushList) {
|
|
|
|
|
if (null == queueOrderPush) continue;
|
|
|
|
|
if (CollectionUtils.isEmpty(pushSourceCodeList) || !pushSourceCodeList.contains(queueOrderPush.getPushSourceCode())) continue;
|
|
|
|
|
//当需要考虑加锁且满足腔数的情况下, 保存排序线工单队列推送锁数据
|
|
|
|
|
if (curPushList.size() >= cellEquipContext.getCavity()) productionCustomContextStepService.dispatchSortQueuePushLockContext(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), queueOrderPush.getId().toString());
|
|
|
|
|
//解锁
|
|
|
|
|
unLock(reqBean.getWorkCenterCode(), queueOrderPush.getPushSourceCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -163,8 +193,8 @@ public class MesWorkOrderQueueAcceptStepService extends BaseStepService {
|
|
|
|
|
try {
|
|
|
|
|
String key = new StringJoiner(MesPcnExtConstWords.AND).add(workCenterCode).add(pushSourceCode).toString();
|
|
|
|
|
ReentrantLock lock = lockMap.computeIfAbsent(key, item -> new ReentrantLock(true));
|
|
|
|
|
//拿不到锁的情况下监控锁是否已经超时
|
|
|
|
|
if (!lock.tryLock(MesPcnExtConstWords.ONE_HUNDRED, TimeUnit.MILLISECONDS) && checkTimeOut(key, lock)) return false;
|
|
|
|
|
//500ms内拿不到锁的情况下监控锁是否已经超时
|
|
|
|
|
if (!lock.tryLock(MesPcnExtConstWords.FIVE_HUNDRED, TimeUnit.MILLISECONDS) && checkTimeOut(key, lock)) return false;
|
|
|
|
|
lockTimeMap.put(key, TimeTool.getNowTime(true));
|
|
|
|
|
return true;
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|