diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesBoxingErrorProofingService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesBoxingErrorProofingService.java index d35c2ab..d3bb7b1 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesBoxingErrorProofingService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesBoxingErrorProofingService.java @@ -61,6 +61,9 @@ public class MesBoxingErrorProofingService implements IMesBoxingErrorProofingSer @Autowired private MesPackageResultRepository mesPackageResultRDao; + @Autowired + private MesPackageSnRepository mesPackageSnRDao; + @Override public ListPager queryMesPackageDetailByPager(MesPackage mesPackage, Pager pager) { @@ -79,24 +82,36 @@ public class MesBoxingErrorProofingService implements IMesBoxingErrorProofingSer MesPackage mesPackage = getMesPackage(mesPackageDetail.getOrganizeCode(), mesPackageDetail.getPackageNo()); if (Objects.nonNull(mesPackage)) { return mesPackage; + }else{ + MesPart mesPart; + Double qty; + String packageOneCode = ""; + //获取包装定义 + MesPackingDefine packingDefine = getMesPackingDefine(mesPackageDetail); + //WMS打印的条码信息 + MesPackageSn mesPackageSn = getMesPackageSn(mesPackageDetail.getOrganizeCode(), mesPackageDetail.getPackageNo()); + if(!Objects.isNull(mesPackageSn)){ + mesPart = getPart(mesPackageSn.getOrganizeCode(),mesPackageSn.getPartNo()); + qty = mesPackageSn.getQty(); + packageOneCode = mesPackageSn.getPackageOneCode(); + }else{ + //解析获取信息保存 + if (StringUtils.isEmpty(packingDefine.getSplitChar())) { + MesPcnException.throwMesBusiException("箱类别代号【%s】分隔符不能为空", packingDefine.getPackCode()); + } + String[] split = mesPackageDetail.getPackageNo().split("\\" + packingDefine.getSplitChar()); + //获取序列号 + checkSerial(packingDefine, split); + //工厂校验 + checkOrganizeCode(mesPackageDetail, packingDefine, split); + //获取物料信息是否存在 + mesPart = getMesPart(mesPackageDetail, packingDefine, split); + //获取数量信息是否存在 + qty = getQty(packingDefine, split); + } + MesPackage packages = getMesPackage(mesPackageDetail, mesPart, qty, packingDefine,packageOneCode); + return mesPackageRDao.insert(packages); } - //获取包装定义 - MesPackingDefine packingDefine = getMesPackingDefine(mesPackageDetail); - //解析获取信息保存 - if (StringUtils.isEmpty(packingDefine.getSplitChar())) { - MesPcnException.throwMesBusiException("箱类别代号【%s】分隔符不能为空", packingDefine.getPackCode()); - } - String[] split = mesPackageDetail.getPackageNo().split("\\" + packingDefine.getSplitChar()); - //获取序列号 - checkSerial(packingDefine, split); - //工厂校验 - checkOrganizeCode(mesPackageDetail, packingDefine, split); - //获取物料信息是否存在 - MesPart mesPart = getMesPart(mesPackageDetail, packingDefine, split); - //获取数量信息是否存在 - Double qty = getQty(packingDefine, split); - MesPackage packages = getMesPackage(mesPackageDetail, mesPart, qty, packingDefine); - return mesPackageRDao.insert(packages); } else { checkNotNull(mesPackageDetail); //校验过程条码是否存在 @@ -425,7 +440,7 @@ public class MesBoxingErrorProofingService implements IMesBoxingErrorProofingSer return Double.parseDouble(split[packingDefine.getQtyIndex() - 1]); } - private MesPackage getMesPackage(MesPackageDetail mesPackageDetail, MesPart mesPart, Double qty, MesPackingDefine packingDefine) { + private MesPackage getMesPackage(MesPackageDetail mesPackageDetail, MesPart mesPart, Double qty, MesPackingDefine packingDefine,String packageOneCode) { //保存包装信息 MesPackage packages = new MesPackage(); packages.setPackageNo(mesPackageDetail.getPackageNo()); @@ -436,6 +451,7 @@ public class MesBoxingErrorProofingService implements IMesBoxingErrorProofingSer packages.setIsSealed(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()); packages.setPrintStatus(MesPcnEnumUtil.PACKAGE_PRINT_STATUS.UNPRINTED.getValue()); packages.setPackageSn(packingDefine.getPackCode()); + packages.setPackageOneCode(packageOneCode); packages.setOrganizeCode(mesPackageDetail.getOrganizeCode()); ConvertBean.serviceModelInitialize(packages, mesPackageDetail.getCreateUser()); return packages; @@ -447,6 +463,12 @@ public class MesBoxingErrorProofingService implements IMesBoxingErrorProofingSer return mesPackageRDao.getByProperty(packBean); } + private MesPackageSn getMesPackageSn(String organizeCode, String packageNo) { + DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode); + DdlPreparedPack.getStringEqualPack(packageNo, "packageNo", packBean); + return mesPackageSnRDao.getByProperty(packBean); + } + private MesPackingDefine getMesPackingDefine(MesPackageDetail mesPackageDetail) { DdlPackBean packBean = DdlPackBean.getDdlPackBean(mesPackageDetail.getOrganizeCode()); DdlPreparedPack.getStringEqualPack(mesPackageDetail.getScanType(), "scanType", packBean); diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/rulematch/MesNumberRuleMatchDispatchService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/rulematch/MesNumberRuleMatchDispatchService.java index 6cc23d6..68a8d84 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/rulematch/MesNumberRuleMatchDispatchService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/rulematch/MesNumberRuleMatchDispatchService.java @@ -1,6 +1,8 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch; import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesNumberRuleMatchDispatchService; +import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionAssemblyNosortContext; +import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionAssemblySortContext; import cn.estsh.i3plus.pojo.mes.bean.MesProdRuleNosortCfg; import cn.estsh.i3plus.pojo.mes.bean.MesProdRuleSortCfg; import cn.estsh.impp.framework.boot.util.SpringContextsUtil; @@ -27,9 +29,11 @@ public class MesNumberRuleMatchDispatchService implements IMesNumberRuleMatchDis if (numberRuleList.get(0) instanceof MesProdRuleNosortCfg) numberRuleList.forEach(o -> matchNumberRule(organizeCode, sn, resultList, o, "mesNumberRuleMatchRegularExpressionService",o, ((MesProdRuleNosortCfg) o).getInPartNoRule())); - if (numberRuleList.get(0) instanceof MesProdRuleSortCfg) numberRuleList.forEach(o -> matchNumberRule(organizeCode, sn, resultList, o, "mesNumberRuleMatchRegularExpressionService",o, ((MesProdRuleNosortCfg) o).getInPartNoRule())); + if (numberRuleList.get(0) instanceof MesProductionAssemblyNosortContext) numberRuleList.forEach(o -> matchNumberRule(organizeCode, sn, resultList, o, "mesNumberRuleMatchRegularExpressionService",o, ((MesProdRuleNosortCfg) o).getInPartNoRule())); + if (numberRuleList.get(0) instanceof MesProductionAssemblySortContext) numberRuleList.forEach(o -> matchNumberRule(organizeCode, sn, resultList, o, "mesNumberRuleMatchRegularExpressionService",o, ((MesProdRuleNosortCfg) o).getInPartNoRule())); + return resultList; } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesAssemblyMatchNosortStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesAssemblyMatchNosortStepService.java index efc18ad..02d4b14 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesAssemblyMatchNosortStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesAssemblyMatchNosortStepService.java @@ -1,239 +1,293 @@ -//package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step; -// -//import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesNumberRuleMatchDispatchService; -//import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProdRuleCfgExtService; -//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.pojo.context.*; -//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.pojo.base.enumutil.CommonEnumUtil; -//import cn.estsh.i3plus.pojo.mes.bean.MesProdRuleNosortCfg; -//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 lombok.extern.slf4j.Slf4j; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.stereotype.Service; -//import org.springframework.util.CollectionUtils; -//import org.springframework.util.StringUtils; -// -//import java.util.ArrayList; -//import java.util.List; -//import java.util.Optional; -//import java.util.stream.Collectors; -//import java.util.stream.Stream; -// -///** -// * @Description : 装配件匹配工步 【非排序】 -// * @Author : wangjie -// **/ -//@Slf4j -//@Service("mesAssemblyMatchNosortStepService") -//public class MesAssemblyMatchNosortStepService extends BaseStepService { -// -// @Autowired -// private IFsmCommonService fsmCommonService; -// -// @Autowired -// private IMesProductionProcessContextStepService productionProcessContextStepService; -// -// @Autowired -// private IMesProductionDispatchContextStepService productionDispatchContextStepService; -// -// @Autowired -// private IMesProdRuleCfgExtService prodRuleCfgExtService; -// -// @Autowired -// private IMesNumberRuleMatchDispatchService numberRuleMatchDispatchService; -// -// @Override -// public StepResult execute(StationRequestBean reqBean) { -// -// StationResultBean resultBean = new StationResultBean(); -// -// StepResult stepResult = StepResult.getSuccessComplete(); -// -// //获取上下文信息 -// MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getCurCellEquipment(reqBean); -// -// //配置错误 抛出异常 -// if (!productionProcessContext.getSuccess()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage()); -// -// //存储生产过程上下文对象 -// productionProcessContextStepService.saveProductionProcessContext(reqBean, productionProcessContext); -// -// //从上下文中取出生产线对象 -// MesCellEquipContext cellEquipContext = productionProcessContext.getCurCellEquip(); -// -// //获取上下文产出零件数据信息集合 -// List productionPartContextList = productionDispatchContextStepService.getProductionPartContext(reqBean); -// -// //获取上下文进料零件条码信息集合 -// List productionPsInContextList = productionDispatchContextStepService.getProductionPsInContext(reqBean); -// -// //获取上下文产品加工规则数据信息集合 -// List prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean); -// -// //获取上下文生产扫/读信息:装配件条码 -// List equipVariableCollectContextList = productionDispatchContextStepService.getScanAssemblySnContext(reqBean); -// -// //删除上下文扫/读信息:装配件条码 -// if (!CollectionUtils.isEmpty(equipVariableCollectContextList)) productionDispatchContextStepService.deleteScanAssemblySnContext(reqBean); -// -// //未知腔数[工位参数] -// String cavityUnknownCfg = fsmCommonService.doHandleFsmWcpcMapDataForDoScan(reqBean).get(MesPcnExtConstWords.CAVITY_UNKNOWN_CFG); -// -// //计算实际需要的腔数 -//// Integer needCavity = getNeedCavity(productionPartContextList, productionPsInContextList, cellEquipContext); -// -// if (!CollectionUtils.isEmpty(productionPartContextList) && !CollectionUtils.isEmpty(productionPsInContextList)) //存在产出零件 存在进料主条码 -// doMatchAssemblyHasPpAndPs(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, productionPartContextList, productionPsInContextList, prodRuleContextList, equipVariableCollectContextList); -// else if (!CollectionUtils.isEmpty(productionPartContextList)) //存在产出零件 不存在进料主条码 -// doMatchAssemblyHasPp(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, productionPartContextList, prodRuleContextList, equipVariableCollectContextList); -// else if (!CollectionUtils.isEmpty(productionPsInContextList)) //不存在产出零件 存在进料主条码 -// doMatchAssemblyHasPs(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, productionPsInContextList, prodRuleContextList, equipVariableCollectContextList); -// else if (StringUtils.isEmpty(cavityUnknownCfg)) //不存在产出零件 不存在进料主条码 根据设备腔数反向匹配加工规则 -// doMatchAssemblyHasCavity(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, prodRuleContextList, equipVariableCollectContextList); -// else //不存在产出零件 不存在进料主条码 未知腔数 反向完成匹配后获取对应的加工规则 -// doMatchAssemblyUnknowCavity(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, prodRuleContextList, equipVariableCollectContextList); -// -// -// return stepResult; -// -// } -// -//// //计算实际需要的腔数 -//// private Integer getNeedCavity(List productionPartContextList, List productionPsInContextList, MesCellEquipContext cellEquipContext) { -//// -//// List ppList = CollectionUtils.isEmpty(productionPartContextList) ? null : productionPartContextList.stream().filter(o -> (null != o && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList()); -//// List psList = CollectionUtils.isEmpty(productionPsInContextList) ? null : productionPsInContextList.stream().filter(o -> (null != o && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList()); -//// -//// Integer ppSize = CollectionUtils.isEmpty(ppList) ? MesPcnExtConstWords.ZERO : ppList.size(); -//// Integer psSize = CollectionUtils.isEmpty(psList) ? MesPcnExtConstWords.ZERO : psList.size(); -//// -//// if (!CollectionUtils.isEmpty(productionPartContextList) && !CollectionUtils.isEmpty(productionPsInContextList)) return (productionPartContextList.size() == productionPsInContextList.size()) ? psSize -//// -//// -//// } -// -// //存在产出零件 存在进料主条码 -// private StepResult doMatchAssemblyHasPpAndPs(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List productionPartContextList, List productionPsInContextList, List prodRuleContextList, List equipVariableCollectContextList) { -// -// if (CollectionUtils.isEmpty(prodRuleContextList)) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "当前上下文中不存在非排序加工规则数据,请重置工序!"); -// -// //存在产出零件 存在进料主条码 不存在待验证装配件条码 -// if (CollectionUtils.isEmpty(equipVariableCollectContextList)) -// return hasUnBindAssembly(prodRuleContextList) ? stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg("当前上下文中不存在待验证的装配件条码,但存在未装配的装配件清单!") : -// (productionPartContextList.size() == productionPsInContextList.size() ? stepResult : -// stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg(String.format("当前上下文中不存在待验证的装配件条码,请扫描第[%s]腔主条码,共[%s]腔", productionPsInContextList.size() + MesPcnExtConstWords.ONE, productionPartContextList.size()))); -// -// Boolean result = false; -// -// //遍历产品加工规则 -// for (MesProdRuleContext prodRuleContext : prodRuleContextList) { -// -// //没有装配件的条件 -// if (null == prodRuleContext || StringUtils.isEmpty(prodRuleContext.getAssemblyDataJson())) continue; -// -// //获取非排序装配件清单 -// List productionAssemblyNosortContextList = prodRuleContext.getNosortAssemblyDataContext(); -// -// //遍历装配件清单 -// for (MesProductionAssemblyNosortContext productionAssemblyNosortContext : productionAssemblyNosortContextList) { -// -// //已装配 -// if (null == productionAssemblyNosortContext || productionAssemblyNosortContext.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) != 0) continue; -// -// //遍历装配件条码 -// for (MesEquipVariableCollectContext equipVariableCollectContext : equipVariableCollectContextList) { -// -// //已被消费 -// if (null == equipVariableCollectContext || equipVariableCollectContext.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0) continue; -// -// //匹配规则 -// List filterList = (List) numberRuleMatchDispatchService.matchNumberRule(reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), Stream.of(productionAssemblyNosortContext).collect(Collectors.toList())); -// -// //匹配失败 -// if (CollectionUtils.isEmpty(filterList)) continue; -// -// result = true; -// -// //匹配成功 -// equipVariableCollectContext.isConsume(); -// -// //装配件清单该数据标记已装配 -// productionAssemblyNosortContext.assemblyStatus().assemblySn(equipVariableCollectContext.getEquipVariableValue()); -// -// } -// -// //是否验证顺序装配 -// if (!StringUtils.isEmpty(prodRuleContext.getIsCheckBindSeq()) && -// prodRuleContext.getIsCheckBindSeq().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0 && equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0 && -// productionAssemblyNosortContext.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) != 0) break; -// -// } -// -// //TODO 发送设备加工参数 -// if (equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0) doSendEquipProdParam(reqBean, resultBean, stepResult, prodRuleContext, productionAssemblyNosortContextList); -// -// } -// -// if (equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0 && result) -// -// -// -// -// return stepResult; -// -// } -// -// //验证是否存在待绑定数据 -// private Boolean hasUnBindAssembly(List prodRuleContextList) { -// Boolean hasUnBindAssembly = false; -// for (MesProdRuleContext prodRuleContext : prodRuleContextList) { -// if (null == prodRuleContext || StringUtils.isEmpty(prodRuleContext.getAssemblyDataJson())) continue; -// List productionAssemblyNosortContextList = prodRuleContext.getNosortAssemblyDataContext(); -// Optional optional = productionAssemblyNosortContextList.stream().filter(o -> (null != o && o.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) == 0)).findFirst(); -// if (null == optional || !optional.isPresent()) continue; -// hasUnBindAssembly = true; -// break; -// } -// return hasUnBindAssembly; -// } -// -// -// -// -// -// -// -// -// -// -// //存在产出零件 不存在进料主条码 -// private void doMatchAssemblyHasPp(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List productionPartContextList, List prodRuleContextList, List equipVariableCollectContextList) { -// } -// -// //不存在产出零件 存在进料主条码 -// private void doMatchAssemblyHasPs(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List productionPsInContextList, List prodRuleContextList, List equipVariableCollectContextList) { -// } -// -// //不存在产出零件 不存在进料主条码 根据设备腔数反向匹配加工规则 -// private void doMatchAssemblyHasCavity(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List prodRuleContextList, List equipVariableCollectContextList) { -// } -// -// //不存在产出零件 不存在进料主条码 未知腔数 反向完成匹配后获取对应的加工规则 -// private void doMatchAssemblyUnknowCavity(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List prodRuleContextList, List equipVariableCollectContextList) { -// } -// -// //TODO 发送设备加工参数 -// private void doSendEquipProdParam(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProdRuleContext prodRuleContext, List productionAssemblyNosortContextList) { -// Optional optional = productionAssemblyNosortContextList.stream().filter(o -> (null != o && o.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) == 0)).findFirst(); -// if (null != optional && optional.isPresent()) return; -// -// } -// -//} +package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step; + +import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesNumberRuleMatchDispatchService; +import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProdRuleCfgExtService; +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.pojo.context.*; +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.pojo.base.enumutil.CommonEnumUtil; +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 lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @Description : 装配件匹配工步 【非排序】 + * @Author : wangjie + **/ +@Slf4j +@Service("mesAssemblyMatchNosortStepService") +public class MesAssemblyMatchNosortStepService extends BaseStepService { + + @Autowired + private IFsmCommonService fsmCommonService; + + @Autowired + private IMesProductionProcessContextStepService productionProcessContextStepService; + + @Autowired + private IMesProductionDispatchContextStepService productionDispatchContextStepService; + + @Autowired + private IMesProdRuleCfgExtService prodRuleCfgExtService; + + @Autowired + private IMesNumberRuleMatchDispatchService numberRuleMatchDispatchService; + + @Override + public StepResult execute(StationRequestBean reqBean) { + + StationResultBean resultBean = new StationResultBean(); + + StepResult stepResult = StepResult.getSuccessComplete(); + + //获取上下文信息 + MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getCurCellEquipment(reqBean); + + //配置错误 抛出异常 + if (!productionProcessContext.getSuccess()) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage()); + + //存储生产过程上下文对象 + productionProcessContextStepService.saveProductionProcessContext(reqBean, productionProcessContext); + + //获取上下文产品加工规则数据信息集合 + List prodRuleContextList = productionDispatchContextStepService.getProdRuleDataContext(reqBean); + + if (CollectionUtils.isEmpty(prodRuleContextList)) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "当前上下文中不存在非排序加工规则数据,请重置工序!"); + + //从上下文中取出生产线对象 + MesCellEquipContext cellEquipContext = productionProcessContext.getCurCellEquip(); + + + //获取上下文产出零件数据信息集合 + List productionPartContextList = productionDispatchContextStepService.getProductionPartContext(reqBean); + + //获取上下文进料零件条码信息集合 + List productionPsInContextList = productionDispatchContextStepService.getProductionPsInContext(reqBean); + + //获取上下文生产扫/读信息:装配件条码 + List equipVariableCollectContextList = productionDispatchContextStepService.getScanAssemblySnContext(reqBean); + + //删除上下文扫/读信息:装配件条码 + if (!CollectionUtils.isEmpty(equipVariableCollectContextList)) productionDispatchContextStepService.deleteScanAssemblySnContext(reqBean); + + //未知腔数[工位参数] + String cavityUnknownCfg = fsmCommonService.doHandleFsmWcpcMapDataForDoScan(reqBean).get(MesPcnExtConstWords.CAVITY_UNKNOWN_CFG); + + if (!CollectionUtils.isEmpty(productionPartContextList) && !CollectionUtils.isEmpty(productionPsInContextList)) //存在产出零件 存在进料主条码 + doMatchAssemblyHasPpAndPs(reqBean, resultBean, stepResult, productionPartContextList, productionPsInContextList, prodRuleContextList, equipVariableCollectContextList); + else if (!CollectionUtils.isEmpty(productionPartContextList)) //存在产出零件 不存在进料主条码 + doMatchAssemblyHasPp(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, productionPartContextList, prodRuleContextList, equipVariableCollectContextList); + else if (!CollectionUtils.isEmpty(productionPsInContextList)) //不存在产出零件 存在进料主条码 + doMatchAssemblyHasPs(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, productionPsInContextList, prodRuleContextList, equipVariableCollectContextList); + else if (StringUtils.isEmpty(cavityUnknownCfg)) //不存在产出零件 不存在进料主条码 根据设备腔数反向匹配加工规则 + doMatchAssemblyHasCavity(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, prodRuleContextList, equipVariableCollectContextList); + else //不存在产出零件 不存在进料主条码 未知腔数 反向完成匹配后获取对应的加工规则 + doMatchAssemblyUnknowCavity(reqBean, resultBean, stepResult, productionProcessContext, cellEquipContext, prodRuleContextList, equipVariableCollectContextList); + + return stepResult; + + } + + //存在产出零件 存在进料主条码 + private StepResult doMatchAssemblyHasPpAndPs(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, + List productionPartContextList, List productionPsInContextList, + List prodRuleContextList, List equipVariableCollectContextList) { + + //存在产出零件 存在进料主条码 不存在待验证装配件条码 + if (CollectionUtils.isEmpty(equipVariableCollectContextList)) + return hasUnBindAssembly(prodRuleContextList) ? + stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg("当前上下文中不存在待验证的装配件条码,但还存在未装配的装配件清单!") : + (productionPartContextList.size() == productionPsInContextList.size() ? stepResult : + stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg( + String.format("当前上下文中不存在待验证的装配件条码,请扫描第[%s]腔主条码,共[%s]腔!", productionPsInContextList.size() + MesPcnExtConstWords.ONE, productionPartContextList.size()))); + + //遍历产品加工规则 + for (MesProdRuleContext prodRuleContext : prodRuleContextList) { + + //没有装配件的条件 + if (null == prodRuleContext || StringUtils.isEmpty(prodRuleContext.getAssemblyDataJson())) continue; + + //获取非排序装配件清单 + List productionAssemblyNosortContextList = prodRuleContext.getNosortAssemblyDataContext(); + + //遍历装配件清单 + for (MesProductionAssemblyNosortContext productionAssemblyNosortContext : productionAssemblyNosortContextList) { + + //已装配 + if (null == productionAssemblyNosortContext || productionAssemblyNosortContext.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) != 0) continue; + + //遍历装配件条码 + for (MesEquipVariableCollectContext equipVariableCollectContext : equipVariableCollectContextList) { + + //已被消费 + if (null == equipVariableCollectContext || equipVariableCollectContext.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0) continue; + + //匹配规则 + List filterList = (List) + numberRuleMatchDispatchService.matchNumberRule(reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), Stream.of(productionAssemblyNosortContext).collect(Collectors.toList())); + + //匹配失败 + if (CollectionUtils.isEmpty(filterList)) continue; + + //匹配成功 + equipVariableCollectContext.isConsume(); + + //装配件清单该数据标记已装配 + productionAssemblyNosortContext.assemblyStatus().assemblySn(equipVariableCollectContext.getEquipVariableValue()); + + } + + //是否验证顺序装配 + if (!StringUtils.isEmpty(prodRuleContext.getIsCheckBindSeq()) && + prodRuleContext.getIsCheckBindSeq().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0 && equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0 && + productionAssemblyNosortContext.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) != 0) break; + + } + + //TODO 发送设备加工参数 + if (equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0) doSendEquipProdParam(reqBean, resultBean, stepResult, prodRuleContext, productionAssemblyNosortContextList); + + } + + List filterList = equipVariableCollectContextList.stream().filter(o -> (null != o && o.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList()); + + if (CollectionUtils.isEmpty(filterList)) { + + Boolean hasUnBindAssembly = hasUnBindAssembly(prodRuleContextList); + if ((!hasUnBindAssembly && equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) == 0) || equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0) + productionDispatchContextStepService.saveProdRuleDataContext(reqBean, prodRuleContextList); + + String msg = String.format("当前上下文中的装配件条码%s匹配完成", filterList.stream().filter(o -> null != o).map(MesEquipVariableCollectContext::getEquipVariableValue).collect(Collectors.toList()).toString()); + return hasUnBindAssembly ? stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg(String.format("%s,但还存在未装配的装配件清单!", msg)) : + (productionPartContextList.size() == productionPsInContextList.size() ? stepResult.msg(msg) : + stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg( + String.format("%s,请扫描第[%s]腔主条码,共[%s]腔!", msg, productionPsInContextList.size() + MesPcnExtConstWords.ONE, productionPartContextList.size()))); + } else { + String msg = String.format("当前上下文中的装配件条码%s匹配失败", filterList.stream().filter(o -> null != o).map(MesEquipVariableCollectContext::getEquipVariableValue).collect(Collectors.toList()).toString()); + return hasUnBindAssembly(prodRuleContextList) ? stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg(String.format("%s,但还存在未装配的装配件清单!", msg)) : + (productionPartContextList.size() == productionPsInContextList.size() ? stepResult.msg(String.format("%s,但不存在未装配的装配件清单!", msg)) : + stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg( + String.format("%s,请扫描第[%s]腔主条码,共[%s]腔!", msg, productionPsInContextList.size() + MesPcnExtConstWords.ONE, productionPartContextList.size()))); + + } + + } + + //验证是否存在待绑定数据 + private Boolean hasUnBindAssembly(List prodRuleContextList) { + Boolean hasUnBindAssembly = false; + for (MesProdRuleContext prodRuleContext : prodRuleContextList) { + if (null == prodRuleContext || StringUtils.isEmpty(prodRuleContext.getAssemblyDataJson())) continue; + List productionAssemblyNosortContextList = prodRuleContext.getNosortAssemblyDataContext(); + Optional optional = productionAssemblyNosortContextList.stream().filter(o -> (null != o && o.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) == 0)).findFirst(); + if (null == optional || !optional.isPresent()) continue; + hasUnBindAssembly = true; + break; + } + return hasUnBindAssembly; + } + + //存在产出零件 不存在进料主条码 + private StepResult doMatchAssemblyHasPp(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List productionPartContextList, List prodRuleContextList, List equipVariableCollectContextList) { + + //存在产出零件 存在进料主条码 不存在待验证装配件条码 + if (CollectionUtils.isEmpty(equipVariableCollectContextList)) + return hasUnBindAssembly(prodRuleContextList) ? stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg("当前上下文中不存在待验证的装配件条码,但还存在未装配的装配件清单!") : stepResult; + + //遍历产品加工规则 + for (MesProdRuleContext prodRuleContext : prodRuleContextList) { + + //没有装配件的条件 + if (null == prodRuleContext || StringUtils.isEmpty(prodRuleContext.getAssemblyDataJson())) continue; + + //获取非排序装配件清单 + List productionAssemblyNosortContextList = prodRuleContext.getNosortAssemblyDataContext(); + + //遍历装配件清单 + for (MesProductionAssemblyNosortContext productionAssemblyNosortContext : productionAssemblyNosortContextList) { + + //已装配 + if (null == productionAssemblyNosortContext || productionAssemblyNosortContext.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) != 0) continue; + + //遍历装配件条码 + for (MesEquipVariableCollectContext equipVariableCollectContext : equipVariableCollectContextList) { + + //已被消费 + if (null == equipVariableCollectContext || equipVariableCollectContext.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0) continue; + + //匹配规则 + List filterList = (List) + numberRuleMatchDispatchService.matchNumberRule(reqBean.getOrganizeCode(), equipVariableCollectContext.getEquipVariableValue(), Stream.of(productionAssemblyNosortContext).collect(Collectors.toList())); + + //匹配失败 + if (CollectionUtils.isEmpty(filterList)) continue; + + //匹配成功 + equipVariableCollectContext.isConsume(); + + //装配件清单该数据标记已装配 + productionAssemblyNosortContext.assemblyStatus().assemblySn(equipVariableCollectContext.getEquipVariableValue()); + + } + + //是否验证顺序装配 + if (!StringUtils.isEmpty(prodRuleContext.getIsCheckBindSeq()) && + prodRuleContext.getIsCheckBindSeq().compareTo(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) == 0 && equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0 && + productionAssemblyNosortContext.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) != 0) break; + + } + + //TODO 发送设备加工参数 + if (equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0) doSendEquipProdParam(reqBean, resultBean, stepResult, prodRuleContext, productionAssemblyNosortContextList); + + } + + List filterList = equipVariableCollectContextList.stream().filter(o -> (null != o && o.getIsConsume().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).collect(Collectors.toList()); + + if (CollectionUtils.isEmpty(filterList)) { + Boolean hasUnBindAssembly = hasUnBindAssembly(prodRuleContextList); + if ((!hasUnBindAssembly && equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) == 0) || equipVariableCollectContextList.get(0).getMessageSource().compareTo(MesExtEnumUtil.CELL_MESSAGE_SOURCE.READ.getValue()) != 0) + productionDispatchContextStepService.saveProdRuleDataContext(reqBean, prodRuleContextList); + String msg = String.format("当前上下文中的装配件条码%s匹配完成", filterList.stream().filter(o -> null != o).map(MesEquipVariableCollectContext::getEquipVariableValue).collect(Collectors.toList()).toString()); + return hasUnBindAssembly ? stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg(String.format("%s,但还存在未装配的装配件清单!", msg)) : stepResult.msg(msg); + } else { + String msg = String.format("当前上下文中的装配件条码%s匹配失败", filterList.stream().filter(o -> null != o).map(MesEquipVariableCollectContext::getEquipVariableValue).collect(Collectors.toList()).toString()); + return hasUnBindAssembly(prodRuleContextList) ? stepResult.isCompleted(false).nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_ASSEMBLY).msg(String.format("%s,但还存在未装配的装配件清单!", msg)) : stepResult.msg(msg); + } + + } + + //不存在产出零件 存在进料主条码 + private void doMatchAssemblyHasPs(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List productionPsInContextList, List prodRuleContextList, List equipVariableCollectContextList) { + } + + //不存在产出零件 不存在进料主条码 根据设备腔数反向匹配加工规则 + private void doMatchAssemblyHasCavity(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List prodRuleContextList, List equipVariableCollectContextList) { + } + + //不存在产出零件 不存在进料主条码 未知腔数 反向完成匹配后获取对应的加工规则 + private void doMatchAssemblyUnknowCavity(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProductionProcessContext productionProcessContext, MesCellEquipContext cellEquipContext, List prodRuleContextList, List equipVariableCollectContextList) { + } + + //TODO 发送设备加工参数 + private void doSendEquipProdParam(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesProdRuleContext prodRuleContext, List productionAssemblyNosortContextList) { + Optional optional = productionAssemblyNosortContextList.stream().filter(o -> (null != o && o.getAssemblyStatus().compareTo(MesExtEnumUtil.ASSEMBLY_STATUS.ASSEMBLY_STATUS_30.getValue()) == 0)).findFirst(); + if (null != optional && optional.isPresent()) return; + + } + +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesMouldRecordGenerateStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesMouldRecordGenerateStepService.java index 58c21a2..66debf6 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesMouldRecordGenerateStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesMouldRecordGenerateStepService.java @@ -95,9 +95,6 @@ public class MesMouldRecordGenerateStepService extends BaseStepService { DdlPreparedPack.getStringEqualPack(equipmentCode, "equipmentCode", packBean); DdlPreparedPack.getStringEqualPack(mouldNo, "mouldNo", packBean); MesMouldMappingCfg mesMouldMappingCfg = mesMouldMappingCfgRepository.getByProperty(packBean); - //配置错误 抛出异常 todo 没找到不能报错,就不填这个字段 - if (mesMouldMappingCfg == null) execExpSendMsgAndThrowEx(reqBean, resultBean, - String.format("请检查模具映射关系维护,根据设备[%s],模具号[%s]", equipmentCode, mouldNo)); MesProdMouldRecord mesProductionRecord = getMesProdMouldRecord(mesCellEquipContext, mouldNo, mesMouldMappingCfg); @@ -111,8 +108,8 @@ public class MesMouldRecordGenerateStepService extends BaseStepService { private MesProdMouldRecord getMesProdMouldRecord(MesCellEquipContext mesCellEquipContext, String mouldNo, MesMouldMappingCfg mesMouldMappingCfg) { MesProdMouldRecord mesProdMouldRecord = new MesProdMouldRecord(); mesProdMouldRecord.setEquipId(mesCellEquipContext.getEquipId()); - mesProdMouldRecord.setMeterName(mesMouldMappingCfg.getMeterName()); - mesProdMouldRecord.setAssetNum(mesMouldMappingCfg.getAssetNum()); + mesProdMouldRecord.setMeterName(mesMouldMappingCfg == null ? null : mesMouldMappingCfg.getMeterName()); + mesProdMouldRecord.setAssetNum(mesMouldMappingCfg == null ? null : mesMouldMappingCfg.getAssetNum()); mesProdMouldRecord.setMouldNo(mouldNo); mesProdMouldRecord.setEquipmentCode(mesCellEquipContext.getEquipmentCode()); return mesProdMouldRecord; diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnGenerateStepServiceBak.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnGenerateStepServiceBak.java new file mode 100644 index 0000000..53932bd --- /dev/null +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnGenerateStepServiceBak.java @@ -0,0 +1,200 @@ +package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step; + +import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPojoVersionService; +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.apiservice.util.MesPcnException; +import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPartContext; +import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext; +import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionPsOutContext; +import cn.estsh.i3plus.mes.pcn.api.iservice.busi.ISyncFuncService; +import cn.estsh.i3plus.mes.pcn.serviceimpl.fsm.BaseStepService; +import cn.estsh.i3plus.platform.common.convert.ConvertBean; +import cn.estsh.i3plus.platform.common.tool.JsonUtilTool; +import cn.estsh.i3plus.pojo.base.bean.DdlPackBean; +import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker; +import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack; +import cn.estsh.i3plus.pojo.mes.bean.MesPart; +import cn.estsh.i3plus.pojo.mes.bean.MesPojoVersion; +import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn; +import cn.estsh.i3plus.pojo.mes.bean.MesWorkCell; +import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel; +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.MesPartRepository; +import cn.estsh.i3plus.pojo.mes.repository.MesProduceSnRepository; +import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil; +import cn.hutool.core.date.DateUtil; +import com.google.common.base.Objects; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Description : 生成零件条码 + * @Author : wangjie + **/ +@Slf4j +@Service +public class MesProductSnGenerateStepServiceBak extends BaseStepService { + @Autowired + private SnowflakeIdMaker snowflakeIdMaker; + + @Autowired + private IMesProductionProcessContextStepService productionProcessContextStepService; + + @Autowired + private MesPartRepository mesPartRepository; + + @Autowired + private MesProduceSnRepository mesProduceSnRepository; + + @Autowired + private ISyncFuncService syncFuncService; + + public static final String ORDER_NO_JIS_SORT = "ORDER_NO_JIS_SORT"; + + @Autowired + private IMesProductionDispatchContextStepService mesProductionDispatchContextStepService; + + @Autowired + private IMesPojoVersionService mesPojoVersionService; + + /**todo 有产成无进料场景 + * todo 根据装配件条码没有找到加工规则,如果需要跳过装配件绑定,直接生成条码,就需要不看加工规则,直接根据产成零件生成条码,当前设计方式就需要变更。 + * @param reqBean + * @return + */ + @Override + public StepResult execute(StationRequestBean reqBean) { + + StationResultBean resultBean = new StationResultBean(); + + StepResult stepResult = StepResult.getSuccessComplete(); + String result = mesProductionDispatchContextStepService.getProductResultContext(reqBean); + // 获取上下文信息 + MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getEquipmentVariableList(reqBean, MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PRODUCTION.getValue()); + MesWorkCell mesWorkCell = productionProcessContext.getWorkCell(); + // 获取产出零件信息 + List productionPartContextList = mesProductionDispatchContextStepService.getProductionPartContext(reqBean); + if (CollectionUtils.isEmpty(productionPartContextList)) { + foundExThrow(reqBean, "必过工步不允许跳过"); + } + // 获取零件号,可能存在多个 + List partNoList = productionPartContextList.stream().map(MesProductionPartContext::getPartNo).collect(Collectors.toList()); + // 根据零件号组装产品条码信息 + List mesProduceSns = generateSn(reqBean, productionProcessContext, mesWorkCell, partNoList, result); + // 保存条码信息 + mesProduceSnRepository.saveAll(mesProduceSns); + + savePojoVersion(mesProduceSns); + + List mesProductionPsOutContexts = new ArrayList<>(); + for (MesProduceSn mesProduceSn : mesProduceSns) { + MesProductionPsOutContext mesProductionPsOutContext = new MesProductionPsOutContext(); + BeanUtils.copyProperties(mesProduceSn, mesProductionPsOutContext); + mesProductionPsOutContexts.add(mesProductionPsOutContext); + } + // 放到上下文 + mesProductionDispatchContextStepService.saveProductionPsOutContext(reqBean, mesProductionPsOutContexts); + + return execSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "生成零件条码成功"); + } + + private void savePojoVersion(List mesProduceSns) { + mesProduceSns.forEach(mesProduceSn -> { + MesPojoVersion version = new MesPojoVersion(); + version.setRefId(mesProduceSn.getId()); + version.setRefClass(mesProduceSn.getClass().getName()); + version.setBean(JsonUtilTool.encode(mesProduceSn)); + version.setCreateUser(version.getCreateUser()); + version.setModifyUser(version.getModifyUser()); + version.setVersionMethodName("insert"); + version.setOrganizeCode(mesProduceSn.getOrganizeCode()); + mesPojoVersionService.recordPojoVersion(version); + }); + } + + /** + * 根据零件号组装产品条码信息 + * @param reqBean + * @param productionProcessContext + * @param mesWorkCell + * @param partNoList + * @return + */ + private List generateSn(StationRequestBean reqBean, MesProductionProcessContext productionProcessContext, MesWorkCell mesWorkCell, List partNoList, String result) { + List mesProduceSns = new ArrayList<>(); + for (String partNo : partNoList) { + DdlPackBean packBean = DdlPackBean.getDdlPackBean(reqBean.getOrganizeCode()); + DdlPreparedPack.getStringEqualPack(partNo, "partNo", packBean); + MesPart mesPart = mesPartRepository.getByProperty(packBean); + if (mesPart == null) { + MesPcnException.throwFlowException("零件号不存在"); + } + // 根据条码规则生成条码 + String sn = generateByRule(mesPart); + // 组装条码信息 + MesProduceSn mesProduceSn = generateMesProduceSn(mesPart, sn, mesWorkCell, productionProcessContext, reqBean, result); + ConvertBean.serviceModelInitialize(mesProduceSn, reqBean.getUserInfo()); + mesProduceSns.add(mesProduceSn); + } + return mesProduceSns; + } + + /** + * 生成条码 + * @param mesPart + * @return + */ + private String generateByRule(MesPart mesPart) { + //生成工单号 + GenSerialNoModel genSerialNoModel = new GenSerialNoModel(ORDER_NO_JIS_SORT); + genSerialNoModel.setPartNo(mesPart.getPartNo()); + List resultList = syncFuncService.syncSerialNo(genSerialNoModel, mesPart.getCreateUser(), mesPart.getOrganizeCode(), 1).getResultList(); + return resultList.get(0); + } + + private MesProduceSn generateMesProduceSn(MesPart mesPart, String sn, MesWorkCell mesWorkCell,MesProductionProcessContext productionProcessContext, StationRequestBean reqBean, String result) { + long serialNum = snowflakeIdMaker.nextId(); + + MesProduceSn mesProduceSn = new MesProduceSn(); + mesProduceSn.setSerialNumber(serialNum + ""); + mesProduceSn.setProductSn(sn); + mesProduceSn.setCustSn(sn); + mesProduceSn.setPartNo(mesPart.getPartNo()); + mesProduceSn.setPartName(mesPart.getPartName()); + mesProduceSn.setAreaCode(mesWorkCell.getAreaCode()); + mesProduceSn.setWorkCenterCode(mesWorkCell.getWorkCenterCode()); + mesProduceSn.setWorkCellCode(mesWorkCell.getWorkCellCode()); + mesProduceSn.setProcessLabelTemplate(mesPart.getProcessLabelTemplate()); + mesProduceSn.setCustLabelTemplate(mesPart.getCustLabelTemplate()); + mesProduceSn.setProcessLabelTemplate(mesPart.getProcessLabelTemplate()); + mesProduceSn.setQty(1d); + mesProduceSn.setSnStatus(10); + Integer qcStatus = MesExtEnumUtil.PRODUCE_QC_STATUS.QUALIFIED.getValue(); + if (Objects.equal(MesExtEnumUtil.EQUIP_VARIABLE_CFG_CATEGORY.PRODUCT_SCRAP.getValue(), result)) { + qcStatus = MesExtEnumUtil.PRODUCE_QC_STATUS.SCRAP.getValue(); + } else if (Objects.equal(MesExtEnumUtil.EQUIP_VARIABLE_CFG_CATEGORY.PRODUCT_SUSPICIOUS.getValue(), result)) { + qcStatus = MesExtEnumUtil.PRODUCE_QC_STATUS.SUSPICIOUS.getValue(); + } + mesProduceSn.setQcStatus(qcStatus); + mesProduceSn.setLotNo(DateUtil.format(new Date(), "YYYYMMDD")); + mesProduceSn.setRouteCode(reqBean.getRouteCode()); + mesProduceSn.setProcessCode(productionProcessContext.getProcessCode()); + mesProduceSn.setCraftCode(productionProcessContext.getCraftCode()); + mesProduceSn.setPrintCount(0); + mesProduceSn.setPrintStatus(10); + mesProduceSn.setOrganizeCode(reqBean.getOrganizeCode()); + + return mesProduceSn; + } +} diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnScanNosortStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnScanNosortStepService.java index dc6f36d..4a83d7a 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnScanNosortStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesProductSnScanNosortStepService.java @@ -257,7 +257,7 @@ public class MesProductSnScanNosortStepService extends BaseStepService { } - ////比对产出零件的空腔数量与主条码的空腔数量, 产出零件的空腔数必须小于 剩余待扫描主条码数量加上已扫描的空腔数量 + ////比对产出零件的空腔数量与主条码的空腔数量, 产出零件的空腔数必须小于等于 剩余待扫描主条码数量加上已扫描的空腔数量 private StepResult checkFinishCodeSize(StepResult stepResult, List productionPartContextList, List productionPsInContextList, Boolean scanInfoIsFinishCode) { //没有产出零件 不需要对比空腔数量 @@ -273,13 +273,13 @@ public class MesProductSnScanNosortStepService extends BaseStepService { //剩余待扫描主条码数量 Integer remainSize = productionPartContextList.size() - (CollectionUtils.isEmpty(productionPsInContextList) ? MesPcnExtConstWords.ZERO : productionPsInContextList.size()) - MesPcnExtConstWords.ONE; - return ppSize.compareTo(remainSize + psSize) < 0 ? stepResult : stepResult.isCompleted(false).msg(String.format("产出零件存在空腔数[%s],扫描的主条码空腔数[%s],当前主条码必须扫描空腔码!", ppSize, psSize)); + return ppSize.compareTo(remainSize + psSize) <= 0 ? stepResult : stepResult.isCompleted(false).msg(String.format("产出零件存在空腔数[%s],扫描的主条码空腔数[%s],当前主条码必须扫描空腔码!", ppSize, psSize)); } private Boolean checkIsAllFinishCode(List productionPsInContextList, List equipVariableCollectContextList) { //扫描场景 验证是否全部为空腔 - Optional optional = productionPsInContextList.stream().filter(o -> (null != o && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).findFirst(); + Optional optional = CollectionUtils.isEmpty(productionPsInContextList) ? null : productionPsInContextList.stream().filter(o -> (null != o && o.getIsFinishCode().compareTo(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()) == 0)).findFirst(); //已验证的主条码全部空腔 并且 当前待验证主条码不存在数据 则全部空腔 return ((null == optional || !optional.isPresent()) && CollectionUtils.isEmpty(equipVariableCollectContextList)) ? true : false; } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesSendEquipParamsCmdStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesSendEquipParamsCmdStepService.java index c136a4c..2678ba1 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesSendEquipParamsCmdStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesSendEquipParamsCmdStepService.java @@ -5,6 +5,7 @@ import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch.strategy.Abs 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.pojo.base.bean.DdlPackBean; import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil; import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack; @@ -122,10 +123,21 @@ public class MesSendEquipParamsCmdStepService extends BaseStepService { * @return */ private List getMesEquipmentProdParamCfgs(StationRequestBean reqBean, List prodRuleContextList, List mesEquipmentProdParamCfgList) { + + MesProductionProcessContext productionProcessContext = productionProcessContextStepService.getCurCellEquipment(reqBean); + + for (MesProdRuleContext mesProdRuleContext : prodRuleContextList) { List mesEquipmentProdParamCfgs= new ArrayList<>(); + + //从上下文中取出生产线对象 + MesWorkCenter workCenter = productionProcessContext.getWorkCenter(); + + //排序线 主条码验证工步 + + // 获取加工参数 - if (Objects.equal(MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue(), reqBean.getWorkCenterCode())) { + if (MesExtEnumUtil.WORK_CENTER_TYPE.NOSORT.getValue() == workCenter.getCenterType()){ DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(); DdlPreparedPack.getNumEqualPack(mesProdRuleContext.getPid(), "sourceId", ddlPackBean);