From 50dc46df91825d588097535534a0e70a8a8c959e Mon Sep 17 00:00:00 2001
From: whycxzp <perryhsu@163.com>
Date: 星期二, 06 九月 2022 15:34:15 +0800
Subject: [PATCH] 产品bom关联关系更新,修复

---
 src/main/java/com/whyc/service/ProductService.java |  441 +++++++++++++++++++++++++++++++-----------------------
 1 files changed, 254 insertions(+), 187 deletions(-)

diff --git a/src/main/java/com/whyc/service/ProductService.java b/src/main/java/com/whyc/service/ProductService.java
index a3382ca..96d9ea6 100644
--- a/src/main/java/com/whyc/service/ProductService.java
+++ b/src/main/java/com/whyc/service/ProductService.java
@@ -280,13 +280,19 @@
         return list;
     }
 
-    public Response add(Product product) {
+    public Response add(Product product) throws IOException {
         String parentCode = product.getParentCode();
         String customCode = product.getCustomCode();
         String parentModel = product.getParentModel();
         List<ProductBom> bomList = product.getBomList();
         String fileUrl = product.getFileUrl();
         Date date = new Date();
+        boolean isCopyCustom = false;
+        //鍒ゆ柇鏄惁涓轰緷鎹骇鍝佸鍒跺畾鍒剁殑浜у搧
+        if(bomList == null){
+            bomList = pbService.getBomByProductId(product.getId());
+            isCopyCustom = true;
+        }
         //鏌ヨ浜у搧鏈�鏂扮殑鐗堟湰鍙�
         ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode);
         ProductHistory enabledProduct = phService.getEnabledByParentCodeAndCustomCode(parentCode, customCode);
@@ -297,221 +303,282 @@
         Integer nextVersion = currentVersion + 1;
         //浜у搧鐗╂枡鍏崇郴杩佺Щ
         //鏌ヨ鐢熸晥鐗堟湰鐨勫叧鑱斿叧绯�
-        if(latestProduct!=null &&enabledProduct!=null) {
-            List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion());
-            if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) {
-                //鏈�鏂扮増鏈敓鏁�,鍏宠仈鍏崇郴鐗堟湰杩炵潃鐨�
-                mphService.updateVersionBatch(mpList);
-            } else {
-                //鏃х増鏈敓鏁�,鍏宠仈鍏崇郴鐗堟湰涓嶈繛鐫�
-                mpList.forEach(mp -> {
-                    mp.setSVersion(nextVersion);
-                    mp.setEVersion(nextVersion);
-                });
-                mphService.insertBatch(mpList);
+        Product copyCustomProduct = null;
+        if(isCopyCustom){
+            //鏌ヨ浜у搧瀵瑰簲鐨勫叧鑱斿叧绯�
+            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);
+        }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 {
+                        //鏃х増鏈敓鏁�,鍏宠仈鍏崇郴鐗堟湰涓嶈繛鐫�
+                        mpList.forEach(mp -> {
+                            mp.setSVersion(nextVersion);
+                            mp.setEVersion(nextVersion);
+                        });
+                        mphService.insertBatch(mpList);
+                    }
+                }
             }
         }
 
         //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞
         //鏂囦欢杞Щ,鏈窡瀛愪欢鎸傞挬鐨勬墍鏈夊浘绾稿浘鐗囪浆绉诲埌浜у搧鐗堟湰涓�:doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/
         //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/
