diff --git a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/jx/IJxPlcExtService.java b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/jx/IJxPlcExtService.java index 0ef37ca..9dda627 100644 --- a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/jx/IJxPlcExtService.java +++ b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/jx/IJxPlcExtService.java @@ -81,11 +81,11 @@ public interface IJxPlcExtService { /** * 获取对象结构信息 * @param organizeCode 工厂代码 - * @param plcCodeList PLC代码集合 + * @param plcCodeList2Cell PLC代码集合 * @return 对象结构信息 */ @ApiOperation(value = "获取对象结构信息", notes = "获取对象结构信息") - List getObjectCfgDbList(String organizeCode, List plcCodeList); + List getObjectCfgDbList(String organizeCode, List plcCodeList2Cell); } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectProductDataStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectProductDataStepService.java index f5d18b4..9389cbc 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectProductDataStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/collect/SxThirdPartyPlcCollectProductDataStepService.java @@ -17,9 +17,7 @@ import lombok.extern.slf4j.Slf4j; 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; /** @@ -96,10 +94,13 @@ public class SxThirdPartyPlcCollectProductDataStepService implements ISxThirdPar List lineDataList = new ArrayList<>(); for (MesObjectCfg objectCfg : objectCfgList) { if (null == objectCfg) continue; + List plcCodeList = Arrays.asList(objectCfg.getPlcCode().split(MesPcnExtConstWords.COMMA)); + Optional plcCodeOp = targetFieldList.stream().filter(o -> (StringUtils.isEmpty(o) && plcCodeList.contains(o))).findFirst(); + if (null == plcCodeOp || !plcCodeOp.isPresent()) continue; ProductDataModel productDataModel = new ProductDataModel(); productDataModel.setFieldCode(objectCfg.getFieldCode()); productDataModel.setFieldName(objectCfg.getFieldName()); - productDataModel.setFieldValue((String) ((Map) stepResult.getData()).get(objectCfg.getPlcCode())); + productDataModel.setFieldValue((String) ((Map) stepResult.getData()).get(plcCodeOp.get())); lineDataList.add(productDataModel); } return lineDataList; diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/jx/JxPlcExtService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/jx/JxPlcExtService.java index 2c33f82..241a149 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/jx/JxPlcExtService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/jx/JxPlcExtService.java @@ -20,6 +20,8 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.text.MessageFormat; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -102,13 +104,14 @@ public class JxPlcExtService implements IJxPlcExtService { } @Override - public List getObjectCfgDbList(String organizeCode, List plcCodeList) { + public List getObjectCfgDbList(String organizeCode, List plcCodeList2Cell) { if (StringUtils.isEmpty(organizeCode)) return null; List objectCfgDbList = objectCfgRepository.findByProperty( new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_VALID, MesPcnExtConstWords.IS_DELETED}, new Object[]{organizeCode, CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue()}); objectCfgDbList = CollectionUtils.isEmpty(objectCfgDbList) ? null : - objectCfgDbList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPlcCode()) && plcCodeList.contains(o.getPlcCode()))).collect(Collectors.toList()); + objectCfgDbList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getPlcCode()) && !Collections.disjoint(plcCodeList2Cell, Arrays.asList(o.getPlcCode().split(MesPcnExtConstWords.COMMA))))).collect(Collectors.toList()); return objectCfgDbList; } + } \ No newline at end of file diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxSnProcessingCollectProductDataStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxSnProcessingCollectProductDataStepService.java index 53ea434..85e29ce 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxSnProcessingCollectProductDataStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/step/jx/JxSnProcessingCollectProductDataStepService.java @@ -24,10 +24,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.StringJoiner; +import java.util.*; import java.util.stream.Collectors; /** @@ -92,12 +89,7 @@ public class JxSnProcessingCollectProductDataStepService extends BaseStepService String[] plcCodeArr = checkPlcCodeIsValid(reqBean, resultBean, plcCodes, key); - String plcCodeListStr = plcExtService.getCachedData(key, MesPcnExtConstWords.PLC_CODE_UC); - List plcCodeList = !StringUtils.isEmpty(plcCodeListStr) ? JSONObject.parseArray(plcCodeListStr, String.class) : doHandlePlcCodeList(reqBean, resultBean, key); - - List plcCodeList2Cfg = checkObjectCfgIsValid(reqBean, resultBean, plcCodeList, key); - - doHandlePlcCodeList(reqBean, key, plcCodeListStr, plcCodeList, plcCodeList2Cfg); + List plcCodeList2Cell = doPlcCodeList2Cell(reqBean, resultBean, plcCodeArr, key); String curExecWorkOrderNo = getCurExecWorkOrderNo(reqBean, resultBean); @@ -108,7 +100,7 @@ public class JxSnProcessingCollectProductDataStepService extends BaseStepService .location(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode()) .order(orderModel.getOrderNo(), orderModel.getPartNo(), orderModel.getPartNameRdd()) .sn(reqBean.getSerialNumber(), reqBean.getProductSn()).manageCode(reqBean.getTray()) - .plcCode2Flag(plcCodeArr[0], plcCodeArr[1]).plcCode2DataList(plcCodeList) + .plcCode2Flag(plcCodeArr[0], plcCodeArr[1]).plcCode2DataList(plcCodeList2Cell) .timeOut(reqBean.getWcpcMap().get(MesPcnExtConstWords.TIME_OUT_CFG))); ((ISxThirdPartyPlcCollectDataJobService) SpringContextsUtil.getBean(MesPcnExtConstWords.SX_TPPC_SUFFIX + MesPcnExtConstWords.PRODUCT_DATA + MesPcnExtConstWords.SERVICE_SUFFIX)).doThirdPartyPlcCollectData(paramMap); @@ -117,6 +109,28 @@ public class JxSnProcessingCollectProductDataStepService extends BaseStepService } + private List doPlcCodeList2Cell(StationRequestBean reqBean, StationResultBean resultBean, String[] plcCodeArr, String key) { + String plcCodeList2CellStr = plcExtService.getCachedData(key, MesPcnExtConstWords.PLC_CODE_UC); + String objectCfgListStr = plcExtService.getCachedData(key, MesPcnExtConstWords.OBJECT_CODE_UC); + + List plcCodeList2Cell = !StringUtils.isEmpty(plcCodeList2CellStr) ? JSONObject.parseArray(plcCodeList2CellStr, String.class) : null; + if (!CollectionUtils.isEmpty(plcCodeList2Cell)) plcCodeList2Cell.removeAll(Arrays.asList(plcCodeArr)); + + List objectCfgList = !StringUtils.isEmpty(objectCfgListStr) ? JSONObject.parseArray(objectCfgListStr, MesObjectCfg.class) : null; + + if (!CollectionUtils.isEmpty(plcCodeList2Cell) && !CollectionUtils.isEmpty(objectCfgList) && checkObjectCfgIsValid(reqBean, resultBean, plcCodeList2Cell, objectCfgList, false)) return plcCodeList2Cell; + + plcCodeList2Cell = doHandlePlcCodeList2Cell(reqBean, resultBean, plcCodeArr, key); + objectCfgList = getObjectCfgDbList(reqBean, resultBean, plcCodeList2Cell); + + checkObjectCfgIsValid(reqBean, resultBean, plcCodeList2Cell, objectCfgList, true); + + plcExtService.doCacheData(reqBean.getOrganizeCode(), key, MesPcnExtConstWords.PLC_CODE_UC, JSONObject.toJSONString(plcCodeList2Cell)); + plcExtService.doCacheData(reqBean.getOrganizeCode(), key, MesPcnExtConstWords.OBJECT_CODE_UC, JSONObject.toJSONString(objectCfgList)); + + return plcCodeList2Cell; + } + private String[] checkPlcCodeIsValid(StationRequestBean reqBean, StationResultBean resultBean, String plcCodes, String key) { String[] plcCodeArr = plcCodes.split(MesPcnExtConstWords.COMMA); if (plcCodeArr.length != 2) execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("生产线[%s]工位[%s]工位参数[%s]维护的PLC代码[%s]无效!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), MesPcnExtConstWords.PLC_CODE_UC, plcCodes)); @@ -130,36 +144,30 @@ public class JxSnProcessingCollectProductDataStepService extends BaseStepService return plcCodeArr; } - private List doHandlePlcCodeList(StationRequestBean reqBean, StationResultBean resultBean, String key) { + private List doHandlePlcCodeList2Cell(StationRequestBean reqBean, StationResultBean resultBean, String[] plcCodeArr, String key) { List plcList = plcExtService.getPlcDbList(reqBean.getOrganizeCode(), reqBean.getWorkCenterCode(), reqBean.getWorkCellCode()); plcList = CollectionUtils.isEmpty(plcList) ? null : plcList.stream().filter(o -> (null != o && !StringUtils.isEmpty(o.getChannel()) && !StringUtils.isEmpty(o.getDevice()) && !StringUtils.isEmpty(o.getTagAddress()))).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(plcList)) plcList.removeAll(Arrays.asList(plcCodeArr)); if (CollectionUtils.isEmpty(plcList)) execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("生产线[%s]工位[%s]未配置有效的数据位PLC信息!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode())); plcList.forEach(o -> plcExtService.doCacheData(reqBean.getOrganizeCode(), key, o.getPlcCode(), JSONObject.toJSONString(o))); return plcList.stream().filter(o -> null != o).map(MesPlc::getPlcCode).collect(Collectors.toList()); } - private void doHandlePlcCodeList(StationRequestBean reqBean, String key, String plcCodeListStr, List plcCodeList, List plcCodeList2Cfg) { - if (!StringUtils.isEmpty(plcCodeListStr) && (plcCodeList.containsAll(plcCodeList2Cfg) && plcCodeList2Cfg.containsAll(plcCodeList))) return; - plcExtService.doCacheData(reqBean.getOrganizeCode(), key, MesPcnExtConstWords.PLC_CODE_UC, JSONObject.toJSONString(plcCodeList2Cfg)); - } - - private List checkObjectCfgIsValid(StationRequestBean reqBean, StationResultBean resultBean, List plcCodeList, String key) { - String value = plcExtService.getCachedData(key, MesPcnExtConstWords.OBJECT_CODE_UC); - List objectCfgList = !StringUtils.isEmpty(value) ? JSONObject.parseArray(value, MesObjectCfg.class) : getObjectCfgDbList(reqBean, resultBean, plcCodeList); - - List plcCodeList2ObjectCfg = CollectionUtils.isEmpty(objectCfgList) ? null : objectCfgList.stream().filter(o -> null != o).map(MesObjectCfg::getPlcCode).collect(Collectors.toList()); - plcCodeList2ObjectCfg = CollectionUtils.isEmpty(plcCodeList2ObjectCfg) ? null : plcCodeList2ObjectCfg.stream().filter(o -> !StringUtils.isEmpty(o)).distinct().collect(Collectors.toList()); - - if (CollectionUtils.isEmpty(plcCodeList2ObjectCfg)) execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("生产线[%s]工位[%s]配置的数据位PLC信息未关联有效的对象结构信息!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode())); - - if (StringUtils.isEmpty(value)) plcExtService.doCacheData(reqBean.getOrganizeCode(), key, MesPcnExtConstWords.OBJECT_CODE_UC, JSONObject.toJSONString(objectCfgList)); - - List plcCodeList2Cfg = objectCfgList.stream().filter(o -> null != o).map(MesObjectCfg::getPlcCode).collect(Collectors.toList()); - return plcCodeList2Cfg.stream().filter(o -> null != o).distinct().collect(Collectors.toList()); + private Boolean checkObjectCfgIsValid(StationRequestBean reqBean, StationResultBean resultBean, List plcCodeList2Cell, List objectCfgList, Boolean flag) { + for (MesObjectCfg objectCfg : objectCfgList) { + if (null == objectCfg) continue; + List plcCodeList = Arrays.asList(objectCfg.getPlcCode().split(MesPcnExtConstWords.COMMA)); + List filterList = plcCodeList2Cell.stream().filter(o -> (!StringUtils.isEmpty(o) && plcCodeList.contains(o))).collect(Collectors.toList()); + if (!flag && (CollectionUtils.isEmpty(filterList) || filterList.size() != 1)) return false; + if (flag && filterList.size() != 1) + execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("生产线[%s]工位[%s]配置的数据位PLC代码集合%s,检查对象结构信息ID[%s]对应的PLC代码集合[%s],一条对象结构信息只能关联工位的一个数据位PLC代码!", + reqBean.getWorkCenterCode(), reqBean.getWorkCellCode(), plcCodeList2Cell.toString(), objectCfg.getId(), objectCfg.getPlcCode())); + } + return true; } - private List getObjectCfgDbList(StationRequestBean reqBean, StationResultBean resultBean, List plcCodeList) { - List objectCfgList = plcExtService.getObjectCfgDbList(reqBean.getOrganizeCode(), plcCodeList); + private List getObjectCfgDbList(StationRequestBean reqBean, StationResultBean resultBean, List plcCodeList2Cell) { + List objectCfgList = plcExtService.getObjectCfgDbList(reqBean.getOrganizeCode(), plcCodeList2Cell); if (CollectionUtils.isEmpty(objectCfgList)) execExpSendMsgAndThrowEx(reqBean, resultBean, String.format("生产线[%s]工位[%s]配置的数据位PLC信息未维护有效的对象结构信息!", reqBean.getWorkCenterCode(), reqBean.getWorkCellCode())); return objectCfgList; }