tags/yfai-pcn-ext-v1.0
王杰 12 months ago
parent 704fe19c39
commit 596f6490d8

@ -0,0 +1,15 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import io.swagger.annotations.ApiOperation;
import java.util.List;
public interface IMesNumberRuleMatchDispatchService {
@ApiOperation(value = "编码规则匹配")
default List<?> matchNumberRule(String organizeCode, String sn, List<?> numberRuleList) { return numberRuleList; }
@ApiOperation(value = "编码规则匹配")
default Boolean matchNumberRule(String organizeCode, String sn, Object... params) { return true; }
}

@ -15,7 +15,10 @@ public interface IMesProdRuleCfgExtService {
@ApiOperation(value = "【非排序线】获取产品加工规则")
List<MesProdRuleNosortCfg> getProdRuleNosortCfgList(MesProdRuleContext prodRuleContext);
@ApiOperation(value = "【非排序线】获取产品加工规则")
List<MesProdRuleNosortCfg> getProdRuleNosortCfgList(MesProdRuleContext... prodRuleContext);
@ApiOperation(value = "【非排序线】获取产品加工规则对应的装配件信息")
MesProdRuleContext getProdRuleContext(MesProdRuleNosortCfg prodRuleNosortCfg, MesProductionPartContext productionPartContext);
MesProdRuleContext getProdRuleContext(MesProdRuleNosortCfg prodRuleNosortCfg, Integer foreignKey);
}

