| | |
| | | String fileUrl = product.getFileUrl(); |
| | | Date date = new Date(); |
| | | boolean isCopyCustom = false; |
| | | Product relatedProduct = null; |
| | | //判断是否为依据产品复制定制的产品 |
| | | if(bomList == null){ |
| | | bomList = pbService.getBomByProductId(product.getId()); |
| | | isCopyCustom = true; |
| | | }else{ |
| | | if(product.getId() != null){ //关联关系从产品id继承 |
| | | relatedProduct = getById(product.getId()); |
| | | } |
| | | } |
| | | //查询产品最新的版本号 |
| | | //查询新增产品最新的版本号 |
| | | ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode); |
| | | ProductHistory enabledProduct = phService.getEnabledByParentCodeAndCustomCode(parentCode, customCode); |
| | | int currentVersion = 0; |
| | |
| | | //查询产品对应的关联关系 |
| | | copyCustomProduct = getById(product.getId()); |
| | | List<MaterialProductHistory> relatedList = mphService.getListByParentCodeAndCustomCodeAndVersion(copyCustomProduct.getParentCode(), copyCustomProduct.getCustomCode(), copyCustomProduct.getVersion()); |
| | | relatedList.forEach(related->related.setCustomCode(product.getCustomCode())); |
| | | mphService.insertBatch(relatedList); |
| | | relatedList.forEach(related->{ |
| | | related.setCustomCode(product.getCustomCode()); |
| | | related.setSVersion(nextVersion); |
| | | related.setEVersion(nextVersion); |
| | | related.setCreateTime(date); |
| | | }); |
| | | if(relatedList.size()!=0){ |
| | | mphService.insertBatch(relatedList); |
| | | } |
| | | }else { |
| | | if (latestProduct != null && enabledProduct != null) { |
| | | List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion()); |
| | | if(mpList.size()!=0) { //存在关联关系 |
| | | if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) { |
| | | //最新版本生效,关联关系版本连着的 |
| | | mphService.updateVersionBatch(mpList); |
| | | } else { |
| | | //旧版本生效,关联关系版本不连着 |
| | | if(relatedProduct == null |
| | | || (relatedProduct.getParentCode().equals(product.getParentCode()) |
| | | && relatedProduct.getCustomCode().equals(product.getCustomCode()) |
| | | ) |
| | | ) { //属于是产品升级 |
| | | if (latestProduct != null && enabledProduct != null) { |
| | | List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion()); |
| | | if (mpList.size() != 0) { //存在关联关系 |
| | | //当前的产品bom明细包含 继承的产品子件物料,继承关系保留 |
| | | //设置mpList关联的物料详细信息 |
| | | mpList = mphService.getListWithMaterialInfo(mpList); |
| | | List<String> newBomMaterialStrList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList()); |
| | | mpList = mpList.stream().filter(mp -> newBomMaterialStrList.contains(mp.getSubMaterial().getSubCode() + "/" + mp.getSubMaterial().getSubModel())).collect(Collectors.toList()); |
| | | if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) { |
| | | //最新版本生效,关联关系版本连着的 |
| | | mphService.updateVersionBatch(mpList); |
| | | } else { |
| | | //旧版本生效,关联关系版本不连着 |
| | | mpList.forEach(mp -> { |
| | | mp.setSVersion(nextVersion); |
| | | mp.setEVersion(nextVersion); |
| | | }); |
| | | mphService.insertBatch(mpList); |
| | | } |
| | | } |
| | | } |
| | | }else{ //属于不同产品继承关联关系 |
| | | List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(relatedProduct.getParentCode(), relatedProduct.getCustomCode(), relatedProduct.getVersion()); |
| | | if(mpList.size()!=0) { |
| | | //当前的产品bom明细包含 继承的产品子件物料,保留 |
| | | //设置mpList关联的物料详细信息 |
| | | mpList = mphService.getListWithMaterialInfo(mpList); |
| | | List<String> newBomMaterialStrList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList()); |
| | | mpList = mpList.stream().filter(mp -> newBomMaterialStrList.contains(mp.getSubMaterial().getSubCode() + "/" + mp.getSubMaterial().getSubModel())).collect(Collectors.toList()); |
| | | if(mpList.size()!=0) { |
| | | mpList.forEach(mp -> { |
| | | mp.setParentCode(parentCode); |
| | | mp.setCustomCode(customCode); |
| | | mp.setSVersion(nextVersion); |
| | | mp.setEVersion(nextVersion); |
| | | mp.setCreateTime(date); |
| | | }); |
| | | mphService.insertBatch(mpList); |
| | | } |