whycxzp
2023-03-13 fcdb42dcfda2adccfd8cf42e16c2d6fa73732f1d
src/main/java/com/whyc/service/ProductService.java
@@ -288,6 +288,51 @@
                    }
                    bomList.add(bom);
                }
                //产生的bom物料列表,查询是否有 相同编码和型号的
                List<Material> existMaterialListWithSameSubCodeAndModel = mService.getSameSubCodeAndModel(bomList);
                List<String> dbCodeModelUnionList = existMaterialListWithSameSubCodeAndModel.stream().map(material -> material.getSubCode() + "/" + (material.getSubModel().contains("-[系统追加-")?material.getSubModel().split("-\\[系统追加-")[0]:material.getSubModel())).collect(Collectors.toList());
                //List<String> dbCodeOriginalModelUnionList = existMaterialListWithSameSubCodeAndModel.stream().map(material -> material.getSubCode() + "/" + material.getSubModel()).collect(Collectors.toList());
                List<String> dbCodeModelCategoryUnionList = existMaterialListWithSameSubCodeAndModel.stream().map(material -> material.getSubCode() + "/" + (material.getSubModel().contains("-[系统追加-")?material.getSubModel().split("-\\[系统追加-")[0]:material.getSubModel())+"/"+material.getCategory()).collect(Collectors.toList());
                List<String> dbCodeOriginalModelCategoryUnionList = existMaterialListWithSameSubCodeAndModel.stream().map(material -> material.getSubCode() + "/" + material.getSubModel()+"/"+material.getCategory()).collect(Collectors.toList());
                bomList.forEach(bom->{
                    //同编码和型号
                    String codeModelUnionStr = bom.getSubCode() + "/" + bom.getSubModel();
                    if(dbCodeModelUnionList.contains(codeModelUnionStr)){
                        String codeModelCategoryUnionStr = bom.getSubCode() + "/" + bom.getSubModel() + "/" + bom.getCategory();
                        if(dbCodeModelCategoryUnionList.contains(codeModelCategoryUnionStr)){
                            //相同类别,完全相同. 型号需要与数据库内记录的处理保持一致
                            if(!dbCodeOriginalModelCategoryUnionList.contains(codeModelCategoryUnionStr)){
                                bom.setSubModel(bom.getSubModel()+"-[系统追加-"+bom.getCategory()+"]");
                            }
                        }else{ //不同类别
                            //重写型号
                            bom.setSubModel(bom.getSubModel()+"-[系统追加-"+bom.getCategory()+"]");
                        }
                    }
                });
                //上传的bom物料列表自己对比,校验是否 [编号/型号相同]及[编号/型号,类别相同]
                List<ProductBom> reviewedBomList = new LinkedList<>();
                for (int i1 = 0; i1 < bomList.size(); i1++) {
                    ProductBom bom = bomList.get(i1);
                    for (int j = 0; j < reviewedBomList.size(); j++) {
                        ProductBom reviewedBom = reviewedBomList.get(j);
                        if((reviewedBom.getSubCode()+"/"+reviewedBom.getSubModel()).equals(bom.getSubCode()+"/"+bom.getSubModel())){
                            //已经遍历的记录中,与当前正在遍历的记录 编号/型号相同
                            if((reviewedBom.getSubCode()+"/"+reviewedBom.getSubModel()+"/"+reviewedBom.getCategory())
                                    .equals(bom.getSubCode()+"/"+bom.getSubModel()+"/"+bom.getCategory())){
                                //类别相同
                                return response.set(1,false,"解析失败,原因:存在两个完全相同的物料-子件编码"+bom.getSubCode()+"/子件型号"+bom.getSubModel()+"/类别"+reviewedBom.getCategory());
                            }else{
                                //类别不同,型号内系统默认追加类别
                                bomList.get(j).setSubModel(reviewedBom.getSubModel()+"-[系统追加-"+reviewedBom.getCategory()+"]");
                                bomList.get(i1).setSubModel(bom.getSubModel()+"-[系统追加-"+bom.getCategory()+"]");
                            }
                        }
                    }
                    //遍历一个,添加一个到reviewedBomList
                    reviewedBomList.add(bom);
                }
                product.setBomList(bomList);
            }
        }
@@ -311,6 +356,13 @@
        return list;
    }
    /**
     * 这个接口是进行产品新增,产品bom新增的接口.
     * 新增方式有很多,有直接从zip解析新增产品,也可以基于原有产品复制进行定制等.需要注意兼容!
     * @param product 产品新增,bom新增,产品版本更新
     * @return
     * @throws IOException
     */
    @Transactional
    public Response add(Product product) throws IOException {
        String parentCode = product.getParentCode();
@@ -318,7 +370,6 @@
        String parentModel = product.getParentModel();
        List<ProductBom> bomList = product.getBomList();
        String zipFilePath = product.getFileUrl();
        String fileUrl = zipFilePath.substring(0,zipFilePath.lastIndexOf(File.separator));
        Date date = new Date();
        boolean isCopyCustom = false;
        Product relatedProduct = null;
@@ -330,6 +381,11 @@
            if(product.getId() != null){ //关联关系从产品id继承
                relatedProduct = getById(product.getId());
            }
        }
        //不是基于产品复制,则必定存在zip包,必然存在路径
        String fileUrl = null;
        if(!isCopyCustom) {
            fileUrl = zipFilePath.substring(0, zipFilePath.lastIndexOf(File.separator));
        }
        //查询新增产品最新的版本号
        ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode);
@@ -613,6 +669,7 @@
                    material.setPictureUrl(bom.getPictureUrl());
                    // TODO 是否要更新同物料编码的老物料状态为0?
                    material.setStatus(1);
                    material.setCategory(bom.getCategory());
                    material.setSubCode(bom.getSubCode());
                    material.setSubModel(bom.getSubModel());
                    material.setSubName(bom.getSubName());
@@ -657,7 +714,20 @@
            // product的主键沿用对应product_history的
            //根据编码和型号确定物料id并对应quantity,存入数据库.
            //List<Material> bomMaterialList = mService.getListByCodeAndModelList2(bomList);
            List<ProductBom> bomMaterialList = pbService.getListByCodeAndModelList2(bomList);
            //List<ProductBom> bomMaterialList = pbService.getListByCodeAndModelList2(bomList);
            List<Material> existMaterialListWithSameSubCodeAndModel = mService.getSameSubCodeAndModel(bomList);
            List<ProductBom> bomMaterialList;
            bomList.forEach(bom->{
                String codeModelUnionStr = bom.getSubCode() + "/" + bom.getSubModel();
                for (int i = 0; i < existMaterialListWithSameSubCodeAndModel.size(); i++) {
                    Material materialExists = existMaterialListWithSameSubCodeAndModel.get(i);
                    if(codeModelUnionStr.equals(materialExists.getSubCode() + "/" + materialExists.getSubModel())){
                        bom.setId(materialExists.getId());
                        break;
                    }
                }
            });
            bomMaterialList = bomList;
            // -> product_history
            ProductHistory productHistory = new ProductHistory();
            productHistory.setParentCode(product.getParentCode());