@ -45,7 +45,11 @@ public class MesProdRuleCfgExtService implements IMesProdRuleCfgExtService {
//实例化排序线加工规则与装配件数据记录
List<MesProdRuleContext> prodRuleContextList = new ArrayList<>();
productionPartContextList.forEach(o -> prodRuleContextList.add(createSortProdRuleContext(o, assemblyDataMap)));
//实例化排序线加工规则与装配件数据记录
for (int i = 0; i < productionPartContextList.size(); i ++) {
prodRuleContextList.add(createSortProdRuleContext(productionPartContextList.get(i).foreignKey(i + 1), assemblyDataMap));
}
return prodRuleContextList;
@ -69,30 +73,47 @@ public class MesProdRuleCfgExtService implements IMesProdRuleCfgExtService {
public List<MesProdRuleNosortCfg> getProdRuleNosortCfgList(MesProdRuleContext prodRuleContext) {
if (StringUtils.isEmpty(prodRuleContext.getOrganizeCode()) || StringUtils.isEmpty(prodRuleContext.getEquipmentCode())) return null;
DdlPackBean packBean = DdlPackBean.getDdlPackBean(prodRuleContext.getOrganizeCode());
DdlPreparedPack.getStringEqualPack(prodRuleContext.getEquipmentCode(), MesPcnExtConstWords.EQUIPMENT_CODE, packBean);
//outPartNo与outPartNos 带入条件必须互斥 , 此处查询时不作判断
DdlPreparedPack.getStringEqualPack(prodRuleContext.getOutPartNo(), MesPcnExtConstWords.OUT_PART_NO, packBean);
DdlPreparedPack.getInPackList(prodRuleContext.getOutPartNoList(), MesPcnExtConstWords.OUT_PART_NO, packBean);
if (prodRuleContext.getInPartNoIsEmpty()) DdlPreparedPack.getIsNull(MesPcnExtConstWords.IN_PART_NO, packBean);
else {
if (prodRuleContext.getInPartIsEmpty()) {
//进料为NULL
DdlPreparedPack.getIsNull(MesPcnExtConstWords.IN_PART_NO, packBean);
DdlPreparedPack.getIsNull(MesPcnExtConstWords.IN_PART_NO_RULE, packBean);
} else {
//inPartNo与inPartNos 带入条件必须互斥 , 此处查询时不作判断
DdlPreparedPack.getStringEqualPack(prodRuleContext.getInPartNo(), MesPcnExtConstWords.IN_PART_NO, packBean);
DdlPreparedPack.getInPackList(prodRuleContext.getInPartNoList(), MesPcnExtConstWords.IN_PART_NO, packBean);
//进料规则有值
if (prodRuleContext.getInPartRuleIsNotEmpty()) DdlPreparedPack.getIsNotNull(MesPcnExtConstWords.IN_PART_NO_RULE, packBean);
}
if (prodRuleContext.getInPartNoRuleIsEmpty()) DdlPreparedPack.getIsNull(MesPcnExtConstWords.IN_PART_NO_RULE, packBean);
else DdlPreparedPack.getIsNotNull(MesPcnExtConstWords.IN_PART_NO_RULE, packBean);
return prodRuleNoSortCfgRepository.findByHqlWhere(packBean);
}
//【非排序线】获取产品加工规则
@Override
public List<MesProdRuleNosortCfg> getProdRuleNosortCfgList(MesProdRuleContext... prodRuleContexts) {
if (null == prodRuleContexts) return null;
List<MesProdRuleNosortCfg> prodRuleNosortCfgList = null;
for (MesProdRuleContext prodRuleContext : prodRuleContexts) {
if (null == prodRuleContext) continue;
List<MesProdRuleNosortCfg> itemList = getProdRuleNosortCfgList(prodRuleContext);
if (CollectionUtils.isEmpty(itemList)) continue;
if (CollectionUtils.isEmpty(prodRuleNosortCfgList)) prodRuleNosortCfgList = new ArrayList<>();
prodRuleNosortCfgList.addAll(itemList);
}
return prodRuleNosortCfgList;
}
//【非排序线】获取产品加工规则对应的装配件信息
@Override
public MesProdRuleContext getProdRuleContext(MesProdRuleNosortCfg prodRuleNosortCfg, MesProductionPartContext productionPartContext) {
MesProdRuleContext prodRuleContext = new MesProdRuleContext().foreignKey(productionPartContext.getForeignKey()).pid(prodRuleNosortCfg.getId());
public MesProdRuleContext getProdRuleContext(MesProdRuleNosortCfg prodRuleNosortCfg, Integer foreignKey) {
MesProdRuleContext prodRuleContext = new MesProdRuleContext().foreignKey(foreignKey).pid(prodRuleNosortCfg.getId());
BeanUtils.copyProperties(prodRuleNosortCfg, prodRuleContext);
//获取非排序装配件配置信息
if (CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue() == prodRuleContext.getIsHasBind()) prodRuleContext.assemblyDataJson(assemblyExtService.getProductionAssemblyNosortContextList(prodRuleContext.getOrganizeCode(), prodRuleContext.getPid()));

@ -0,0 +1,42 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesNumberRuleMatchDispatchService;
import cn.estsh.i3plus.pojo.mes.bean.MesProdRuleNosortCfg;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Primary
@Service
public class MesNumberRuleMatchDispatchService implements IMesNumberRuleMatchDispatchService {
@Override
public List<?> matchNumberRule(String organizeCode, String sn, List<?> numberRuleList) {
if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(sn) || CollectionUtils.isEmpty(numberRuleList)) return null;
List<Object> resultList = new ArrayList<>();
if (numberRuleList.get(0) instanceof MesProdRuleNosortCfg) numberRuleList.forEach(o -> matchNumberRule(organizeCode, sn, resultList, o, "mesNumberRuleMatchRegularExpressionService", ((MesProdRuleNosortCfg) o).getInPartNoRule()));
return resultList;
}
private void matchNumberRule(String organizeCode, String sn, List<Object> resultList, Object o, String strategyClass, Object... params) {
if (StringUtils.isEmpty(organizeCode) || StringUtils.isEmpty(sn) || StringUtils.isEmpty(strategyClass) || null == o) return;
Boolean result = ((IMesNumberRuleMatchDispatchService) SpringContextsUtil.getBean(strategyClass)).matchNumberRule(organizeCode, sn, o, params);
if (result) resultList.add(o);
}
}

@ -0,0 +1,35 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesNumberRuleMatchDispatchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
*/
@Slf4j
@Service
public class MesNumberRuleMatchRegularExpressionService implements IMesNumberRuleMatchDispatchService {
@Override
public Boolean matchNumberRule(String organizeCode, String sn, Object... params) {
String matchRule = (String) params[0];
return true;
}
public static void main(String[] args) {
Pattern pattern = Pattern.compile("12345*54321");
Matcher matcher = pattern.matcher("12345*54321");
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}

@ -1,13 +1,14 @@
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.IMesProduceSnExtService;
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.serviceimpl.fsm.BaseStepService;
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesProdRuleNosortCfg;
import cn.estsh.i3plus.pojo.mes.bean.MesProduceSn;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCenter;
import cn.estsh.i3plus.pojo.mes.model.StationRequestBean;
import cn.estsh.i3plus.pojo.mes.model.StationResultBean;
@ -19,9 +20,7 @@ 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.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -42,7 +41,7 @@ public class MesAssemblyShowNosortStepService extends BaseStepService {
private IMesProdRuleCfgExtService prodRuleCfgExtService;
@Autowired
private IMesProduceSnExtService produceSnExtService;
private IMesNumberRuleMatchDispatchService numberRuleMatchDispatchService;
@Override
public StepResult execute(StationRequestBean reqBean) {
@ -69,134 +68,183 @@ public class MesAssemblyShowNosortStepService extends BaseStepService {
//获取上下文产出零件数据信息集合
List<MesProductionPartContext> productionPartContextList = productionDispatchContextStepService.getProductionPartContext(reqBean);
//获取上下文读/扫主条码信息集合
List<MesEquipVariableCollectContext> scanProductSnList = productionDispatchContextStepService.getScanProductSnContext(reqBean);
//获取上下文进料零件条码信息集合
List<MesProductionPsInContext> productionPsInContextList = productionDispatchContextStepService.getProductionPsInContext(reqBean);
//根据现有数据【产出零件数据】【读/扫主条码信息】比对上下文中已经存在的加工规则数据信息集合, 没有加工规则的数据进行查询
//根据现有数据【产出零件数据】【进料零件条码信息】比对上下文中已经存在的加工规则数据信息集合, 没有加工规则的数据进行查询
if (CollectionUtils.isEmpty(prodRuleContextList)) prodRuleContextList = new ArrayList<>();
doHandleProdRuleData(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPartContextList, scanProductSnList);
doHandleProdRuleData(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPartContextList, productionPsInContextList);
return stepResult;
}
private void doHandleProdRuleData(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesWorkCenter workCenter, MesCellEquipContext cellEquipContext,
List<MesProdRuleContext> prodRuleContextList, List<MesProductionPartContext> productionPartContextList, List<MesEquipVariableCollectContext> scanProductSnList) {
//没有【产出零件数据】【读/扫主条码信息】,则直接跳过 【当前场景是直接匹配装配件规则来获取产品加工规则】
if (CollectionUtils.isEmpty(productionPartContextList) && CollectionUtils.isEmpty(scanProductSnList)) return;
//如果已经通过主条码条件获取了产品加工规则数据,如果当前上下文没有【读/扫主条码信息】,则直接跳过
if (!CollectionUtils.isEmpty(prodRuleContextList) && !StringUtils.isEmpty(prodRuleContextList.get(0).getProductSn()) && CollectionUtils.isEmpty(scanProductSnList)) return;
List<MesProdRuleContext> prodRuleContextList, List<MesProductionPartContext> productionPartContextList, List<MesProductionPsInContext> productionPsInContextList) {
//没有【产出零件数据】【进料零件条码信息】,则直接跳过 【当前场景是直接匹配装配件规则来获取产品加工规则】
if (CollectionUtils.isEmpty(productionPartContextList) && CollectionUtils.isEmpty(productionPsInContextList)) return;
//根据进料条件获取匹配加工规则数据(只能查询到一条,存在多条则直接跳过,后续通过装配件规则匹配加工规则)
if (CollectionUtils.isEmpty(productionPartContextList)) doHandleProdRuleDataByProductSn(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, scanProductSnList);
if (CollectionUtils.isEmpty(productionPartContextList)) doHandleProdRuleDataByProductSn(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPsInContextList);
//根据是否存在【产出零件数据】获取剩余待匹配的加工规则数据
else doHandleProdRuleDataByProductionPart(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPartContextList, scanProductSnList);
else doHandleProdRuleDataByProductionPart(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPartContextList, productionPsInContextList);
}
//根据是否存在【产出零件数据】获取剩余待匹配的加工规则数据
private void doHandleProdRuleDataByProductionPart(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesWorkCenter workCenter, MesCellEquipContext cellEquipContext,
List<MesProdRuleContext> prodRuleContextList, List<MesProductionPartContext> productionPartContextList, List<MesEquipVariableCollectContext> scanProductSnList) {
List<MesProdRuleContext> prodRuleContextList, List<MesProductionPartContext> productionPartContextList, List<MesProductionPsInContext> productionPsInContextList) {
//加工规则的数据已与产出零件的数量一致
if (!CollectionUtils.isEmpty(prodRuleContextList) && prodRuleContextList.size() == productionPartContextList.size()) return;
//已获取的加工规则数据根据关联键分组
Map<String, MesProdRuleContext> prodRuleContextMap = CollectionUtils.isEmpty(prodRuleContextList) ? null : prodRuleContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).collect(Collectors.toMap(MesProdRuleContext::getForeignKey, o -> o));
//拿到当前最大的foreignKey
Optional<MesProductionPartContext> maxForeignKeyOptional = productionPartContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).max(Comparator.comparing(MesProductionPartContext::getForeignKey));
Integer foreignKey = (null != maxForeignKeyOptional && maxForeignKeyOptional.isPresent()) ? maxForeignKeyOptional.get().getForeignKey() : MesPcnExtConstWords.ZERO;
//上下文当前存在【读/扫主条码信息】, 后面匹配成功的信息会从scanProductSnList中remove掉,所以需要一个标志判断循环是否结束
Boolean isExistPs = CollectionUtils.isEmpty(scanProductSnList) ? false : true;
//搜集未匹配规则的产出零件
List<String> outPartNoList = productionPartContextList.stream().filter(o -> (null != o && StringUtils.isEmpty(o.getForeignKey()) && !StringUtils.isEmpty(o.getPartNo()))).map(MesProductionPartContext::getPartNo).collect(Collectors.toList());
for (MesProductionPartContext productionPartContext : productionPartContextList) {
//没有【进料零件条码信息】信息, 根据进料[NULL]条件获取匹配当前产出零件的加工规则数据(只能查询到一条,存在多条则直接跳过,后续通过装配件规则匹配加工规则)
if (CollectionUtils.isEmpty(productionPsInContextList)) doHandleProdRuleDataByProductionPartAndEmptyProductSn(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPartContextList, outPartNoList, foreignKey);
//存在【产出零件数据】信息, 存在【进料零件条码信息】 获取匹配当前产出零件的加工规则数据
else doHandleProdRuleDataByProductionPartAndProductSn(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPartContextList, productionPsInContextList, outPartNoList, foreignKey);
if (null == productionPartContext) continue;
}
if (StringUtils.isEmpty(productionPartContext.getForeignKey())) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("上下文中的产出零件信息数据异常,缺失数据关联键! 数据详情:[%s]", JSONObject.toJSONString(productionPartContext)));
//没有【进料零件条码信息】信息, 根据进料[NULL]条件获取匹配当前产出零件的加工规则数据(只能查询到一条,存在多条则直接跳过,后续通过装配件规则匹配加工规则)
private void doHandleProdRuleDataByProductionPartAndEmptyProductSn(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesWorkCenter workCenter, MesCellEquipContext cellEquipContext,
List<MesProdRuleContext> prodRuleContextList, List<MesProductionPartContext> productionPartContextList, List<String> outPartNoList, Integer foreignKey) {
//当前上下文中的【读/扫主条码信息】已经全部匹配完成
if (isExistPs && CollectionUtils.isEmpty(scanProductSnList)) break;
//【非排序线】获取产品加工规则 ; 条件进料[NULL]
List<MesProdRuleNosortCfg> prodRuleNosortCfgList = prodRuleCfgExtService.getProdRuleNosortCfgList(new MesProdRuleContext(reqBean.getOrganizeCode()).equipmentCode(cellEquipContext.getEquipmentCode()).outPartNos(outPartNoList).inPartIsEmpty());
//根据产出零件分组数据
Map<String, List<MesProdRuleNosortCfg>> prodRuleNosortCfgMap = groupProdRuleNosortCfgList(prodRuleNosortCfgList);
//当前产出零件已获取过加工规则
if (!CollectionUtils.isEmpty(prodRuleContextMap) && prodRuleContextMap.containsKey(productionPartContext.getForeignKey())) continue;
for (MesProductionPartContext productionPartContext : productionPartContextList) {
//根据进料[NULL]条件获取匹配当前产出零件的加工规则数据(只能查询到一条,存在多条则直接跳过,后续通过装配件规则匹配加工规则)
if (CollectionUtils.isEmpty(scanProductSnList)) doHandleProdRuleDataByProductionPartAndEmptyProductSn(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPartContext);
//根据【读/扫主条码信息】获取匹配当前产出零件的加工规则数据
else doHandleProdRuleDataByProductionPartAndProductSn(reqBean, resultBean, stepResult, workCenter, cellEquipContext, prodRuleContextList, productionPartContext, scanProductSnList);
//foreignKey有值代表已经匹配过产品加工规则
if (null == productionPartContext || !StringUtils.isEmpty(productionPartContext.getForeignKey())) continue;
}
List<MesProdRuleNosortCfg> filterList = !CollectionUtils.isEmpty(prodRuleNosortCfgMap) ? prodRuleNosortCfgMap.get(productionPartContext.getPartNo()) : null;
if (CollectionUtils.isEmpty(prodRuleNosortCfgList)) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查非排序产品加工规则信息,未查询到设备[%s]产出零件[%s]进料零件[空]进料零件规则[空]的配置信息", cellEquipContext.getEquipmentCode(), productionPartContext.getPartNo()));
//【非排序线】获取产品加工规则对应的装配件信息
if (prodRuleNosortCfgList.size() == 1) prodRuleContextList.add(prodRuleCfgExtService.getProdRuleContext(prodRuleNosortCfgList.get(0), productionPartContext.foreignKey(foreignKey += 1).getForeignKey()));
}
if (prodRuleNosortCfgList.size() > 1) this.sendMessage(reqBean, resultBean, String.format(
"显示装配件匹配非排序产品加工规则[%s]条,直接跳过,后续通过装配件规则匹配加工规则,数据源:[%s]!", prodRuleNosortCfgList.size(), JSONObject.toJSONString(productionPartContext)), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
//根据进料[NULL]条件获取匹配当前产出零件的加工规则数据(只能查询到一条,存在多条则直接跳过,后续通过装配件规则匹配加工规则)
private void doHandleProdRuleDataByProductionPartAndEmptyProductSn(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesWorkCenter workCenter, MesCellEquipContext cellEquipContext,
List<MesProdRuleContext> prodRuleContextList, MesProductionPartContext productionPartContext) {
//【非排序线】获取产品加工规则 ; 条件进料[NULL]
List<MesProdRuleNosortCfg> prodRuleNosortCfgList = prodRuleCfgExtService.getProdRuleNosortCfgList(new MesProdRuleContext(reqBean.getOrganizeCode()).equipmentCode(cellEquipContext.getEquipmentCode()).outPartNo(productionPartContext.getPartNo()).inPartNoIsEmpty().inPartNoRuleIsEmpty());
if (CollectionUtils.isEmpty(prodRuleNosortCfgList)) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查非排序产品加工规则信息,未查询到设备[%s]产出零件[%s]进料零件为空的配置信息", cellEquipContext.getEquipmentCode(), productionPartContext.getPartNo()));
if (prodRuleNosortCfgList.size() > 1) return;
//【非排序线】获取产品加工规则对应的装配件信息
MesProdRuleContext prodRuleContext = prodRuleCfgExtService.getProdRuleContext(prodRuleNosortCfgList.get(0), productionPartContext);
prodRuleContextList.add(prodRuleContext);
}
}
//根据进料条件获取匹配加工规则数据(只能查询到一条,存在多条则直接跳过,后续通过装配件规则匹配加工规则)
//没有【产出零件数据】信息 , 根据进料条件获取匹配加工规则数据(只能查询到一条,存在多条则直接跳过,后续通过装配件规则匹配加工规则)
private void doHandleProdRuleDataByProductSn(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesWorkCenter workCenter, MesCellEquipContext cellEquipContext,
List<MesProdRuleContext> prodRuleContextList, List<MesEquipVariableCollectContext> scanProductSnList) {
//查询【读/扫主条码信息】
Map<String, MesProduceSn> produceSnDataMap = produceSnExtService.getProduceSnMap(reqBean.getOrganizeCode(), scanProductSnList.stream().filter(o -> null != o).map(MesEquipVariableCollectContext::getEquipVariableValue).collect(Collectors.toList()));
List<MesProdRuleContext> prodRuleContextList, List<MesProductionPsInContext> productionPsInContextList) {
//【非排序线】获取产品加工规则 ; 分别根据 进料零件有值 与 进料规则不为空 查询 再合并数据返回
List<MesProdRuleNosortCfg> prodRuleNosortCfgList = getProdRuleNosortCfgList(reqBean, cellEquipContext, productionPsInContextList, null);
for (MesEquipVariableCollectContext equipVariableCollectContext : scanProductSnList) {
//拿到当前最大的foreignKey
Optional<MesProductionPsInContext> maxForeignKeyOptional = productionPsInContextList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getForeignKey()))).max(Comparator.comparing(MesProductionPsInContext::getForeignKey));
Integer foreignKey = (null != maxForeignKeyOptional && maxForeignKeyOptional.isPresent()) ? maxForeignKeyOptional.get().getForeignKey() : MesPcnExtConstWords.ZERO;
if (null == equipVariableCollectContext) continue;
for (MesProductionPsInContext productionPsInContext : productionPsInContextList) {
MesProduceSn produceSnData = CollectionUtils.isEmpty(produceSnDataMap) ? null : produceSnDataMap.get(equipVariableCollectContext.getEquipVariableValue());
//foreignKey有值代表已经匹配过产品加工规则
if (null == productionPsInContext || !StringUtils.isEmpty(productionPsInContext.getForeignKey())) continue;
if (null != produceSnData) {}
else {
List<MesProdRuleNosortCfg> filterList;
//搜集进料零件号匹配的产品加工规则
if (!StringUtils.isEmpty(productionPsInContext.getPartNo())) filterList = filterProdRuleNosortCfgList(prodRuleNosortCfgList, productionPsInContext.getPartNo());
//进料零件条码匹配进料零件规则
else filterList = (List<MesProdRuleNosortCfg>) numberRuleMatchDispatchService.matchNumberRule(reqBean.getOrganizeCode(), productionPsInContext.getProductSn(), filterProdRuleNosortCfgList(prodRuleNosortCfgList));
}
if (CollectionUtils.isEmpty(filterList)) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查非排序产品加工规则信息,未查询到设备[%s]进料零件%s的配置信息",
cellEquipContext.getEquipmentCode(), !StringUtils.isEmpty(productionPsInContext.getPartNo()) ? String.format("号匹配[%s]", productionPsInContext.getPartNo()) : String.format("规则匹配[%s]", productionPsInContext.getProductSn())));
//【非排序线】获取产品加工规则对应的装配件信息
if (filterList.size() == 1) prodRuleContextList.add(prodRuleCfgExtService.getProdRuleContext(filterList.get(0), productionPsInContext.foreignKey(foreignKey += 1).getForeignKey()));
if (filterList.size() > 1) this.sendMessage(reqBean, resultBean, String.format(
"显示装配件匹配非排序产品加工规则[%s]条,直接跳过,后续通过装配件规则匹配加工规则,数据源:[%s]!", filterList.size(), JSONObject.toJSONString(productionPsInContext)), MesPcnEnumUtil.STATION_BUSI_TYPE.RUNNING_INFO, MesPcnEnumUtil.STATION_DATA_TYPE.TEXT);
}
//【非排序线】获取产品加工规则
List<MesProdRuleNosortCfg> prodRuleNosortCfgList = prodRuleCfgExtService.getProdRuleNosortCfgList(new MesProdRuleContext(reqBean.getOrganizeCode()).equipmentCode(cellEquipContext.getEquipmentCode()));
// if (CollectionUtils.isEmpty(prodRuleNosortCfgList)) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查非排序产品加工规则信息,未查询到设备[%s]产出零件[%s]进料零件为空的配置信息", cellEquipContext.getEquipmentCode(), productionPartContext.getPartNo()));
if (prodRuleNosortCfgList.size() > 1) return;
}
private List<MesProdRuleNosortCfg> getProdRuleNosortCfgList(StationRequestBean reqBean, MesCellEquipContext cellEquipContext, List<MesProductionPsInContext> productionPsInContextList, List<String> outPartNoList) {
//【非排序线】获取产品加工规则 ; 分别根据 进料零件有值 与 进料规则不为空 查询 再合并数据返回, 条件可能携带产出零件
List<String> inPartNoList = productionPsInContextList.stream().filter(o -> (null != o && StringUtils.isEmpty(o.getForeignKey()) && !StringUtils.isEmpty(o.getPartNo()))).map(MesProductionPsInContext::getPartNo).collect(Collectors.toList());
Optional<MesProductionPsInContext> optional = productionPsInContextList.stream().filter(o -> (null != o && StringUtils.isEmpty(o.getForeignKey()) && StringUtils.isEmpty(o.getPartNo()))).findFirst();
List<MesProdRuleNosortCfg> prodRuleNosortCfgList = prodRuleCfgExtService.getProdRuleNosortCfgList(
!CollectionUtils.isEmpty(inPartNoList) ? new MesProdRuleContext(reqBean.getOrganizeCode()).equipmentCode(cellEquipContext.getEquipmentCode()).inPartNos(inPartNoList).outPartNos(outPartNoList) : null,
(null != optional && optional.isPresent()) ? new MesProdRuleContext(reqBean.getOrganizeCode()).equipmentCode(cellEquipContext.getEquipmentCode()).inPartRuleIsNotEmpty().outPartNos(outPartNoList) : null);
return prodRuleNosortCfgList;
}
//搜集进料零件号匹配的产品加工规则
private List<MesProdRuleNosortCfg> filterProdRuleNosortCfgList(List<MesProdRuleNosortCfg> prodRuleNosortCfgList, String partNo) {
return CollectionUtils.isEmpty(prodRuleNosortCfgList) ? null : prodRuleNosortCfgList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getInPartNo()) && o.getInPartNo().equals(partNo))).collect(Collectors.toList());
}
//搜集进料零件规则有值的产品加工规则
private List<MesProdRuleNosortCfg> filterProdRuleNosortCfgList(List<MesProdRuleNosortCfg> prodRuleNosortCfgList) {
return CollectionUtils.isEmpty(prodRuleNosortCfgList) ? null : prodRuleNosortCfgList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getInPartNoRule()))).collect(Collectors.toList());
}
//根据产出零件分组数据
private Map<String, List<MesProdRuleNosortCfg>> groupProdRuleNosortCfgList(List<MesProdRuleNosortCfg> prodRuleNosortCfgList) {
return CollectionUtils.isEmpty(prodRuleNosortCfgList) ? null : prodRuleNosortCfgList.stream().filter(o -> null != o).collect(Collectors.groupingBy(MesProdRuleNosortCfg::getOutPartNo));
}
//根据【读/扫主条码信息】获取匹配当前产出零件的加工规则数据
//存在【产出零件数据】信息, 存在【进料零件条码信息】 获取匹配当前产出零件的加工规则数据
private void doHandleProdRuleDataByProductionPartAndProductSn(StationRequestBean reqBean, StationResultBean resultBean, StepResult stepResult, MesWorkCenter workCenter, MesCellEquipContext cellEquipContext,
List<MesProdRuleContext> prodRuleContextList, MesProductionPartContext productionPartContext, List<MesEquipVariableCollectContext> scanProductSnList) {
List<MesProdRuleContext> prodRuleContextList, List<MesProductionPartContext> productionPartContextList, List<MesProductionPsInContext> productionPsInContextList, List<String> outPartNoList, Integer foreignKey) {
for (MesEquipVariableCollectContext equipVariableCollectContext : scanProductSnList) {
//【非排序线】获取产品加工规则 ; 分别根据 进料零件有值 与 进料规则不为空 查询 再合并数据返回, 条件携带产出零件
List<MesProdRuleNosortCfg> prodRuleNosortCfgList = getProdRuleNosortCfgList(reqBean, cellEquipContext, productionPsInContextList, outPartNoList);
//根据产出零件分组数据
Map<String, List<MesProdRuleNosortCfg>> prodRuleNosortCfgMap = groupProdRuleNosortCfgList(prodRuleNosortCfgList);
if (null == equipVariableCollectContext) continue;
for (MesProductionPartContext productionPartContext : productionPartContextList) {
//foreignKey有值代表已经匹配过产品加工规则
if (null == productionPartContext || !StringUtils.isEmpty(productionPartContext.getForeignKey())) continue;
//获取匹配产出零件的所有加工规则
List<MesProdRuleNosortCfg> outPartNoProdRuleList = !CollectionUtils.isEmpty(prodRuleNosortCfgMap) ? prodRuleNosortCfgMap.get(productionPartContext.getPartNo()) : null;
MesProdRuleNosortCfg filter = null;
for (MesProductionPsInContext productionPsInContext : productionPsInContextList) {
}
//foreignKey有值代表已经匹配过产品加工规则
if (null == productionPsInContext || !StringUtils.isEmpty(productionPsInContext.getForeignKey())) continue;
}
List<MesProdRuleNosortCfg> innerfilterList;
//搜集进料零件号匹配的产品加工规则
if (!StringUtils.isEmpty(productionPsInContext.getPartNo())) innerfilterList = filterProdRuleNosortCfgList(outPartNoProdRuleList, productionPsInContext.getPartNo());
//进料零件条码匹配进料零件规则
else innerfilterList = (List<MesProdRuleNosortCfg>) numberRuleMatchDispatchService.matchNumberRule(reqBean.getOrganizeCode(), productionPsInContext.getProductSn(), filterProdRuleNosortCfgList(outPartNoProdRuleList));
if (CollectionUtils.isEmpty(innerfilterList) || innerfilterList.size() > 1) continue;
productionPartContext.foreignKey(productionPsInContext.foreignKey(foreignKey += 1).getForeignKey());
filter = innerfilterList.get(0);
break;
}
if (null == filter) execExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), String.format("请检查非排序产品加工规则信息,未查询到设备[%s]产出零件[%s]匹配任意一个主条码的配置信息", cellEquipContext.getEquipmentCode(), productionPartContext.getPartName()));
//【非排序线】获取产品加工规则对应的装配件信息
prodRuleContextList.add(prodRuleCfgExtService.getProdRuleContext(filter, productionPartContext.getForeignKey()));
}
}
}