-        File file = new File(fileUrl);
-        List<String> fileUrlList = new LinkedList<>();
-        List<String> dwgUrlList = null;
-        List<String> picUrlList = null;
-        //瀛樹簬鐗╂枡涓�,bom鍐呮湁瀵瑰簲
-        List<String> materialUrlList = new LinkedList<>();
-        //瀛樹簬浜у搧涓�,bom鍐呮病瀵瑰簲
-        List<String> productUrlList = new LinkedList<>();
+        if(isCopyCustom){
+            //product涓嬬殑鍥剧焊澶嶅埗鍒版柊鐨勮矾寰�
+            String rootFile = CommonUtil.getRootFile();
+            String customStr = copyCustomProduct.getCustomCode().equals("")?"standard":copyCustomProduct.getCustomCode();
+            String fromDir = rootFile + "product" + File.separator + product.getParentModel() + File.separator + customStr + File.separator + copyCustomProduct.getVersion();
+            String toDir = rootFile + "product" + File.separator + product.getParentModel() + File.separator + product.getCustomCode() + File.separator + 1;
+            org.aspectj.util.FileUtil.copyDir(new File(fromDir),new File(toDir));
+            //product_history/product/bom/bom_history
+            // -> his
+            ProductHistory his = new ProductHistory();
+            his.setParentCode(product.getParentCode());
+            his.setParentName(product.getParentName());
+            his.setParentModel(product.getParentModel());
+            his.setCustomCode(product.getCustomCode());
+            his.setCreateTime(date);
+            his.setVersionTime(product.getVersionTime());
+            his.setVersion(1);
+            his.setSubVersionMax(1);
+            his.setEnabled(1);
+            phService.insertAndUpdateEnabled(his);
+            //phService.insert(his);
+            // -> product
+            product.setId(his.getId());
+            product.setCreateTime(date);
+            product.setVersion(1);
+            //insert(product);
+            deleteAndInsert(product);
+            // -> bom
+            bomList.forEach(bom-> {
+                bom.setProductId(product.getId());
+                bom.setSubVersion(1);
+            });
+            pbService.insertBatch(bomList);
+            // -> bom_his
+            List<ProductBomHistory> bomHistoryList = new LinkedList<>();
+            bomList.forEach(bom->{
+                ProductBomHistory bomHistory = new ProductBomHistory();
+                bomHistory.setProductId(his.getId());
+                bomHistory.setMaterialId(bom.getMaterialId());
+                bomHistory.setQuantity(bom.getQuantity());
+                bomHistory.setSubSVersion(1);
+                bomHistory.setSubEVersion(1);
+                bomHistoryList.add(bomHistory);
+            });
+            pbhService.insertBatch(bomHistoryList);
+        }else {
+            File file = new File(fileUrl);
+            List<String> fileUrlList = new LinkedList<>();
+            List<String> dwgUrlList = null;
+            List<String> picUrlList = null;
+            //瀛樹簬鐗╂枡涓�,bom鍐呮湁瀵瑰簲
+            List<String> materialUrlList = new LinkedList<>();
+            //瀛樹簬浜у搧涓�,bom鍐呮病瀵瑰簲
+            List<String> productUrlList = new LinkedList<>();
 
-        //List<Material> materialDwgUrlNameList = new LinkedList<>();
+            //List<Material> materialDwgUrlNameList = new LinkedList<>();
 
-        fileUrlList = FileUtil.getStaticFilePath(file,fileUrlList);
-        //鍥剧焊dwg 瀛愪欢/浜у搧
-        dwgUrlList = fileUrlList.stream().filter(url->url.contains(".dwg")).collect(Collectors.toList());
-        picUrlList = fileUrlList.stream().filter(url->url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList());
+            fileUrlList = FileUtil.getStaticFilePath(file, fileUrlList);
+            //鍥剧焊dwg 瀛愪欢/浜у搧
+            dwgUrlList = fileUrlList.stream().filter(url -> url.contains(".dwg")).collect(Collectors.toList());
+            picUrlList = fileUrlList.stream().filter(url -> url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList());
 
-        dwgUrlList.forEach(dwgUrl->{
-            boolean existFlag = false;
-            for (ProductBom bom :bomList){
-                String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4);
-                String fileFullName = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1);
-                if(bom.getSubModel().toUpperCase().equals(filename.toUpperCase())){
-                    materialUrlList.add(dwgUrl);
-                    existFlag = true;
+            List<ProductBom> finalBomList = bomList;
+            dwgUrlList.forEach(dwgUrl -> {
+                boolean existFlag = false;
+                for (ProductBom bom : finalBomList) {
+                    String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4);
+                    String fileFullName = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1);
+                    if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase())) {
+                        materialUrlList.add(dwgUrl);
+                        existFlag = true;
 
 
-                    bom.setDwgUrl("doc_file" + File.separator + "material"
-                            + File.separator + fileFullName);
-                    break;
+                        bom.setDwgUrl("doc_file" + File.separator + "material"
+                                + File.separator + fileFullName);
+                        break;
+                    }
                 }
-            }
-            if(!existFlag) {
-                productUrlList.add(dwgUrl);
-            }
-        });
-
-        //涓�瀹氭槸鏈夊搴旂墿鏂欑殑,浠巄om鍐呭墺绂荤殑
-        picUrlList.forEach(picUrl->{
-            for (ProductBom bom :bomList){
-                String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1,picUrl.lastIndexOf("."));
-                String fileFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
-                if(bom.getSubModel().toUpperCase().equals(filename.toUpperCase())){
-                    bom.setPictureUrl("doc_file" + File.separator + "material"
-                            + File.separator + fileFullName);
-                    break;
+                if (!existFlag) {
+                    productUrlList.add(dwgUrl);
                 }
+            });
+
+            //涓�瀹氭槸鏈夊搴旂墿鏂欑殑,浠巄om鍐呭墺绂荤殑
+            picUrlList.forEach(picUrl -> {
+                for (ProductBom bom : finalBomList) {
+                    String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.lastIndexOf("."));
+                    String fileFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
+                    if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase())) {
+                        bom.setPictureUrl("doc_file" + File.separator + "material"
+                                + File.separator + fileFullName);
+                        break;
+                    }
+                }
+            });
+
+            //杞Щ璺緞
+            String projectDir = CommonUtil.getProjectDir();
+            //doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/
+            //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/
+            String customCodeString = null;
+            if (customCode != null && !customCode.equals("")) {
+                customCodeString = customCode;
+            } else {
+                customCodeString = "standard";
             }
