whycxzp
2022-09-08 bbf3c5b4db8d1510e3cdae429e1d1fe54249c18e
修复
1个文件已修改
49 ■■■■■ 已修改文件
src/main/java/com/whyc/service/ProductService.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductService.java
@@ -330,33 +330,40 @@
                && relatedProduct.getCustomCode().equals(product.getCustomCode())
                )
            ) { //属于是产品升级或基于标准产品定制
                if (latestProduct != null && enabledProduct != null) {
                    List<MaterialProductHistory> mpList;
                    if(customCode.equals("")){ //产品升级
                        mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion());
                    }else{ //基于标准产品定制
                        int standardEnabledVersion = getVersion(parentCode, "").getVersion();
                        mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode,"",standardEnabledVersion);
                    }
                    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) {
                            if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) {
                                //最新版本生效,关联关系版本连着的
                                mphService.updateVersionBatch(mpList);
                            } else {
                                //旧版本生效,关联关系版本不连着
                List<MaterialProductHistory> mpList;
                if (latestProduct != null && enabledProduct != null) { //产品升级
                    mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion());
                }else{ //基于标准产品定制
                    int standardEnabledVersion = getVersion(parentCode, "").getVersion();
                    mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode,"",standardEnabledVersion);
                }
                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) {
                        if ((latestProduct !=null && enabledProduct!=null) && latestProduct.getVersion().intValue() == enabledProduct.getVersion()) {
                            //最新版本生效,关联关系版本连着的
                            mphService.updateVersionBatch(mpList);
                        } else {
                            //关联关系版本不连着,生成新纪录:包含 升级和基于标准产品定制
                            if(customCode.equals("")) {
                                mpList.forEach(mp -> {
                                    mp.setSVersion(nextVersion);
                                    mp.setEVersion(nextVersion);
                                    mp.setCreateTime(date);
                                });
                                mphService.insertBatch(mpList);
                            }else{
                                mpList.forEach(mp -> {
                                    mp.setCustomCode(customCode);
                                    mp.setSVersion(nextVersion);
                                    mp.setEVersion(nextVersion);
                                    mp.setCreateTime(date);
                                });
                            }
                            mphService.insertBatch(mpList);
                        }
                    }
                }