@ -38,7 +38,7 @@ public class MesAssemblyShowContext implements Serializable {
private Integer assemblyStatus;
@ApiParam("装配件条码确认方式")
private String matchType;
private Integer matchType;
@ApiParam("装配零件状态")
private String assemblyStatusName;

@ -11,6 +11,7 @@ import org.springframework.util.StringUtils;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* -
@ -23,8 +24,8 @@ public class MesProdRuleContext implements Serializable {
@ApiParam("组织代码")
public String organizeCode;
@ApiParam(name = "数据关联键 排序:生产工单号 非排序:snowflakeId")
private String foreignKey;
@ApiParam(name = "数据关联键")
private Integer foreignKey;
@ApiParam("装配件绑定清单 [JSON]List<MesProductionAssemblyContext>")
public String assemblyDataJson;
@ -45,12 +46,6 @@ public class MesProdRuleContext implements Serializable {
@ApiParam(name = "读/扫主条码信息(内制件/外协件),不一定有值")
private String productSn;
@ApiParam(name = "进料零件号是否为空")
private Boolean inPartNoIsEmpty = false;
@ApiParam(name = "进料零件规则是否为空")
private Boolean inPartNoRuleIsEmpty = false;
@ApiParam("非排序产品加工规则ID")
public Long pid;
@ -91,6 +86,13 @@ public class MesProdRuleContext implements Serializable {
private String packageEquSignal;
//----------仅作为查询条件冗余-------------
@ApiParam(name = "进料零件号与规则是否均为空")
private Boolean inPartIsEmpty = false;
@ApiParam(name = "进料规则是否有值")
private Boolean inPartRuleIsNotEmpty = false;
@ApiParam(name = "进料零件号")
private String inPartNos;
@ -110,18 +112,18 @@ public class MesProdRuleContext implements Serializable {
this.processCode = processCode;
}
public MesProdRuleContext foreignKey(String foreignKey) {
public MesProdRuleContext foreignKey(Integer foreignKey) {
this.foreignKey = foreignKey;
return this;
}
public MesProdRuleContext inPartNoIsEmpty() {
this.inPartNoIsEmpty = true;
public MesProdRuleContext inPartIsEmpty() {
this.inPartIsEmpty = true;
return this;
}
public MesProdRuleContext inPartNoRuleIsEmpty() {
this.inPartNoRuleIsEmpty = true;
public MesProdRuleContext inPartRuleIsNotEmpty() {
this.inPartRuleIsNotEmpty = true;
return this;
}
@ -142,6 +144,7 @@ public class MesProdRuleContext implements Serializable {
public MesProdRuleContext inPartNos(List<String> inPartNoList) {
if (CollectionUtils.isEmpty(inPartNoList)) return this;
inPartNoList = inPartNoList.stream().filter(o -> !StringUtils.isEmpty(o)).distinct().collect(Collectors.toList());
if (inPartNoList.size() > 1) this.inPartNos = JSONObject.toJSONString(inPartNoList);
else this.inPartNo = inPartNoList.get(0);
return this;
@ -149,6 +152,7 @@ public class MesProdRuleContext implements Serializable {
public MesProdRuleContext outPartNos(List<String> outPartNoList) {
if (CollectionUtils.isEmpty(outPartNoList)) return this;
outPartNoList = outPartNoList.stream().filter(o -> !StringUtils.isEmpty(o)).distinct().collect(Collectors.toList());
if (outPartNoList.size() > 1) this.outPartNos = JSONObject.toJSONString(outPartNoList);
else this.outPartNo = outPartNoList.get(0);
return this;

@ -15,8 +15,8 @@ public class MesProductionPartContext implements Serializable {
private static final long serialVersionUID = 5562937531822977296L;
@ApiParam(name = "数据关联键 排序:生产工单号 非排序:snowflakeId")
private String foreignKey;
@ApiParam(name = "数据关联键")
private Integer foreignKey;
@ApiParam("组织代码")
private String organizeCode;
@ -41,18 +41,11 @@ public class MesProductionPartContext implements Serializable {
public MesProductionPartContext copyMouldMultiCavity(MesMouldMultiCavity mouldMultiCavity) {
BeanUtils.copyProperties(mouldMultiCavity, this);
this.foreignKey = mouldMultiCavity.getId().toString();
return this;
}
//-------以下场景预留未开发-------
public MesProductionPartContext copyWorkOrder(String workOrderNo) {
this.foreignKey = workOrderNo + "腔顺序号";
return this;
}
public MesProductionPartContext copyPartNo(String partNo) {
this.foreignKey = partNo + "腔顺序号";
public MesProductionPartContext foreignKey(Integer foreignKey) {
this.foreignKey = foreignKey;
return this;
}

@ -13,10 +13,10 @@ import java.io.Serializable;
@Data
public class MesProductionPsInContext implements Serializable {
private static final long serialVersionUID = 5562937531822977296L;
private static final long serialVersionUID = 4337949265011880288L;
@ApiParam(name = "数据关联键 排序:生产工单号 非排序:snowflakeId")
private String foreignKey;
private Integer foreignKey;
@ApiParam("组织代码")
private String organizeCode;
@ -55,5 +55,10 @@ public class MesProductionPsInContext implements Serializable {
@ApiParam(name = "前道工艺防错结果")
private Integer checkCraftResult = MesPcnExtConstWords.ZERO;
public MesProductionPsInContext foreignKey(Integer foreignKey) {
this.foreignKey = foreignKey;
return this;
}
}

@ -130,6 +130,8 @@ public class MesPcnExtConstWords {
// 最大重试次数[工步参数]
public static final Integer MAX_RETRY_TIMES_DEFAULT = 10;
// 未知腔数[工位参数]
public static final String CAVITY_UNKNOWN_CFG = "CAVITY_UNKNOWN_CFG";
// 0

Loading…
Cancel
Save