-        });
-
-        //杞Щ璺緞
-        String projectDir = CommonUtil.getProjectDir();
-        //doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/
-        //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/
-        String customCodeString = null;
-        if(customCode!=null && !customCode.equals("")) {
-            customCodeString = customCode;
-        }else{
-            customCodeString = "standard";
-        }
-        String productDir = projectDir + File.separator + "doc_file" + File.separator + "product" + File.separator + parentModel
-                + File.separator + customCodeString + File.separator +nextVersion;
-        String materialDir = projectDir + File.separator + "doc_file" + File.separator + "material";
-        File productDirFile = new File(productDir);
-        File materialFile = new File(materialDir);
-        if(!productDirFile.exists()){
-            productDirFile.mkdirs();
-        }
-        if(!materialFile.exists()){
-            materialFile.mkdirs();
-        }
-        productUrlList.forEach(productUrl->{
-            String dwgName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1, productUrl.length() - 4);
-
-            try {
-                FileCopyUtils.copy(new File(productUrl),new File(productDir+File.separator+dwgName+".dwg"));
-            } catch (IOException e) {
-                e.printStackTrace();
+            String productDir = projectDir + File.separator + "doc_file" + File.separator + "product" + File.separator + parentModel
+                    + File.separator + customCodeString + File.separator + nextVersion;
+            String materialDir = projectDir + File.separator + "doc_file" + File.separator + "material";
+            File productDirFile = new File(productDir);
+            File materialFile = new File(materialDir);
+            if (!productDirFile.exists()) {
+                productDirFile.mkdirs();
             }
-        });
-
-        materialUrlList.forEach(materialUrl->{
-            String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4);
-            try {
-                FileCopyUtils.copy(new File(materialUrl),new File(materialDir+File.separator+dwgName+".dwg"));
-            } catch (IOException e) {
-                e.printStackTrace();
+            if (!materialFile.exists()) {
+                materialFile.mkdirs();
             }
-        });
+            productUrlList.forEach(productUrl -> {
+                String dwgName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1, productUrl.length() - 4);
 
-        picUrlList.forEach(picUrl->{
-            String picFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
-            try {
-                FileCopyUtils.copy(new File(picUrl),new File(materialDir+File.separator+picFullName));
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        });
+                try {
+                    FileCopyUtils.copy(new File(productUrl), new File(productDir + File.separator + dwgName + ".dwg"));
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            });
 
-        //鐗╂枡琛ㄤ腑涓嶅瓨鍦ㄧ殑(渚濇嵁:鐗╂枡缂栫爜+鐗╂枡鍨嬪彿),鍒欐坊鍔犲埌鐗╂枡琛ㄤ腑鍘�(鍖呭惈product杩欎釜鐗╂枡)
-        List<Material> materialExistList = mService.getListByCodeAndModelList2(bomList);
-        List<String> subCodeList = materialExistList.stream().map(Material::getSubCode).collect(Collectors.toList());
-        List<Material> materialList = new LinkedList<>();
-        bomList.forEach(bom->{
-            if(!subCodeList.contains(bom.getSubCode())){
+            materialUrlList.forEach(materialUrl -> {
+                String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4);
+                try {
+                    FileCopyUtils.copy(new File(materialUrl), new File(materialDir + File.separator + dwgName + ".dwg"));
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            });
+
+            picUrlList.forEach(picUrl -> {
+                String picFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
+                try {
+                    FileCopyUtils.copy(new File(picUrl), new File(materialDir + File.separator + picFullName));
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            });
+
+            //鐗╂枡琛ㄤ腑涓嶅瓨鍦ㄧ殑(渚濇嵁:鐗╂枡缂栫爜+鐗╂枡鍨嬪彿),鍒欐坊鍔犲埌鐗╂枡琛ㄤ腑鍘�(鍖呭惈product杩欎釜鐗╂枡)
+            List<Material> materialExistList = mService.getListByCodeAndModelList2(bomList);
+            List<String> subCodeList = materialExistList.stream().map(Material::getSubCode).collect(Collectors.toList());
+            List<Material> materialList = new LinkedList<>();
+            bomList.forEach(bom -> {
+                if (!subCodeList.contains(bom.getSubCode())) {
+                    Material material = new Material();
+                    material.setCategory(bom.getCategory());
+                    material.setCreateDate(bom.getCreateDate());
+                    material.setDwgUrl(bom.getDwgUrl());
+                    material.setFileUrl(bom.getFileUrl());
+                    material.setMaterial(bom.getMaterial());
+                    material.setNotes(bom.getNotes());
+                    material.setPictureUrl(bom.getPictureUrl());
+                    material.setProducer(bom.getProducer());
+                    // TODO 鏄惁瑕佹洿鏂板悓鐗╂枡缂栫爜鐨勮�佺墿鏂欑姸鎬佷负0?
+                    material.setStatus(1);
+                    material.setSubCode(bom.getSubCode());
+                    material.setSubModel(bom.getSubModel());
+                    material.setSubName(bom.getSubName());
+                    material.setSurfaceDetail(bom.getSurfaceDetail());
+                    material.setThickness(bom.getThickness());
+                    material.setType(bom.getType());
+                    material.setUnit(bom.getUnit());
+
+                    materialList.add(material);
+                }
+            });
+            //姣嶆枡鏄惁瀛樺湪
+            Material materialDB = mService.getByCodeAndModel(product.getParentCode(), product.getParentModel());
+            if (materialDB == null) {
                 Material material = new Material();
-                material.setCategory(bom.getCategory());
-                material.setCreateDate(bom.getCreateDate());
-                material.setDwgUrl(bom.getDwgUrl());
-                material.setFileUrl(bom.getFileUrl());
-                material.setMaterial(bom.getMaterial());
-                material.setNotes(bom.getNotes());
-                material.setPictureUrl(bom.getPictureUrl());
-                material.setProducer(bom.getProducer());
-                // TODO 鏄惁瑕佹洿鏂板悓鐗╂枡缂栫爜鐨勮�佺墿鏂欑姸鎬佷负0?
-                material.setStatus(1);
-                material.setSubCode(bom.getSubCode());
-                material.setSubModel(bom.getSubModel());
-                material.setSubName(bom.getSubName());
-                material.setSurfaceDetail(bom.getSurfaceDetail());
-                material.setThickness(bom.getThickness());
-                material.setType(bom.getType());
-                material.setUnit(bom.getUnit());
+                material.setSubCode(product.getParentCode());
+                material.setSubName(product.getParentName());
+                material.setSubModel(product.getParentModel());
 
                 materialList.add(material);
             }
-        });
-        //姣嶆枡鏄惁瀛樺湪
-        Material materialDB = mService.getByCodeAndModel(product.getParentCode(),product.getParentModel());
-        if(materialDB==null) {
-            Material material = new Material();
-            material.setSubCode(product.getParentCode());
-            material.setSubName(product.getParentName());
-            material.setSubModel(product.getParentModel());
+            mService.insertBatch(materialList);
 
-            materialList.add(material);
+            //鏇存柊product_history/product_bom_history/product/product_bom,
+            // product鐨勪富閿部鐢ㄥ搴攑roduct_history鐨�
+            //鏍规嵁缂栫爜鍜屽瀷鍙风‘瀹氱墿鏂檌d骞跺搴攓uantity,瀛樺叆鏁版嵁搴�.
+            //List<Material> bomMaterialList = mService.getListByCodeAndModelList2(bomList);
+            List<ProductBom> bomMaterialList = pbService.getListByCodeAndModelList2(bomList);
+            // -> product_history
+            ProductHistory productHistory = new ProductHistory();
+            productHistory.setParentCode(product.getParentCode());
+            productHistory.setParentName(product.getParentName());
+            productHistory.setParentModel(product.getParentModel());
+            productHistory.setNotes(product.getNotes());
+            productHistory.setCustomCode(product.getCustomCode());
+            productHistory.setCreateTime(date);
+            productHistory.setVersionTime(product.getVersionTime());
+            productHistory.setVersion(nextVersion);
+            //鐗堟湰鏂板,鍒濆bom瀛愪欢鐗堟湰涓�1
+            productHistory.setSubVersionMax(1);
+            productHistory.setEnabled(1);
+            phService.insertAndUpdateEnabled(productHistory);
+            // -> product
+            product.setId(productHistory.getId());
+            product.setCreateTime(date);
+            product.setVersion(nextVersion);
+            deleteAndInsert(product);
+            // -> product_bom
+            List<ProductBom> productBomList = new LinkedList<>();
+            bomMaterialList.forEach(bomMaterial -> {
+                ProductBom bom = new ProductBom();
+                bom.setProductId(product.getId());
+                bom.setMaterialId(bomMaterial.getId());
+                bom.setQuantity(bomMaterial.getQuantity());
+                bom.setSubVersion(1);
+                bom.setCreateDate(date);
+
+                productBomList.add(bom);
+            });
+            pbService.insertBatch(productBomList);
+            // -> product_bom_history
+            List<ProductBomHistory> bomHistoryList = new LinkedList<>();
+            bomMaterialList.forEach(bomMaterial -> {
+                ProductBomHistory bomHistory = new ProductBomHistory();
+                bomHistory.setProductId(productHistory.getId());
+                bomHistory.setMaterialId(bomMaterial.getId());
+                bomHistory.setQuantity(bomMaterial.getQuantity());
+                bomHistory.setSubSVersion(1);
+                bomHistory.setSubEVersion(1);
+                bomHistory.setCreateDate(date);
+
+                bomHistoryList.add(bomHistory);
+            });
+            pbhService.insertBatch(bomHistoryList);
+
         }
-        mService.insertBatch(materialList);
-
-        //鏇存柊product_history/product_bom_history/product/product_bom,
-        // product鐨勪富閿部鐢ㄥ搴攑roduct_history鐨�
-        //鏍规嵁缂栫爜鍜屽瀷鍙风‘瀹氱墿鏂檌d骞跺搴攓uantity,瀛樺叆鏁版嵁搴�.
-        //List<Material> bomMaterialList = mService.getListByCodeAndModelList2(bomList);
-        List<ProductBom> bomMaterialList = pbService.getListByCodeAndModelList2(bomList);
-        // -> product_history
-        ProductHistory productHistory = new ProductHistory();
-        productHistory.setParentCode(product.getParentCode());
-        productHistory.setParentName(product.getParentName());
-        productHistory.setParentModel(product.getParentModel());
-        productHistory.setNotes(product.getNotes());
-        productHistory.setCustomCode(product.getCustomCode());
-        productHistory.setCreateTime(date);
-        productHistory.setVersionTime(product.getVersionTime());
-        productHistory.setVersion(nextVersion);
-        //鐗堟湰鏂板,鍒濆bom瀛愪欢鐗堟湰涓�1
-        productHistory.setSubVersionMax(1);
-        productHistory.setEnabled(1);
-        phService.insertAndUpdateEnabled(productHistory);
-        // -> product
-        product.setId(productHistory.getId());
-        product.setCreateTime(date);
-        product.setVersion(nextVersion);
-        deleteAndInsert(product);
-        // -> product_bom
-        List<ProductBom> productBomList = new LinkedList<>();
-        bomMaterialList.forEach(bomMaterial->{
-            ProductBom bom = new ProductBom();
-            bom.setProductId(product.getId());
-            bom.setMaterialId(bomMaterial.getId());
-            bom.setQuantity(bomMaterial.getQuantity());
-            bom.setSubVersion(1);
-            bom.setCreateDate(date);
-
-            productBomList.add(bom);
-        });
-        pbService.insertBatch(productBomList);
-        // -> product_bom_history
-        List<ProductBomHistory> bomHistoryList = new LinkedList<>();
-        bomMaterialList.forEach(bomMaterial->{
-            ProductBomHistory bomHistory = new ProductBomHistory();
-            bomHistory.setProductId(productHistory.getId());
-            bomHistory.setMaterialId(bomMaterial.getId());
-            bomHistory.setQuantity(bomMaterial.getQuantity());
-            bomHistory.setSubSVersion(1);
-            bomHistory.setSubEVersion(1);
-            bomHistory.setCreateDate(date);
-
-            bomHistoryList.add(bomHistory);
-        });
-        pbhService.insertBatch(bomHistoryList);
-
         return new Response().setII(1,"鏂板瀹屾垚");
     }
 
     private void deleteAndInsert(Product product) {
         Product productDB = getByProductCodeAndCustomCode(product.getParentCode(), product.getCustomCode());
-        mapper.deleteById(productDB.getId());
-        pbService.deleteByProductId(productDB.getId());
+        if(productDB!=null) {
+            mapper.deleteById(productDB.getId());
+            pbService.deleteByProductId(productDB.getId());
+        }
         mapper.insert(product);
     }
 

--
Gitblit v1.9.1