diff --git a/src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java b/src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java index 90f78e98..306940dc 100644 --- a/src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java +++ b/src/main/java/com/spring/modules/part/service/impl/PartInformationServiceImpl.java @@ -1785,6 +1785,9 @@ public class PartInformationServiceImpl extends ServiceImpl().eq("site", inData.getSite()).eq("part_no", inData.getPartNo())); if (partInformationEntity != null) { @@ -1793,7 +1796,19 @@ public class PartInformationServiceImpl extends ServiceImpl().eq("site", inData.getPreviousVersion().getSite()).eq("part_no", inData.getPreviousVersion().getPartNo())); - temporaryCopyPart(inData, fromPart); + try { + temporaryCopyPart(inData, fromPart); + } catch (Exception e) { + // 调用删除接口 + String deleteCopyPartURL = apiUrl + "/part/ifs/removeCopyPartForInventoryPart"; + ResponseData deleteCopyPartResponse = HttpClientUtil.doPostByRawWithPLM(deleteCopyPartURL, ifsCatalog); + if (!"200".equals(deleteCopyPartResponse.getCode())) { + throw new RuntimeException(e.getMessage() + "; IFS删除Copy part关联信息异常:" + deleteCopyPartResponse.getMsg()); + } + throw new RuntimeException(e.getMessage()); + } + + // if ("Y".equals(fromPart.getStatus())) { // officialCopyPart(inData, fromPart); // } else { @@ -2118,1985 +2133,1987 @@ public class PartInformationServiceImpl extends ServiceImpl masterPartModalConvert(PartIfsCatalogProperty ifsPartCatalogItem, PartInformationVo inData) { - List partModalList = new ArrayList<>(); - PartSubPropertiesValueHeaderData headerData = new PartSubPropertiesValueHeaderData(); - headerData.setSite("*"); - headerData.setPartNo(inData.getPartNo()); - headerData.setCodeNo(ifsPartCatalogItem.getTechnicalClass()); - headerData.setSubCodeSeqNo(Double.valueOf("1")); - headerData.setRecordType("MP"); - partModalList.add(headerData); - return partModalList; - } /** - * Master Part 属性对象转换 - * @param ifsPartCatalogItems + * 临时物料的copy part * @param inData - * @return + * @param fromPart */ - private List masterPartItemConvert(List ifsPartCatalogItems, PartInformationVo inData) { - List partItemList = new ArrayList<>(); - int count = 1; - for (PartIfsCatalogProperty ifsInventoryItem : ifsPartCatalogItems) { - PartSubPropertiesValueData partItem = new PartSubPropertiesValueData(); - partItem.setSite("*"); - partItem.setPartNo(inData.getPartNo()); - partItem.setCodeNo(ifsInventoryItem.getTechnicalClass()); - partItem.setSubCodeSeqNo(Double.valueOf("1")); - partItem.setItemNo((double) count++); - partItem.setPropertiesItemNo(ifsInventoryItem.getAttribute()); - partItem.setTextValue(ifsInventoryItem.getValueText()); - partItem.setNumValue(Double.valueOf(ifsInventoryItem.getValueNo())); - partItem.setRecordType("MP"); - partItemList.add(partItem); + @Transactional + public void temporaryCopyPart(PartInformationVo inData, PartInformationEntity fromPart) { + CopyPart copyPart = new CopyPart(); + copyPart.setOriContract(fromPart.getSite()); + copyPart.setOriPartNo(fromPart.getPartNo()); + copyPart.setContract(inData.getSite()); + copyPart.setPartNo(inData.getPartNo()); + copyPart.setPartDesc(inData.getPartDesc()); + copyPart.setCopyGeneral(inData.getCopyGeneral()); + copyPart.setCopyManufacturing(inData.getCopyManufacturing()); + copyPart.setCopyDefaultLocation(inData.getCopyDefaultLocation()); + copyPart.setCopyCharacteristic(inData.getCopyCharacteristic()); + copyPart.setCopyPPGeneral(inData.getCopyPPGeneral()); + copyPart.setCopyPPDocumentTexts(inData.getCopyPPDocumentTexts()); + copyPart.setCopyPPConnectedObjects(inData.getCopyPPConnectedObjects()); + copyPart.setCopySPPGeneral(inData.getCopySPPGeneral()); + copyPart.setCopySPPDocumentTexts(inData.getCopySPPDocumentTexts()); + copyPart.setCopySPGeneral(inData.getCopySPGeneral()); + copyPart.setCopySPCharacteristics(inData.getCopySPCharacteristics()); + copyPart.setCopySPDocumentTexts(inData.getCopySPDocumentTexts()); + copyPart.setCopySPLanguageDescription(inData.getCopySPLanguageDescription()); + // 调用IFS的copyPart接口 + String copyPartURL = apiUrl + "/part/ifs/syncCopyPartForInventoryPart"; + ResponseData copyPartResponse = HttpClientUtil.doPostByRawWithPLM(copyPartURL, copyPart); + if (!"200".equals(copyPartResponse.getCode())) { + throw new RuntimeException("ifs 库存件copyPart异常:" + copyPartResponse.getMsg()); } - return partItemList; - } - /** - * 组合 InventoryPart 对象 - * @param ifsInventoryPart - * @param ifsInventoryPartPlanning - * @param ifsInventoryPartManufacturing - * @param ifsInventoryPartCost - * @return - */ - private PartInformationEntity getInventoryPartInformation(PartInformationVo inData, PartIfsInventory ifsInventoryPart, PartIfsInventoryPlan ifsInventoryPartPlanning, PartIfsInventoryManufacture ifsInventoryPartManufacturing, PartIfsInventoryConfig ifsInventoryPartCost) { - PartInformationEntity partInformation = new PartInformationEntity(); - partInformation.setSite(ifsInventoryPart.getContract()); - partInformation.setPartNo(ifsInventoryPart.getPartNo()); - partInformation.setPartDesc(ifsInventoryPart.getPartDesc()); - partInformation.setStatus("Y"); - partInformation.setActive("Y"); - partInformation.setPartType(ifsInventoryPart.getTypeCode()); // 零件类型 - partInformation.setHazardCode(ifsInventoryPart.getHazardCode()); // 安全代码 - partInformation.setProductGroupId4(ifsInventoryPart.getPlannerBuyer()); // 计划人 - partInformation.setProductGroupId3(ifsInventoryPart.getAccountingGroup()); // 会计组 - partInformation.setUmId(ifsInventoryPart.getUnitMeas()); // 库存计量单位 - partInformation.setGroupId(ifsInventoryPart.getPartProductCode()); // 产品代码 - partInformation.setProductGroupId1(ifsInventoryPart.getPrimeCommodity()); // 商品组1 - partInformation.setFamilyId(ifsInventoryPart.getPartProductFamily()); // 产品大类 - partInformation.setProductGroupId2(ifsInventoryPart.getSecondCommodity()); // 商品组2 - partInformation.setTypeDesignation(ifsInventoryPart.getTypeDesignation()); // 类型指定 - partInformation.setAssetClass(ifsInventoryPart.getAssetClass()); // 资产等级 - partInformation.setDimQuality(ifsInventoryPart.getDimQuality()); // 尺寸/材质 - partInformation.setPartStatus(ifsInventoryPart.getPartStatus()); // 零件状态 - partInformation.setWeightNet(UtilsClass.stringToBigDecimal(ifsInventoryPart.getWeightNet())); // 净重 - partInformation.setUomForWeightNet(ifsInventoryPart.getUomForWeightNet()); // 净重单位 - partInformation.setVolumeNet(UtilsClass.stringToBigDecimal(ifsInventoryPart.getVolumeNet())); // 净数量 - partInformation.setUomForVolumeNet(ifsInventoryPart.getUomForVolumeNet()); // 数量单位 - partInformation.setAbcClass(ifsInventoryPart.getAbcClass()); // ABC类 - partInformation.setFrequencyClass(ifsInventoryPart.getFrequencyClass()); // 频率级别 - partInformation.setLifecycleStage(ifsInventoryPart.getLifecycleStage()); // 生命周期阶段 - partInformation.setManufacturingLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPart.getManufLeadtime())); // 制造备货期 - partInformation.setCountryOfOrigin(ifsInventoryPart.getCountryOfOrigin()); // 来源国家 - partInformation.setExpectedLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPart.getExpectedLeadtime())); // 预期提前期 - partInformation.setDurabilityDay(UtilsClass.stringToInteger(ifsInventoryPart.getDurabilityDay())); // 天数 - partInformation.setRegionOfOrigin(ifsInventoryPart.getRegionOfOrigin()); // 区域代码 - partInformation.setIntrastatConvFactor(UtilsClass.stringToBigDecimal(ifsInventoryPart.getIntrastatConvFactor())); // 州内转换因子 - partInformation.setCustomsStatNo(ifsInventoryPart.getCustomsStatNo()); // 海关统计序号 - partInformation.setRemark(ifsInventoryPart.getNoteText()); // 备注 - partInformation.setInventoryValuationMethod(ifsInventoryPart.getInventoryValuationMethod()); // 库存估价方法 - partInformation.setPartCostGroupId(ifsInventoryPart.getPartCostGroupId()); // 零件成本组 - partInformation.setInventoryPartCostLevel(ifsInventoryPart.getInventoryPartCostLevel()); // 库存件成本层 - partInformation.setInvoiceConsideration(ifsInventoryPart.getInvoiceConsideration()); // 供应商发票事项 - partInformation.setZeroCostFlag(ifsInventoryPart.getZeroCostFlag()); // 零成本 - partInformation.setCreateBy(inData.getCreateBy()); // 创建人 - if (ifsInventoryPartCost != null) { - partInformation.setConfigurationId(ifsInventoryPartCost.getConfigurationId()); // 配置标识 - partInformation.setEstimatedMaterialCost(UtilsClass.stringToBigDecimal(ifsInventoryPartCost.getEstimatedMaterialCost())); // 估计物料成本 + + // 判断master part 是否存在,否则新增 + MasterPartInformationEntity masterPartInformation = masterPartInformationMapper.selectOne(new QueryWrapper().eq("part_no", inData.getPartNo())); + if (masterPartInformation == null) { + MasterPartInformationEntity masterPart = masterPartInformationMapper.selectOne(new QueryWrapper().eq("part_no", fromPart.getPartNo())); + masterPart.setPartNo(inData.getPartNo()); + masterPartInformationMapper.insert(masterPart); } - if (ifsInventoryPartPlanning != null) { - partInformation.setPlanningMethod(ifsInventoryPartPlanning.getPlanningMethod()); // 计划方法 - partInformation.setSafetyStock(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getSafetyStock())); // 安全库存 - partInformation.setMinOrderQty(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getMinOrderQty())); // 最小批量 - partInformation.setMaxOrderQty(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getMaxOrderQty())); // 最大批量 - partInformation.setMulOrderQty(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getMulOrderQty())); // 多种批量大小 - partInformation.setSafetyLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getSafetyLeadTime())); // 安全提前期 - partInformation.setShrinkageFac(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getShrinkageFac())); // 报废因子 - partInformation.setStdOrderQty(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getStdOrderSize())); // 标准批量大小 + // master part 模板和属性 + List checkValueHeaderData = partInformationMapper.getMasterPartModal("*", fromPart.getPartNo(), "MP"); + if (!checkValueHeaderData.isEmpty()) { + List valueHeaders = checkValueHeaderData.stream().map(a -> { + a.setPartNo(inData.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartModelHeaders(valueHeaders); } - if (ifsInventoryPartManufacturing != null) { - partInformation.setCumLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getCumLeadtime())); // 累计提前期 - partInformation.setBackFlushPart(ifsInventoryPartManufacturing.getBackflushPart()); // 预留/下发来源 - partInformation.setByProdAsSupplyInMrpDb(ifsInventoryPartManufacturing.getByProdAsSupplyInMrpDb()); // 将副产品用作MRP中的供应 - partInformation.setUnprotectedLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getUnprotectedLeadTime())); // 未受保护提前期 - partInformation.setIssueType(ifsInventoryPartManufacturing.getIssueType()); // 预留/下发方法 - partInformation.setMrpControlFlagDb(ifsInventoryPartManufacturing.getMrpControlFlagDb()); // MRP控制 - partInformation.setFixedLeadTimeDay(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getFixedLeadtimeDay())); // 按日固定提前期 - partInformation.setOverReporting(ifsInventoryPartManufacturing.getOverReporting()); // 过度报告 - partInformation.setUseTheoreticalDensityDb(ifsInventoryPartManufacturing.getUseTheoriticalDensityDb()); // 使用理论 - partInformation.setVariableLeadTimeDay(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getVariableLeadtimeDay())); // 按天的可变化提前期 - partInformation.setOverReportTolerance(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getOverReportTolerance())); // 报告公差过大 - partInformation.setFixedLeadTimeHour(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getFixedLeadtimeHour())); // 按小时的固定提前期 - partInformation.setDensity(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getDensity())); // 密度 - partInformation.setVariableLeadTimeHour(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getVariableLeadtimeHour())); // 按小时计算的可变提前期 + PartSubPropertiesValueData valueData = new PartSubPropertiesValueData(); + valueData.setSite("*"); + valueData.setPartNo(fromPart.getPartNo()); + valueData.setRecordType("MP"); + // 物料属性 + List fromPartItems1 = partInformationMapper.getItemModal(valueData); + if (!fromPartItems1.isEmpty()) { + List toPartItems1 = fromPartItems1.stream().map(a -> { + a.setSite("*"); + a.setPartNo(inData.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartModelDetails(toPartItems1); } - return partInformation; - } - /** - * Inventory Part Revision对象转换 - * @param ifsInventoryPartRevision - * @param inData - * @return - */ - private List inventoryPartRevisionConvert(List ifsInventoryPartRevision, PartInformationVo inData) { - List partRevisionList = new ArrayList<>(); - for (PartIfsInventoryRevision ifsInventoryRevision : ifsInventoryPartRevision) { - PartRevisionEntity partRevision = new PartRevisionEntity(); - partRevision.setSite(ifsInventoryRevision.getContract()); - partRevision.setPartNo(ifsInventoryRevision.getPartNo()); - partRevision.setEngChgLevel(Integer.parseInt(ifsInventoryRevision.getEngChgLevel())); - partRevision.setEffPhaseInDate(DateUtils.getStringToDate(ifsInventoryRevision.getEffPhaseInDate(), "yyyy-MM-dd")); - partRevision.setEffPhaseOutDate(DateUtils.getStringToDate(ifsInventoryRevision.getEffPhaseOutDate(), "yyyy-MM-dd")); - partRevision.setRevisionText(ifsInventoryRevision.getRevisionText()); - partRevision.setProductStatus(ifsInventoryRevision.getProductStatus()); - partRevision.setRepairStatus(ifsInventoryRevision.getRepairStatus()); - partRevision.setEngRevision(ifsInventoryRevision.getEngRevision()); - partRevision.setCreateBy(inData.getCreateBy()); - partRevisionList.add(partRevision); - } - return partRevisionList; - } - /** - * Inventory Part Location对象转换 - * @param ifsInventoryPartLocation - * @param inData - * @return - */ - private List inventoryPartLocationConvert(List ifsInventoryPartLocation, PartInformationVo inData) { - List partLocationList = new ArrayList<>(); - for (PartIfsInventoryLocation ifsInventoryLocation : ifsInventoryPartLocation) { - LocationInformationVo partLocation = new LocationInformationVo(); - partLocation.setSite(ifsInventoryLocation.getContract()); - partLocation.setPartNo(ifsInventoryLocation.getPartNo()); - partLocation.setLocationId(ifsInventoryLocation.getLocationNo()); - partLocationList.add(partLocation); - } - return partLocationList; - } + // Inventory Part + PartInformationEntity toPart = new PartInformationEntity(); + toPart.setSite(inData.getSite()); + toPart.setPartNo(inData.getPartNo()); + toPart.setPartDesc(inData.getPartDesc()); + toPart.setStatus(fromPart.getStatus()); - /** - * Inventory Part 属性对象转换 - * @param ifsInventoryPartItem - * @param inData - * @return - */ - private List inventoryPartItemConvert(List ifsInventoryPartItem, PartInformationVo inData) { - List partItemList = new ArrayList<>(); - int count = 1; - for (PartIfsInventoryProperty ifsInventoryItem : ifsInventoryPartItem) { - PartSubPropertiesValueData partItem = new PartSubPropertiesValueData(); - partItem.setSite(ifsInventoryItem.getContract()); - partItem.setPartNo(ifsInventoryItem.getPartNo()); - partItem.setCodeNo(ifsInventoryItem.getEngAttribute()); - partItem.setSubCodeSeqNo(Double.valueOf("1")); - partItem.setItemNo((double) count++); - partItem.setPropertiesItemNo(ifsInventoryItem.getCharacteristicCode()); - partItem.setTextValue(ifsInventoryItem.getAttrValueAlpha()); - partItem.setNumValue(Double.valueOf(ifsInventoryItem.getAttrValueNumeric())); - partItem.setRecordType("IP"); - partItemList.add(partItem); - } - return partItemList; - } + // General + toPart.setPartType(fromPart.getPartType()); // 零件类型 + toPart.setHazardCode(fromPart.getHazardCode()); // 安全代码 + toPart.setProductGroupId4(fromPart.getProductGroupId4()); // 计划人 + toPart.setProductGroupId3(fromPart.getProductGroupId3()); // 会计组 + toPart.setUmId(fromPart.getUmId()); // 库存计量单位 + toPart.setGroupId(fromPart.getGroupId()); // 产品代码 + toPart.setProductGroupId1(fromPart.getProductGroupId1()); // 商品组1 + toPart.setFamilyId(fromPart.getFamilyId()); // 产品大类 + toPart.setProductGroupId2(fromPart.getProductGroupId2()); // 商品组2 + toPart.setTypeDesignation(fromPart.getTypeDesignation()); // 类型指定 + toPart.setAssetClass(fromPart.getAssetClass()); // 资产等级 + toPart.setDimQuality(fromPart.getDimQuality()); // 尺寸/材质 + toPart.setPartStatus(fromPart.getPartStatus()); // 零件状态 + toPart.setWeightNet(fromPart.getWeightNet()); // 净重 + toPart.setUomForWeightNet(fromPart.getUomForWeightNet()); // 净重单位 + toPart.setVolumeNet(fromPart.getVolumeNet()); // 净数量 + toPart.setUomForVolumeNet(fromPart.getUomForVolumeNet()); // 数量单位 + toPart.setAbcClass(fromPart.getAbcClass()); // ABC类 + toPart.setFrequencyClass(fromPart.getFrequencyClass()); // 频率级别 + toPart.setLifecycleStage(fromPart.getLifecycleStage()); // 生命周期阶段 + toPart.setManufacturingLeadTime(fromPart.getManufacturingLeadTime()); // 制造备货期 + toPart.setCountryOfOrigin(fromPart.getCountryOfOrigin()); // 来源国家 + toPart.setExpectedLeadTime(fromPart.getExpectedLeadTime()); // 预期提前期 + toPart.setDurabilityDay(fromPart.getDurabilityDay()); // 天数 + toPart.setRegionOfOrigin(fromPart.getRegionOfOrigin()); // 区域代码 + toPart.setIntrastatConvFactor(fromPart.getIntrastatConvFactor()); // 州内转换因子 + toPart.setCustomsStatNo(fromPart.getCustomsStatNo()); // 海关统计序号 + toPart.setRemark(fromPart.getRemark()); // 备注 + toPart.setInventoryValuationMethod(fromPart.getInventoryValuationMethod()); // 库存估价方法 + toPart.setPartCostGroupId(fromPart.getPartCostGroupId()); // 零件成本组 + toPart.setInventoryPartCostLevel(fromPart.getInventoryPartCostLevel()); // 库存件成本层 + toPart.setInvoiceConsideration(fromPart.getInvoiceConsideration()); // 供应商发票事项 + toPart.setZeroCostFlag(fromPart.getZeroCostFlag()); // 零成本 + toPart.setCreateBy(inData.getCreateBy()); // 创建人 + toPart.setConfigurationId(fromPart.getConfigurationId()); // 配置标识 + toPart.setEstimatedMaterialCost(fromPart.getEstimatedMaterialCost()); // 估计物料成本 + toPart.setPlanningMethod(fromPart.getPlanningMethod()); // 计划方法 + toPart.setSafetyStock(fromPart.getSafetyStock()); // 安全库存 + toPart.setMinOrderQty(fromPart.getMinOrderQty()); // 最小批量 + toPart.setMaxOrderQty(fromPart.getMaxOrderQty()); // 最大批量 + toPart.setMulOrderQty(fromPart.getMulOrderQty()); // 多种批量大小 + toPart.setSafetyLeadTime(fromPart.getSafetyLeadTime()); // 安全提前期 + toPart.setShrinkageFac(fromPart.getShrinkageFac()); // 报废因子 + toPart.setStdOrderQty(fromPart.getStdOrderQty()); // 标准批量大小 - /** - * Routing Header对象转换 - * @param ifsRoutingHeaders - * @param inData - * @return - */ - private List routingHeaderDataConvert(List ifsRoutingHeaders, PartInformationVo inData) { - List headerList = new ArrayList<>(); - for (RoutingIfsHeader header : ifsRoutingHeaders) { - RoutingHeaderVo headerEntity = new RoutingHeaderVo(); - headerEntity.setSite(header.getContract()); - headerEntity.setPartNo(header.getPartNo()); - headerEntity.setRoutingRevision(Integer.parseInt(header.getRoutingRevision())); - headerEntity.setRoutingType(header.getRoutingType()); - headerEntity.setPhaseInDate(DateUtils.getStringToDate(header.getPhaseInDate(), "yyyy-MM-dd")); - headerEntity.setPhaseOutDate(DateUtils.getStringToDate(header.getPhaseOutDate(), "yyyy-MM-dd")); - headerEntity.setNoteText(header.getNoteText()); - headerEntity.setCreateBy(inData.getCreateBy()); - headerEntity.setOfficialFlag("Y"); - headerList.add(headerEntity); + // Manufacturing + if ("Y".equals(inData.getCopyManufacturing())) { + toPart.setCumLeadTime(fromPart.getCumLeadTime()); // 累计提前期 + toPart.setBackFlushPart(fromPart.getBackFlushPart()); // 预留/下发来源 + toPart.setByProdAsSupplyInMrpDb(fromPart.getByProdAsSupplyInMrpDb()); // 将副产品用作MRP中的供应 + toPart.setUnprotectedLeadTime(fromPart.getUnprotectedLeadTime()); // 未受保护提前期 + toPart.setIssueType(fromPart.getIssueType()); // 预留/下发方法 + toPart.setMrpControlFlagDb(fromPart.getMrpControlFlagDb()); // MRP控制 + toPart.setFixedLeadTimeDay(fromPart.getFixedLeadTimeDay()); // 按日固定提前期 + toPart.setOverReporting(fromPart.getOverReporting()); // 过度报告 + toPart.setUseTheoreticalDensityDb(fromPart.getUseTheoreticalDensityDb()); // 使用理论 + toPart.setVariableLeadTimeDay(fromPart.getVariableLeadTimeDay()); // 按天的可变化提前期 + toPart.setOverReportTolerance(fromPart.getOverReportTolerance()); // 报告公差过大 + toPart.setFixedLeadTimeHour(fromPart.getFixedLeadTimeHour()); // 按小时的固定提前期 + toPart.setDensity(fromPart.getDensity()); // 密度 + toPart.setVariableLeadTimeHour(fromPart.getVariableLeadTimeHour()); // 按小时计算的可变提前期 } - return headerList; - } - /** - * Routing Detail对象转换 - * @param ifsRoutingDetails - * @param inData - * @return - */ - private List routingDetailDataConvert(List ifsRoutingDetails, PartInformationVo inData) { - List detailList = new ArrayList<>(); - for (RoutingIfsAlternative detail : ifsRoutingDetails) { - RoutingDetailVo detailEntity = new RoutingDetailVo(); - detailEntity.setSite(detail.getContract()); - detailEntity.setPartNo(detail.getPartNo()); - detailEntity.setRoutingRevision(Integer.parseInt(detail.getRoutingRevision())); - detailEntity.setRoutingType(detail.getRoutingType()); - detailEntity.setAlternativeNo(detail.getAlternativeNo()); - detailEntity.setAlternativeDescription(detail.getAlternativeDesc()); - detailEntity.setStatus(detail.getState()); - detailEntity.setNoteText(detail.getNoteText()); - detailEntity.setCreateBy(inData.getCreateBy()); - detailEntity.setOfficialFlag("Y"); - detailList.add(detailEntity); + // Characteristic + if ("Y".equals(inData.getCopyCharacteristic())) { + toPart.setCodeNo(fromPart.getCodeNo()); // 属性模板 + valueData.setSite(inData.getSite()); + valueData.setRecordType("IP"); + // 新增物料属性 + List fromPartItems2 = partInformationMapper.getItemModal(valueData); + if (!fromPartItems2.isEmpty()) { + List toPartItems2 = fromPartItems2.stream().map(a -> { + a.setSite(inData.getSite()); + a.setPartNo(inData.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartModelDetails(toPartItems2); + } } - return detailList; - } + // 新增 + partInformationMapper.insert(toPart); + // 当前日期 + Date actualDate = DateUtils.getStringToDate(DateUtils.getStringNow2(), "yyyy-MM-dd"); - /** - * Routing Item对象转换 - * @param ifsRoutingComponents - * @return - */ - private List routingItemDataConvert(List ifsRoutingComponents, PartInformationVo inData) { - List componentList = new ArrayList<>(); - for (RoutingIfsItem component : ifsRoutingComponents) { - RoutingComponentVo componentEntity = new RoutingComponentVo(); - componentEntity.setSite(component.getContract()); - componentEntity.setPartNo(component.getPartNo()); - componentEntity.setRoutingRevision(Integer.parseInt(component.getRoutingRevision())); - componentEntity.setRoutingType(component.getRoutingType()); - componentEntity.setAlternativeNo(component.getAlternativeNo()); - componentEntity.setOperationId(Integer.parseInt(component.getOperationId())); - componentEntity.setOperationNo(Integer.parseInt(component.getOperationNo())); - componentEntity.setOperationName(component.getOperationDesc()); - componentEntity.setEfficiencyFactor(UtilsClass.stringToBigDecimal(component.getEfficiencyFactor())); - componentEntity.setMachRunFactor(UtilsClass.stringToBigDecimal(component.getMachRunFactor())); - componentEntity.setMachSetupTime(UtilsClass.stringToBigDecimal(component.getMachSetupTime())); - componentEntity.setRunTimeCode(component.getRunTimeCode()); - componentEntity.setLaborRunFactor(UtilsClass.stringToBigDecimal(component.getLaborRunFactor())); - componentEntity.setLaborSetupTime(UtilsClass.stringToBigDecimal(component.getLaborSetupTime())); - componentEntity.setCrewSize(UtilsClass.stringToInteger(component.getCrewSize())); - componentEntity.setSetupCrewSize(UtilsClass.stringToInteger(component.getSetupCrewSize())); - componentEntity.setOutsideOpItem(component.getOutsideOpItem()); - componentEntity.setMachineNo(component.getMachineNo()); - componentEntity.setWorkCenterNo(component.getWorkCenterNo()); - componentEntity.setLaborClassNo(component.getLaborClassNo()); - componentEntity.setSetupLaborClassNo(component.getSetupLaborClassNo()); - componentEntity.setOverlap(UtilsClass.stringToInteger(component.getOverlap())); - componentEntity.setNoteText(component.getNoteText()); - componentEntity.setIfsRowId(component.getIfsRowId()); - componentEntity.setIfsRowVersion(component.getIfsRowVersion()); - componentEntity.setCreateBy(inData.getCreateBy()); - componentList.add(componentEntity); + // Revisions + List fromRevisionList = partInformationMapper.getFromPartRevision(fromPart.getSite(), fromPart.getPartNo(), toPart.getSite(), toPart.getPartNo(), inData.getCreateBy()); + HashMap revisionMap = new HashMap<>(); + if (!fromRevisionList.isEmpty()) { + int num = 1; + for (PartRevisionEntity partRevisionEntity : fromRevisionList) { + revisionMap.put(partRevisionEntity.getEngChgLevel(), num); + partRevisionEntity.setEngChgLevel(num++); + partRevisionEntity.setEffPhaseInDate(actualDate); + partRevisionEntity.setProductStatus("Not In Effect"); + partRevisionEntity.setRepairStatus("Not In Effect"); + } + partInformationMapper.saveRevisions(fromRevisionList); } - return componentList; - } - /** - * Routing Tool对象转换 - * @param ifsRoutingTools - * @param inData - * @param operationMap - * @return - */ - private List routingToolDataConvert(List ifsRoutingTools, PartInformationVo inData, HashMap operationMap) { - List routingToolList = new ArrayList<>(); - for (RoutingIfsTool ifsTool : ifsRoutingTools) { - RoutingToolEntity routingTool = new RoutingToolEntity(); - routingTool.setSite(ifsTool.getContract()); - routingTool.setPartNo(ifsTool.getPartNo()); - routingTool.setRoutingRevision(Integer.parseInt(ifsTool.getRoutingRevision())); - routingTool.setRoutingType(ifsTool.getRoutingType()); - routingTool.setAlternativeNo(ifsTool.getAlternativeNo()); - routingTool.setOperationId(operationMap.get(Integer.parseInt(ifsTool.getOperationId()))); - routingTool.setToolId(ifsTool.getToolId()); - routingTool.setToolQty(UtilsClass.stringToInteger(ifsTool.getToolQuantity())); - routingTool.setRemark(ifsTool.getNoteText()); - routingTool.setCreateBy(inData.getCreateBy()); - routingTool.setIfsRowId(ifsTool.getIfsRowId()); - routingTool.setIfsRowVersion(ifsTool.getIfsRowVersion()); - routingToolList.add(routingTool); + // 新增物料默认库位 + if ("Y".equals(inData.getCopyDefaultLocation())) { + List fromLocationList = partInformationMapper.getPartDefaultLocations(fromPart); + if (!fromLocationList.isEmpty()) { + List ifsDefaultLocations = fromLocationList.stream().map(a -> { + a.setSite(toPart.getSite()); + a.setPartNo(toPart.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartDefaultLocation(ifsDefaultLocations); + } } - return routingToolList; - } - /** - * Routing Guideline对象转换 - * @param ifsRoutingGuidelines - * @param inData - * @param operationMap - * @return - */ - private List routingGuidelineDataConvert(List ifsRoutingGuidelines, PartInformationVo inData, HashMap operationMap) { - List routingGuidelineList = new ArrayList<>(); - for (RoutingIfsGuideLine ifsGuideline : ifsRoutingGuidelines) { - WorkGuidelineEntity routingGuideline = new WorkGuidelineEntity(); - routingGuideline.setSite(ifsGuideline.getContract()); - routingGuideline.setPartNo(ifsGuideline.getPartNo()); - routingGuideline.setRoutingRevision(Integer.parseInt(ifsGuideline.getRoutingRevision())); - routingGuideline.setRoutingType(ifsGuideline.getRoutingType()); - routingGuideline.setAlternativeNo(ifsGuideline.getAlternativeNo()); - routingGuideline.setOperationId(operationMap.get(Integer.parseInt(ifsGuideline.getOperationId()))); - routingGuideline.setGuidelineSeq(UtilsClass.stringToInteger(ifsGuideline.getGuidelineSeq())); - routingGuideline.setGuidelineDesc(ifsGuideline.getGuidelineDesc()); - routingGuideline.setGuidelineText(ifsGuideline.getGuidelineText()); - routingGuideline.setGuidelineType(ifsGuideline.getOperWorkGuideType()); - routingGuideline.setSignOffRequired(ifsGuideline.getSignOffReq()); - routingGuideline.setInspectionSignOffRequired(ifsGuideline.getInspectSignOffReq()); - routingGuideline.setCreateBy(inData.getCreateBy()); - routingGuideline.setIfsRowId(ifsGuideline.getIfsRowId()); - routingGuideline.setIfsRowVersion(ifsGuideline.getIfsRowVersion()); - routingGuidelineList.add(routingGuideline); + // 代理商、制造商、文档 + List agents = partInformationMapper.getPartAgents(fromPart); + List manufacturers = partInformationMapper.getPartManufacturers(fromPart); + List files = partInformationMapper.getPartFiles(fromPart); + if (!agents.isEmpty()) { + List ifsAgents = agents.stream().map(a -> { + a.setSite(toPart.getSite()); + a.setPartNo(toPart.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartAgent(ifsAgents); + } + if (!manufacturers.isEmpty()) { + List ifsManufacturers = manufacturers.stream().map(a -> { + a.setSite(toPart.getSite()); + a.setPartNo(toPart.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartManufacturer(ifsManufacturers); + } + if (!files.isEmpty()) { + List ifsFiles = files.stream().map(a -> { + a.setOrderRef1(toPart.getSite()); + a.setOrderRef2(toPart.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartFile(ifsFiles); } - return routingGuidelineList; - } - /** - * BOM Header对象转换 - * @param ifsBomHeaders - * @param inData - * @return - */ - private List bomHeaderDataConvert(List ifsBomHeaders, PartInformationVo inData) { - List headerList = new ArrayList<>(); - for (BomIfsHeader header : ifsBomHeaders) { - BomHeaderVo headerEntity = new BomHeaderVo(); - headerEntity.setSite(header.getContract()); - headerEntity.setPartNo(header.getPartNo()); - headerEntity.setEngChgLevel(Integer.parseInt(header.getEngChgLevel())); - headerEntity.setBomType(header.getBomType()); - headerEntity.setEffPhaseInDate(DateUtils.getStringToDate(header.getEffPhaseInDate(), "yyyy-MM-dd")); - headerEntity.setEffPhaseOutDate(DateUtils.getStringToDate(header.getEffPhaseOutDate(), "yyyy-MM-dd")); - headerEntity.setNoteText(header.getNoteText()); - headerEntity.setEngRevision(header.getEngRevision()); - headerEntity.setCreateBy(inData.getCreateBy()); - headerEntity.setOfficialFlag("Y"); - headerList.add(headerEntity); + // 新增Routing + HashMap operationMap = new HashMap(); // 存放新的operationId + List routingHeaderList = routingManagementMapper.selectRoutingHeaderByPartNo(fromPart.getSite(), fromPart.getPartNo()); + List routingDetailList = routingManagementMapper.selectRoutingDetailByPartNo(fromPart.getSite(), fromPart.getPartNo()); + List routingComponentList = routingManagementMapper.selectRoutingComponentByPartNo(fromPart.getSite(), fromPart.getPartNo()); + List routingToolList = routingManagementMapper.selectRoutingToolByPartNo(fromPart.getSite(), fromPart.getPartNo()); + List routingGuidelineList = routingManagementMapper.selectRoutingGuidelineByPartNo(fromPart.getSite(), fromPart.getPartNo()); + if (!routingHeaderList.isEmpty()) { + for (RoutingHeaderVo routingHeader : routingHeaderList) { + routingHeader.setSite(toPart.getSite()); + routingHeader.setPartNo(toPart.getPartNo()); + routingHeader.setCreateBy(inData.getCreateBy()); + } + routingManagementMapper.saveRoutingHeaderList(routingHeaderList); + } + if (!routingDetailList.isEmpty()) { + for (RoutingDetailVo routingDetail : routingDetailList) { + routingDetail.setSite(toPart.getSite()); + routingDetail.setPartNo(toPart.getPartNo()); + routingDetail.setCreateBy(inData.getCreateBy()); + } + routingManagementMapper.saveRoutingDetailList(routingDetailList); + } + if (!routingComponentList.isEmpty()) { + Integer oldOperationId; + for (RoutingComponentVo routingComponent : routingComponentList) { + oldOperationId = routingComponent.getOperationId(); + routingComponent.setSite(toPart.getSite()); + routingComponent.setPartNo(toPart.getPartNo()); + routingComponent.setCreateBy(inData.getCreateBy()); + routingManagementMapper.saveRoutingComponent(routingComponent); + operationMap.put(oldOperationId, routingComponent.getOperationId()); + } + } + if (!routingToolList.isEmpty()) { + for (RoutingToolEntity routingTool : routingToolList) { + routingTool.setSite(toPart.getSite()); + routingTool.setPartNo(toPart.getPartNo()); + routingTool.setOperationId(operationMap.get(routingTool.getOperationId())); + routingTool.setCreateBy(inData.getCreateBy()); + } + routingManagementMapper.saveRoutingTool(routingToolList); + } + if (!routingGuidelineList.isEmpty()) { + for (WorkGuidelineEntity workGuideline : routingGuidelineList) { + workGuideline.setSite(toPart.getSite()); + workGuideline.setPartNo(toPart.getPartNo()); + workGuideline.setOperationId(operationMap.get(workGuideline.getOperationId())); + workGuideline.setCreateBy(inData.getCreateBy()); + } + routingManagementMapper.saveGuideLine(routingGuidelineList); + } + + // 新增BOM + List bomHeaderList = bomManagementMapper.selectBomHeaderByPartNo(fromPart.getSite(), fromPart.getPartNo()); + List bomDetailList = bomManagementMapper.selectBomDetailByPartNo(fromPart.getSite(), fromPart.getPartNo()); + List bomComponentList = bomManagementMapper.selectBomComponentByPartNo(fromPart.getSite(), fromPart.getPartNo()); + List bomManufStructCostDistribList = bomManagementMapper.selectBomManufStructCostDistribByPartNo(fromPart.getSite(), fromPart.getPartNo()); + if (!bomHeaderList.isEmpty()) { + for (BomHeaderVo bomHeader : bomHeaderList) { + bomHeader.setSite(toPart.getSite()); + bomHeader.setPartNo(toPart.getPartNo()); + bomHeader.setEngChgLevel(revisionMap.get(bomHeader.getEngChgLevel())); + bomHeader.setEffPhaseInDate(actualDate); + bomHeader.setCreateBy(inData.getCreateBy()); + } + partInformationMapper.saveBomHeaders(bomHeaderList); + } + if (!bomDetailList.isEmpty()) { + for (BomDetailVo bomDetail : bomDetailList) { + bomDetail.setSite(toPart.getSite()); + bomDetail.setPartNo(toPart.getPartNo()); + bomDetail.setEngChgLevel(revisionMap.get(bomDetail.getEngChgLevel())); + bomDetail.setCreateBy(inData.getCreateBy()); + bomDetail.setStatus("Tentative"); + } + partInformationMapper.saveIfsBomAlternatives(bomDetailList); + } + if (!bomComponentList.isEmpty()) { + for (BomComponentVo bomComponent : bomComponentList) { + bomComponent.setSite(toPart.getSite()); + bomComponent.setPartNo(toPart.getPartNo()); + bomComponent.setEngChgLevel(revisionMap.get(bomComponent.getEngChgLevel())); + bomComponent.setCreateBy(inData.getCreateBy()); + } + bomManagementMapper.saveBomComponents(bomComponentList); + } + if (!bomManufStructCostDistribList.isEmpty()) { + for (BomManufStructCostDistribVo bomManufStructCostDistrib : bomManufStructCostDistribList) { + bomManufStructCostDistrib.setSite(toPart.getSite()); + bomManufStructCostDistrib.setPartNo(toPart.getPartNo()); + bomManufStructCostDistrib.setEngChgLevel(revisionMap.get(bomManufStructCostDistrib.getEngChgLevel())); + bomManufStructCostDistrib.setCreateBy(inData.getCreateBy()); + } + bomManagementMapper.saveBomManufStructCostDistrib(bomManufStructCostDistribList); } - return headerList; } /** - * BOM Detail对象转换 - * @param ifsBomDetails + * 新增物料版本 * @param inData - * @return */ - private List bomDetailDataConvert(List ifsBomDetails, PartInformationVo inData) { - List detailList = new ArrayList<>(); - for (BomIfsAlternative detail : ifsBomDetails) { - BomDetailVo detailEntity = new BomDetailVo(); - detailEntity.setSite(detail.getContract()); - detailEntity.setPartNo(detail.getPartNo()); - detailEntity.setEngChgLevel(Integer.parseInt(detail.getEngChgLevel())); - detailEntity.setBomType(detail.getBomType()); - detailEntity.setAlternativeNo(detail.getAlternativeNo()); - detailEntity.setAlternativeDescription(detail.getAlternativeDesc()); - detailEntity.setStatus(detail.getState()); - detailEntity.setDetailNoteText(detail.getNoteText()); - detailEntity.setCreateBy(inData.getCreateBy()); - detailEntity.setOfficialFlag("Y"); - detailList.add(detailEntity); + @Override + @Transactional + public void saveRevision(PartRevisionEntity inData) { + // 校验版本是否已存在 + List revisions = partInformationMapper.queryRevision(inData); + if (!revisions.isEmpty()) { + throw new RuntimeException("版本已存在!"); + } + // 新增revision + partInformationMapper.saveRevision(inData); + + PartInformationEntity partData = partInformationMapper.selectOne(new QueryWrapper().eq("site", inData.getSite()).eq("part_no", inData.getPartNo())); + + // 新增 BOM + if (!"Purchased (raw)".equals(partData.getPartType())) { + BomHeaderEntity bomHeader = new BomHeaderEntity(); + bomHeader.setSite(partData.getSite()); + bomHeader.setPartNo(partData.getPartNo()); + if (partData.getPartType().contains("Manufactured")) { + bomHeader.setBomType("Manufacturing"); + } else if ("Purchased".equals(partData.getPartType())) { + bomHeader.setBomType("Purchase"); + } + bomHeader.setEffPhaseInDate(inData.getEffPhaseInDate()); + bomHeader.setEffPhaseOutDate(inData.getEffPhaseOutDate()); + bomHeader.setEngChgLevel(inData.getEngChgLevel()); + bomHeader.setOfficialFlag("N"); + bomManagementMapper.saveBomHeader(bomHeader); + // 创建默认替代* + BomDetailEntity bomDetail = new BomDetailEntity(); + BeanUtils.copyProperties(bomHeader,bomDetail); + bomDetail.setAlternativeNo("*"); + bomDetail.setAlternativeDescription("*"); + bomDetail.setStatus("Tentative"); + bomDetail.setOfficialFlag("N"); + bomManagementMapper.bomDetailSave(bomDetail); + } + + if (dataUrl) { + // 判断是否为正式物料 + if ("Y".equals(partData.getStatus())) { + // 同步ifs + // 先判断ifs那边是否已存在该物料版本 + PartIfsInventoryRevision partIfsInventoryRevision = getPartIfsInventoryRevision(inData); + String queryPartRevisionURL = apiUrl + "/part/ifs/getInventoryPartRevision"; + ResponseData queryPartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(queryPartRevisionURL, partIfsInventoryRevision); + if ("200".equals(queryPartRevisionResponse.getCode())) { // 存在,修改 + // ifs修改物料版本 + String updatePartRevisionURL = apiUrl + "/part/ifs/modifyInventoryPartRevisionToIfs"; + ResponseData updatePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(updatePartRevisionURL, partIfsInventoryRevision); + if (!"200".equals(updatePartRevisionResponse.getCode())) { + throw new RuntimeException("ifs 库存件版本修改异常:" + updatePartRevisionResponse.getMsg()); + } + } else { // 不存在,新增 + // ifs新增物料版本 + String savePartRevisionURL = apiUrl + "/part/ifs/syncInventoryPartRevisionToIfs"; + ResponseData savePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(savePartRevisionURL, partIfsInventoryRevision); + if (!"200".equals(savePartRevisionResponse.getCode())) { + throw new RuntimeException("ifs 库存件版本新增异常:" + savePartRevisionResponse.getMsg()); + } + } + } } - return detailList; } /** - * BOM Item对象转换 - * @param ifsBomComponents + * 删除物料版本 * @param inData - * @return */ - private List bomItemDataConvert(List ifsBomComponents, PartInformationVo inData, HashMap operationMap) { - List componentList = new ArrayList<>(); - for (BomIfsItem component : ifsBomComponents) { - BomComponentVo componentEntity = new BomComponentVo(); - componentEntity.setSite(component.getContract()); - componentEntity.setPartNo(component.getPartNo()); - componentEntity.setEngChgLevel(Integer.parseInt(component.getEngChgLevel())); - componentEntity.setBomType(component.getBomType()); - componentEntity.setAlternativeNo(component.getAlternativeNo()); - componentEntity.setComponentPart(component.getComponentPart()); - componentEntity.setPrintUnit(component.getPrintUnit()); - componentEntity.setQtyPerAssembly(UtilsClass.stringToBigDecimal(component.getQtyPerAssembly())); - componentEntity.setComponentScrap(UtilsClass.stringToBigDecimal(component.getComponentScrap())); - componentEntity.setIssueType(component.getIssueType()); - componentEntity.setShrinkageFactor(UtilsClass.stringToBigDecimal(component.getShrinkageFactor())); - componentEntity.setLineItemNo(Integer.parseInt(component.getLineItemNo())); - componentEntity.setOperationNo(Integer.parseInt(component.getOperationNo())); - componentEntity.setIssueToLoc(component.getIssueToLoc()); - componentEntity.setNoteText(component.getNoteText()); - componentEntity.setLineSequence(Integer.parseInt(component.getLineSequence())); - componentEntity.setConsumptionItem(component.getConsumptionItem()); - componentEntity.setCreateBy(inData.getCreateBy()); - componentList.add(componentEntity); + @Override + @Transactional + public void deleteRevision(PartRevisionEntity inData) { + // 查询该版本的bom,判断bom的替代状态 + List bomDetailList = partInformationMapper.queryBomAlternative(inData); + if (!bomDetailList.isEmpty()) { + for (BomDetailEntity bomDetail : bomDetailList) { + if ("Buildable".equals(bomDetail.getStatus()) || "Obsolete".equals(bomDetail.getStatus())) { + throw new RuntimeException("存在状态为 Buildable 或者 Obsolete 的Bom!"); + } + } + } + // 删除revision + partInformationMapper.deleteRevision(inData); + // 删除该版本下的bomHeader + bomManagementMapper.delete(new QueryWrapper().eq("site", inData.getSite()).eq("part_no", inData.getPartNo()).eq("eng_chg_level", inData.getEngChgLevel())); + // 删除该版本下的bomDetail + partInformationMapper.deleteBomDetail(inData); + // 删除该版本下的bomComponent + partInformationMapper.deleteBomComponent(inData); + // 删除该版本下的副产品成本分配数据 + partInformationMapper.deleteManufStruct(inData); + + if (dataUrl) { + // 判断是否为正式物料 + PartInformationEntity partData = partInformationMapper.selectOne(new QueryWrapper().eq("site", inData.getSite()).eq("part_no", inData.getPartNo())); + if ("Y".equals(partData.getStatus())) { // 同步ifs,删除revision + PartIfsInventoryRevision partIfsInventoryRevision = new PartIfsInventoryRevision(); + partIfsInventoryRevision.setContract(inData.getSite()); + partIfsInventoryRevision.setPartNo(inData.getPartNo()); + partIfsInventoryRevision.setEngChgLevel(inData.getEngChgLevel().toString()); + String deletePartRevisionURL = apiUrl + "/part/ifs/removeInventoryPartRevisionToIfs"; + ResponseData deletePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(deletePartRevisionURL, partIfsInventoryRevision); + if (!"200".equals(deletePartRevisionResponse.getCode())) { + throw new RuntimeException("ifs 库存件版本删除异常:" + deletePartRevisionResponse.getMsg()); + } + } } - return componentList; } /** - * - * @param ifsBomManufStructCostDistribs - * @param inData + * 查询part + * @author: zelian_wu + * date 2023/11/21 * @return */ - private List bomManufStructCostDistribDataConvert(List ifsBomManufStructCostDistribs, PartInformationVo inData) { - List bomManufStructCostDistribVoList = new ArrayList<>(); - for (BomIfsManufStructCostDistrib structCostDistrib : ifsBomManufStructCostDistribs) { - BomManufStructCostDistribVo vo = new BomManufStructCostDistribVo(); - vo.setSite(structCostDistrib.getContract()); - vo.setPartNo(structCostDistrib.getPartNo()); - vo.setEngChgLevel(Integer.parseInt(structCostDistrib.getEngChgLevel())); - vo.setBomType(structCostDistrib.getBomType()); - vo.setAlternativeNo(structCostDistrib.getAlternativeNo()); - vo.setByProdLineItemNo(Integer.parseInt(structCostDistrib.getByProdLineItemNo())); - vo.setComponentLineItemNo(Integer.parseInt(structCostDistrib.getComponentLineItemNo())); - vo.setItemCostDistribution(structCostDistrib.getItemCostDistribution().isEmpty() ? Double.valueOf("0") : Double.valueOf(structCostDistrib.getItemCostDistribution())); - vo.setComponentPartNo(structCostDistrib.getComponentPartNo()); - vo.setByProdPartNo(structCostDistrib.getByProductPartNo()); - vo.setCreateBy(inData.getCreateBy()); - bomManufStructCostDistribVoList.add(vo); + @Override + public IPage searchPartList(Integer no,Integer size,PartInformationVo part) { + Page page = new Page<>(no, size); + return baseMapper.queryPartByPartNo(page,part); + } + + @Override + public List searchPartList(String site,String partNo) { + LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); + wrapper.eq(PartInformationEntity::getSite,site).eq(PartInformationEntity::getActive,"Y"); + if (StringUtils.hasText(partNo)){ + wrapper.eq(PartInformationEntity::getPartNo,partNo); } - return bomManufStructCostDistribVoList; + return list(wrapper); } /** - * 临时物料的copy part + * @description: 材料报表 -- 所有信息展示 + * @author: yzz + * @date: 2024年2月19日 16点55分 + * @param: [data] + * @return: com.spring.common.utils.R + **/ + @Override + public PageUtils partAllInfoSearch(PartInformationVo data) { + IPage resultList = this.partInformationMapper.partAllInfoSearch(new Page(data.getPage(), data.getLimit()), data); + return new PageUtils(resultList); + } + + /** + * 获取项目物料编码 * @param inData - * @param fromPart + * @return */ - @Transactional - public void temporaryCopyPart(PartInformationVo inData, PartInformationEntity fromPart) { - CopyPart copyPart = new CopyPart(); - copyPart.setOriContract(fromPart.getSite()); - copyPart.setOriPartNo(fromPart.getPartNo()); - copyPart.setContract(inData.getSite()); - copyPart.setPartNo(inData.getPartNo()); - copyPart.setPartDesc(inData.getPartDesc()); - copyPart.setCopyGeneral(inData.getCopyGeneral()); - copyPart.setCopyManufacturing(inData.getCopyManufacturing()); - copyPart.setCopyDefaultLocation(inData.getCopyDefaultLocation()); - copyPart.setCopyCharacteristic(inData.getCopyCharacteristic()); - copyPart.setCopyPPGeneral(inData.getCopyPPGeneral()); - copyPart.setCopyPPDocumentTexts(inData.getCopyPPDocumentTexts()); - copyPart.setCopyPPConnectedObjects(inData.getCopyPPConnectedObjects()); - copyPart.setCopySPPGeneral(inData.getCopySPPGeneral()); - copyPart.setCopySPPDocumentTexts(inData.getCopySPPDocumentTexts()); - copyPart.setCopySPGeneral(inData.getCopySPGeneral()); - copyPart.setCopySPCharacteristics(inData.getCopySPCharacteristics()); - copyPart.setCopySPDocumentTexts(inData.getCopySPDocumentTexts()); - copyPart.setCopySPLanguageDescription(inData.getCopySPLanguageDescription()); - // 调用IFS的copyPart接口 - String copyPartURL = apiUrl + "/part/ifs/syncCopyPartForInventoryPart"; - ResponseData copyPartResponse = HttpClientUtil.doPostByRawWithPLM(copyPartURL, copyPart); - if (!"200".equals(copyPartResponse.getCode())) { - throw new RuntimeException("ifs 库存件copyPart异常:" + copyPartResponse.getMsg()); + @Override + public String getProjectPartNo(PlmProjectPartData inData) { + String no = transNoControlService.transNo(inData.getSite(), "project_part_no"); + if (no == null) { + throw new RuntimeException("请维护编码生成规则(TransNoControl)!"); } + return no + "A01"; + } + /** + * 获取当前行项目物料对象 + * @param inData + * @return + */ + @Override + public PartInformationVo getProjectPartRow(PlmProjectPartData inData) { + TransNoControlData noData = partInformationMapper.getTranNoData(inData.getSite(), "project_part_no"); + int a = noData.getTransNo().length() + noData.getLength(); - // 判断master part 是否存在,否则新增 - MasterPartInformationEntity masterPartInformation = masterPartInformationMapper.selectOne(new QueryWrapper().eq("part_no", inData.getPartNo())); - if (masterPartInformation == null) { - MasterPartInformationEntity masterPart = masterPartInformationMapper.selectOne(new QueryWrapper().eq("part_no", fromPart.getPartNo())); - masterPart.setPartNo(inData.getPartNo()); - masterPartInformationMapper.insert(masterPart); - } - // master part 模板和属性 - List checkValueHeaderData = partInformationMapper.getMasterPartModal("*", fromPart.getPartNo(), "MP"); - if (!checkValueHeaderData.isEmpty()) { - List valueHeaders = checkValueHeaderData.stream().map(a -> { - a.setPartNo(inData.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartModelHeaders(valueHeaders); + // 根据配置截取物料编码 + String partNo = inData.getTestPartNo().substring(0, a); + PartInformationVo part = partInformationMapper.getProjectPartRow(inData.getSite(), partNo); + + if (0 < (Integer.parseInt(part.getPartNo().substring(a + 1)) + 1) && (Integer.parseInt(part.getPartNo().substring(a + 1)) + 1) < 10) { + part.setPartNo(part.getPartNo().substring(0, a + 1) + "0" +(Integer.parseInt(part.getPartNo().substring(a + 1)) + 1)); + } else { + part.setPartNo(part.getPartNo().substring(0, a + 1) + (Integer.parseInt(part.getPartNo().substring(a + 1)) + 1)); } - PartSubPropertiesValueData valueData = new PartSubPropertiesValueData(); - valueData.setSite("*"); - valueData.setPartNo(fromPart.getPartNo()); - valueData.setRecordType("MP"); - // 物料属性 - List fromPartItems1 = partInformationMapper.getItemModal(valueData); - if (!fromPartItems1.isEmpty()) { - List toPartItems1 = fromPartItems1.stream().map(a -> { - a.setSite("*"); - a.setPartNo(inData.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartModelDetails(toPartItems1); + return part; + } + + /** + * 获取当前行项目物料对象 + * @param inData + * @return + */ + @Override + public PartInformationVo getProjectPartRow2(PlmProjectPartData inData) { + PartInformationVo part = partInformationMapper.getProjectPartRow2(inData); + return part; + } + + /** + * 获取当前项目不包含的物料 + * @param data + * @return + */ + @Override + public PageUtils getProjectPartList1(PlmProjectPartData data) { + IPage list; + String[] arr = convertToSQLString(data.getPartNos()).replace("(", "").replace(")", "").replace("'", "").split(","); + data.setArr(arr); + if ("N".equals(data.getSearchType())) { + // Inventory Part + list = partInformationMapper.getProjectPartList3(new Page(data.getPage(), data.getLimit()), data); + } else { + // Project Part + list = partInformationMapper.getProjectPartList1(new Page(data.getPage(), data.getLimit()), data); } + return new PageUtils(list); + } + /** + * 获取当前项目所包含的物料 + * @param data + * @return + */ + @Override + public List getProjectPartList2(PlmProjectPartData data) { + List list = partInformationMapper.getProjectPartList2(data); + return list; + } - // Inventory Part - PartInformationEntity toPart = new PartInformationEntity(); - toPart.setSite(inData.getSite()); - toPart.setPartNo(inData.getPartNo()); - toPart.setPartDesc(inData.getPartDesc()); - toPart.setStatus(fromPart.getStatus()); + /** + * 新增项目物料 + * @param data + * @return + */ + @Override + public Map addProjectPart(PlmProjectPartData data) { + List partList = data.getPartList().stream().map(a -> { + a.setProjectId(data.getProjectId()); + a.setCreateBy(data.getCreateBy()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.addProjectPart(partList); + //List row1 = partInformationMapper.getProjectPartList1(data); + List row2 = partInformationMapper.getProjectPartList2(data); + HashMap map = new HashMap<>(); + //map.put("row1", row1); + map.put("row2", row2); + return map; + } - // General - toPart.setPartType(fromPart.getPartType()); // 零件类型 - toPart.setHazardCode(fromPart.getHazardCode()); // 安全代码 - toPart.setProductGroupId4(fromPart.getProductGroupId4()); // 计划人 - toPart.setProductGroupId3(fromPart.getProductGroupId3()); // 会计组 - toPart.setUmId(fromPart.getUmId()); // 库存计量单位 - toPart.setGroupId(fromPart.getGroupId()); // 产品代码 - toPart.setProductGroupId1(fromPart.getProductGroupId1()); // 商品组1 - toPart.setFamilyId(fromPart.getFamilyId()); // 产品大类 - toPart.setProductGroupId2(fromPart.getProductGroupId2()); // 商品组2 - toPart.setTypeDesignation(fromPart.getTypeDesignation()); // 类型指定 - toPart.setAssetClass(fromPart.getAssetClass()); // 资产等级 - toPart.setDimQuality(fromPart.getDimQuality()); // 尺寸/材质 - toPart.setPartStatus(fromPart.getPartStatus()); // 零件状态 - toPart.setWeightNet(fromPart.getWeightNet()); // 净重 - toPart.setUomForWeightNet(fromPart.getUomForWeightNet()); // 净重单位 - toPart.setVolumeNet(fromPart.getVolumeNet()); // 净数量 - toPart.setUomForVolumeNet(fromPart.getUomForVolumeNet()); // 数量单位 - toPart.setAbcClass(fromPart.getAbcClass()); // ABC类 - toPart.setFrequencyClass(fromPart.getFrequencyClass()); // 频率级别 - toPart.setLifecycleStage(fromPart.getLifecycleStage()); // 生命周期阶段 - toPart.setManufacturingLeadTime(fromPart.getManufacturingLeadTime()); // 制造备货期 - toPart.setCountryOfOrigin(fromPart.getCountryOfOrigin()); // 来源国家 - toPart.setExpectedLeadTime(fromPart.getExpectedLeadTime()); // 预期提前期 - toPart.setDurabilityDay(fromPart.getDurabilityDay()); // 天数 - toPart.setRegionOfOrigin(fromPart.getRegionOfOrigin()); // 区域代码 - toPart.setIntrastatConvFactor(fromPart.getIntrastatConvFactor()); // 州内转换因子 - toPart.setCustomsStatNo(fromPart.getCustomsStatNo()); // 海关统计序号 - toPart.setRemark(fromPart.getRemark()); // 备注 - toPart.setInventoryValuationMethod(fromPart.getInventoryValuationMethod()); // 库存估价方法 - toPart.setPartCostGroupId(fromPart.getPartCostGroupId()); // 零件成本组 - toPart.setInventoryPartCostLevel(fromPart.getInventoryPartCostLevel()); // 库存件成本层 - toPart.setInvoiceConsideration(fromPart.getInvoiceConsideration()); // 供应商发票事项 - toPart.setZeroCostFlag(fromPart.getZeroCostFlag()); // 零成本 - toPart.setCreateBy(inData.getCreateBy()); // 创建人 - toPart.setConfigurationId(fromPart.getConfigurationId()); // 配置标识 - toPart.setEstimatedMaterialCost(fromPart.getEstimatedMaterialCost()); // 估计物料成本 - toPart.setPlanningMethod(fromPart.getPlanningMethod()); // 计划方法 - toPart.setSafetyStock(fromPart.getSafetyStock()); // 安全库存 - toPart.setMinOrderQty(fromPart.getMinOrderQty()); // 最小批量 - toPart.setMaxOrderQty(fromPart.getMaxOrderQty()); // 最大批量 - toPart.setMulOrderQty(fromPart.getMulOrderQty()); // 多种批量大小 - toPart.setSafetyLeadTime(fromPart.getSafetyLeadTime()); // 安全提前期 - toPart.setShrinkageFac(fromPart.getShrinkageFac()); // 报废因子 - toPart.setStdOrderQty(fromPart.getStdOrderQty()); // 标准批量大小 + /** + * 新增项目物料 + * @param data + */ + @Override + @Transactional + public void addProjectPart2(PlmProjectPartData data) { + List partList = data.getPartList().stream().map(a -> { + a.setProjectId(data.getProjectId()); + a.setCustomerNo(data.getCustomerNo()); + a.setCreateBy(data.getCreateBy()); + a.setPartNoSource(data.getPartNoSource()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.addProjectPart(partList); + partInformationMapper.addCustomerPartInfo(partList); + } - // Manufacturing - if ("Y".equals(inData.getCopyManufacturing())) { - toPart.setCumLeadTime(fromPart.getCumLeadTime()); // 累计提前期 - toPart.setBackFlushPart(fromPart.getBackFlushPart()); // 预留/下发来源 - toPart.setByProdAsSupplyInMrpDb(fromPart.getByProdAsSupplyInMrpDb()); // 将副产品用作MRP中的供应 - toPart.setUnprotectedLeadTime(fromPart.getUnprotectedLeadTime()); // 未受保护提前期 - toPart.setIssueType(fromPart.getIssueType()); // 预留/下发方法 - toPart.setMrpControlFlagDb(fromPart.getMrpControlFlagDb()); // MRP控制 - toPart.setFixedLeadTimeDay(fromPart.getFixedLeadTimeDay()); // 按日固定提前期 - toPart.setOverReporting(fromPart.getOverReporting()); // 过度报告 - toPart.setUseTheoreticalDensityDb(fromPart.getUseTheoreticalDensityDb()); // 使用理论 - toPart.setVariableLeadTimeDay(fromPart.getVariableLeadTimeDay()); // 按天的可变化提前期 - toPart.setOverReportTolerance(fromPart.getOverReportTolerance()); // 报告公差过大 - toPart.setFixedLeadTimeHour(fromPart.getFixedLeadTimeHour()); // 按小时的固定提前期 - toPart.setDensity(fromPart.getDensity()); // 密度 - toPart.setVariableLeadTimeHour(fromPart.getVariableLeadTimeHour()); // 按小时计算的可变提前期 - } + /** + * 查询变更记录 + * @param data + * @return + */ + @Override + public List getChangeRecordByPartNo(PlmProjectPartData data) { + List list = partInformationMapper.getChangeRecordByPartNo(data); + return list; + } - // Characteristic - if ("Y".equals(inData.getCopyCharacteristic())) { - toPart.setCodeNo(fromPart.getCodeNo()); // 属性模板 - valueData.setSite(inData.getSite()); - valueData.setRecordType("IP"); - // 新增物料属性 - List fromPartItems2 = partInformationMapper.getItemModal(valueData); - if (!fromPartItems2.isEmpty()) { - List toPartItems2 = fromPartItems2.stream().map(a -> { - a.setSite(inData.getSite()); - a.setPartNo(inData.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartModelDetails(toPartItems2); - } - } - // 新增 - partInformationMapper.insert(toPart); - // 当前日期 - Date actualDate = DateUtils.getStringToDate(DateUtils.getStringNow2(), "yyyy-MM-dd"); + /** + * 查询变更记录 + * @param data + * @return + */ + @Override + public List getChangeRecordByPartNo2(PlmProjectPartData data) { + List list = partInformationMapper.getChangeRecordByPartNo2(data); + return list; + } - // Revisions - List fromRevisionList = partInformationMapper.getFromPartRevision(fromPart.getSite(), fromPart.getPartNo(), toPart.getSite(), toPart.getPartNo(), inData.getCreateBy()); - HashMap revisionMap = new HashMap<>(); - if (!fromRevisionList.isEmpty()) { - int num = 1; - for (PartRevisionEntity partRevisionEntity : fromRevisionList) { - revisionMap.put(partRevisionEntity.getEngChgLevel(), num); - partRevisionEntity.setEngChgLevel(num++); - partRevisionEntity.setEffPhaseInDate(actualDate); - partRevisionEntity.setProductStatus("Not In Effect"); - partRevisionEntity.setRepairStatus("Not In Effect"); + /** + * 查出该物料的BOM和routing的替代 + * @param data + * @return + */ + @Override + public Map getBomAndRoutingList(PartInformationEntity data) { + HashMap map = new HashMap<>(); + List bomList = partInformationMapper.queryBomAlternativeList(data); + List routingList = partInformationMapper.queryRoutingAlternativeList(data); + map.put("bomList", bomList); + map.put("routingList", routingList); + return map; + } + + /** + * 转正式物料 + * @param data + */ + @Override + @Transactional + public void + partInformationToOfficial(PartInformationVo data) { + // 判断选择的BOM替代的子料是否都为正式物料 + if (!data.getBomAlternativeList().isEmpty()) { + for (BomDetailVo vo : data.getBomAlternativeList()) { + List componentPartList = partInformationMapper.getComponentPart(vo); + for (PartInformationVo partInformationVo : componentPartList) { + if (!"Y".equals(partInformationVo.getStatus())) { + throw new RuntimeException("替代下含有非正式物料(BOM版本:" + partInformationVo.getBomType() + ", 替代名称为:" + partInformationVo.getAlternativeDescription() + ")!"); + } + } } - partInformationMapper.saveRevisions(fromRevisionList); } + PartInformationEntity partData = partInformationMapper.selectOne(new QueryWrapper().eq("site", data.getSite()).eq("part_no", data.getPartNo())); - // 新增物料默认库位 - if ("Y".equals(inData.getCopyDefaultLocation())) { - List fromLocationList = partInformationMapper.getPartDefaultLocations(fromPart); - if (!fromLocationList.isEmpty()) { - List ifsDefaultLocations = fromLocationList.stream().map(a -> { - a.setSite(toPart.getSite()); - a.setPartNo(toPart.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartDefaultLocation(ifsDefaultLocations); + // 编辑原物料 + UpdateWrapper updateInformationWrapper = new UpdateWrapper<>(); + updateInformationWrapper.eq("site", data.getSite()); + updateInformationWrapper.eq("part_no", data.getPartNo()); + partInformationMapper.update(data, updateInformationWrapper); + // 物料属性 + PartSubPropertiesValueData valueData = new PartSubPropertiesValueData(); + valueData.setSite(data.getSite()); + valueData.setPartNo(data.getPartNo()); + valueData.setCodeNo(data.getCodeNo()); + valueData.setRecordType("IP"); + // 删除物料的属性模板 + partInformationMapper.deletePartSubPropertiesValueHeader(valueData); + // 删除物料的属性 + partInformationMapper.deletePartSubPropertiesValue(valueData); + // 重新加载属性模板 + partInformationMapper.savePartSubPropertiesValueHeader(valueData); + // 重新加载物料的属性 + for (PartSubPropertiesValueData itemDate : data.getPartItemList()) { + itemDate.setSite(data.getSite()); + itemDate.setPartNo(data.getPartNo()); + itemDate.setRecordType("IP"); + itemDate.setCodeNo(data.getCodeNo()); + itemDate.setSubCodeSeqNo(Double.valueOf("1")); + itemDate.setItNo(itemDate.getPropertiesItemNo()); + List checkItem = partInformationMapper.checkItem(itemDate); + if (checkItem.isEmpty()) { + throw new RuntimeException("该项目编码不存在!"); + } + List checkDetail = partInformationMapper.checkPartItem(itemDate); + if (!checkDetail.isEmpty()) { + throw new RuntimeException("该项目已存在!"); } + itemDate.setItemNo(partInformationMapper.getModalDetailSeqNo(itemDate)); + partInformationMapper.addPartItem(itemDate); } - // 代理商、制造商、文档 - List agents = partInformationMapper.getPartAgents(fromPart); - List manufacturers = partInformationMapper.getPartManufacturers(fromPart); - List files = partInformationMapper.getPartFiles(fromPart); - if (!agents.isEmpty()) { - List ifsAgents = agents.stream().map(a -> { - a.setSite(toPart.getSite()); - a.setPartNo(toPart.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartAgent(ifsAgents); - } - if (!manufacturers.isEmpty()) { - List ifsManufacturers = manufacturers.stream().map(a -> { - a.setSite(toPart.getSite()); - a.setPartNo(toPart.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartManufacturer(ifsManufacturers); + // 如果原物料类型改为了 Purchased (raw) 则删除 BOM 和 routing + if ("Purchased (raw)".equals(data.getPartType()) && !data.getPartType().equals(partData.getPartType())) { + partInformationMapper.deleteBomHeaderByPartNo(data); // BOM header + partInformationMapper.deleteBomDetailByPartNo(data); // BOM detail + partInformationMapper.deleteBomComponentByPartNo(data); // BOM component + partInformationMapper.deleteBomManufStructCostDistribByPartNo(data); // BOM 副产品成本分配 + partInformationMapper.deleteRoutingHeaderByPartNo(data); // Routing header + partInformationMapper.deleteRoutingDetailByPartNo(data); // Routing detail + partInformationMapper.deleteRoutingComponentByPartNo(data); // Routing component + partInformationMapper.deleteRoutingToolByPartNo(data); // Routing tool + partInformationMapper.deleteRoutingGuideLineByPartNo(data); // Routing guide line } - if (!files.isEmpty()) { - List ifsFiles = files.stream().map(a -> { - a.setOrderRef1(toPart.getSite()); - a.setOrderRef2(toPart.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartFile(ifsFiles); + + // 创建IFS物料 + PartInformationEntity ifsPart = new PartInformationEntity(); + BeanUtils.copyProperties(data, ifsPart); + ifsPart.setPartNo(data.getIfsPartNo()); + ifsPart.setPlmPartNo(data.getPartNo()); + ifsPart.setCreateBy(data.getUpdateBy()); + ifsPart.setStatus("Y"); + ifsPart.setIfsPartNo(""); + partInformationMapper.insert(ifsPart); + + // 创建IFS物料的属性 +// List modelHeaders = partInformationMapper.getModelHeader(data.getSite(), data.getPartNo(), data.getCodeNo(), "IP", data.getIfsPartNo()); + List modelDetails = partInformationMapper.getModelDetail(data.getSite(), data.getPartNo(), data.getCodeNo(), "IP", data.getIfsPartNo()); +// if (!modelHeaders.isEmpty()) { +// partInformationMapper.savePartModelHeaders(modelHeaders); +// } + if (!modelDetails.isEmpty()) { + partInformationMapper.savePartModelDetails(modelDetails); } - // 新增Routing - HashMap operationMap = new HashMap(); // 存放新的operationId - List routingHeaderList = routingManagementMapper.selectRoutingHeaderByPartNo(fromPart.getSite(), fromPart.getPartNo()); - List routingDetailList = routingManagementMapper.selectRoutingDetailByPartNo(fromPart.getSite(), fromPart.getPartNo()); - List routingComponentList = routingManagementMapper.selectRoutingComponentByPartNo(fromPart.getSite(), fromPart.getPartNo()); - List routingToolList = routingManagementMapper.selectRoutingToolByPartNo(fromPart.getSite(), fromPart.getPartNo()); - List routingGuidelineList = routingManagementMapper.selectRoutingGuidelineByPartNo(fromPart.getSite(), fromPart.getPartNo()); - if (!routingHeaderList.isEmpty()) { - for (RoutingHeaderVo routingHeader : routingHeaderList) { - routingHeader.setSite(toPart.getSite()); - routingHeader.setPartNo(toPart.getPartNo()); - routingHeader.setCreateBy(inData.getCreateBy()); - } - routingManagementMapper.saveRoutingHeaderList(routingHeaderList); - } - if (!routingDetailList.isEmpty()) { - for (RoutingDetailVo routingDetail : routingDetailList) { - routingDetail.setSite(toPart.getSite()); - routingDetail.setPartNo(toPart.getPartNo()); - routingDetail.setCreateBy(inData.getCreateBy()); - } - routingManagementMapper.saveRoutingDetailList(routingDetailList); - } - if (!routingComponentList.isEmpty()) { - Integer oldOperationId; - for (RoutingComponentVo routingComponent : routingComponentList) { - oldOperationId = routingComponent.getOperationId(); - routingComponent.setSite(toPart.getSite()); - routingComponent.setPartNo(toPart.getPartNo()); - routingComponent.setCreateBy(inData.getCreateBy()); - routingManagementMapper.saveRoutingComponent(routingComponent); - operationMap.put(oldOperationId, routingComponent.getOperationId()); - } - } - if (!routingToolList.isEmpty()) { - for (RoutingToolEntity routingTool : routingToolList) { - routingTool.setSite(toPart.getSite()); - routingTool.setPartNo(toPart.getPartNo()); - routingTool.setOperationId(operationMap.get(routingTool.getOperationId())); - routingTool.setCreateBy(inData.getCreateBy()); - } - routingManagementMapper.saveRoutingTool(routingToolList); - } - if (!routingGuidelineList.isEmpty()) { - for (WorkGuidelineEntity workGuideline : routingGuidelineList) { - workGuideline.setSite(toPart.getSite()); - workGuideline.setPartNo(toPart.getPartNo()); - workGuideline.setOperationId(operationMap.get(workGuideline.getOperationId())); - workGuideline.setCreateBy(inData.getCreateBy()); - } - routingManagementMapper.saveGuideLine(routingGuidelineList); - } + // 反刷项目物料的finalPartNo + partInformationMapper.updateProjectFinalPart(data); - // 新增BOM - List bomHeaderList = bomManagementMapper.selectBomHeaderByPartNo(fromPart.getSite(), fromPart.getPartNo()); - List bomDetailList = bomManagementMapper.selectBomDetailByPartNo(fromPart.getSite(), fromPart.getPartNo()); - List bomComponentList = bomManagementMapper.selectBomComponentByPartNo(fromPart.getSite(), fromPart.getPartNo()); - List bomManufStructCostDistribList = bomManagementMapper.selectBomManufStructCostDistribByPartNo(fromPart.getSite(), fromPart.getPartNo()); - if (!bomHeaderList.isEmpty()) { - for (BomHeaderVo bomHeader : bomHeaderList) { - bomHeader.setSite(toPart.getSite()); - bomHeader.setPartNo(toPart.getPartNo()); - bomHeader.setEngChgLevel(revisionMap.get(bomHeader.getEngChgLevel())); - bomHeader.setEffPhaseInDate(actualDate); - bomHeader.setCreateBy(inData.getCreateBy()); - } - partInformationMapper.saveBomHeaders(bomHeaderList); - } - if (!bomDetailList.isEmpty()) { - for (BomDetailVo bomDetail : bomDetailList) { - bomDetail.setSite(toPart.getSite()); - bomDetail.setPartNo(toPart.getPartNo()); - bomDetail.setEngChgLevel(revisionMap.get(bomDetail.getEngChgLevel())); - bomDetail.setCreateBy(inData.getCreateBy()); - bomDetail.setStatus("Tentative"); - } - partInformationMapper.saveIfsBomAlternatives(bomDetailList); - } - if (!bomComponentList.isEmpty()) { - for (BomComponentVo bomComponent : bomComponentList) { - bomComponent.setSite(toPart.getSite()); - bomComponent.setPartNo(toPart.getPartNo()); - bomComponent.setEngChgLevel(revisionMap.get(bomComponent.getEngChgLevel())); - bomComponent.setCreateBy(inData.getCreateBy()); - } - bomManagementMapper.saveBomComponents(bomComponentList); - } - if (!bomManufStructCostDistribList.isEmpty()) { - for (BomManufStructCostDistribVo bomManufStructCostDistrib : bomManufStructCostDistribList) { - bomManufStructCostDistrib.setSite(toPart.getSite()); - bomManufStructCostDistrib.setPartNo(toPart.getPartNo()); - bomManufStructCostDistrib.setEngChgLevel(revisionMap.get(bomManufStructCostDistrib.getEngChgLevel())); - bomManufStructCostDistrib.setCreateBy(inData.getCreateBy()); - } - bomManagementMapper.saveBomManufStructCostDistrib(bomManufStructCostDistribList); + // 创建IFS物料的 revision + List partRevisionList = partInformationMapper.getFromPartRevision2(data.getSite(), data.getPartNo(), data.getIfsPartNo(), ifsPart.getCreateBy()); + if (!partRevisionList.isEmpty()) { + partInformationMapper.saveRevisions(partRevisionList); } - } - /** - * 新增物料版本 - * @param inData - */ - @Override - @Transactional - public void saveRevision(PartRevisionEntity inData) { - // 校验版本是否已存在 - List revisions = partInformationMapper.queryRevision(inData); - if (!revisions.isEmpty()) { - throw new RuntimeException("版本已存在!"); - } - // 新增revision - partInformationMapper.saveRevision(inData); + // 同步物料件 + MasterPartInformationEntity masterPartInformation = new MasterPartInformationEntity(); + masterPartInformation.setPartNo(ifsPart.getPartNo()); + masterPartInformation.setPlmPartNo(data.getPartNo()); + masterPartInformationService.toBecomeOfficialMasterPart(masterPartInformation); - PartInformationEntity partData = partInformationMapper.selectOne(new QueryWrapper().eq("site", inData.getSite()).eq("part_no", inData.getPartNo())); + // 1、库存件 + PartIfsInventory partIfsInventory = getPartIfsInventory(ifsPart); // 主表对象 + try { + // 同步数据到 IFS + if (dataUrl) { + PartIfsInventoryConfig partIfsInventoryConfig = getPartIfsInventoryConfig(ifsPart); // costs对象 + PartIfsInventoryManufacture partIfsInventoryManufacture = getPartIfsInventoryManufacture(ifsPart); // Manufacturing对象 + PartIfsInventoryPlan partIfsInventoryPlan = getPartIfsInventoryPlan(ifsPart); // planning对象 + List revisionList = partInformationMapper.getPartRevisionList(ifsPart); // revision对象 + PartIfsInventoryModel partIfsInventoryModel = getPartIfsInventoryModel(ifsPart); // 模板对象 + List propertyList = partInformationMapper.getPartPropertyList(ifsPart.getSite(), ifsPart.getPartNo(), ifsPart.getCodeNo(), "IP"); // 属性对象 - // 新增 BOM - if (!"Purchased (raw)".equals(partData.getPartType())) { - BomHeaderEntity bomHeader = new BomHeaderEntity(); - bomHeader.setSite(partData.getSite()); - bomHeader.setPartNo(partData.getPartNo()); - if (partData.getPartType().contains("Manufactured")) { - bomHeader.setBomType("Manufacturing"); - } else if ("Purchased".equals(partData.getPartType())) { - bomHeader.setBomType("Purchase"); - } - bomHeader.setEffPhaseInDate(inData.getEffPhaseInDate()); - bomHeader.setEffPhaseOutDate(inData.getEffPhaseOutDate()); - bomHeader.setEngChgLevel(inData.getEngChgLevel()); - bomHeader.setOfficialFlag("N"); - bomManagementMapper.saveBomHeader(bomHeader); - // 创建默认替代* - BomDetailEntity bomDetail = new BomDetailEntity(); - BeanUtils.copyProperties(bomHeader,bomDetail); - bomDetail.setAlternativeNo("*"); - bomDetail.setAlternativeDescription("*"); - bomDetail.setStatus("Tentative"); - bomDetail.setOfficialFlag("N"); - bomManagementMapper.bomDetailSave(bomDetail); - } + // 校验revision +// boolean b = revisionList.stream().anyMatch(a -> a.getEffPhaseOutDate() == null || a.getEffPhaseOutDate().isEmpty() || a.getEngRevision() == null || a.getEngRevision().isEmpty()); +// if (b) { +// throw new RuntimeException("请维护库存件版本的失效时间 和 工程版本号!"); +// } - if (dataUrl) { - // 判断是否为正式物料 - if ("Y".equals(partData.getStatus())) { - // 同步ifs - // 先判断ifs那边是否已存在该物料版本 - PartIfsInventoryRevision partIfsInventoryRevision = getPartIfsInventoryRevision(inData); - String queryPartRevisionURL = apiUrl + "/part/ifs/getInventoryPartRevision"; - ResponseData queryPartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(queryPartRevisionURL, partIfsInventoryRevision); - if ("200".equals(queryPartRevisionResponse.getCode())) { // 存在,修改 - // ifs修改物料版本 - String updatePartRevisionURL = apiUrl + "/part/ifs/modifyInventoryPartRevisionToIfs"; - ResponseData updatePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(updatePartRevisionURL, partIfsInventoryRevision); - if (!"200".equals(updatePartRevisionResponse.getCode())) { - throw new RuntimeException("ifs 库存件版本修改异常:" + updatePartRevisionResponse.getMsg()); + // 1.1 库存件主表数据 + String getInventoryPartURL = apiUrl + "/part/ifs/getInventoryPart"; + ResponseData getInventoryPartResponse = HttpClientUtil.doPostByRawWithPLM(getInventoryPartURL, partIfsInventory); + if (!"200".equals(getInventoryPartResponse.getCode())) { // 新增 + String addInventoryPartURL = apiUrl + "/part/ifs/syncInventoryPartToIfs"; + ResponseData addInventoryPartResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartURL, partIfsInventory); + if (!"200".equals(addInventoryPartResponse.getCode())) { + throw new RuntimeException("IFS库存件新增异常:" + addInventoryPartResponse.getMsg()); } - } else { // 不存在,新增 - // ifs新增物料版本 - String savePartRevisionURL = apiUrl + "/part/ifs/syncInventoryPartRevisionToIfs"; - ResponseData savePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(savePartRevisionURL, partIfsInventoryRevision); - if (!"200".equals(savePartRevisionResponse.getCode())) { - throw new RuntimeException("ifs 库存件版本新增异常:" + savePartRevisionResponse.getMsg()); + } else { // 修改 + String updateInventoryPartURL = apiUrl + "/part/ifs/modifyInventoryPartToIfs"; + ResponseData updateInventoryPartResponse = HttpClientUtil.doPostByRawWithPLM(updateInventoryPartURL, partIfsInventory); + if (!"200".equals(updateInventoryPartResponse.getCode())) { + throw new RuntimeException("IFS库存件修改异常:" + updateInventoryPartResponse.getMsg()); } } - } - } - } - - /** - * 删除物料版本 - * @param inData - */ - @Override - @Transactional - public void deleteRevision(PartRevisionEntity inData) { - // 查询该版本的bom,判断bom的替代状态 - List bomDetailList = partInformationMapper.queryBomAlternative(inData); - if (!bomDetailList.isEmpty()) { - for (BomDetailEntity bomDetail : bomDetailList) { - if ("Buildable".equals(bomDetail.getStatus()) || "Obsolete".equals(bomDetail.getStatus())) { - throw new RuntimeException("存在状态为 Buildable 或者 Obsolete 的Bom!"); + // 1.2 库存件 Costs 表数据 + String addInventoryPartCostsURL = apiUrl + "/part/ifs/modifyInventoryPartCostToIfs"; + ResponseData addInventoryPartCostsResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartCostsURL, partIfsInventoryConfig); + if (!"200".equals(addInventoryPartCostsResponse.getCode())) { + throw new RuntimeException("IFS库存件Costs修改异常:" + addInventoryPartCostsResponse.getMsg()); } - } - } - // 删除revision - partInformationMapper.deleteRevision(inData); - // 删除该版本下的bomHeader - bomManagementMapper.delete(new QueryWrapper().eq("site", inData.getSite()).eq("part_no", inData.getPartNo()).eq("eng_chg_level", inData.getEngChgLevel())); - // 删除该版本下的bomDetail - partInformationMapper.deleteBomDetail(inData); - // 删除该版本下的bomComponent - partInformationMapper.deleteBomComponent(inData); - // 删除该版本下的副产品成本分配数据 - partInformationMapper.deleteManufStruct(inData); - - if (dataUrl) { - // 判断是否为正式物料 - PartInformationEntity partData = partInformationMapper.selectOne(new QueryWrapper().eq("site", inData.getSite()).eq("part_no", inData.getPartNo())); - if ("Y".equals(partData.getStatus())) { // 同步ifs,删除revision - PartIfsInventoryRevision partIfsInventoryRevision = new PartIfsInventoryRevision(); - partIfsInventoryRevision.setContract(inData.getSite()); - partIfsInventoryRevision.setPartNo(inData.getPartNo()); - partIfsInventoryRevision.setEngChgLevel(inData.getEngChgLevel().toString()); - String deletePartRevisionURL = apiUrl + "/part/ifs/removeInventoryPartRevisionToIfs"; - ResponseData deletePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(deletePartRevisionURL, partIfsInventoryRevision); - if (!"200".equals(deletePartRevisionResponse.getCode())) { - throw new RuntimeException("ifs 库存件版本删除异常:" + deletePartRevisionResponse.getMsg()); + // 1.3 库存件 Manufacturing 表数据 + String addInventoryPartManufacturingURL = apiUrl + "/part/ifs/modifyInventoryPartManufactureToIfs"; + ResponseData addInventoryPartManufacturingResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartManufacturingURL, partIfsInventoryManufacture); + if (!"200".equals(addInventoryPartManufacturingResponse.getCode())) { + throw new RuntimeException("IFS库存件Manufacturing修改异常:" + addInventoryPartManufacturingResponse.getMsg()); + } + // 1.4 库存件 Planning 表数据 + String addInventoryPartPlanningURL = apiUrl + "/part/ifs/modifyInventoryPartPlanToIfs"; + ResponseData addInventoryPartPlanningResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartPlanningURL, partIfsInventoryPlan); + if (!"200".equals(addInventoryPartPlanningResponse.getCode())) { + throw new RuntimeException("IFS库存件Planning修改异常:" + addInventoryPartPlanningResponse.getMsg()); + } + // 1.5 库存件 revision 表数据 + for (PartIfsInventoryRevision revision : revisionList) { + String queryPartRevisionURL = apiUrl + "/part/ifs/getInventoryPartRevision"; + ResponseData queryPartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(queryPartRevisionURL, revision); + if (!"200".equals(queryPartRevisionResponse.getCode())) { // 说明库存件版本不存在,走新增 + String savePartRevisionURL = apiUrl + "/part/ifs/syncInventoryPartRevisionToIfs"; + ResponseData savePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(savePartRevisionURL, revision); + if (!"200".equals(savePartRevisionResponse.getCode())) { + throw new RuntimeException("IFS库存件版本新增异常:" + savePartRevisionResponse.getMsg()); + } + } else { + // 修改 + String updatePartRevisionURL = apiUrl + "/part/ifs/modifyInventoryPartRevisionToIfs"; + ResponseData updatePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(updatePartRevisionURL, revision); + if (!"200".equals(updatePartRevisionResponse.getCode())) { + throw new RuntimeException("IFS库存件版本修改异常:" + updatePartRevisionResponse.getMsg()); + } + } } - } - } - } - - /** - * 查询part - * @author: zelian_wu - * date 2023/11/21 - * @return - */ - @Override - public IPage searchPartList(Integer no,Integer size,PartInformationVo part) { - Page page = new Page<>(no, size); - return baseMapper.queryPartByPartNo(page,part); - } - - @Override - public List searchPartList(String site,String partNo) { - LambdaUpdateWrapper wrapper = new LambdaUpdateWrapper<>(); - wrapper.eq(PartInformationEntity::getSite,site).eq(PartInformationEntity::getActive,"Y"); - if (StringUtils.hasText(partNo)){ - wrapper.eq(PartInformationEntity::getPartNo,partNo); - } - return list(wrapper); - } - /** - * @description: 材料报表 -- 所有信息展示 - * @author: yzz - * @date: 2024年2月19日 16点55分 - * @param: [data] - * @return: com.spring.common.utils.R - **/ - @Override - public PageUtils partAllInfoSearch(PartInformationVo data) { - IPage resultList = this.partInformationMapper.partAllInfoSearch(new Page(data.getPage(), data.getLimit()), data); - return new PageUtils(resultList); - } + // 1.6 同步库存件的模板和属性 + if (partIfsInventoryModel.getEngAttribute() != null && !partIfsInventoryModel.getEngAttribute().isEmpty()) { + String addInventoryPartModelURL = apiUrl + "/part/ifs/modifyInventoryPartCharacteristicTemplate"; + ResponseData addInventoryPartModelResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartModelURL, partIfsInventoryModel); + if (!"200".equals(addInventoryPartModelResponse.getCode())) { + throw new RuntimeException("IFS库存件模板新增异常:" + addInventoryPartModelResponse.getMsg()); + } + } + if (!propertyList.isEmpty()) { + String addInventoryPartPropertyURL = apiUrl + "/part/ifs/syncInventoryPartCharacteristics"; + ResponseData addInventoryPartPropertyResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartPropertyURL, propertyList); + if (!"200".equals(addInventoryPartPropertyResponse.getCode())) { + throw new RuntimeException("IFS库存件属性新增异常:" + addInventoryPartPropertyResponse.getMsg()); + } + } - /** - * 获取项目物料编码 - * @param inData - * @return - */ - @Override - public String getProjectPartNo(PlmProjectPartData inData) { - String no = transNoControlService.transNo(inData.getSite(), "project_part_no"); - if (no == null) { - throw new RuntimeException("请维护编码生成规则(TransNoControl)!"); - } - return no + "A01"; - } + } - /** - * 获取当前行项目物料对象 - * @param inData - * @return - */ - @Override - public PartInformationVo getProjectPartRow(PlmProjectPartData inData) { - TransNoControlData noData = partInformationMapper.getTranNoData(inData.getSite(), "project_part_no"); - int a = noData.getTransNo().length() + noData.getLength(); + // 创建 IFS 物料的 BOM 和 Routing + // 所选 BOM 替代 + List bomAlternativeList = data.getBomAlternativeList(); + List routingAlternativeList = data.getRoutingAlternativeList(); + if (!"Purchased (raw)".equals(ifsPart.getPartType())) { + if (!bomAlternativeList.isEmpty()) { + // 若物料存在Repair类型的BOM,则校验是否有其它类型的BOM,否则提示 不存在与该物料相同的BOM类型! + // 使用 groupBy 分组并检查 + Map> groupedBOMs = bomAlternativeList.stream().collect(Collectors.groupingBy(bom -> "Repair".equals(bom.getBomType()))); + boolean hasRepairBom = !groupedBOMs.getOrDefault(true, Collections.emptyList()).isEmpty(); + boolean hasOtherBom = !groupedBOMs.getOrDefault(false, Collections.emptyList()).isEmpty(); + if (hasRepairBom && !hasOtherBom) { + throw new RuntimeException("不存在与该物料相同的BOM类型!"); + } - // 根据配置截取物料编码 - String partNo = inData.getTestPartNo().substring(0, a); - PartInformationVo part = partInformationMapper.getProjectPartRow(inData.getSite(), partNo); + // 对所选替代的版本进行去重 + TreeSet bomHeaderList = bomAlternativeList.stream().collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(BomDetailEntity::getEngChgLevel)))); + for (BomDetailVo bomDetailVo : bomHeaderList) { + BomHeaderEntity bomHeader = new BomHeaderEntity(); + bomHeader.setSite(ifsPart.getSite()); + bomHeader.setPartNo(ifsPart.getPartNo()); + if (ifsPart.getPartType().contains("Manufactured")) { + bomHeader.setBomType("Manufacturing"); + } else if ("Purchased".equals(ifsPart.getPartType())) { + bomHeader.setBomType("Purchase"); + } + bomHeader.setEffPhaseInDate(bomDetailVo.getEffPhaseInDate()); + bomHeader.setEffPhaseOutDate(bomDetailVo.getEffPhaseOutDate()); + bomHeader.setEngChgLevel(bomDetailVo.getEngChgLevel()); + bomHeader.setNoteText(bomDetailVo.getBomHeaderNoteText()); + bomHeader.setEngRevision(bomDetailVo.getEngRevision()); + bomHeader.setOfficialFlag("Y"); - if (0 < (Integer.parseInt(part.getPartNo().substring(a + 1)) + 1) && (Integer.parseInt(part.getPartNo().substring(a + 1)) + 1) < 10) { - part.setPartNo(part.getPartNo().substring(0, a + 1) + "0" +(Integer.parseInt(part.getPartNo().substring(a + 1)) + 1)); - } else { - part.setPartNo(part.getPartNo().substring(0, a + 1) + (Integer.parseInt(part.getPartNo().substring(a + 1)) + 1)); - } - return part; - } + // 新增IFS 物料的 BOM 主信息 + bomManagementMapper.saveBomHeader(bomHeader); - /** - * 获取当前行项目物料对象 - * @param inData - * @return - */ - @Override - public PartInformationVo getProjectPartRow2(PlmProjectPartData inData) { - PartInformationVo part = partInformationMapper.getProjectPartRow2(inData); - return part; - } + // 同步 BOM Header 数据到 IFS + if (dataUrl) { + BomIfsHeader bomIfsHeader = new BomIfsHeader(); + bomIfsHeader.setContract(bomHeader.getSite()); + bomIfsHeader.setPartNo(bomHeader.getPartNo()); + bomIfsHeader.setEngChgLevel(bomHeader.getEngChgLevel().toString()); + bomIfsHeader.setBomType(bomHeader.getBomType()); + bomIfsHeader.setEffPhaseInDate(DateUtils.format(bomHeader.getEffPhaseInDate())); + bomIfsHeader.setEffPhaseOutDate(bomHeader.getEffPhaseOutDate() == null ? "" : DateUtils.format(bomHeader.getEffPhaseOutDate())); + bomIfsHeader.setNoteText(bomHeader.getNoteText()); + String getBomHeaderURL = apiUrl + "/bom/ifs/getBomHeader"; + ResponseData getBomHeaderResponse = HttpClientUtil.doPostByRawWithPLM(getBomHeaderURL, bomIfsHeader); + if (!"200".equals(getBomHeaderResponse.getCode())) { // 新增 + String addBomHeaderURL = apiUrl + "/bom/ifs/syncBomHeaderToIfs"; + ResponseData addBomHeaderResponse = HttpClientUtil.doPostByRawWithPLM(addBomHeaderURL, bomIfsHeader); + if (!"200".equals(addBomHeaderResponse.getCode())) { + throw new RuntimeException("IFS BOMHeader新增异常:" + addBomHeaderResponse.getMsg()); + } + } else { + // 修改 + String updateBomHeaderURL = apiUrl + "/bom/ifs/modifyBomHeaderToIfs"; + ResponseData updateBomHeaderResponse = HttpClientUtil.doPostByRawWithPLM(updateBomHeaderURL, bomIfsHeader); + if (!"200".equals(updateBomHeaderResponse.getCode())) { + throw new RuntimeException("IFS BOMHeader修改异常:" + updateBomHeaderResponse.getMsg()); + } + } + } + } - /** - * 获取当前项目不包含的物料 - * @param data - * @return - */ - @Override - public PageUtils getProjectPartList1(PlmProjectPartData data) { - IPage list; - String[] arr = convertToSQLString(data.getPartNos()).replace("(", "").replace(")", "").replace("'", "").split(","); - data.setArr(arr); - if ("N".equals(data.getSearchType())) { - // Inventory Part - list = partInformationMapper.getProjectPartList3(new Page(data.getPage(), data.getLimit()), data); - } else { - // Project Part - list = partInformationMapper.getProjectPartList1(new Page(data.getPage(), data.getLimit()), data); - } - return new PageUtils(list); - } + for (BomDetailVo bomDetailVo : bomAlternativeList) { + // 查原物料的替代 + BomDetailEntity bomDetail = bomManagementMapper.queryDetailDataByNo(bomDetailVo); + // 查询原物料的 BOM 子物料 + List componentDataList = bomManagementMapper.queryBomComponentAll(bomDetailVo); + // 查询原BOM副产品成本分配数据列表 + List manufStructCostDistribList = bomManagementMapper.queryBomManufStructCostDistrib(bomDetailVo); - /** - * 获取当前项目所包含的物料 - * @param data - * @return - */ - @Override - public List getProjectPartList2(PlmProjectPartData data) { - List list = partInformationMapper.getProjectPartList2(data); - return list; - } + // 创建 IFS 物料 BOM 的 替代 + bomDetail.setPartNo(ifsPart.getPartNo()); + bomDetail.setOfficialFlag("Y"); + bomManagementMapper.bomDetailSave(bomDetail); - /** - * 新增项目物料 - * @param data - * @return - */ - @Override - public Map addProjectPart(PlmProjectPartData data) { - List partList = data.getPartList().stream().map(a -> { - a.setProjectId(data.getProjectId()); - a.setCreateBy(data.getCreateBy()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.addProjectPart(partList); - //List row1 = partInformationMapper.getProjectPartList1(data); - List row2 = partInformationMapper.getProjectPartList2(data); - HashMap map = new HashMap<>(); - //map.put("row1", row1); - map.put("row2", row2); - return map; - } + // 同步数据到 IFS + if (dataUrl) { + BomIfsAlternative bomIfsAlternative = new BomIfsAlternative(); + bomIfsAlternative.setContract(bomDetail.getSite()); + bomIfsAlternative.setPartNo(bomDetail.getPartNo()); + bomIfsAlternative.setEngChgLevel(bomDetail.getEngChgLevel().toString()); + bomIfsAlternative.setBomType(bomDetail.getBomType()); + bomIfsAlternative.setAlternativeNo(bomDetail.getAlternativeNo()); + bomIfsAlternative.setAlternativeDesc(bomDetail.getAlternativeDescription()); + bomIfsAlternative.setNoteText(bomDetail.getDetailNoteText()); + String getBomDetailURL = apiUrl + "/bom/ifs/getBomAlternative"; + ResponseData getBomDetailResponse = HttpClientUtil.doPostByRawWithPLM(getBomDetailURL, bomIfsAlternative); + if (!"200".equals(getBomDetailResponse.getCode())) { // 新增 + String addBomDetailURL = apiUrl + "/bom/ifs/syncBomAlternativeToIfs"; + ResponseData addBomDetailResponse = HttpClientUtil.doPostByRawWithPLM(addBomDetailURL, bomIfsAlternative); + if (!"200".equals(addBomDetailResponse.getCode())) { + throw new RuntimeException("IFS BOMAlternative新增异常:" + addBomDetailResponse.getMsg()); + } + } else { // 修改 + String updateBomDetailURL = apiUrl + "/bom/ifs/modifyBomAlternativeToIfs"; + ResponseData updateBomDetailResponse = HttpClientUtil.doPostByRawWithPLM(updateBomDetailURL, bomIfsAlternative); + if (!"200".equals(updateBomDetailResponse.getCode())) { + throw new RuntimeException("IFS BOMAlternative修改异常:" + updateBomDetailResponse.getMsg()); + } + } + } - /** - * 新增项目物料 - * @param data - */ - @Override - @Transactional - public void addProjectPart2(PlmProjectPartData data) { - List partList = data.getPartList().stream().map(a -> { - a.setProjectId(data.getProjectId()); - a.setCustomerNo(data.getCustomerNo()); - a.setCreateBy(data.getCreateBy()); - a.setPartNoSource(data.getPartNoSource()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.addProjectPart(partList); - partInformationMapper.addCustomerPartInfo(partList); - } - - /** - * 查询变更记录 - * @param data - * @return - */ - @Override - public List getChangeRecordByPartNo(PlmProjectPartData data) { - List list = partInformationMapper.getChangeRecordByPartNo(data); - return list; - } - - /** - * 查询变更记录 - * @param data - * @return - */ - @Override - public List getChangeRecordByPartNo2(PlmProjectPartData data) { - List list = partInformationMapper.getChangeRecordByPartNo2(data); - return list; - } + // 创建 IFS 物料 BOM 的 子物料 + if (!componentDataList.isEmpty()) { + List ifsBomComponentList = componentDataList.stream().map(c -> { + c.setPartNo(ifsPart.getPartNo()); + c.setAlternativeNo(bomDetail.getAlternativeNo()); + return c; + }).collect(Collectors.toList()); + bomManagementMapper.saveBomComponents(ifsBomComponentList); + // 同步数据到 IFS + if (dataUrl) { + bomDetailVo.setPartNo(ifsPart.getPartNo()); + bomDetailVo.setAlternativeNo(bomDetail.getAlternativeNo()); + List componentList = bomManagementMapper.getBomComponent(bomDetailVo); + if (!componentList.isEmpty()) { + String addBomComponentURL = apiUrl + "/bom/ifs/syncBomIfsItemsToIfs"; + ResponseData addBomComponentResponse = HttpClientUtil.doPostByRawWithPLM(addBomComponentURL, componentList); + if (!"200".equals(addBomComponentResponse.getCode())) { + throw new RuntimeException("IFS BOM子物料新增异常:" + addBomComponentResponse.getMsg()); + } + } + } + } - /** - * 查出该物料的BOM和routing的替代 - * @param data - * @return - */ - @Override - public Map getBomAndRoutingList(PartInformationEntity data) { - HashMap map = new HashMap<>(); - List bomList = partInformationMapper.queryBomAlternativeList(data); - List routingList = partInformationMapper.queryRoutingAlternativeList(data); - map.put("bomList", bomList); - map.put("routingList", routingList); - return map; - } + // 创建 IFS 物料 BOM 的 副产品成本分配 + if (!manufStructCostDistribList.isEmpty()) { + // 创建副产品成本分配数据 + List collect1 = manufStructCostDistribList.stream().map(b -> { + b.setPartNo(ifsPart.getPartNo()); + b.setAlternativeNo(bomDetail.getAlternativeNo()); + return b; + }).collect(Collectors.toList()); + bomManagementMapper.saveBomManufStructCostDistrib(collect1); - /** - * 转正式物料 - * @param data - */ - @Override - @Transactional - public void - partInformationToOfficial(PartInformationVo data) { - // 判断选择的BOM替代的子料是否都为正式物料 - if (!data.getBomAlternativeList().isEmpty()) { - for (BomDetailVo vo : data.getBomAlternativeList()) { - List componentPartList = partInformationMapper.getComponentPart(vo); - for (PartInformationVo partInformationVo : componentPartList) { - if (!"Y".equals(partInformationVo.getStatus())) { - throw new RuntimeException("替代下含有非正式物料(BOM版本:" + partInformationVo.getBomType() + ", 替代名称为:" + partInformationVo.getAlternativeDescription() + ")!"); + // 更新ifs的副产品成本分配数据 + List bomIfsManufStructCostDistribs = new ArrayList<>(); + for (BomManufStructCostDistribVo bomManufStructCostDistribVo : collect1) { + BomIfsManufStructCostDistrib bomIfsManufStructCostDistrib = new BomIfsManufStructCostDistrib(); + bomIfsManufStructCostDistrib.setContract(bomManufStructCostDistribVo.getSite()); + bomIfsManufStructCostDistrib.setPartNo(bomManufStructCostDistribVo.getPartNo()); + bomIfsManufStructCostDistrib.setEngChgLevel(bomManufStructCostDistribVo.getEngChgLevel().toString()); + bomIfsManufStructCostDistrib.setBomType(bomManufStructCostDistribVo.getBomType()); + bomIfsManufStructCostDistrib.setAlternativeNo(bomManufStructCostDistribVo.getAlternativeNo()); + bomIfsManufStructCostDistrib.setByProdLineItemNo(bomManufStructCostDistribVo.getByProdLineItemNo().toString()); + bomIfsManufStructCostDistrib.setComponentLineItemNo(bomManufStructCostDistribVo.getComponentLineItemNo().toString()); + bomIfsManufStructCostDistrib.setItemCostDistribution(bomManufStructCostDistribVo.getItemCostDistribution() == null ? "" : bomManufStructCostDistribVo.getItemCostDistribution().toString()); + bomIfsManufStructCostDistrib.setComponentPartNo(bomManufStructCostDistribVo.getComponentPartNo()); + bomIfsManufStructCostDistrib.setByProductPartNo(bomManufStructCostDistribVo.getByProdPartNo()); + bomIfsManufStructCostDistribs.add(bomIfsManufStructCostDistrib); + } + String updateBomManufStructCostDistribURL = apiUrl + "/bom/ifs/modifyBomManufStructCostDistribsToIfs"; + ResponseData updateBomManufStructCostDistribResponse = HttpClientUtil.doPostByRawWithPLM(updateBomManufStructCostDistribURL, bomIfsManufStructCostDistribs); + if (!"200".equals(updateBomManufStructCostDistribResponse.getCode())) { + throw new RuntimeException("IFS Bom副产品成本分配修改异常:" + updateBomManufStructCostDistribResponse.getMsg()); + } + } } } - } - } - PartInformationEntity partData = partInformationMapper.selectOne(new QueryWrapper().eq("site", data.getSite()).eq("part_no", data.getPartNo())); - // 编辑原物料 - UpdateWrapper updateInformationWrapper = new UpdateWrapper<>(); - updateInformationWrapper.eq("site", data.getSite()); - updateInformationWrapper.eq("part_no", data.getPartNo()); - partInformationMapper.update(data, updateInformationWrapper); - // 物料属性 - PartSubPropertiesValueData valueData = new PartSubPropertiesValueData(); - valueData.setSite(data.getSite()); - valueData.setPartNo(data.getPartNo()); - valueData.setCodeNo(data.getCodeNo()); - valueData.setRecordType("IP"); - // 删除物料的属性模板 - partInformationMapper.deletePartSubPropertiesValueHeader(valueData); - // 删除物料的属性 - partInformationMapper.deletePartSubPropertiesValue(valueData); - // 重新加载属性模板 - partInformationMapper.savePartSubPropertiesValueHeader(valueData); - // 重新加载物料的属性 - for (PartSubPropertiesValueData itemDate : data.getPartItemList()) { - itemDate.setSite(data.getSite()); - itemDate.setPartNo(data.getPartNo()); - itemDate.setRecordType("IP"); - itemDate.setCodeNo(data.getCodeNo()); - itemDate.setSubCodeSeqNo(Double.valueOf("1")); - itemDate.setItNo(itemDate.getPropertiesItemNo()); - List checkItem = partInformationMapper.checkItem(itemDate); - if (checkItem.isEmpty()) { - throw new RuntimeException("该项目编码不存在!"); - } - List checkDetail = partInformationMapper.checkPartItem(itemDate); - if (!checkDetail.isEmpty()) { - throw new RuntimeException("该项目已存在!"); - } - itemDate.setItemNo(partInformationMapper.getModalDetailSeqNo(itemDate)); - partInformationMapper.addPartItem(itemDate); - } + // Routing + if (!routingAlternativeList.isEmpty()) { + // 新增 IFS 物料的 Routing + if (ifsPart.getPartType().contains("Manufactured")) { + RoutingHeaderEntity headerEntity = routingManagementMapper.selectOne(new QueryWrapper().eq("site", data.getSite()).eq("part_no", data.getPartNo()).eq("routing_revision", routingAlternativeList.get(0).getRoutingRevision()).eq("routing_type", routingAlternativeList.get(0).getRoutingType())); + headerEntity.setPartNo(ifsPart.getPartNo()); + headerEntity.setOfficialFlag("Y"); + // 新增 routing 主信息 + routingManagementMapper.saveRoutingHeader(headerEntity); - // 如果原物料类型改为了 Purchased (raw) 则删除 BOM 和 routing - if ("Purchased (raw)".equals(data.getPartType()) && !data.getPartType().equals(partData.getPartType())) { - partInformationMapper.deleteBomHeaderByPartNo(data); // BOM header - partInformationMapper.deleteBomDetailByPartNo(data); // BOM detail - partInformationMapper.deleteBomComponentByPartNo(data); // BOM component - partInformationMapper.deleteBomManufStructCostDistribByPartNo(data); // BOM 副产品成本分配 - partInformationMapper.deleteRoutingHeaderByPartNo(data); // Routing header - partInformationMapper.deleteRoutingDetailByPartNo(data); // Routing detail - partInformationMapper.deleteRoutingComponentByPartNo(data); // Routing component - partInformationMapper.deleteRoutingToolByPartNo(data); // Routing tool - partInformationMapper.deleteRoutingGuideLineByPartNo(data); // Routing guide line - } + // 同步数据到 IFS + if (dataUrl) { + RoutingIfsHeader routingIfsHeader = new RoutingIfsHeader(); + routingIfsHeader.setContract(headerEntity.getSite()); + routingIfsHeader.setPartNo(headerEntity.getPartNo()); + routingIfsHeader.setRoutingRevision(headerEntity.getRoutingRevision().toString()); + routingIfsHeader.setRoutingType(headerEntity.getRoutingType()); + routingIfsHeader.setPhaseInDate(DateUtils.format(headerEntity.getPhaseInDate())); + routingIfsHeader.setPhaseOutDate(DateUtils.format(headerEntity.getPhaseOutDate())); + routingIfsHeader.setNoteText(headerEntity.getNoteText()); + String getRoutingHeaderURL = apiUrl + "/routing/ifs/getRoutingHeader"; + ResponseData getRoutingHeaderResponse = HttpClientUtil.doPostByRawWithPLM(getRoutingHeaderURL, routingIfsHeader); + if (!"200".equals(getRoutingHeaderResponse.getCode())) { // 新增 + String addRoutingHeaderURL = apiUrl + "/routing/ifs/syncRoutingHeaderToIfs"; + ResponseData addRoutingHeaderResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingHeaderURL, routingIfsHeader); + if (!"200".equals(addRoutingHeaderResponse.getCode())) { + throw new RuntimeException("IFS RoutingHeader新增异常:" + addRoutingHeaderResponse.getMsg()); + } + } else { // 修改 + String updateRoutingHeaderURL = apiUrl + "/routing/ifs/modifyRoutingHeaderToIfs"; + ResponseData updateRoutingHeaderResponse = HttpClientUtil.doPostByRawWithPLM(updateRoutingHeaderURL, routingIfsHeader); + if (!"200".equals(updateRoutingHeaderResponse.getCode())) { + throw new RuntimeException("IFS RoutingHeader修改异常:" + updateRoutingHeaderResponse.getMsg()); + } + } + } - // 创建IFS物料 - PartInformationEntity ifsPart = new PartInformationEntity(); - BeanUtils.copyProperties(data, ifsPart); - ifsPart.setPartNo(data.getIfsPartNo()); - ifsPart.setPlmPartNo(data.getPartNo()); - ifsPart.setCreateBy(data.getUpdateBy()); - ifsPart.setStatus("Y"); - ifsPart.setIfsPartNo(""); - partInformationMapper.insert(ifsPart); + // 创建 IFS 物料的 Routing 子物料 + for (RoutingDetailVo routingDetailVo : routingAlternativeList) { + // 查询原物料的 Routing 替代 + RoutingDetailEntity routingDetailEntity = routingManagementMapper.queryDetailDataByNo(routingDetailVo); + // 查询原物料的 Routing 工序 + List operationDataList = routingManagementMapper.queryRoutingComponent(routingDetailVo); - // 创建IFS物料的属性 -// List modelHeaders = partInformationMapper.getModelHeader(data.getSite(), data.getPartNo(), data.getCodeNo(), "IP", data.getIfsPartNo()); - List modelDetails = partInformationMapper.getModelDetail(data.getSite(), data.getPartNo(), data.getCodeNo(), "IP", data.getIfsPartNo()); -// if (!modelHeaders.isEmpty()) { -// partInformationMapper.savePartModelHeaders(modelHeaders); -// } - if (!modelDetails.isEmpty()) { - partInformationMapper.savePartModelDetails(modelDetails); - } + // 创建 IFS 物料 Routing 的 替代 + routingDetailEntity.setPartNo(ifsPart.getPartNo()); + routingDetailEntity.setOfficialFlag("Y"); + routingManagementMapper.routingDetailSave(routingDetailEntity); - // 反刷项目物料的finalPartNo - partInformationMapper.updateProjectFinalPart(data); + // 同步数据到 IFS + if (dataUrl) { + RoutingIfsAlternative routingIfsAlternative = getIfsRoutingDetail(routingDetailEntity); + String getRoutingDetailURL = apiUrl + "/routing/ifs/getRoutingAlternative"; + ResponseData getRoutingDetailResponse = HttpClientUtil.doPostByRawWithPLM(getRoutingDetailURL, routingIfsAlternative); + if (!"200".equals(getRoutingDetailResponse.getCode())) { // 新增 + String addRoutingDetailURL = apiUrl + "/routing/ifs/syncRoutingAlternativeToIfs"; + ResponseData addRoutingDetailResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingDetailURL, routingIfsAlternative); + if (!"200".equals(addRoutingDetailResponse.getCode())) { + throw new RuntimeException("IFS RoutingAlternative新增异常:" + addRoutingDetailResponse.getMsg()); + } + } else { // 修改 + String updateRoutingDetailURL = apiUrl + "/routing/ifs/modifyRoutingAlternativeToIfs"; + ResponseData updateRoutingDetailResponse = HttpClientUtil.doPostByRawWithPLM(updateRoutingDetailURL, routingIfsAlternative); + if (!"200".equals(updateRoutingDetailResponse.getCode())) { + throw new RuntimeException("IFS RoutingAlternative修改异常:" + updateRoutingDetailResponse.getMsg()); + } + } + } - // 创建IFS物料的 revision - List partRevisionList = partInformationMapper.getFromPartRevision2(data.getSite(), data.getPartNo(), data.getIfsPartNo(), ifsPart.getCreateBy()); - if (!partRevisionList.isEmpty()) { - partInformationMapper.saveRevisions(partRevisionList); - } - - // 同步物料件 - MasterPartInformationEntity masterPartInformation = new MasterPartInformationEntity(); - masterPartInformation.setPartNo(ifsPart.getPartNo()); - masterPartInformation.setPlmPartNo(data.getPartNo()); - masterPartInformationService.toBecomeOfficialMasterPart(masterPartInformation); + // 创建 IFS 物料 Routing 的 工序 + if (!operationDataList.isEmpty()) { + RoutingComponentVo oldComponent = new RoutingComponentVo(); + for (RoutingComponentVo componentEntity : operationDataList) { + BeanUtils.copyProperties(componentEntity,oldComponent); + componentEntity.setPartNo(ifsPart.getPartNo()); + componentEntity.setAlternativeNo(routingDetailEntity.getAlternativeNo()); + routingManagementMapper.saveRoutingComponent(componentEntity); - // 1、库存件 - PartIfsInventory partIfsInventory = getPartIfsInventory(ifsPart); // 主表对象 - try { - // 同步数据到 IFS - if (dataUrl) { - PartIfsInventoryConfig partIfsInventoryConfig = getPartIfsInventoryConfig(ifsPart); // costs对象 - PartIfsInventoryManufacture partIfsInventoryManufacture = getPartIfsInventoryManufacture(ifsPart); // Manufacturing对象 - PartIfsInventoryPlan partIfsInventoryPlan = getPartIfsInventoryPlan(ifsPart); // planning对象 - List revisionList = partInformationMapper.getPartRevisionList(ifsPart); // revision对象 - PartIfsInventoryModel partIfsInventoryModel = getPartIfsInventoryModel(ifsPart); // 模板对象 - List propertyList = partInformationMapper.getPartPropertyList(ifsPart.getSite(), ifsPart.getPartNo(), ifsPart.getCodeNo(), "IP"); // 属性对象 + // 同步数据到 IFS + if (dataUrl) { + LinkedList routingIfsItems = new LinkedList<>(); + RoutingIfsItem routingIfsItem = getIfsRoutingComponent(componentEntity); + routingIfsItems.add(routingIfsItem); + String addRoutingComponentURL = apiUrl + "/routing/ifs/syncRoutingIfsItemsToIfs"; + ResponseData addRoutingComponentResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingComponentURL, routingIfsItems); + if (!"200".equals(addRoutingComponentResponse.getCode())) { + throw new RuntimeException("IFS RoutingItem新增异常:" + addRoutingComponentResponse.getMsg()); + } + String s = String.valueOf(addRoutingComponentResponse.getObj()); + List ifsItems = JSON.parseArray(s, RoutingIfsItem.class); + if (ifsItems.isEmpty()) { + throw new RuntimeException("IFS RoutingItem新增接口返回值异常!"); + } + for (RoutingIfsItem ifsItem : ifsItems) { // 修改ifs关键字 + routingManagementMapper.updateIfsRowKeyAndRevision(ifsItem); + } + } - // 校验revision -// boolean b = revisionList.stream().anyMatch(a -> a.getEffPhaseOutDate() == null || a.getEffPhaseOutDate().isEmpty() || a.getEngRevision() == null || a.getEngRevision().isEmpty()); -// if (b) { -// throw new RuntimeException("请维护库存件版本的失效时间 和 工程版本号!"); -// } + // 查询原物料的 Routing Tool + List toolList = routingManagementMapper.getRoutingToolByOperation(oldComponent); + // 创建 IFS 物料 Routing 的 Tool + if (!toolList.isEmpty()) { + List tools = toolList.stream().map(a -> { + a.setPartNo(ifsPart.getPartNo()); + a.setAlternativeNo(componentEntity.getAlternativeNo()); + a.setOperationId(componentEntity.getOperationId()); + return a; + }).collect(Collectors.toList()); + routingManagementMapper.saveRoutingTool(tools); + // 同步数据到 IFS + if (dataUrl) { + List ifsRoutingTools = routingManagementMapper.getRoutingToolByOperationToIfs(componentEntity.getSite(), componentEntity.getPartNo(), componentEntity.getRoutingType(), componentEntity.getRoutingRevision(), componentEntity.getAlternativeNo(), componentEntity.getOperationId()); + String addRoutingToolURL = apiUrl + "/routing/ifs/syncRoutingIfsToolsToIfs"; + ResponseData addRoutingToolResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingToolURL, ifsRoutingTools); + if (!"200".equals(addRoutingToolResponse.getCode())) { + throw new RuntimeException("IFS RoutingTool新增异常:" + addRoutingToolResponse.getMsg()); + } + String s = String.valueOf(addRoutingToolResponse.getObj()); + List ifsTools = JSON.parseArray(s, RoutingIfsTool.class); + if (ifsTools.isEmpty()) { + throw new RuntimeException("IFS RoutingTool新增接口返回值异常!"); + } + for (RoutingIfsTool ifsTool : ifsTools) { // 修改ifs关键字 + routingManagementMapper.updateIfsToolRowKeyAndRevision(ifsTool); + } + } + } - // 1.1 库存件主表数据 - String getInventoryPartURL = apiUrl + "/part/ifs/getInventoryPart"; - ResponseData getInventoryPartResponse = HttpClientUtil.doPostByRawWithPLM(getInventoryPartURL, partIfsInventory); - if (!"200".equals(getInventoryPartResponse.getCode())) { // 新增 - String addInventoryPartURL = apiUrl + "/part/ifs/syncInventoryPartToIfs"; - ResponseData addInventoryPartResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartURL, partIfsInventory); - if (!"200".equals(addInventoryPartResponse.getCode())) { - throw new RuntimeException("IFS库存件新增异常:" + addInventoryPartResponse.getMsg()); - } - } else { // 修改 - String updateInventoryPartURL = apiUrl + "/part/ifs/modifyInventoryPartToIfs"; - ResponseData updateInventoryPartResponse = HttpClientUtil.doPostByRawWithPLM(updateInventoryPartURL, partIfsInventory); - if (!"200".equals(updateInventoryPartResponse.getCode())) { - throw new RuntimeException("IFS库存件修改异常:" + updateInventoryPartResponse.getMsg()); - } - } - // 1.2 库存件 Costs 表数据 - String addInventoryPartCostsURL = apiUrl + "/part/ifs/modifyInventoryPartCostToIfs"; - ResponseData addInventoryPartCostsResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartCostsURL, partIfsInventoryConfig); - if (!"200".equals(addInventoryPartCostsResponse.getCode())) { - throw new RuntimeException("IFS库存件Costs修改异常:" + addInventoryPartCostsResponse.getMsg()); - } - // 1.3 库存件 Manufacturing 表数据 - String addInventoryPartManufacturingURL = apiUrl + "/part/ifs/modifyInventoryPartManufactureToIfs"; - ResponseData addInventoryPartManufacturingResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartManufacturingURL, partIfsInventoryManufacture); - if (!"200".equals(addInventoryPartManufacturingResponse.getCode())) { - throw new RuntimeException("IFS库存件Manufacturing修改异常:" + addInventoryPartManufacturingResponse.getMsg()); - } - // 1.4 库存件 Planning 表数据 - String addInventoryPartPlanningURL = apiUrl + "/part/ifs/modifyInventoryPartPlanToIfs"; - ResponseData addInventoryPartPlanningResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartPlanningURL, partIfsInventoryPlan); - if (!"200".equals(addInventoryPartPlanningResponse.getCode())) { - throw new RuntimeException("IFS库存件Planning修改异常:" + addInventoryPartPlanningResponse.getMsg()); - } - // 1.5 库存件 revision 表数据 - for (PartIfsInventoryRevision revision : revisionList) { - String queryPartRevisionURL = apiUrl + "/part/ifs/getInventoryPartRevision"; - ResponseData queryPartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(queryPartRevisionURL, revision); - if (!"200".equals(queryPartRevisionResponse.getCode())) { // 说明库存件版本不存在,走新增 - String savePartRevisionURL = apiUrl + "/part/ifs/syncInventoryPartRevisionToIfs"; - ResponseData savePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(savePartRevisionURL, revision); - if (!"200".equals(savePartRevisionResponse.getCode())) { - throw new RuntimeException("IFS库存件版本新增异常:" + savePartRevisionResponse.getMsg()); - } - } else { - // 修改 - String updatePartRevisionURL = apiUrl + "/part/ifs/modifyInventoryPartRevisionToIfs"; - ResponseData updatePartRevisionResponse = HttpClientUtil.doPostByRawWithPLM(updatePartRevisionURL, revision); - if (!"200".equals(updatePartRevisionResponse.getCode())) { - throw new RuntimeException("IFS库存件版本修改异常:" + updatePartRevisionResponse.getMsg()); + // 查询原物料的 workGuide Line + List guideLineList = routingManagementMapper.getGuideLineByOperation(oldComponent); + // 创建 IFS 物料 Routing 的 workGuide Line + if (!guideLineList.isEmpty()) { + List guideLines = guideLineList.stream().map(x -> { + x.setPartNo(ifsPart.getPartNo()); + x.setAlternativeNo(componentEntity.getAlternativeNo()); + x.setOperationId(componentEntity.getOperationId()); + return x; + }).collect(Collectors.toList()); + routingManagementMapper.saveGuideLine(guideLines); + // 同步数据到 IFS + if (dataUrl) { + List ifsRoutingGuidelines = routingManagementMapper.getRoutingGuidelineByOperationToIfs(componentEntity.getSite(), componentEntity.getPartNo(), componentEntity.getRoutingType(), componentEntity.getRoutingRevision(), componentEntity.getAlternativeNo(), componentEntity.getOperationId()); + String addRoutingGuidelineURL = apiUrl + "/routing/ifs/syncRoutingIfsGuideLinesToIfs"; + ResponseData addRoutingGuidelineResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingGuidelineURL, ifsRoutingGuidelines); + if (!"200".equals(addRoutingGuidelineResponse.getCode())) { + throw new RuntimeException("IFS RoutingGuideline新增异常:" + addRoutingGuidelineResponse.getMsg()); + } + String s = String.valueOf(addRoutingGuidelineResponse.getObj()); + List ifsGuidelines = JSON.parseArray(s, RoutingIfsGuideLine.class); + if (ifsGuidelines.isEmpty()) { + throw new RuntimeException("IFS RoutingGuideline新增接口返回值异常!"); + } + for (RoutingIfsGuideLine ifsGuideline : ifsGuidelines) { // 修改ifs关键字 + routingManagementMapper.updateIfsGuidelineRowKeyAndRevision(ifsGuideline); + } + } + } + } + } } } } + } - // 1.6 同步库存件的模板和属性 - if (partIfsInventoryModel.getEngAttribute() != null && !partIfsInventoryModel.getEngAttribute().isEmpty()) { - String addInventoryPartModelURL = apiUrl + "/part/ifs/modifyInventoryPartCharacteristicTemplate"; - ResponseData addInventoryPartModelResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartModelURL, partIfsInventoryModel); - if (!"200".equals(addInventoryPartModelResponse.getCode())) { - throw new RuntimeException("IFS库存件模板新增异常:" + addInventoryPartModelResponse.getMsg()); - } - } - if (!propertyList.isEmpty()) { - String addInventoryPartPropertyURL = apiUrl + "/part/ifs/syncInventoryPartCharacteristics"; - ResponseData addInventoryPartPropertyResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartPropertyURL, propertyList); - if (!"200".equals(addInventoryPartPropertyResponse.getCode())) { - throw new RuntimeException("IFS库存件属性新增异常:" + addInventoryPartPropertyResponse.getMsg()); - } - } + // 创建 IFS 物料的代理商、制造商、默认库位、文档 + List agents = partInformationMapper.getPartAgents(data); + List manufacturers = partInformationMapper.getPartManufacturers(data); + List defaultLocations = partInformationMapper.getPartDefaultLocations(data); + List files = partInformationMapper.getPartFiles(data); + if (!agents.isEmpty()) { + List ifsAgents = agents.stream().map(a -> { + a.setPartNo(ifsPart.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartAgent(ifsAgents); } - // 创建 IFS 物料的 BOM 和 Routing - // 所选 BOM 替代 - List bomAlternativeList = data.getBomAlternativeList(); - List routingAlternativeList = data.getRoutingAlternativeList(); - if (!"Purchased (raw)".equals(ifsPart.getPartType())) { - if (!bomAlternativeList.isEmpty()) { - // 若物料存在Repair类型的BOM,则校验是否有其它类型的BOM,否则提示 不存在与该物料相同的BOM类型! - // 使用 groupBy 分组并检查 - Map> groupedBOMs = bomAlternativeList.stream().collect(Collectors.groupingBy(bom -> "Repair".equals(bom.getBomType()))); - boolean hasRepairBom = !groupedBOMs.getOrDefault(true, Collections.emptyList()).isEmpty(); - boolean hasOtherBom = !groupedBOMs.getOrDefault(false, Collections.emptyList()).isEmpty(); - if (hasRepairBom && !hasOtherBom) { - throw new RuntimeException("不存在与该物料相同的BOM类型!"); - } + if (!manufacturers.isEmpty()) { + List ifsManufacturers = manufacturers.stream().map(a -> { + a.setPartNo(ifsPart.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartManufacturer(ifsManufacturers); + } - // 对所选替代的版本进行去重 - TreeSet bomHeaderList = bomAlternativeList.stream().collect(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(BomDetailEntity::getEngChgLevel)))); - for (BomDetailVo bomDetailVo : bomHeaderList) { - BomHeaderEntity bomHeader = new BomHeaderEntity(); - bomHeader.setSite(ifsPart.getSite()); - bomHeader.setPartNo(ifsPart.getPartNo()); - if (ifsPart.getPartType().contains("Manufactured")) { - bomHeader.setBomType("Manufacturing"); - } else if ("Purchased".equals(ifsPart.getPartType())) { - bomHeader.setBomType("Purchase"); - } - bomHeader.setEffPhaseInDate(bomDetailVo.getEffPhaseInDate()); - bomHeader.setEffPhaseOutDate(bomDetailVo.getEffPhaseOutDate()); - bomHeader.setEngChgLevel(bomDetailVo.getEngChgLevel()); - bomHeader.setNoteText(bomDetailVo.getBomHeaderNoteText()); - bomHeader.setEngRevision(bomDetailVo.getEngRevision()); - bomHeader.setOfficialFlag("Y"); + if (!defaultLocations.isEmpty()) { + List ifsDefaultLocations = defaultLocations.stream().map(a -> { + a.setPartNo(ifsPart.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartDefaultLocation(ifsDefaultLocations); - // 新增IFS 物料的 BOM 主信息 - bomManagementMapper.saveBomHeader(bomHeader); + // 同步数据到 IFS + if (dataUrl) { + // location对象 + List locationList = partInformationMapper.getPartLocationList(ifsPart); + // 库存件 Location 表数据 + String addInventoryPartLocationURL = apiUrl + "/part/ifs/syncInventoryPartLocationsToIfs"; + ResponseData addInventoryPartLocationResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartLocationURL, locationList); + if (!"200".equals(addInventoryPartLocationResponse.getCode())) { + throw new RuntimeException("IFS 库存件Location新增异常:" + addInventoryPartLocationResponse.getMsg()); + } + } + } - // 同步 BOM Header 数据到 IFS - if (dataUrl) { - BomIfsHeader bomIfsHeader = new BomIfsHeader(); - bomIfsHeader.setContract(bomHeader.getSite()); - bomIfsHeader.setPartNo(bomHeader.getPartNo()); - bomIfsHeader.setEngChgLevel(bomHeader.getEngChgLevel().toString()); - bomIfsHeader.setBomType(bomHeader.getBomType()); - bomIfsHeader.setEffPhaseInDate(DateUtils.format(bomHeader.getEffPhaseInDate())); - bomIfsHeader.setEffPhaseOutDate(bomHeader.getEffPhaseOutDate() == null ? "" : DateUtils.format(bomHeader.getEffPhaseOutDate())); - bomIfsHeader.setNoteText(bomHeader.getNoteText()); - String getBomHeaderURL = apiUrl + "/bom/ifs/getBomHeader"; - ResponseData getBomHeaderResponse = HttpClientUtil.doPostByRawWithPLM(getBomHeaderURL, bomIfsHeader); - if (!"200".equals(getBomHeaderResponse.getCode())) { // 新增 - String addBomHeaderURL = apiUrl + "/bom/ifs/syncBomHeaderToIfs"; - ResponseData addBomHeaderResponse = HttpClientUtil.doPostByRawWithPLM(addBomHeaderURL, bomIfsHeader); - if (!"200".equals(addBomHeaderResponse.getCode())) { - throw new RuntimeException("IFS BOMHeader新增异常:" + addBomHeaderResponse.getMsg()); - } - } else { - // 修改 - String updateBomHeaderURL = apiUrl + "/bom/ifs/modifyBomHeaderToIfs"; - ResponseData updateBomHeaderResponse = HttpClientUtil.doPostByRawWithPLM(updateBomHeaderURL, bomIfsHeader); - if (!"200".equals(updateBomHeaderResponse.getCode())) { - throw new RuntimeException("IFS BOMHeader修改异常:" + updateBomHeaderResponse.getMsg()); - } - } - } - } - - for (BomDetailVo bomDetailVo : bomAlternativeList) { - // 查原物料的替代 - BomDetailEntity bomDetail = bomManagementMapper.queryDetailDataByNo(bomDetailVo); - // 查询原物料的 BOM 子物料 - List componentDataList = bomManagementMapper.queryBomComponentAll(bomDetailVo); - // 查询原BOM副产品成本分配数据列表 - List manufStructCostDistribList = bomManagementMapper.queryBomManufStructCostDistrib(bomDetailVo); + if (!files.isEmpty()) { + List ifsFiles = files.stream().map(a -> { + a.setOrderRef2(ifsPart.getPartNo()); + return a; + }).collect(Collectors.toList()); + partInformationMapper.savePartFile(ifsFiles); + } + } catch (Exception e) { + // 删除库存件关联信息 + String deleteInventoryPartURL = apiUrl + "/part/ifs/removeInventoryPartRelationInfo"; + ResponseData deleteInventoryPartResponse = HttpClientUtil.doPostByRawWithPLM(deleteInventoryPartURL, partIfsInventory); + if (!"200".equals(deleteInventoryPartResponse.getCode())) { + throw new RuntimeException(e.getMessage() + "; IFS删除库存件关联信息异常:" + deleteInventoryPartResponse.getMsg()); + } + throw new RuntimeException(e.getMessage()); + } + } - // 创建 IFS 物料 BOM 的 替代 - bomDetail.setPartNo(ifsPart.getPartNo()); - bomDetail.setOfficialFlag("Y"); - bomManagementMapper.bomDetailSave(bomDetail); + /** + * 下一个物料编码 + * @param data + * @return + */ + @Override + public String getNextPartNo(PartInformationVo data) { +// Integer no = partInformationMapper.getNextPartNo(data); +// +// // 如果是 null,则默认为 1;否则递增 +// no = (no == null ? 1 : no + 1); +// +// // 使用 String.format 自动填充前导零 +// String formattedNo = String.format("%05d", no); +// +// return data.getIfsPartNo() + formattedNo; - // 同步数据到 IFS - if (dataUrl) { - BomIfsAlternative bomIfsAlternative = new BomIfsAlternative(); - bomIfsAlternative.setContract(bomDetail.getSite()); - bomIfsAlternative.setPartNo(bomDetail.getPartNo()); - bomIfsAlternative.setEngChgLevel(bomDetail.getEngChgLevel().toString()); - bomIfsAlternative.setBomType(bomDetail.getBomType()); - bomIfsAlternative.setAlternativeNo(bomDetail.getAlternativeNo()); - bomIfsAlternative.setAlternativeDesc(bomDetail.getAlternativeDescription()); - bomIfsAlternative.setNoteText(bomDetail.getDetailNoteText()); - String getBomDetailURL = apiUrl + "/bom/ifs/getBomAlternative"; - ResponseData getBomDetailResponse = HttpClientUtil.doPostByRawWithPLM(getBomDetailURL, bomIfsAlternative); - if (!"200".equals(getBomDetailResponse.getCode())) { // 新增 - String addBomDetailURL = apiUrl + "/bom/ifs/syncBomAlternativeToIfs"; - ResponseData addBomDetailResponse = HttpClientUtil.doPostByRawWithPLM(addBomDetailURL, bomIfsAlternative); - if (!"200".equals(addBomDetailResponse.getCode())) { - throw new RuntimeException("IFS BOMAlternative新增异常:" + addBomDetailResponse.getMsg()); - } - } else { // 修改 - String updateBomDetailURL = apiUrl + "/bom/ifs/modifyBomAlternativeToIfs"; - ResponseData updateBomDetailResponse = HttpClientUtil.doPostByRawWithPLM(updateBomDetailURL, bomIfsAlternative); - if (!"200".equals(updateBomDetailResponse.getCode())) { - throw new RuntimeException("IFS BOMAlternative修改异常:" + updateBomDetailResponse.getMsg()); - } - } - } + String nextPartNo = partInformationMapper.getNextPartNo2(data); + return nextPartNo; + } - // 创建 IFS 物料 BOM 的 子物料 - if (!componentDataList.isEmpty()) { - List ifsBomComponentList = componentDataList.stream().map(c -> { - c.setPartNo(ifsPart.getPartNo()); - c.setAlternativeNo(bomDetail.getAlternativeNo()); - return c; - }).collect(Collectors.toList()); - bomManagementMapper.saveBomComponents(ifsBomComponentList); - // 同步数据到 IFS - if (dataUrl) { - bomDetailVo.setPartNo(ifsPart.getPartNo()); - bomDetailVo.setAlternativeNo(bomDetail.getAlternativeNo()); - List componentList = bomManagementMapper.getBomComponent(bomDetailVo); - if (!componentList.isEmpty()) { - String addBomComponentURL = apiUrl + "/bom/ifs/syncBomIfsItemsToIfs"; - ResponseData addBomComponentResponse = HttpClientUtil.doPostByRawWithPLM(addBomComponentURL, componentList); - if (!"200".equals(addBomComponentResponse.getCode())) { - throw new RuntimeException("IFS BOM子物料新增异常:" + addBomComponentResponse.getMsg()); - } - } - } - } + /** + * 判断字符串是否能转为整数 + * @param str + * @return + */ + public static boolean isNumeric(String str) { + try { + Integer.parseInt(str); + return true; + } catch (NumberFormatException e) { + return false; + } + } - // 创建 IFS 物料 BOM 的 副产品成本分配 - if (!manufStructCostDistribList.isEmpty()) { - // 创建副产品成本分配数据 - List collect1 = manufStructCostDistribList.stream().map(b -> { - b.setPartNo(ifsPart.getPartNo()); - b.setAlternativeNo(bomDetail.getAlternativeNo()); - return b; - }).collect(Collectors.toList()); - bomManagementMapper.saveBomManufStructCostDistrib(collect1); + @Override + public List queryPart(PartInformationVo data) { + return baseMapper.queryPart(data); + } - // 更新ifs的副产品成本分配数据 - List bomIfsManufStructCostDistribs = new ArrayList<>(); - for (BomManufStructCostDistribVo bomManufStructCostDistribVo : collect1) { - BomIfsManufStructCostDistrib bomIfsManufStructCostDistrib = new BomIfsManufStructCostDistrib(); - bomIfsManufStructCostDistrib.setContract(bomManufStructCostDistribVo.getSite()); - bomIfsManufStructCostDistrib.setPartNo(bomManufStructCostDistribVo.getPartNo()); - bomIfsManufStructCostDistrib.setEngChgLevel(bomManufStructCostDistribVo.getEngChgLevel().toString()); - bomIfsManufStructCostDistrib.setBomType(bomManufStructCostDistribVo.getBomType()); - bomIfsManufStructCostDistrib.setAlternativeNo(bomManufStructCostDistribVo.getAlternativeNo()); - bomIfsManufStructCostDistrib.setByProdLineItemNo(bomManufStructCostDistribVo.getByProdLineItemNo().toString()); - bomIfsManufStructCostDistrib.setComponentLineItemNo(bomManufStructCostDistribVo.getComponentLineItemNo().toString()); - bomIfsManufStructCostDistrib.setItemCostDistribution(bomManufStructCostDistribVo.getItemCostDistribution() == null ? "" : bomManufStructCostDistribVo.getItemCostDistribution().toString()); - bomIfsManufStructCostDistrib.setComponentPartNo(bomManufStructCostDistribVo.getComponentPartNo()); - bomIfsManufStructCostDistrib.setByProductPartNo(bomManufStructCostDistribVo.getByProdPartNo()); - bomIfsManufStructCostDistribs.add(bomIfsManufStructCostDistrib); - } - String updateBomManufStructCostDistribURL = apiUrl + "/bom/ifs/modifyBomManufStructCostDistribsToIfs"; - ResponseData updateBomManufStructCostDistribResponse = HttpClientUtil.doPostByRawWithPLM(updateBomManufStructCostDistribURL, bomIfsManufStructCostDistribs); - if (!"200".equals(updateBomManufStructCostDistribResponse.getCode())) { - throw new RuntimeException("IFS Bom副产品成本分配修改异常:" + updateBomManufStructCostDistribResponse.getMsg()); - } - } - } + /** + * 项目物料Excel导入 + * @param file + * @param data + */ + @Override + @Transactional + public void uploadProjectPartExcel(MultipartFile file, GetParamInData data) { + try{ + // 转流 + InputStream is = file.getInputStream(); + // 读取工作簿 + XSSFWorkbook workbook = new XSSFWorkbook(is); + // 读取工作表 + XSSFSheet sheet = workbook.getSheetAt(0); + // 获取行数 + int rows = sheet.getPhysicalNumberOfRows(); + // 声明对象 + PartInformationVo task = null; + // 遍历每一行(从第二行开始) + for (int j = 1; j < rows; j++) { + // 实例化对象 + task = new PartInformationVo(); + //获得该行 + XSSFRow row = sheet.getRow(j); + // 为对象赋值 + task.setSite(data.getOrderRef1()); // site + task.setProjectId(data.getOrderRef2()); // 项目编码 + task.setCustomerNo(data.getOrderRef3()); // 客户编码 + String no = transNoControlService.transNo(data.getOrderRef1(), "project_part_no"); + if (no == null) { + throw new RuntimeException("请维护编码生成规则(TransNoControl)!"); + } + task.setPartNo(no + "A01"); // 物料编码 + task.setBuNo(row.getCell(0).getStringCellValue()); // BU + task.setPartDesc(row.getCell(1).getStringCellValue()); // 物料描述 + task.setCustomerPartNo(row.getCell(2).getStringCellValue()); // 客户料号 + task.setPartType(row.getCell(3).getStringCellValue()); // 零件类型 + task.setProductGroupId4(row.getCell(4).getStringCellValue()); // 计划人 + task.setUmId(row.getCell(5).getStringCellValue()); // 计量单位 + if (row.getCell(6) == null) { // 属性模板 + task.setCodeNo(""); + } else { + task.setCodeNo(row.getCell(6).getStringCellValue()); } + task.setUomForWeightNet("kg"); + task.setUomForVolumeNet("m3"); + task.setActive("Y"); + task.setLotTrackingCode("Order Based"); + task.setCreateBy(data.getCreateBy()); + task.setAssetClass("S"); + task.setAbcClass("C"); + task.setFrequencyClass("Very Slow Mover"); + task.setLifecycleStage("Development"); + task.setStatus("N"); + task.setPartStatus("A"); + task.setConfigurationId("*"); + task.setInventoryValuationMethod("Standard Cost"); + task.setInventoryPartCostLevel("Cost Per Part"); + task.setInvoiceConsideration("Ignore Invoice Price"); + task.setZeroCostFlag("Zero Cost Forbidden"); + task.setBackFlushPart("All Locations"); + task.setIssueType("Reserve And Backflush"); + task.setMrpControlFlagDb("Y"); + task.setOverReporting("Allowed"); - // Routing - if (!routingAlternativeList.isEmpty()) { - // 新增 IFS 物料的 Routing - if (ifsPart.getPartType().contains("Manufactured")) { - RoutingHeaderEntity headerEntity = routingManagementMapper.selectOne(new QueryWrapper().eq("site", data.getSite()).eq("part_no", data.getPartNo()).eq("routing_revision", routingAlternativeList.get(0).getRoutingRevision()).eq("routing_type", routingAlternativeList.get(0).getRoutingType())); - headerEntity.setPartNo(ifsPart.getPartNo()); - headerEntity.setOfficialFlag("Y"); - // 新增 routing 主信息 - routingManagementMapper.saveRoutingHeader(headerEntity); + // 调用新增方法 + partInformationSave2(task); + } + } catch (Exception e) { + throw new RuntimeException("导入失败:"+e.getMessage()); + } + } - // 同步数据到 IFS - if (dataUrl) { - RoutingIfsHeader routingIfsHeader = new RoutingIfsHeader(); - routingIfsHeader.setContract(headerEntity.getSite()); - routingIfsHeader.setPartNo(headerEntity.getPartNo()); - routingIfsHeader.setRoutingRevision(headerEntity.getRoutingRevision().toString()); - routingIfsHeader.setRoutingType(headerEntity.getRoutingType()); - routingIfsHeader.setPhaseInDate(DateUtils.format(headerEntity.getPhaseInDate())); - routingIfsHeader.setPhaseOutDate(DateUtils.format(headerEntity.getPhaseOutDate())); - routingIfsHeader.setNoteText(headerEntity.getNoteText()); - String getRoutingHeaderURL = apiUrl + "/routing/ifs/getRoutingHeader"; - ResponseData getRoutingHeaderResponse = HttpClientUtil.doPostByRawWithPLM(getRoutingHeaderURL, routingIfsHeader); - if (!"200".equals(getRoutingHeaderResponse.getCode())) { // 新增 - String addRoutingHeaderURL = apiUrl + "/routing/ifs/syncRoutingHeaderToIfs"; - ResponseData addRoutingHeaderResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingHeaderURL, routingIfsHeader); - if (!"200".equals(addRoutingHeaderResponse.getCode())) { - throw new RuntimeException("IFS RoutingHeader新增异常:" + addRoutingHeaderResponse.getMsg()); - } - } else { // 修改 - String updateRoutingHeaderURL = apiUrl + "/routing/ifs/modifyRoutingHeaderToIfs"; - ResponseData updateRoutingHeaderResponse = HttpClientUtil.doPostByRawWithPLM(updateRoutingHeaderURL, routingIfsHeader); - if (!"200".equals(updateRoutingHeaderResponse.getCode())) { - throw new RuntimeException("IFS RoutingHeader修改异常:" + updateRoutingHeaderResponse.getMsg()); - } - } - } + /** + * 查询文件ID + * @param data + * @return + */ + @Override + public SysOssEntity queryFileId(SysOssEntity data) { + List list = partInformationMapper.queryFileId(data); + if (list.isEmpty()) { + throw new RuntimeException("未查到该文件ID,请检查数据!"); + } + return list.get(0); + } - // 创建 IFS 物料的 Routing 子物料 - for (RoutingDetailVo routingDetailVo : routingAlternativeList) { - // 查询原物料的 Routing 替代 - RoutingDetailEntity routingDetailEntity = routingManagementMapper.queryDetailDataByNo(routingDetailVo); - // 查询原物料的 Routing 工序 - List operationDataList = routingManagementMapper.queryRoutingComponent(routingDetailVo); + /** + * 下载文件 + * @param id + * @param response + * @throws UnsupportedEncodingException + */ + @Override + public void downLoadObjectFile(Integer id, HttpServletResponse response) throws UnsupportedEncodingException { + // 处理路径和名称 + List getFileData = partInformationMapper.getFileData(id); + if (getFileData.isEmpty()) { + throw new RuntimeException("该文件不存在,请刷新列表"); + } + File file = new File(getFileData.get(0).getUrl()); + //读取缓存1kb + byte[] buffer = new byte[1024]; + FileInputStream fis = null; + BufferedInputStream bis = null; + FileOutputStream fos = null; + BufferedOutputStream bos = null; + response.setContentType("application/force-download;charset=utf-8"); + response.setHeader("Content-disposition", "attachment; filename=" + new String(getFileData.get(0).getFileName().getBytes("gbk"), "iso8859-1")); + try { + //读取文件 + fis = new FileInputStream(file); + //加缓存 + bis = new BufferedInputStream(fis); + //开始读取 + int i = bis.read(buffer); + //设置输出流 + ServletOutputStream os = response.getOutputStream(); + //开始循环读取 + while (i != -1) { + os.write(buffer, 0, i); + i = bis.read(buffer); + } + fis.close(); + fos.close(); + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + } - // 创建 IFS 物料 Routing 的 替代 - routingDetailEntity.setPartNo(ifsPart.getPartNo()); - routingDetailEntity.setOfficialFlag("Y"); - routingManagementMapper.routingDetailSave(routingDetailEntity); + /** + * 获取下一个物料revision + * @param inData + * @return + */ + @Override + public Map getPartRevisionEngChgLevel(PartRevisionVo inData) { + HashMap map = new HashMap<>(); + // 获取最大的partRevision + List revisionList = partInformationMapper.getMaxPartRevision(inData.getSite(), inData.getPartNo()); - // 同步数据到 IFS - if (dataUrl) { - RoutingIfsAlternative routingIfsAlternative = getIfsRoutingDetail(routingDetailEntity); - String getRoutingDetailURL = apiUrl + "/routing/ifs/getRoutingAlternative"; - ResponseData getRoutingDetailResponse = HttpClientUtil.doPostByRawWithPLM(getRoutingDetailURL, routingIfsAlternative); - if (!"200".equals(getRoutingDetailResponse.getCode())) { // 新增 - String addRoutingDetailURL = apiUrl + "/routing/ifs/syncRoutingAlternativeToIfs"; - ResponseData addRoutingDetailResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingDetailURL, routingIfsAlternative); - if (!"200".equals(addRoutingDetailResponse.getCode())) { - throw new RuntimeException("IFS RoutingAlternative新增异常:" + addRoutingDetailResponse.getMsg()); - } - } else { // 修改 - String updateRoutingDetailURL = apiUrl + "/routing/ifs/modifyRoutingAlternativeToIfs"; - ResponseData updateRoutingDetailResponse = HttpClientUtil.doPostByRawWithPLM(updateRoutingDetailURL, routingIfsAlternative); - if (!"200".equals(updateRoutingDetailResponse.getCode())) { - throw new RuntimeException("IFS RoutingAlternative修改异常:" + updateRoutingDetailResponse.getMsg()); - } - } - } + if (revisionList.isEmpty()) { + map.put("engChgLevel", 1); + map.put("engRevision", 1); + } else { + map.put("engChgLevel", revisionList.get(0).getEngChgLevel() + 1); + map.put("engRevision", revisionList.get(0).getEngChgLevel() + 1); + } + return map; + } - // 创建 IFS 物料 Routing 的 工序 - if (!operationDataList.isEmpty()) { - RoutingComponentVo oldComponent = new RoutingComponentVo(); - for (RoutingComponentVo componentEntity : operationDataList) { - BeanUtils.copyProperties(componentEntity,oldComponent); - componentEntity.setPartNo(ifsPart.getPartNo()); - componentEntity.setAlternativeNo(routingDetailEntity.getAlternativeNo()); - routingManagementMapper.saveRoutingComponent(componentEntity); + /** + * 查询物料的 unitCost 列表 + * @param inData + * @return + */ + @Override + public List queryPartUnitCostList(InventoryPartUnitCostSumEntity inData) { + List list = partInformationMapper.queryPartUnitCostList(inData); + return list; + } - // 同步数据到 IFS - if (dataUrl) { - LinkedList routingIfsItems = new LinkedList<>(); - RoutingIfsItem routingIfsItem = getIfsRoutingComponent(componentEntity); - routingIfsItems.add(routingIfsItem); - String addRoutingComponentURL = apiUrl + "/routing/ifs/syncRoutingIfsItemsToIfs"; - ResponseData addRoutingComponentResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingComponentURL, routingIfsItems); - if (!"200".equals(addRoutingComponentResponse.getCode())) { - throw new RuntimeException("IFS RoutingItem新增异常:" + addRoutingComponentResponse.getMsg()); - } - String s = String.valueOf(addRoutingComponentResponse.getObj()); - List ifsItems = JSON.parseArray(s, RoutingIfsItem.class); - if (ifsItems.isEmpty()) { - throw new RuntimeException("IFS RoutingItem新增接口返回值异常!"); - } - for (RoutingIfsItem ifsItem : ifsItems) { // 修改ifs关键字 - routingManagementMapper.updateIfsRowKeyAndRevision(ifsItem); - } - } + /** + * 同步 unitValue 到PLM + */ + @Override + @Transactional + public void syncUnitValueToPLM(InventoryPartUnitCostSumVo data) { + // 查出最大的 rowVersion + String rowVersion = partInformationMapper.getMaxUnitValueRowVersion(); + data.setIfsRowVersion(rowVersion); + // 调用接口获得IFS数据 + String getIfsUnitValuesURL = apiUrl + "/base/ifs/getIfsInventoryValues"; + ResponseData getIfsUnitValuesResponse = HttpClientUtil.doPostByRawWithPLM(getIfsUnitValuesURL, data); + if (!"200".equals(getIfsUnitValuesResponse.getCode())) { + throw new RuntimeException("同步Unit Value信息异常:" + getIfsUnitValuesResponse.getMsg()); + } + String UnitValuesObj = String.valueOf(getIfsUnitValuesResponse.getObj()); + List ifsUnitValues = JSON.parseArray(UnitValuesObj, InventoryPartUnitCostSumEntity.class); + // 查询PLM数据 + String[] arr = data.getSiteCon().replace("(", "").replace(")", "").replace("'", "").split(","); + List plmUnitValues = partInformationMapper.getPLMUnitValues(arr); - // 查询原物料的 Routing Tool - List toolList = routingManagementMapper.getRoutingToolByOperation(oldComponent); - // 创建 IFS 物料 Routing 的 Tool - if (!toolList.isEmpty()) { - List tools = toolList.stream().map(a -> { - a.setPartNo(ifsPart.getPartNo()); - a.setAlternativeNo(componentEntity.getAlternativeNo()); - a.setOperationId(componentEntity.getOperationId()); - return a; - }).collect(Collectors.toList()); - routingManagementMapper.saveRoutingTool(tools); - // 同步数据到 IFS - if (dataUrl) { - List ifsRoutingTools = routingManagementMapper.getRoutingToolByOperationToIfs(componentEntity.getSite(), componentEntity.getPartNo(), componentEntity.getRoutingType(), componentEntity.getRoutingRevision(), componentEntity.getAlternativeNo(), componentEntity.getOperationId()); - String addRoutingToolURL = apiUrl + "/routing/ifs/syncRoutingIfsToolsToIfs"; - ResponseData addRoutingToolResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingToolURL, ifsRoutingTools); - if (!"200".equals(addRoutingToolResponse.getCode())) { - throw new RuntimeException("IFS RoutingTool新增异常:" + addRoutingToolResponse.getMsg()); - } - String s = String.valueOf(addRoutingToolResponse.getObj()); - List ifsTools = JSON.parseArray(s, RoutingIfsTool.class); - if (ifsTools.isEmpty()) { - throw new RuntimeException("IFS RoutingTool新增接口返回值异常!"); - } - for (RoutingIfsTool ifsTool : ifsTools) { // 修改ifs关键字 - routingManagementMapper.updateIfsToolRowKeyAndRevision(ifsTool); - } - } - } + // 转换列表为映射以便于比较 + Map mapListAll = ifsUnitValues.stream() + .collect(Collectors.toMap(InventoryPartUnitCostSumEntity::getKey, Function.identity())); + Map mapList1 = plmUnitValues.stream() + .collect(Collectors.toMap(InventoryPartUnitCostSumEntity::getKey, Function.identity())); - // 查询原物料的 workGuide Line - List guideLineList = routingManagementMapper.getGuideLineByOperation(oldComponent); - // 创建 IFS 物料 Routing 的 workGuide Line - if (!guideLineList.isEmpty()) { - List guideLines = guideLineList.stream().map(x -> { - x.setPartNo(ifsPart.getPartNo()); - x.setAlternativeNo(componentEntity.getAlternativeNo()); - x.setOperationId(componentEntity.getOperationId()); - return x; - }).collect(Collectors.toList()); - routingManagementMapper.saveGuideLine(guideLines); - // 同步数据到 IFS - if (dataUrl) { - List ifsRoutingGuidelines = routingManagementMapper.getRoutingGuidelineByOperationToIfs(componentEntity.getSite(), componentEntity.getPartNo(), componentEntity.getRoutingType(), componentEntity.getRoutingRevision(), componentEntity.getAlternativeNo(), componentEntity.getOperationId()); - String addRoutingGuidelineURL = apiUrl + "/routing/ifs/syncRoutingIfsGuideLinesToIfs"; - ResponseData addRoutingGuidelineResponse = HttpClientUtil.doPostByRawWithPLM(addRoutingGuidelineURL, ifsRoutingGuidelines); - if (!"200".equals(addRoutingGuidelineResponse.getCode())) { - throw new RuntimeException("IFS RoutingGuideline新增异常:" + addRoutingGuidelineResponse.getMsg()); - } - String s = String.valueOf(addRoutingGuidelineResponse.getObj()); - List ifsGuidelines = JSON.parseArray(s, RoutingIfsGuideLine.class); - if (ifsGuidelines.isEmpty()) { - throw new RuntimeException("IFS RoutingGuideline新增接口返回值异常!"); - } - for (RoutingIfsGuideLine ifsGuideline : ifsGuidelines) { // 修改ifs关键字 - routingManagementMapper.updateIfsGuidelineRowKeyAndRevision(ifsGuideline); - } - } - } - } - } - } - } - } - } + // 找出需要新增的对象(IFS有而PLM没有的) + Set keysToAdd = new HashSet<>(mapListAll.keySet()); + keysToAdd.removeAll(mapList1.keySet()); + List toAdd = keysToAdd.stream() + .map(mapListAll::get) + .collect(Collectors.toList()); + + // 找出需要更新的对象(ifsRowVersion不同) + Set commonKeys = new HashSet<>(mapListAll.keySet()); + commonKeys.retainAll(mapList1.keySet()); + List toUpdate = commonKeys.stream() + .filter(key -> !mapListAll.get(key).getIfsRowVersion().equals(mapList1.get(key).getIfsRowVersion())) + .map(key -> mapListAll.get(key)) // 选择listAll中的版本进行更新 + .collect(Collectors.toList()); - // 创建 IFS 物料的代理商、制造商、默认库位、文档 - List agents = partInformationMapper.getPartAgents(data); - List manufacturers = partInformationMapper.getPartManufacturers(data); - List defaultLocations = partInformationMapper.getPartDefaultLocations(data); - List files = partInformationMapper.getPartFiles(data); + // 新增 + if (!toAdd.isEmpty()) { + // 分批插入 + int batchSize = 100; // 假设每批100条记录 + for (int i = 0; i < toAdd.size(); i += batchSize) { + int end = Math.min(i + batchSize, toAdd.size()); + List subList = toAdd.subList(i, end); + partInformationMapper.syncSaveUnitValue(subList); + } + } + // 修改 + if (!toUpdate.isEmpty()) { + // 分批修改 + int batchSize = 100; // 假设每批100条记录 + for (int i = 0; i < toUpdate.size(); i += batchSize) { + int end = Math.min(i + batchSize, toUpdate.size()); + List subList = toUpdate.subList(i, end); + partInformationMapper.syncUpdateUnitValue(subList); + } + } + } - if (!agents.isEmpty()) { - List ifsAgents = agents.stream().map(a -> { - a.setPartNo(ifsPart.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartAgent(ifsAgents); + @Override + @Transactional + public List getItemListByCodeNo(PartSubPropertiesValueData data) { + List result = partInformationMapper.getItemListByCodeNo(data); + for (int i = 0; i < result.size(); i++) { + if ("Y".equals(result.get(i).getValueChooseFlag())) { + List availableList = partInformationMapper.getAvailableValueList(result.get(i)); + result.get(i).setAvailableValueList(availableList); } + } + return result; + } - if (!manufacturers.isEmpty()) { - List ifsManufacturers = manufacturers.stream().map(a -> { - a.setPartNo(ifsPart.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartManufacturer(ifsManufacturers); + /** + * 查属性模板,不包括已存在的 + * @param data + * @return + */ + @Override + public List getItemExclusionAlreadyExists(PartSubPropertiesValueData data) { + String[] arr = convertToSQLString(data.getItemNos()).replace("(", "").replace(")", "").replace("'", "").split(","); + data.setArr(arr); + List list = partInformationMapper.getItemExclusionAlreadyExists(data); + for (int i = 0; i < list.size(); i++) { + if ("Y".equals(list.get(i).getValueChooseFlag())) { + List availableList = partInformationMapper.getAvailableValueList(list.get(i)); + list.get(i).setAvailableValueList(availableList); } + } + return list; + } - if (!defaultLocations.isEmpty()) { - List ifsDefaultLocations = defaultLocations.stream().map(a -> { - a.setPartNo(ifsPart.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartDefaultLocation(ifsDefaultLocations); - // 同步数据到 IFS - if (dataUrl) { - // location对象 - List locationList = partInformationMapper.getPartLocationList(ifsPart); - // 库存件 Location 表数据 - String addInventoryPartLocationURL = apiUrl + "/part/ifs/syncInventoryPartLocationsToIfs"; - ResponseData addInventoryPartLocationResponse = HttpClientUtil.doPostByRawWithPLM(addInventoryPartLocationURL, locationList); - if (!"200".equals(addInventoryPartLocationResponse.getCode())) { - throw new RuntimeException("IFS 库存件Location新增异常:" + addInventoryPartLocationResponse.getMsg()); - } - } - } - if (!files.isEmpty()) { - List ifsFiles = files.stream().map(a -> { - a.setOrderRef2(ifsPart.getPartNo()); - return a; - }).collect(Collectors.toList()); - partInformationMapper.savePartFile(ifsFiles); - } - } catch (Exception e) { - // 删除库存件关联信息 - String deleteInventoryPartURL = apiUrl + "/part/ifs/removeInventoryPartRelationInfo"; - ResponseData deleteInventoryPartResponse = HttpClientUtil.doPostByRawWithPLM(deleteInventoryPartURL, partIfsInventory); - if (!"200".equals(deleteInventoryPartResponse.getCode())) { - throw new RuntimeException(e.getMessage() + "; IFS删除库存件关联信息异常:" + deleteInventoryPartResponse.getMsg()); - } - throw new RuntimeException(e.getMessage()); + /** + * 组合 MasterPart 对象 + * @param ifsPartCatalog + * @param inData + * @return + */ + private MasterPartInformationEntity getMasterPartInformation(PartIfsCatalog ifsPartCatalog, PartInformationVo inData) { + MasterPartInformationEntity masterPart = new MasterPartInformationEntity(); + masterPart.setPartNo(ifsPartCatalog.getPartNo()); + masterPart.setPartDesc(ifsPartCatalog.getPartDesc()); + masterPart.setPartMainGroup(ifsPartCatalog.getPartMainGroup()); + masterPart.setWeightNet(UtilsClass.stringToBigDecimal(ifsPartCatalog.getWeightNet())); + masterPart.setUomForWeightNet(ifsPartCatalog.getUomForWeightNet()); + masterPart.setVolumeNet(UtilsClass.stringToBigDecimal(ifsPartCatalog.getVolumeNet())); + masterPart.setUomForVolumeNet(ifsPartCatalog.getUomForVolumeNet()); + masterPart.setConditionCodeUsageDb(ifsPartCatalog.getConditionCodeUsageDb()); + masterPart.setMultilevelTrackingDb(ifsPartCatalog.getMultilevelTrackingDb()); + masterPart.setAllowAsNotConsumedDb(ifsPartCatalog.getAllowAsNotConsumedDb()); + masterPart.setLotTrackingCode(ifsPartCatalog.getLotTrackingCode()); + masterPart.setLotQuantityRule(ifsPartCatalog.getLotQuantityRule()); + masterPart.setSubLotRule(ifsPartCatalog.getSubLotRule()); + masterPart.setComponentLotRule(ifsPartCatalog.getComponentLotRule()); + masterPart.setCodeNo(ifsPartCatalog.getTechnicalClass()); + masterPart.setUmId(ifsPartCatalog.getUnitCode()); + masterPart.setOfficialFlag("Y"); + masterPart.setIfsRowId(ifsPartCatalog.getIfsRowId()); + masterPart.setIfsRowVersion(ifsPartCatalog.getIfsRowVersion()); + masterPart.setCreateBy(inData.getCreateBy()); + return masterPart; + } + + /** + * Master Part 模板对象转换 + * @param ifsPartCatalogItem + * @param inData + * @return + */ + private List masterPartModalConvert(PartIfsCatalogProperty ifsPartCatalogItem, PartInformationVo inData) { + List partModalList = new ArrayList<>(); + PartSubPropertiesValueHeaderData headerData = new PartSubPropertiesValueHeaderData(); + headerData.setSite("*"); + headerData.setPartNo(inData.getPartNo()); + headerData.setCodeNo(ifsPartCatalogItem.getTechnicalClass()); + headerData.setSubCodeSeqNo(Double.valueOf("1")); + headerData.setRecordType("MP"); + partModalList.add(headerData); + return partModalList; + } + + /** + * Master Part 属性对象转换 + * @param ifsPartCatalogItems + * @param inData + * @return + */ + private List masterPartItemConvert(List ifsPartCatalogItems, PartInformationVo inData) { + List partItemList = new ArrayList<>(); + int count = 1; + for (PartIfsCatalogProperty ifsInventoryItem : ifsPartCatalogItems) { + PartSubPropertiesValueData partItem = new PartSubPropertiesValueData(); + partItem.setSite("*"); + partItem.setPartNo(inData.getPartNo()); + partItem.setCodeNo(ifsInventoryItem.getTechnicalClass()); + partItem.setSubCodeSeqNo(Double.valueOf("1")); + partItem.setItemNo((double) count++); + partItem.setPropertiesItemNo(ifsInventoryItem.getAttribute()); + partItem.setTextValue(ifsInventoryItem.getValueText()); + partItem.setNumValue(Double.valueOf(ifsInventoryItem.getValueNo())); + partItem.setRecordType("MP"); + partItemList.add(partItem); + } + return partItemList; + } + + /** + * 组合 InventoryPart 对象 + * @param ifsInventoryPart + * @param ifsInventoryPartPlanning + * @param ifsInventoryPartManufacturing + * @param ifsInventoryPartCost + * @return + */ + private PartInformationEntity getInventoryPartInformation(PartInformationVo inData, PartIfsInventory ifsInventoryPart, PartIfsInventoryPlan ifsInventoryPartPlanning, PartIfsInventoryManufacture ifsInventoryPartManufacturing, PartIfsInventoryConfig ifsInventoryPartCost) { + PartInformationEntity partInformation = new PartInformationEntity(); + partInformation.setSite(ifsInventoryPart.getContract()); + partInformation.setPartNo(ifsInventoryPart.getPartNo()); + partInformation.setPartDesc(ifsInventoryPart.getPartDesc()); + partInformation.setStatus("Y"); + partInformation.setActive("Y"); + partInformation.setPartType(ifsInventoryPart.getTypeCode()); // 零件类型 + partInformation.setHazardCode(ifsInventoryPart.getHazardCode()); // 安全代码 + partInformation.setProductGroupId4(ifsInventoryPart.getPlannerBuyer()); // 计划人 + partInformation.setProductGroupId3(ifsInventoryPart.getAccountingGroup()); // 会计组 + partInformation.setUmId(ifsInventoryPart.getUnitMeas()); // 库存计量单位 + partInformation.setGroupId(ifsInventoryPart.getPartProductCode()); // 产品代码 + partInformation.setProductGroupId1(ifsInventoryPart.getPrimeCommodity()); // 商品组1 + partInformation.setFamilyId(ifsInventoryPart.getPartProductFamily()); // 产品大类 + partInformation.setProductGroupId2(ifsInventoryPart.getSecondCommodity()); // 商品组2 + partInformation.setTypeDesignation(ifsInventoryPart.getTypeDesignation()); // 类型指定 + partInformation.setAssetClass(ifsInventoryPart.getAssetClass()); // 资产等级 + partInformation.setDimQuality(ifsInventoryPart.getDimQuality()); // 尺寸/材质 + partInformation.setPartStatus(ifsInventoryPart.getPartStatus()); // 零件状态 + partInformation.setWeightNet(UtilsClass.stringToBigDecimal(ifsInventoryPart.getWeightNet())); // 净重 + partInformation.setUomForWeightNet(ifsInventoryPart.getUomForWeightNet()); // 净重单位 + partInformation.setVolumeNet(UtilsClass.stringToBigDecimal(ifsInventoryPart.getVolumeNet())); // 净数量 + partInformation.setUomForVolumeNet(ifsInventoryPart.getUomForVolumeNet()); // 数量单位 + partInformation.setAbcClass(ifsInventoryPart.getAbcClass()); // ABC类 + partInformation.setFrequencyClass(ifsInventoryPart.getFrequencyClass()); // 频率级别 + partInformation.setLifecycleStage(ifsInventoryPart.getLifecycleStage()); // 生命周期阶段 + partInformation.setManufacturingLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPart.getManufLeadtime())); // 制造备货期 + partInformation.setCountryOfOrigin(ifsInventoryPart.getCountryOfOrigin()); // 来源国家 + partInformation.setExpectedLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPart.getExpectedLeadtime())); // 预期提前期 + partInformation.setDurabilityDay(UtilsClass.stringToInteger(ifsInventoryPart.getDurabilityDay())); // 天数 + partInformation.setRegionOfOrigin(ifsInventoryPart.getRegionOfOrigin()); // 区域代码 + partInformation.setIntrastatConvFactor(UtilsClass.stringToBigDecimal(ifsInventoryPart.getIntrastatConvFactor())); // 州内转换因子 + partInformation.setCustomsStatNo(ifsInventoryPart.getCustomsStatNo()); // 海关统计序号 + partInformation.setRemark(ifsInventoryPart.getNoteText()); // 备注 + partInformation.setInventoryValuationMethod(ifsInventoryPart.getInventoryValuationMethod()); // 库存估价方法 + partInformation.setPartCostGroupId(ifsInventoryPart.getPartCostGroupId()); // 零件成本组 + partInformation.setInventoryPartCostLevel(ifsInventoryPart.getInventoryPartCostLevel()); // 库存件成本层 + partInformation.setInvoiceConsideration(ifsInventoryPart.getInvoiceConsideration()); // 供应商发票事项 + partInformation.setZeroCostFlag(ifsInventoryPart.getZeroCostFlag()); // 零成本 + partInformation.setCreateBy(inData.getCreateBy()); // 创建人 + if (ifsInventoryPartCost != null) { + partInformation.setConfigurationId(ifsInventoryPartCost.getConfigurationId()); // 配置标识 + partInformation.setEstimatedMaterialCost(UtilsClass.stringToBigDecimal(ifsInventoryPartCost.getEstimatedMaterialCost())); // 估计物料成本 + } + if (ifsInventoryPartPlanning != null) { + partInformation.setPlanningMethod(ifsInventoryPartPlanning.getPlanningMethod()); // 计划方法 + partInformation.setSafetyStock(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getSafetyStock())); // 安全库存 + partInformation.setMinOrderQty(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getMinOrderQty())); // 最小批量 + partInformation.setMaxOrderQty(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getMaxOrderQty())); // 最大批量 + partInformation.setMulOrderQty(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getMulOrderQty())); // 多种批量大小 + partInformation.setSafetyLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getSafetyLeadTime())); // 安全提前期 + partInformation.setShrinkageFac(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getShrinkageFac())); // 报废因子 + partInformation.setStdOrderQty(UtilsClass.stringToBigDecimal(ifsInventoryPartPlanning.getStdOrderSize())); // 标准批量大小 + } + if (ifsInventoryPartManufacturing != null) { + partInformation.setCumLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getCumLeadtime())); // 累计提前期 + partInformation.setBackFlushPart(ifsInventoryPartManufacturing.getBackflushPart()); // 预留/下发来源 + partInformation.setByProdAsSupplyInMrpDb(ifsInventoryPartManufacturing.getByProdAsSupplyInMrpDb()); // 将副产品用作MRP中的供应 + partInformation.setUnprotectedLeadTime(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getUnprotectedLeadTime())); // 未受保护提前期 + partInformation.setIssueType(ifsInventoryPartManufacturing.getIssueType()); // 预留/下发方法 + partInformation.setMrpControlFlagDb(ifsInventoryPartManufacturing.getMrpControlFlagDb()); // MRP控制 + partInformation.setFixedLeadTimeDay(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getFixedLeadtimeDay())); // 按日固定提前期 + partInformation.setOverReporting(ifsInventoryPartManufacturing.getOverReporting()); // 过度报告 + partInformation.setUseTheoreticalDensityDb(ifsInventoryPartManufacturing.getUseTheoriticalDensityDb()); // 使用理论 + partInformation.setVariableLeadTimeDay(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getVariableLeadtimeDay())); // 按天的可变化提前期 + partInformation.setOverReportTolerance(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getOverReportTolerance())); // 报告公差过大 + partInformation.setFixedLeadTimeHour(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getFixedLeadtimeHour())); // 按小时的固定提前期 + partInformation.setDensity(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getDensity())); // 密度 + partInformation.setVariableLeadTimeHour(UtilsClass.stringToBigDecimal(ifsInventoryPartManufacturing.getVariableLeadtimeHour())); // 按小时计算的可变提前期 } + return partInformation; } /** - * 下一个物料编码 - * @param data + * Inventory Part Revision对象转换 + * @param ifsInventoryPartRevision + * @param inData * @return */ - @Override - public String getNextPartNo(PartInformationVo data) { -// Integer no = partInformationMapper.getNextPartNo(data); -// -// // 如果是 null,则默认为 1;否则递增 -// no = (no == null ? 1 : no + 1); -// -// // 使用 String.format 自动填充前导零 -// String formattedNo = String.format("%05d", no); -// -// return data.getIfsPartNo() + formattedNo; - - String nextPartNo = partInformationMapper.getNextPartNo2(data); - return nextPartNo; + private List inventoryPartRevisionConvert(List ifsInventoryPartRevision, PartInformationVo inData) { + List partRevisionList = new ArrayList<>(); + for (PartIfsInventoryRevision ifsInventoryRevision : ifsInventoryPartRevision) { + PartRevisionEntity partRevision = new PartRevisionEntity(); + partRevision.setSite(ifsInventoryRevision.getContract()); + partRevision.setPartNo(ifsInventoryRevision.getPartNo()); + partRevision.setEngChgLevel(Integer.parseInt(ifsInventoryRevision.getEngChgLevel())); + partRevision.setEffPhaseInDate(DateUtils.getStringToDate(ifsInventoryRevision.getEffPhaseInDate(), "yyyy-MM-dd")); + partRevision.setEffPhaseOutDate(DateUtils.getStringToDate(ifsInventoryRevision.getEffPhaseOutDate(), "yyyy-MM-dd")); + partRevision.setRevisionText(ifsInventoryRevision.getRevisionText()); + partRevision.setProductStatus(ifsInventoryRevision.getProductStatus()); + partRevision.setRepairStatus(ifsInventoryRevision.getRepairStatus()); + partRevision.setEngRevision(ifsInventoryRevision.getEngRevision()); + partRevision.setCreateBy(inData.getCreateBy()); + partRevisionList.add(partRevision); + } + return partRevisionList; } /** - * 判断字符串是否能转为整数 - * @param str + * Inventory Part Location对象转换 + * @param ifsInventoryPartLocation + * @param inData * @return */ - public static boolean isNumeric(String str) { - try { - Integer.parseInt(str); - return true; - } catch (NumberFormatException e) { - return false; + private List inventoryPartLocationConvert(List ifsInventoryPartLocation, PartInformationVo inData) { + List partLocationList = new ArrayList<>(); + for (PartIfsInventoryLocation ifsInventoryLocation : ifsInventoryPartLocation) { + LocationInformationVo partLocation = new LocationInformationVo(); + partLocation.setSite(ifsInventoryLocation.getContract()); + partLocation.setPartNo(ifsInventoryLocation.getPartNo()); + partLocation.setLocationId(ifsInventoryLocation.getLocationNo()); + partLocationList.add(partLocation); } + return partLocationList; } - @Override - public List queryPart(PartInformationVo data) { - return baseMapper.queryPart(data); + /** + * Inventory Part 属性对象转换 + * @param ifsInventoryPartItem + * @param inData + * @return + */ + private List inventoryPartItemConvert(List ifsInventoryPartItem, PartInformationVo inData) { + List partItemList = new ArrayList<>(); + int count = 1; + for (PartIfsInventoryProperty ifsInventoryItem : ifsInventoryPartItem) { + PartSubPropertiesValueData partItem = new PartSubPropertiesValueData(); + partItem.setSite(ifsInventoryItem.getContract()); + partItem.setPartNo(ifsInventoryItem.getPartNo()); + partItem.setCodeNo(ifsInventoryItem.getEngAttribute()); + partItem.setSubCodeSeqNo(Double.valueOf("1")); + partItem.setItemNo((double) count++); + partItem.setPropertiesItemNo(ifsInventoryItem.getCharacteristicCode()); + partItem.setTextValue(ifsInventoryItem.getAttrValueAlpha()); + partItem.setNumValue(Double.valueOf(ifsInventoryItem.getAttrValueNumeric())); + partItem.setRecordType("IP"); + partItemList.add(partItem); + } + return partItemList; } /** - * 项目物料Excel导入 - * @param file - * @param data + * Routing Header对象转换 + * @param ifsRoutingHeaders + * @param inData + * @return */ - @Override - @Transactional - public void uploadProjectPartExcel(MultipartFile file, GetParamInData data) { - try{ - // 转流 - InputStream is = file.getInputStream(); - // 读取工作簿 - XSSFWorkbook workbook = new XSSFWorkbook(is); - // 读取工作表 - XSSFSheet sheet = workbook.getSheetAt(0); - // 获取行数 - int rows = sheet.getPhysicalNumberOfRows(); - // 声明对象 - PartInformationVo task = null; - // 遍历每一行(从第二行开始) - for (int j = 1; j < rows; j++) { - // 实例化对象 - task = new PartInformationVo(); - //获得该行 - XSSFRow row = sheet.getRow(j); - // 为对象赋值 - task.setSite(data.getOrderRef1()); // site - task.setProjectId(data.getOrderRef2()); // 项目编码 - task.setCustomerNo(data.getOrderRef3()); // 客户编码 - String no = transNoControlService.transNo(data.getOrderRef1(), "project_part_no"); - if (no == null) { - throw new RuntimeException("请维护编码生成规则(TransNoControl)!"); - } - task.setPartNo(no + "A01"); // 物料编码 - task.setBuNo(row.getCell(0).getStringCellValue()); // BU - task.setPartDesc(row.getCell(1).getStringCellValue()); // 物料描述 - task.setCustomerPartNo(row.getCell(2).getStringCellValue()); // 客户料号 - task.setPartType(row.getCell(3).getStringCellValue()); // 零件类型 - task.setProductGroupId4(row.getCell(4).getStringCellValue()); // 计划人 - task.setUmId(row.getCell(5).getStringCellValue()); // 计量单位 - if (row.getCell(6) == null) { // 属性模板 - task.setCodeNo(""); - } else { - task.setCodeNo(row.getCell(6).getStringCellValue()); - } - task.setUomForWeightNet("kg"); - task.setUomForVolumeNet("m3"); - task.setActive("Y"); - task.setLotTrackingCode("Order Based"); - task.setCreateBy(data.getCreateBy()); - task.setAssetClass("S"); - task.setAbcClass("C"); - task.setFrequencyClass("Very Slow Mover"); - task.setLifecycleStage("Development"); - task.setStatus("N"); - task.setPartStatus("A"); - task.setConfigurationId("*"); - task.setInventoryValuationMethod("Standard Cost"); - task.setInventoryPartCostLevel("Cost Per Part"); - task.setInvoiceConsideration("Ignore Invoice Price"); - task.setZeroCostFlag("Zero Cost Forbidden"); - task.setBackFlushPart("All Locations"); - task.setIssueType("Reserve And Backflush"); - task.setMrpControlFlagDb("Y"); - task.setOverReporting("Allowed"); - - // 调用新增方法 - partInformationSave2(task); - } - } catch (Exception e) { - throw new RuntimeException("导入失败:"+e.getMessage()); + private List routingHeaderDataConvert(List ifsRoutingHeaders, PartInformationVo inData) { + List headerList = new ArrayList<>(); + for (RoutingIfsHeader header : ifsRoutingHeaders) { + RoutingHeaderVo headerEntity = new RoutingHeaderVo(); + headerEntity.setSite(header.getContract()); + headerEntity.setPartNo(header.getPartNo()); + headerEntity.setRoutingRevision(Integer.parseInt(header.getRoutingRevision())); + headerEntity.setRoutingType(header.getRoutingType()); + headerEntity.setPhaseInDate(DateUtils.getStringToDate(header.getPhaseInDate(), "yyyy-MM-dd")); + headerEntity.setPhaseOutDate(DateUtils.getStringToDate(header.getPhaseOutDate(), "yyyy-MM-dd")); + headerEntity.setNoteText(header.getNoteText()); + headerEntity.setCreateBy(inData.getCreateBy()); + headerEntity.setOfficialFlag("Y"); + headerList.add(headerEntity); } + return headerList; } /** - * 查询文件ID - * @param data + * Routing Detail对象转换 + * @param ifsRoutingDetails + * @param inData * @return */ - @Override - public SysOssEntity queryFileId(SysOssEntity data) { - List list = partInformationMapper.queryFileId(data); - if (list.isEmpty()) { - throw new RuntimeException("未查到该文件ID,请检查数据!"); + private List routingDetailDataConvert(List ifsRoutingDetails, PartInformationVo inData) { + List detailList = new ArrayList<>(); + for (RoutingIfsAlternative detail : ifsRoutingDetails) { + RoutingDetailVo detailEntity = new RoutingDetailVo(); + detailEntity.setSite(detail.getContract()); + detailEntity.setPartNo(detail.getPartNo()); + detailEntity.setRoutingRevision(Integer.parseInt(detail.getRoutingRevision())); + detailEntity.setRoutingType(detail.getRoutingType()); + detailEntity.setAlternativeNo(detail.getAlternativeNo()); + detailEntity.setAlternativeDescription(detail.getAlternativeDesc()); + detailEntity.setStatus(detail.getState()); + detailEntity.setNoteText(detail.getNoteText()); + detailEntity.setCreateBy(inData.getCreateBy()); + detailEntity.setOfficialFlag("Y"); + detailList.add(detailEntity); } - return list.get(0); + return detailList; } /** - * 下载文件 - * @param id - * @param response - * @throws UnsupportedEncodingException + * Routing Item对象转换 + * @param ifsRoutingComponents + * @return */ - @Override - public void downLoadObjectFile(Integer id, HttpServletResponse response) throws UnsupportedEncodingException { - // 处理路径和名称 - List getFileData = partInformationMapper.getFileData(id); - if (getFileData.isEmpty()) { - throw new RuntimeException("该文件不存在,请刷新列表"); - } - File file = new File(getFileData.get(0).getUrl()); - //读取缓存1kb - byte[] buffer = new byte[1024]; - FileInputStream fis = null; - BufferedInputStream bis = null; - FileOutputStream fos = null; - BufferedOutputStream bos = null; - response.setContentType("application/force-download;charset=utf-8"); - response.setHeader("Content-disposition", "attachment; filename=" + new String(getFileData.get(0).getFileName().getBytes("gbk"), "iso8859-1")); - try { - //读取文件 - fis = new FileInputStream(file); - //加缓存 - bis = new BufferedInputStream(fis); - //开始读取 - int i = bis.read(buffer); - //设置输出流 - ServletOutputStream os = response.getOutputStream(); - //开始循环读取 - while (i != -1) { - os.write(buffer, 0, i); - i = bis.read(buffer); - } - fis.close(); - fos.close(); - } catch (Exception e) { - throw new RuntimeException(e.getMessage()); + private List routingItemDataConvert(List ifsRoutingComponents, PartInformationVo inData) { + List componentList = new ArrayList<>(); + for (RoutingIfsItem component : ifsRoutingComponents) { + RoutingComponentVo componentEntity = new RoutingComponentVo(); + componentEntity.setSite(component.getContract()); + componentEntity.setPartNo(component.getPartNo()); + componentEntity.setRoutingRevision(Integer.parseInt(component.getRoutingRevision())); + componentEntity.setRoutingType(component.getRoutingType()); + componentEntity.setAlternativeNo(component.getAlternativeNo()); + componentEntity.setOperationId(Integer.parseInt(component.getOperationId())); + componentEntity.setOperationNo(Integer.parseInt(component.getOperationNo())); + componentEntity.setOperationName(component.getOperationDesc()); + componentEntity.setEfficiencyFactor(UtilsClass.stringToBigDecimal(component.getEfficiencyFactor())); + componentEntity.setMachRunFactor(UtilsClass.stringToBigDecimal(component.getMachRunFactor())); + componentEntity.setMachSetupTime(UtilsClass.stringToBigDecimal(component.getMachSetupTime())); + componentEntity.setRunTimeCode(component.getRunTimeCode()); + componentEntity.setLaborRunFactor(UtilsClass.stringToBigDecimal(component.getLaborRunFactor())); + componentEntity.setLaborSetupTime(UtilsClass.stringToBigDecimal(component.getLaborSetupTime())); + componentEntity.setCrewSize(UtilsClass.stringToInteger(component.getCrewSize())); + componentEntity.setSetupCrewSize(UtilsClass.stringToInteger(component.getSetupCrewSize())); + componentEntity.setOutsideOpItem(component.getOutsideOpItem()); + componentEntity.setMachineNo(component.getMachineNo()); + componentEntity.setWorkCenterNo(component.getWorkCenterNo()); + componentEntity.setLaborClassNo(component.getLaborClassNo()); + componentEntity.setSetupLaborClassNo(component.getSetupLaborClassNo()); + componentEntity.setOverlap(UtilsClass.stringToInteger(component.getOverlap())); + componentEntity.setNoteText(component.getNoteText()); + componentEntity.setIfsRowId(component.getIfsRowId()); + componentEntity.setIfsRowVersion(component.getIfsRowVersion()); + componentEntity.setCreateBy(inData.getCreateBy()); + componentList.add(componentEntity); } + return componentList; } /** - * 获取下一个物料revision + * Routing Tool对象转换 + * @param ifsRoutingTools * @param inData + * @param operationMap * @return */ - @Override - public Map getPartRevisionEngChgLevel(PartRevisionVo inData) { - HashMap map = new HashMap<>(); - // 获取最大的partRevision - List revisionList = partInformationMapper.getMaxPartRevision(inData.getSite(), inData.getPartNo()); - - if (revisionList.isEmpty()) { - map.put("engChgLevel", 1); - map.put("engRevision", 1); - } else { - map.put("engChgLevel", revisionList.get(0).getEngChgLevel() + 1); - map.put("engRevision", revisionList.get(0).getEngChgLevel() + 1); + private List routingToolDataConvert(List ifsRoutingTools, PartInformationVo inData, HashMap operationMap) { + List routingToolList = new ArrayList<>(); + for (RoutingIfsTool ifsTool : ifsRoutingTools) { + RoutingToolEntity routingTool = new RoutingToolEntity(); + routingTool.setSite(ifsTool.getContract()); + routingTool.setPartNo(ifsTool.getPartNo()); + routingTool.setRoutingRevision(Integer.parseInt(ifsTool.getRoutingRevision())); + routingTool.setRoutingType(ifsTool.getRoutingType()); + routingTool.setAlternativeNo(ifsTool.getAlternativeNo()); + routingTool.setOperationId(operationMap.get(Integer.parseInt(ifsTool.getOperationId()))); + routingTool.setToolId(ifsTool.getToolId()); + routingTool.setToolQty(UtilsClass.stringToInteger(ifsTool.getToolQuantity())); + routingTool.setRemark(ifsTool.getNoteText()); + routingTool.setCreateBy(inData.getCreateBy()); + routingTool.setIfsRowId(ifsTool.getIfsRowId()); + routingTool.setIfsRowVersion(ifsTool.getIfsRowVersion()); + routingToolList.add(routingTool); } - return map; + return routingToolList; } /** - * 查询物料的 unitCost 列表 + * Routing Guideline对象转换 + * @param ifsRoutingGuidelines * @param inData + * @param operationMap * @return */ - @Override - public List queryPartUnitCostList(InventoryPartUnitCostSumEntity inData) { - List list = partInformationMapper.queryPartUnitCostList(inData); - return list; + private List routingGuidelineDataConvert(List ifsRoutingGuidelines, PartInformationVo inData, HashMap operationMap) { + List routingGuidelineList = new ArrayList<>(); + for (RoutingIfsGuideLine ifsGuideline : ifsRoutingGuidelines) { + WorkGuidelineEntity routingGuideline = new WorkGuidelineEntity(); + routingGuideline.setSite(ifsGuideline.getContract()); + routingGuideline.setPartNo(ifsGuideline.getPartNo()); + routingGuideline.setRoutingRevision(Integer.parseInt(ifsGuideline.getRoutingRevision())); + routingGuideline.setRoutingType(ifsGuideline.getRoutingType()); + routingGuideline.setAlternativeNo(ifsGuideline.getAlternativeNo()); + routingGuideline.setOperationId(operationMap.get(Integer.parseInt(ifsGuideline.getOperationId()))); + routingGuideline.setGuidelineSeq(UtilsClass.stringToInteger(ifsGuideline.getGuidelineSeq())); + routingGuideline.setGuidelineDesc(ifsGuideline.getGuidelineDesc()); + routingGuideline.setGuidelineText(ifsGuideline.getGuidelineText()); + routingGuideline.setGuidelineType(ifsGuideline.getOperWorkGuideType()); + routingGuideline.setSignOffRequired(ifsGuideline.getSignOffReq()); + routingGuideline.setInspectionSignOffRequired(ifsGuideline.getInspectSignOffReq()); + routingGuideline.setCreateBy(inData.getCreateBy()); + routingGuideline.setIfsRowId(ifsGuideline.getIfsRowId()); + routingGuideline.setIfsRowVersion(ifsGuideline.getIfsRowVersion()); + routingGuidelineList.add(routingGuideline); + } + return routingGuidelineList; } /** - * 同步 unitValue 到PLM + * BOM Header对象转换 + * @param ifsBomHeaders + * @param inData + * @return */ - @Override - @Transactional - public void syncUnitValueToPLM(InventoryPartUnitCostSumVo data) { - // 查出最大的 rowVersion - String rowVersion = partInformationMapper.getMaxUnitValueRowVersion(); - data.setIfsRowVersion(rowVersion); - // 调用接口获得IFS数据 - String getIfsUnitValuesURL = apiUrl + "/base/ifs/getIfsInventoryValues"; - ResponseData getIfsUnitValuesResponse = HttpClientUtil.doPostByRawWithPLM(getIfsUnitValuesURL, data); - if (!"200".equals(getIfsUnitValuesResponse.getCode())) { - throw new RuntimeException("同步Unit Value信息异常:" + getIfsUnitValuesResponse.getMsg()); + private List bomHeaderDataConvert(List ifsBomHeaders, PartInformationVo inData) { + List headerList = new ArrayList<>(); + for (BomIfsHeader header : ifsBomHeaders) { + BomHeaderVo headerEntity = new BomHeaderVo(); + headerEntity.setSite(header.getContract()); + headerEntity.setPartNo(header.getPartNo()); + headerEntity.setEngChgLevel(Integer.parseInt(header.getEngChgLevel())); + headerEntity.setBomType(header.getBomType()); + headerEntity.setEffPhaseInDate(DateUtils.getStringToDate(header.getEffPhaseInDate(), "yyyy-MM-dd")); + headerEntity.setEffPhaseOutDate(DateUtils.getStringToDate(header.getEffPhaseOutDate(), "yyyy-MM-dd")); + headerEntity.setNoteText(header.getNoteText()); + headerEntity.setEngRevision(header.getEngRevision()); + headerEntity.setCreateBy(inData.getCreateBy()); + headerEntity.setOfficialFlag("Y"); + headerList.add(headerEntity); } - String UnitValuesObj = String.valueOf(getIfsUnitValuesResponse.getObj()); - List ifsUnitValues = JSON.parseArray(UnitValuesObj, InventoryPartUnitCostSumEntity.class); - // 查询PLM数据 - String[] arr = data.getSiteCon().replace("(", "").replace(")", "").replace("'", "").split(","); - List plmUnitValues = partInformationMapper.getPLMUnitValues(arr); - - // 转换列表为映射以便于比较 - Map mapListAll = ifsUnitValues.stream() - .collect(Collectors.toMap(InventoryPartUnitCostSumEntity::getKey, Function.identity())); - Map mapList1 = plmUnitValues.stream() - .collect(Collectors.toMap(InventoryPartUnitCostSumEntity::getKey, Function.identity())); - - // 找出需要新增的对象(IFS有而PLM没有的) - Set keysToAdd = new HashSet<>(mapListAll.keySet()); - keysToAdd.removeAll(mapList1.keySet()); - List toAdd = keysToAdd.stream() - .map(mapListAll::get) - .collect(Collectors.toList()); - - // 找出需要更新的对象(ifsRowVersion不同) - Set commonKeys = new HashSet<>(mapListAll.keySet()); - commonKeys.retainAll(mapList1.keySet()); - List toUpdate = commonKeys.stream() - .filter(key -> !mapListAll.get(key).getIfsRowVersion().equals(mapList1.get(key).getIfsRowVersion())) - .map(key -> mapListAll.get(key)) // 选择listAll中的版本进行更新 - .collect(Collectors.toList()); + return headerList; + } - // 新增 - if (!toAdd.isEmpty()) { - // 分批插入 - int batchSize = 100; // 假设每批100条记录 - for (int i = 0; i < toAdd.size(); i += batchSize) { - int end = Math.min(i + batchSize, toAdd.size()); - List subList = toAdd.subList(i, end); - partInformationMapper.syncSaveUnitValue(subList); - } - } - // 修改 - if (!toUpdate.isEmpty()) { - // 分批修改 - int batchSize = 100; // 假设每批100条记录 - for (int i = 0; i < toUpdate.size(); i += batchSize) { - int end = Math.min(i + batchSize, toUpdate.size()); - List subList = toUpdate.subList(i, end); - partInformationMapper.syncUpdateUnitValue(subList); - } + /** + * BOM Detail对象转换 + * @param ifsBomDetails + * @param inData + * @return + */ + private List bomDetailDataConvert(List ifsBomDetails, PartInformationVo inData) { + List detailList = new ArrayList<>(); + for (BomIfsAlternative detail : ifsBomDetails) { + BomDetailVo detailEntity = new BomDetailVo(); + detailEntity.setSite(detail.getContract()); + detailEntity.setPartNo(detail.getPartNo()); + detailEntity.setEngChgLevel(Integer.parseInt(detail.getEngChgLevel())); + detailEntity.setBomType(detail.getBomType()); + detailEntity.setAlternativeNo(detail.getAlternativeNo()); + detailEntity.setAlternativeDescription(detail.getAlternativeDesc()); + detailEntity.setStatus(detail.getState()); + detailEntity.setDetailNoteText(detail.getNoteText()); + detailEntity.setCreateBy(inData.getCreateBy()); + detailEntity.setOfficialFlag("Y"); + detailList.add(detailEntity); } + return detailList; } - @Override - @Transactional - public List getItemListByCodeNo(PartSubPropertiesValueData data) { - List result = partInformationMapper.getItemListByCodeNo(data); - for (int i = 0; i < result.size(); i++) { - if ("Y".equals(result.get(i).getValueChooseFlag())) { - List availableList = partInformationMapper.getAvailableValueList(result.get(i)); - result.get(i).setAvailableValueList(availableList); - } + /** + * BOM Item对象转换 + * @param ifsBomComponents + * @param inData + * @return + */ + private List bomItemDataConvert(List ifsBomComponents, PartInformationVo inData, HashMap operationMap) { + List componentList = new ArrayList<>(); + for (BomIfsItem component : ifsBomComponents) { + BomComponentVo componentEntity = new BomComponentVo(); + componentEntity.setSite(component.getContract()); + componentEntity.setPartNo(component.getPartNo()); + componentEntity.setEngChgLevel(Integer.parseInt(component.getEngChgLevel())); + componentEntity.setBomType(component.getBomType()); + componentEntity.setAlternativeNo(component.getAlternativeNo()); + componentEntity.setComponentPart(component.getComponentPart()); + componentEntity.setPrintUnit(component.getPrintUnit()); + componentEntity.setQtyPerAssembly(UtilsClass.stringToBigDecimal(component.getQtyPerAssembly())); + componentEntity.setComponentScrap(UtilsClass.stringToBigDecimal(component.getComponentScrap())); + componentEntity.setIssueType(component.getIssueType()); + componentEntity.setShrinkageFactor(UtilsClass.stringToBigDecimal(component.getShrinkageFactor())); + componentEntity.setLineItemNo(Integer.parseInt(component.getLineItemNo())); + componentEntity.setOperationNo(Integer.parseInt(component.getOperationNo())); + componentEntity.setIssueToLoc(component.getIssueToLoc()); + componentEntity.setNoteText(component.getNoteText()); + componentEntity.setLineSequence(Integer.parseInt(component.getLineSequence())); + componentEntity.setConsumptionItem(component.getConsumptionItem()); + componentEntity.setCreateBy(inData.getCreateBy()); + componentList.add(componentEntity); } - return result; + return componentList; } /** - * 查属性模板,不包括已存在的 - * @param data + * + * @param ifsBomManufStructCostDistribs + * @param inData * @return */ - @Override - public List getItemExclusionAlreadyExists(PartSubPropertiesValueData data) { - String[] arr = convertToSQLString(data.getItemNos()).replace("(", "").replace(")", "").replace("'", "").split(","); - data.setArr(arr); - List list = partInformationMapper.getItemExclusionAlreadyExists(data); - for (int i = 0; i < list.size(); i++) { - if ("Y".equals(list.get(i).getValueChooseFlag())) { - List availableList = partInformationMapper.getAvailableValueList(list.get(i)); - list.get(i).setAvailableValueList(availableList); - } + private List bomManufStructCostDistribDataConvert(List ifsBomManufStructCostDistribs, PartInformationVo inData) { + List bomManufStructCostDistribVoList = new ArrayList<>(); + for (BomIfsManufStructCostDistrib structCostDistrib : ifsBomManufStructCostDistribs) { + BomManufStructCostDistribVo vo = new BomManufStructCostDistribVo(); + vo.setSite(structCostDistrib.getContract()); + vo.setPartNo(structCostDistrib.getPartNo()); + vo.setEngChgLevel(Integer.parseInt(structCostDistrib.getEngChgLevel())); + vo.setBomType(structCostDistrib.getBomType()); + vo.setAlternativeNo(structCostDistrib.getAlternativeNo()); + vo.setByProdLineItemNo(Integer.parseInt(structCostDistrib.getByProdLineItemNo())); + vo.setComponentLineItemNo(Integer.parseInt(structCostDistrib.getComponentLineItemNo())); + vo.setItemCostDistribution(structCostDistrib.getItemCostDistribution().isEmpty() ? Double.valueOf("0") : Double.valueOf(structCostDistrib.getItemCostDistribution())); + vo.setComponentPartNo(structCostDistrib.getComponentPartNo()); + vo.setByProdPartNo(structCostDistrib.getByProductPartNo()); + vo.setCreateBy(inData.getCreateBy()); + bomManufStructCostDistribVoList.add(vo); } - return list; + return bomManufStructCostDistribVoList; } - }