|
|
|
@ -1,23 +1,24 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesShiftService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionRecordService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesWorkOrderExtService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProdRuleContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsInContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.context.*;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
|
|
|
|
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.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.MathOperation;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesProductionRecord;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrderControlQtyRecord;
|
|
|
|
|
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.repository.MesWorkOrderControlQtyRecordRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
@ -27,10 +28,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.StringJoiner;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -51,11 +49,19 @@ public class MesProductionDataSaveBeforeControlOrderStepService extends BaseStep
|
|
|
|
|
private IMesProductionRecordService productionRecordService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesShiftService shiftService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesWorkOrderExtService workOrderExtService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesWorkOrderControlQtyRecordRepository workOrderControlQtyRecordRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public StepResult execute(StationRequestBean reqBean) {
|
|
|
|
|
|
|
|
|
|
StepResult stepResult = StepResult.getSuccessComplete();
|
|
|
|
|
|
|
|
|
|
StationResultBean resultBean = new StationResultBean();
|
|
|
|
|
|
|
|
|
|
//获取上下文信息: 处理加工不可用规则
|
|
|
|
@ -76,6 +82,11 @@ public class MesProductionDataSaveBeforeControlOrderStepService extends BaseStep
|
|
|
|
|
//获取进料主条码数据信息
|
|
|
|
|
List<MesProductionPsInContext> productionPsInContextList = productionDispatchContextStepService.getProductionPsInContext(reqBean);
|
|
|
|
|
Map<Integer, MesProductionPsInContext> psiMap = CollectionUtils.isEmpty(productionPsInContextList) ? null : productionPsInContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).collect(Collectors.toMap(MesProductionPsInContext::getForeignKey, o -> o));
|
|
|
|
|
//获取上下文产出零件信息
|
|
|
|
|
List<MesProductionPartContext> productionPartContextList = productionDispatchContextStepService.getProductionPartContext(reqBean);
|
|
|
|
|
|
|
|
|
|
//当前不能生产的零件号
|
|
|
|
|
List<String> unProductionPartNoList = null;
|
|
|
|
|
|
|
|
|
|
Loop:
|
|
|
|
|
synchronized (new StringJoiner(MesPcnExtConstWords.COLON).add(reqBean.getOrganizeCode()).add(reqBean.getWorkCenterCode()).add(MesPcnExtConstWords.WORK_ORDER_COMPLETE_CONTEXT).toString().intern()) {
|
|
|
|
@ -87,15 +98,34 @@ public class MesProductionDataSaveBeforeControlOrderStepService extends BaseStep
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(reportPsMap)) break Loop;
|
|
|
|
|
|
|
|
|
|
List<MesWorkOrder> workOrderList = workOrderExtService.getWorkOrderList()
|
|
|
|
|
//需要汇报的零件号
|
|
|
|
|
List<String> partNoList = new ArrayList<>(reportPsMap.keySet());
|
|
|
|
|
|
|
|
|
|
//根据当前时间计算实际整天班次的时间
|
|
|
|
|
Map<String, String> shiftTimeMap = shiftService.calcAllDayShiftTimeMapByCurTime(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode());
|
|
|
|
|
|
|
|
|
|
//控制工单数量查询
|
|
|
|
|
Map<String, Double> controlOrderQtyMap = workOrderExtService.getControlOrderQtyMap(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(),
|
|
|
|
|
partNoList, shiftTimeMap.get(MesPcnExtConstWords.START_TIME), shiftTimeMap.get(MesPcnExtConstWords.END_TIME));
|
|
|
|
|
|
|
|
|
|
//存在工单的零件号
|
|
|
|
|
List<String> existOrderPartNoList = CollectionUtils.isEmpty(controlOrderQtyMap) ? null : new ArrayList<>(controlOrderQtyMap.keySet());
|
|
|
|
|
|
|
|
|
|
//查询存在工单的零件号对应的完成工单数量
|
|
|
|
|
Map<String, Double> completeOrderQtyMap = workOrderExtService.getCompleteOrderQtyMap(
|
|
|
|
|
reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), existOrderPartNoList, shiftTimeMap.get(MesPcnExtConstWords.LOT_NO));
|
|
|
|
|
|
|
|
|
|
//匹配失败需要清除本次扫描/读取信息
|
|
|
|
|
if (!stepResult.isCompleted() && workOrderCheckCompleteQtyStepService.doBusiCheckToDelete(reqBean, stepResult, productionPartContextList, productionPsInContextList))
|
|
|
|
|
return stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_PART_NO);
|
|
|
|
|
Double planQty, completeQty;
|
|
|
|
|
for (Map.Entry<String, List<MesProductionPsOutContext>> entry : reportPsMap.entrySet()) {
|
|
|
|
|
if (null == entry) continue;
|
|
|
|
|
planQty = (!CollectionUtils.isEmpty(controlOrderQtyMap) && controlOrderQtyMap.containsKey(entry.getKey())) ? controlOrderQtyMap.get(entry.getKey()) : new Double(MesPcnExtConstWords.ZERO);
|
|
|
|
|
completeQty = (!CollectionUtils.isEmpty(completeOrderQtyMap) && completeOrderQtyMap.containsKey(entry.getKey())) ? completeOrderQtyMap.get(entry.getKey()) : new Double(MesPcnExtConstWords.ZERO);
|
|
|
|
|
if (MathOperation.compareTo(MathOperation.add(completeQty, new Double(entry.getValue().size())), planQty) <= 0) continue;
|
|
|
|
|
if (CollectionUtils.isEmpty(unProductionPartNoList)) unProductionPartNoList = new ArrayList<>();
|
|
|
|
|
unProductionPartNoList.add(entry.getKey());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(unProductionPartNoList)) break Loop;
|
|
|
|
|
|
|
|
|
|
//非排序线 保存加工结果工步 execute 方法 使用的是 新事务
|
|
|
|
|
stepResult = ((IStepService) SpringContextsUtil.getBean("mesProductionDataSaveStepService")).execute(reqBean);
|
|
|
|
@ -107,10 +137,38 @@ public class MesProductionDataSaveBeforeControlOrderStepService extends BaseStep
|
|
|
|
|
stepService.executeStepAfterExecute(reqBean, stepResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stepResult.isCompleted()) insertWorkOrderControlQtyRecord(reqBean, reportPsMap, shiftTimeMap.get(MesPcnExtConstWords.LOT_NO));
|
|
|
|
|
|
|
|
|
|
return stepResult;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//非排序线 保存加工结果工步 execute 方法 使用的是 新事务
|
|
|
|
|
return ((IStepService) SpringContextsUtil.getBean("mesProductionDataSaveStepService")).execute(reqBean);
|
|
|
|
|
if (CollectionUtils.isEmpty(unProductionPartNoList))
|
|
|
|
|
return ((IStepService) SpringContextsUtil.getBean("mesProductionDataSaveStepService")).execute(reqBean);
|
|
|
|
|
|
|
|
|
|
stepNonCompleteAndSendMsg(reqBean, resultBean.writeDbLog(), stepResult, String.format("控制加工单数量验证零件号%s当前无法继续生产!", unProductionPartNoList.toString()));
|
|
|
|
|
|
|
|
|
|
stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY);
|
|
|
|
|
if (!CollectionUtils.isEmpty(productionPsInContextList)) {
|
|
|
|
|
productionDispatchContextStepService.removeProductionPsInContext(reqBean);
|
|
|
|
|
stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_PRODUCT_SN);
|
|
|
|
|
}
|
|
|
|
|
if (!CollectionUtils.isEmpty(productionPartContextList)) {
|
|
|
|
|
productionDispatchContextStepService.removeProductionPartContext(reqBean);
|
|
|
|
|
productionProcessContextStepService.removeFunctionChooseCavityOrderContext(reqBean);
|
|
|
|
|
productionProcessContextStepService.removeFunctionChooseCavityPartContext(reqBean);
|
|
|
|
|
stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_PART_NO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
productionDispatchContextStepService.removeProdRuleDataContext(reqBean);
|
|
|
|
|
if (productionDispatchContextStepService.checkFirstMouldNoIsExistContext(reqBean)) {
|
|
|
|
|
//存在头道模具号场景下 必须抛出异常 因为头道模具号的接口逻辑会配置非常变值,也就是每次返回回去都会拿到头道模具号 就会出现死循环线程
|
|
|
|
|
productionDispatchContextStepService.removeFirstMouldNoContext(reqBean);
|
|
|
|
|
foundExThrowNoShowMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stepResult;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -141,4 +199,41 @@ public class MesProductionDataSaveBeforeControlOrderStepService extends BaseStep
|
|
|
|
|
return (null != optional && optional.isPresent()) ? true : false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void insertWorkOrderControlQtyRecord(StationRequestBean reqBean, Map<String, List<MesProductionPsOutContext>> reportPsMap, String lotNo) {
|
|
|
|
|
if (CollectionUtils.isEmpty(reportPsMap)) return;
|
|
|
|
|
|
|
|
|
|
//获取上下文产品加工规则数据信息集合
|
|
|
|
|
List<MesProdRuleContext> prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean);
|
|
|
|
|
//加工规则根据数据关联键分组
|
|
|
|
|
Map<Integer, MesProdRuleContext> prodRuleContextMap = CollectionUtils.isEmpty(prodRuleContextList) ? null :
|
|
|
|
|
prodRuleContextList.stream().filter(o -> null != o).collect(Collectors.toMap(MesProdRuleContext::getForeignKey, o -> o));
|
|
|
|
|
|
|
|
|
|
//获取上下文工位扫描监控信息
|
|
|
|
|
MesScanMonitorContext scanMonitorContext = productionProcessContextStepService.getScanMonitorContext(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode());
|
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, List<MesProductionPsOutContext>> entry : reportPsMap.entrySet()) {
|
|
|
|
|
if (null == entry) continue;
|
|
|
|
|
for (MesProductionPsOutContext productionPsOutContext : entry.getValue()) {
|
|
|
|
|
if (null == productionPsOutContext) continue;
|
|
|
|
|
MesWorkOrderControlQtyRecord workOrderControlQtyRecord = new MesWorkOrderControlQtyRecord();
|
|
|
|
|
workOrderControlQtyRecord.setOrganizeCode(reqBean.getOrganizeCode());
|
|
|
|
|
workOrderControlQtyRecord.setWorkCenterCode(reqBean.getWorkCenterCode());
|
|
|
|
|
workOrderControlQtyRecord.setWorkCellCode(reqBean.getWorkCellCode());
|
|
|
|
|
workOrderControlQtyRecord.setProductSn(productionPsOutContext.getProductSn());
|
|
|
|
|
workOrderControlQtyRecord.setQty(productionPsOutContext.getQty());
|
|
|
|
|
workOrderControlQtyRecord.setPartNo(productionPsOutContext.getPartNo());
|
|
|
|
|
workOrderControlQtyRecord.setLotNo(lotNo);
|
|
|
|
|
workOrderControlQtyRecord.setShiftCode(productionPsOutContext.getShiftCode());
|
|
|
|
|
workOrderControlQtyRecord.setShiftGroup(productionPsOutContext.getShiftGroup());
|
|
|
|
|
workOrderControlQtyRecord.setPid(productionPsOutContext.getId());
|
|
|
|
|
if (null != scanMonitorContext) workOrderControlQtyRecord.setMouldRecordId(scanMonitorContext.getMouldRecordId());
|
|
|
|
|
if (!CollectionUtils.isEmpty(prodRuleContextMap) && prodRuleContextMap.containsKey(productionPsOutContext.getForeignKey())) {
|
|
|
|
|
workOrderControlQtyRecord.setProductionRecordId(prodRuleContextMap.get(productionPsOutContext.getForeignKey()).getProductionRecordId());
|
|
|
|
|
}
|
|
|
|
|
ConvertBean.serviceModelInitialize(workOrderControlQtyRecord, reqBean.getUserInfo());
|
|
|
|
|
workOrderControlQtyRecordRepository.insert(workOrderControlQtyRecord);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|