From cf9a5039e6db9d1d5963e3fe1a37d00169ec2ef7 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期三, 25 六月 2025 11:18:22 +0800
Subject: [PATCH] 验收报告修改

---
 src/main/java/com/whyc/service/ProductService.java |  611 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 546 insertions(+), 65 deletions(-)

diff --git a/src/main/java/com/whyc/service/ProductService.java b/src/main/java/com/whyc/service/ProductService.java
index c63dbcc..bdc8e43 100644
--- a/src/main/java/com/whyc/service/ProductService.java
+++ b/src/main/java/com/whyc/service/ProductService.java
@@ -3,17 +3,19 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.whyc.dto.FileUrlDTO;
 import com.whyc.dto.Response;
+import com.whyc.mapper.ProductHistoryMapper;
 import com.whyc.mapper.ProductMapper;
 import com.whyc.pojo.*;
-import com.whyc.util.ActionUtil;
-import com.whyc.util.CommonUtil;
-import com.whyc.util.FileUtil;
-import com.whyc.util.Zip4jUtil;
+import com.whyc.util.DateUtil;
+import com.whyc.util.*;
+import org.apache.poi.hssf.usermodel.*;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -23,12 +25,19 @@
 import java.io.*;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 @Service
 public class ProductService {
     @Autowired(required = false)
     private ProductMapper mapper;
+
+    @Autowired(required = false)
+    private ProductHistoryMapper hisMapper;
 
     @Autowired
     private ProductHistoryService phService;
@@ -45,10 +54,16 @@
     @Autowired
     private MaterialService mService;
 
+    @Autowired
+    private ProductLockLogService productLockLogService;
+
+    @Autowired
+    private MaterialHistoryService materialHistoryService;
+
     //鏌ヨ鍑烘墍鏈夌殑浜у搧淇℃伅(鍒嗛〉鍔犳ā绯婃煡璇�<浜у搧鐨勭紪鐮侊紝鍨嬪彿锛屽悕瀛楋紝瀹氬埗琛ㄧ紪鍙�>
-    public Response getAllProduct(String subCode,String parentCode, String parentName, String parentModel, String customCode, int pageCurr, int pageSize) {
-        /*PageHelper.startPage(pageCurr,pageSize);
-        QueryWrapper wrapper=new QueryWrapper();
+    public Response getAllProduct(String subCode,String parentCode, String parentName, String parentModel, String customCode,Integer enabled, int pageCurr, int pageSize) {
+        PageHelper.startPage(pageCurr,pageSize);
+        /*QueryWrapper wrapper=new QueryWrapper();
         if(parentCode!=null){
             wrapper.like("parent_code",parentCode);
         }
@@ -67,7 +82,15 @@
         }
         wrapper.orderByAsc("id");
         List list=mapper.selectList(wrapper);*/
-        List list=mapper.getAllProduct(subCode,parentCode,parentName,parentModel,customCode);
+        List<Product> list=mapper.getAllProduct(subCode,parentCode,parentName,parentModel,customCode,enabled);
+        /*list.stream().forEach(product -> {
+            //1.鏌ヨ鏄惁瀛樺湪璇ヨ褰�
+            QueryWrapper qwrapper=new QueryWrapper();
+            qwrapper.eq("id",product.getId());
+            qwrapper.last("limit 1");
+            ProductHistory pHis=hisMapper.selectOne(qwrapper);
+            product.setEnabled(pHis.getEnabled());
+        });*/
         PageInfo pageInfo=new PageInfo(list);
         return new Response().setII(1,list.size()>0,pageInfo,"杩斿洖浜у搧淇℃伅");
     }
@@ -126,8 +149,11 @@
         File parentFile = new File(filePath);
         String originalFilename = file.getOriginalFilename();
         File zipFile = new File(filePath + File.separator + originalFilename);
-        if (!zipFile.exists()) {
+        /*if (!zipFile.exists()) {
             zipFile.mkdirs();
+        }*/
+        if (!parentFile.exists()) {
+            parentFile.mkdirs();
         }
         file.transferTo(zipFile);
         //瑙e帇鏂囦欢澶�
@@ -142,14 +168,16 @@
             String fileTempUrl = fileList.get(i);
             //鏌ヨ闇�涓婁紶鐨刡om鏁版嵁
             //if (fileTempUrl.contains(".xls") && fileTempUrl.contains("(BOM)")) {
+            int excelType = 1; //.xls
             if (fileTempUrl.substring(fileTempUrl.lastIndexOf(File.separator)+1).contains("(BOM).xls")) {
                 Workbook workbook = null;
                 InputStream inputStream = new FileInputStream(new File(fileTempUrl));
                 workbook = WorkbookFactory.create(inputStream);
                 inputStream.close();
-                List<? extends PictureData> allPictures = workbook.getAllPictures();
+                //List<? extends PictureData> allPictures = workbook.getAllPictures();
                 if(fileTempUrl.substring(fileTempUrl.lastIndexOf(".")+1).equals("xlsx")) {
-                    Collections.sort(allPictures, new Comparator<PictureData>() {
+                    excelType = 2; //.xlsx
+                    /*Collections.sort(allPictures, new Comparator<PictureData>() {
                         @Override
                         public int compare(PictureData o1, PictureData o2) {
                             // Name: /xl/media/image1.png - Content Type: image/png
@@ -167,19 +195,76 @@
 
 
                         }
-                    });
+                    });*/
                 }
                 //鍙栫涓�涓猻heet琛�
                 Sheet sheet = workbook.getSheetAt(0);
+                //瀛樺偍鍥剧墖淇℃伅鍙婃墍鍦ㄥ垎椤�
+                Map<Integer,PictureData> pictureDataMap = new HashMap<>();
+                if(excelType == 1){ //.xls
+                    HSSFPatriarch drawingPatriarch = ((HSSFSheet) sheet).getDrawingPatriarch();
+                    if(drawingPatriarch!=null) {
+                        List<HSSFShape> children = drawingPatriarch.getChildren();
+                        for (HSSFShape child : children) {
+                            HSSFPicture picture = (HSSFPicture) child;
+                            HSSFPictureData pictureData = picture.getPictureData();
+                            HSSFClientAnchor anchor = (HSSFClientAnchor) child.getAnchor();
+                            //琛�,涓嶈兘璺ㄨ;
+                            int row1 = anchor.getRow1();
+                            int row2 = anchor.getRow2();
+                            if (row1 == row2) {
+                                //涓嶈法琛�,鏈夋晥
+                                pictureDataMap.put(row1, pictureData);
+                            }
+                        }
+                    }
+                }
+                else if(excelType == 2){ //.xlsx
+                    XSSFDrawing drawingPatriarch = ((XSSFSheet) sheet).getDrawingPatriarch();
+                    if(drawingPatriarch!=null) {
+                        List<XSSFShape> children = drawingPatriarch.getShapes();
+                        for (XSSFShape child : children) {
+                            XSSFPicture picture = (XSSFPicture) child;
+                            XSSFPictureData pictureData = picture.getPictureData();
+                            XSSFClientAnchor anchor = (XSSFClientAnchor) child.getAnchor();
+                            //琛�,涓嶈兘璺ㄨ;
+                            int row1 = anchor.getRow1();
+                            int row2 = anchor.getRow2();
+                            if (row1 == row2) {
+                                //涓嶈法琛�,鏈夋晥
+                                pictureDataMap.put(row1, pictureData);
+                            }
+                        }
+                    }
+                }
+                Set<Integer> pictureRowSet = new HashSet<>();
+                if(!pictureDataMap.isEmpty()) {
+                    pictureRowSet = pictureDataMap.keySet();
+                }
                 int lastRowNum = sheet.getLastRowNum();
                 //鍙栫涓夎,骞朵互绗笁琛屽紑濮�
                 Row row2 = sheet.getRow(1);
+                //鐜板湪瑙勫畾涓�17鍒�
                 short lastCellNum = row2.getLastCellNum();
+                if(lastCellNum !=18){
+                    return response.set(1, false, "涓婁紶鏂囦欢鐨刡om娓呭崟鍒楁暟涓嶅");
+                }
                 for (int k = 2; k < lastRowNum + 1; k++) {
                     if(k==2){
                         product.setParentCode(sheet.getRow(2).getCell(1).getStringCellValue());
+                        if(!originalFilename.contains(product.getParentCode())){
+                            return response.set(1,false,"涓婁紶鐨勪骇鍝佸帇缂╁寘蹇呴』鍖呭惈浜у搧缂栫爜");
+                        }
                         product.setParentName(sheet.getRow(2).getCell(2).getStringCellValue());
-                        product.setParentModel(sheet.getRow(2).getCell(3).getStringCellValue());
+                        String parentModel = sheet.getRow(2).getCell(3).getStringCellValue();
+                        parentModel = parentModel.trim();
+                        String regexStr = "[\\/*?\"|:<>\t]";
+                        boolean matches = Pattern.compile(regexStr).matcher(parentModel).find();
+                        if(!matches) {
+                            product.setParentModel(parentModel);
+                        }else{
+                            return response.set(1,false,"姣嶆枡鍨嬪彿鍖呭惈闈炴硶瀛楃:\\/*?\"|:<>鎴栧墠缃┖鏍�");
+                        }
                     }
                     ProductBom bom = new ProductBom();
                     for (int j = 0; j < lastCellNum; j++) {
@@ -187,10 +272,13 @@
                         Cell cell = row.getCell(j);
                         String cellValue = null;
                         Double cellValueInt = 0d;
-                        if (j == 9 || j == 0) {
+                        if (j == 9 || j == 0) { //1鍜�10鍒椾负鏁板��
                             cellValueInt = cell.getNumericCellValue();
-                        } else if (j != 15) {
+                        } else if (j != 16) { //16鍒椾负鍥剧墖
                             cellValue = cell.getStringCellValue();
+                        }
+                        if(cellValue!=null) {
+                            cellValue = cellValue.trim();
                         }
                         switch (j) {
                             case 0: {
@@ -238,22 +326,27 @@
                             }
                             break;
                             case 11: {
-                                bom.setMaterial(cellValue);
+                                bom.setProducerSpecification(cellValue);
                             }
                             break;
                             case 12: {
-                                bom.setThickness(cellValue);
+                                bom.setMaterial(cellValue);
                             }
                             break;
                             case 13: {
-                                bom.setSurfaceDetail(cellValue);
+                                bom.setThickness(cellValue);
                             }
                             break;
                             case 14: {
-                                bom.setNotes(cellValue);
+                                bom.setSurfaceDetail(cellValue);
                             }
                             break;
                             case 15: {
+                                bom.setNotes(cellValue);
+                            }
+                            break;
+                            case 16: {
+                                /* 寮冪敤,涓嶉�傜敤浜� 鍥剧墖涓嶆寜椤哄簭鎽嗘斁鎯呭喌
                                 //鍥剧墖,浠�0寮�濮�,鍒板浘鐗噑ize涓烘
                                 int m = k - 2;
                                 if (m < allPictures.size()) {
@@ -265,8 +358,36 @@
                                         provingFile.mkdirs();
                                     }
                                     String suffix = pictureData.suggestFileExtension();
-                                    String picturePath = approvingPath + File.separator + bom.getSubModel() + "." + suffix;
-                                    String picturePathFront = "doc_file" + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp + File.separator + bom.getSubModel() + "." + suffix;
+                                    String picturePath = approvingPath + File.separator + bom.getSubModel() + "-bom." + suffix;
+                                    String picturePathFront = "doc_file" + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp + File.separator + bom.getSubModel() + "-bom." + suffix;
+                                    byte[] data = pictureData.getData();
+                                    FileOutputStream fileOutputStream = null;
+                                    File pictureFile = new File(picturePath);
+                                    fileOutputStream = new FileOutputStream(pictureFile);
+                                    fileOutputStream.write(data);
+
+                                    bom.setPictureUrl(picturePathFront);
+                                }*/
+                                if (!pictureRowSet.isEmpty() && pictureRowSet.contains(k)) {
+
+                                    PictureData pictureData = pictureDataMap.get(k);
+                                    //鍒ゆ柇鐗╂枡鍨嬪彿鏄惁鍖呭惈闈炴硶瀛楃(鍥剧墖浼氳浆鍖栦负璺緞)
+                                    if(bom.getSubModel()!=null) {
+                                        String regexStr = "[\\/*?\"|:<>\t]";
+                                        boolean matches = Pattern.compile(regexStr).matcher(bom.getSubModel()).find();
+                                        if (matches) {
+                                            return response.set(1, false, "鍨嬪彿涓�"+bom.getSubModel()+"鐨勭墿鏂欏寘鍚潪娉曞瓧绗�:\\/*?\"|:<>鎴栧墠缃┖鏍�");
+                                        }
+                                    }
+                                    //鍥剧墖瀛樺偍 product_submit/username/2022-07/
+                                    String approvingPath = rootFile + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp;
+                                    File provingFile = new File(approvingPath);
+                                    if (!provingFile.exists()) {
+                                        provingFile.mkdirs();
+                                    }
+                                    String suffix = pictureData.suggestFileExtension();
+                                    String picturePath = approvingPath + File.separator + bom.getSubModel() + "-bom." + suffix;
+                                    String picturePathFront = "doc_file" + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp + File.separator + bom.getSubModel() + "-bom." + suffix;
                                     byte[] data = pictureData.getData();
                                     FileOutputStream fileOutputStream = null;
                                     File pictureFile = new File(picturePath);
@@ -277,16 +398,40 @@
                                 }
                             }
                             break;
+                            case 17: {
+                                if(cellValue!=null && !cellValue.trim().equals("")) {
+                                    if(cellValue.contains(",") || cellValue.contains("锛�")){
+                                        bom.setRelatedMaterialCodes(cellValue);
+                                    }else{
+                                        return response.set(1, false, "涓婁紶鏂囦欢鐨刡om娓呭崟鍐呮浛鏂欐牸寮忎笉瀵�");
+                                    }
+                                }
+                            }
+                            break;
                         }
                     }
                     bomList.add(bom);
                 }
+                //杩藉姞鐗╂枡瑙勮寖鏍¢獙 鏆傛椂鍘婚櫎杩欎釜鍔熻兘
+                /*List<MaterialCheckDTO> checkList = bomList.stream().map(bom->{
+                    MaterialCheckDTO dto = new MaterialCheckDTO();
+                    dto.setNum(bom.getId());
+                    dto.setSubCode(bom.getSubCode());
+                    dto.setSubName(bom.getSubName());
+                    dto.setSubModel(bom.getSubModel());
+                    return dto;
+                }).collect(Collectors.toList());
+                List<MaterialCheckDTO> irregularList = CommonUtil.checkFormat(checkList);
+                if(irregularList.size()>0){
+                    return response.setII(1,false,irregularList,"鍚嶇О鎴栧瀷鍙峰懡鍚嶄笉瑙勮寖");
+                }*/
                 product.setBomList(bomList);
             }
         }
         //浜у搧bom瀵规瘮
         Map<String,List> compareMap = pbhService.parseCompare(baseProduct,product);
-        return response.setIII(1, true, product,compareMap, filePath);
+        //return response.setIII(1, true, product,compareMap, filePath);
+        return response.setIII(1, true, product,compareMap, zipFile.toString());
 
     }
 
@@ -303,16 +448,32 @@
         return list;
     }
 
-    @Transactional
+    /**
+     * 杩欎釜鎺ュ彛鏄繘琛屼骇鍝佹柊澧�,浜у搧bom鏂板鐨勬帴鍙�.
+     * 鏂板鏂瑰紡鏈夊緢澶�,鏈夌洿鎺ヤ粠zip瑙f瀽鏂板浜у搧,涔熷彲浠ュ熀浜庡師鏈変骇鍝佸鍒惰繘琛屽畾鍒剁瓑.闇�瑕佹敞鎰忓吋瀹�!
+     * @param product 浜у搧鏂板,bom鏂板,浜у搧鐗堟湰鏇存柊
+     * @return
+     * @throws IOException
+     */
+    @Transactional(rollbackFor = {RuntimeException.class,Exception.class})
     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();
+        String zipFilePath = product.getFileUrl();
         Date date = new Date();
+        String dateStr = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date);
+        Long userId = ActionUtil.getUser().getId();
         boolean isCopyCustom = false;
         Product relatedProduct = null;
+        //鏍¢獙鍑℃槸鏈夊畾鍒惰〃鍗曞彿鐨勪骇鍝侊紝涓嶈兘浣跨敤宸蹭笂浼犺繃鐨勬爣鍑嗕骇鍝佺紪鐮�
+        if(customCode!=null && !customCode.trim().equals("")){
+            ProductHistory standard = phService.getStandard(parentCode);
+            if(standard !=null){
+                return new Response().set(1,false,"绯荤粺瀛樺湪姝ゆ姣嶇墿鏂欑紪鐮佺殑鏍囧噯浜у搧,鎷掔粷鎻愪氦");
+            }
+        }
         //鍒ゆ柇鏄惁涓轰緷鎹骇鍝佸鍒跺畾鍒剁殑浜у搧
         if(bomList == null){
             bomList = pbService.getBomByProductId(product.getId());
@@ -321,6 +482,11 @@
             if(product.getId() != null){ //鍏宠仈鍏崇郴浠庝骇鍝乮d缁ф壙
                 relatedProduct = getById(product.getId());
             }
+        }
+        //涓嶆槸鍩轰簬浜у搧澶嶅埗,鍒欏繀瀹氬瓨鍦▃ip鍖�,蹇呯劧瀛樺湪璺緞
+        String fileUrl = null;
+        if(!isCopyCustom) {
+            fileUrl = zipFilePath.substring(0, zipFilePath.lastIndexOf(File.separator));
         }
         //鏌ヨ鏂板浜у搧鏈�鏂扮殑鐗堟湰鍙�
         ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode);
@@ -414,6 +580,103 @@
             }
         }
 
+        //鏌ヨ鏄惁bomList涓湁鏇挎枡
+        // 鏈夌殑璇�,妫�鏌ュ叧鑱旇〃涓槸鍚﹀凡瀛樺湪鎴栨湰鐗堟湰宸茬敓鏁�
+        List<MaterialProductHistory> newAddedList = new LinkedList<>();
+        List<MaterialProductHistory> versionUpdateList = new LinkedList<>();
+
+        List<MaterialProductHistory> mpListInDB = mphService.getListByParentCodeAndCustomCodeAndSubMaterialIdAndVersion(parentCode,customCode,bomList,currentVersion);
+        List<String> subMaterialListInDB = mpListInDB.stream().map(mp->mp.getSubMaterial().getSubCode()+"_"+mp.getSubMaterial().getSubModel()).collect(Collectors.toList());
+        bomList.forEach(bom->{
+            if(bom.getRelatedMaterialCodes()!=null) {
+                String relatedMaterialCodes = bom.getRelatedMaterialCodes().trim();
+                if (!relatedMaterialCodes.equals("")) {
+                    if(subMaterialListInDB!=null&&subMaterialListInDB.size()>0){
+                        if (subMaterialListInDB.contains(bom.getSubCode()+"_"+bom.getSubModel())) { //褰撳墠鐗╂枡鏈夋浛浠f枡
+                            String[] relatedList;
+                            if (relatedMaterialCodes.contains(",")) {
+                                relatedList = relatedMaterialCodes.split(",");
+                            } else {
+                                relatedList = relatedMaterialCodes.split("锛�");
+                            }
+                            for (String related : relatedList) {
+                                bom.setRelatedMaterialCodes(related);
+                                boolean exists = false;
+                                for (MaterialProductHistory mp : mpListInDB) {
+                                    //鐗╂枡鐩稿悓,鏇夸唬鏂欑浉鍚�
+                                    if ((mp.getSubMaterial().getSubCode()+"_"+mp.getSubMaterial().getSubModel()).equals(bom.getSubCode()+"_"+bom.getSubModel())
+                                            && mp.getRelatedSubMaterial().getSubCode().equals(related)) {
+                                        //鍙彲鑳藉瓨鍦�0 鍜� 1 鐨勬儏鍐�,鍥犱负鏌ヨ鐨勬槸 >=涓婁釜鐗堟湰
+                                        if (nextVersion - mp.getEVersion() == 0) { //宸插瓨鍦�,鏃犻渶娣诲姞
+                                            //break;
+                                        } else if (nextVersion - mp.getEVersion() == 1) {  //鏇存柊鍒板綋鍓嶇増鏈�
+                                            mp.setEVersion(nextVersion);
+                                            versionUpdateList.add(mp);
+                                        }
+                                        exists = true;
+                                    }
+                                }
+                                if(!exists) { //涓嶅瓨鍦ㄧ浉閭诲強鐩稿悓鐨勮褰曠増鏈�,鏂板
+                                    MaterialProductHistory newTemp = new MaterialProductHistory();
+                                    newTemp.setParentCode(parentCode);
+                                    newTemp.setCustomCode(customCode);
+                                    newTemp.setSubCode(bom.getSubCode());
+                                    Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel(),true);
+                                    newTemp.setSubMaterialId(material.getId());
+                                    newTemp.setSVersion(nextVersion);
+                                    newTemp.setEVersion(nextVersion);
+                                    newTemp.setQuantity(bom.getQuantity());
+                                    //2323-09-08 涓庢潹绾㈠叞寰俊纭<灏辨寜鐓ф垜涓婁紶娓呭崟鐨勬椂闂达紝绯荤粺閲屾渶鏂扮殑鏄暐鍨嬪彿锛屽氨鍙栦粈涔堝瀷鍙�>
+                                    Material relatedMaterial = mService.getLastByCode(related);
+                                    if(relatedMaterial == null){
+                                        throw new RuntimeException("褰撳墠鏇挎枡"+related+",缂栫爜鍦ㄥ钩鍙颁腑涓嶅瓨鍦�,鏃犳硶鍏宠仈鏇夸唬");
+                                    }
+                                    newTemp.setMaterialId(relatedMaterial.getId());
+                                    newTemp.setCreateTime(date);
+                                    newAddedList.add(newTemp);
+                                }
+                            }
+                        }
+                        else{
+                            String[] relatedList;
+                            if (relatedMaterialCodes.contains(",")) {
+                                relatedList = relatedMaterialCodes.split(",");
+                            } else {
+                                relatedList = relatedMaterialCodes.split("锛�");
+                            }
+                            for (String related : relatedList) {
+                                MaterialProductHistory newTemp = new MaterialProductHistory();
+                                newTemp.setParentCode(parentCode);
+                                newTemp.setCustomCode(customCode);
+                                newTemp.setSubCode(bom.getSubCode());
+                                Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel(),true);
+                                newTemp.setSubMaterialId(material.getId());
+                                newTemp.setSVersion(nextVersion);
+                                newTemp.setEVersion(nextVersion);
+                                newTemp.setQuantity(bom.getQuantity());
+                                //2323-09-08 涓庢潹绾㈠叞寰俊纭<灏辨寜鐓ф垜涓婁紶娓呭崟鐨勬椂闂达紝绯荤粺閲屾渶鏂扮殑鏄暐鍨嬪彿锛屽氨鍙栦粈涔堝瀷鍙�>
+                                Material relatedMaterial = mService.getLastByCode(related);
+                                if(relatedMaterial == null){
+                                    throw new RuntimeException("褰撳墠鏇挎枡"+related+",缂栫爜鍦ㄥ钩鍙颁腑涓嶅瓨鍦�,鏃犳硶鍏宠仈鏇夸唬");
+                                }
+                                newTemp.setMaterialId(relatedMaterial.getId());
+                                newTemp.setCreateTime(date);
+                                newAddedList.add(newTemp);
+                            }
+                        }
+                    }
+                }
+            }
+        });
+        //鎵ц鏇存柊
+        if(newAddedList.size()!=0) {
+            mphService.insertBatch(newAddedList);
+        }
+        if(versionUpdateList.size()!=0) {
+            mphService.updateVersionBatch(versionUpdateList);
+        }
+
+
         //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞
         //鏂囦欢杞Щ,鏈窡瀛愪欢鎸傞挬鐨勬墍鏈夊浘绾稿浘鐗囪浆绉诲埌浜у搧鐗堟湰涓�:doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/
         //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/
@@ -435,14 +698,15 @@
             his.setVersionTime(product.getVersionTime());
             his.setVersion(1);
             his.setSubVersionMax(1);
-            his.setEnabled(1);
+            //涓婁紶鍚庣殑鏈�鍒濆浣胯兘鐘舵�佷负-1
+            //绗竴娆¤В閿佸悗,鍚庣画鐨勯攣瀹氬拰瑙i攣鍦�0鍜�1涔嬮棿鍒囨崲
+            his.setEnabled(-1);
             phService.insertAndUpdateEnabled(his);
             //phService.insert(his);
-            // -> product
+            // -> product 鐜版湁浜у搧鍜屼骇鍝乥om闇�瑕佹彃鍏�,version榛樿涓�-1,鍚屾椂瑕佸仛鍒犻櫎鍘熸潵鐨勬棫鐗堟湰
             product.setId(his.getId());
             product.setCreateTime(date);
-            product.setVersion(1);
-            //insert(product);
+            product.setVersion(-1);
             deleteAndInsert(product);
             // -> bom
             bomList.forEach(bom-> {
@@ -457,6 +721,13 @@
                 bomHistory.setProductId(his.getId());
                 bomHistory.setMaterialId(bom.getMaterialId());
                 bomHistory.setQuantity(bom.getQuantity());
+                bomHistory.setCategory(bom.getCategory());
+                bomHistory.setMaterial(bom.getMaterial());
+                bomHistory.setNotes(bom.getNotes());
+                bomHistory.setProducer(bom.getProducer());
+                bomHistory.setProducerSpecification(bom.getProducerSpecification());
+                bomHistory.setSurfaceDetail(bom.getSurfaceDetail());
+                bomHistory.setThickness(bom.getThickness());
                 bomHistory.setSubSVersion(1);
                 bomHistory.setSubEVersion(1);
                 bomHistoryList.add(bomHistory);
@@ -466,7 +737,7 @@
             File file = new File(fileUrl);
             List<String> fileUrlList = new LinkedList<>();
             List<String> excelExcludeUrlList = null;
-            List<String> picUrlList = null;
+            List<String> picUrlList = new LinkedList<>();
             //瀛樹簬鐗╂枡涓�,bom鍐呮湁瀵瑰簲
             List<String> materialUrlList = new LinkedList<>();
             //瀛樹簬浜у搧涓�,bom鍐呮病瀵瑰簲
@@ -477,21 +748,32 @@
             fileUrlList = FileUtil.getStaticFilePath(file, fileUrlList);
             //鍥剧焊dwg 瀛愪欢/浜у搧
             excelExcludeUrlList = fileUrlList.stream().filter(url -> !(url.contains(".xls") || url.contains(".xlsx"))).collect(Collectors.toList());
-            picUrlList = fileUrlList.stream().filter(url -> url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList());
+            //picUrlList = fileUrlList.stream().filter(url -> url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList());
 
             List<ProductBom> finalBomList = bomList;
             excelExcludeUrlList.forEach(excelExcludeUr -> {
                 boolean existFlag = false;
                 for (ProductBom bom : finalBomList) {
-                    String filename = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1, excelExcludeUr.length() - 4);
+                    String filename = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1, excelExcludeUr.lastIndexOf("."));
                     String fileFullName = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1);
+                    String fileSuffix = fileFullName.substring(fileFullName.lastIndexOf("."));
                     if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase()) && excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("dwg")) {
                         materialUrlList.add(excelExcludeUr);
                         existFlag = true;
 
 
-                        bom.setDwgUrl("doc_file" + File.separator + "material"
-                                + File.separator + fileFullName);
+                        bom.setDwgUrl("doc_file" + File.separator + "material" + File.separator + bom.getSubCode() + "-" + bom.getSubModel()
+                                + File.separator + filename + "_" + dateStr + fileSuffix);
+                        break;
+                    }
+                    else if((bom.getSubModel().toUpperCase()+"-BOM").equals(filename.toUpperCase()) && (excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("png") ||excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("jpeg"))
+                    ){
+                        picUrlList.add(excelExcludeUr);
+                        existFlag = true;
+
+
+                        bom.setPictureUrl("doc_file" + File.separator + "material" + File.separator + bom.getSubCode() + "-" + bom.getSubModel()
+                                + File.separator + filename + "_" + dateStr + fileSuffix);
                         break;
                     }
                 }
@@ -500,18 +782,18 @@
                 }
             });
 
-            //涓�瀹氭槸鏈夊搴旂墿鏂欑殑,浠巄om鍐呭墺绂荤殑
+            /*//涓�瀹氭槸鏈夊搴旂墿鏂欑殑,鍖呭惈浠巄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())) {
+                    if ((bom.getSubModel().toUpperCase()+"-BOM").equals(filename.toUpperCase())) {
                         bom.setPictureUrl("doc_file" + File.separator + "material"
                                 + File.separator + fileFullName);
                         break;
                     }
                 }
-            });
+            });*/
 
             //杞Щ璺緞
             String projectDir = CommonUtil.getProjectDir();
@@ -534,6 +816,10 @@
             if (!materialFile.exists()) {
                 materialFile.mkdirs();
             }
+            //涔嬪墠涓婁紶鐨勪骇鍝乥om鍘嬬缉鍖�,杞Щ鍒版寮忕増鏈笅鐣欏瓨
+            File zipFileNew = new File(productDir + File.separator + zipFilePath.substring(zipFilePath.lastIndexOf(File.separator) + 1));
+            FileCopyUtils.copy(new File(zipFilePath), zipFileNew);
+
             productUrlList.forEach(productUrl -> {
                 String fileName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1);
 
@@ -544,72 +830,156 @@
                 }
             });
 
-            materialUrlList.forEach(materialUrl -> {
-                String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4);
+            //鐗╂枡dwg鍥剧焊瀛樺埌瀵瑰簲鐨� 鐗╂枡缂栫爜+鍨嬪彿 涓嬮潰
+            for (String materialUrl : materialUrlList) {
                 try {
-                    FileCopyUtils.copy(new File(materialUrl), new File(materialDir + File.separator + dwgName + ".dwg"));
+                    String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4);
+                    //纭畾鐗╂枡鐨勫叿浣撳瀷鍙�
+                    String subModel = null;
+                    String subCode = null;
+                    for (ProductBom bom : bomList) {
+                        String bomSubMode = bom.getSubModel();
+                        if (bomSubMode.toUpperCase().equals(dwgName.toUpperCase())) {
+                            subModel = bomSubMode;
+                            subCode = bom.getSubCode();
+                            break;
+                        }
+                    }
+                    File dwgFile;
+                    if (subModel != null) {
+                        dwgFile = new File(materialDir + File.separator + subCode + "-" + subModel + File.separator + dwgName + "_" + dateStr + ".dwg");
+                        File dwgDir = new File(materialDir + File.separator + subCode + "-" + subModel);
+                        if(!dwgDir.exists()){
+                            dwgDir.mkdirs();
+                        }
+                    } else {
+                        dwgFile = new File(materialDir + File.separator + dwgName + "_" + dateStr + ".dwg");
+                    }
+                    if (!dwgFile.exists()) {
+                        FileCopyUtils.copy(new File(materialUrl), dwgFile);
+                    }
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
-            });
+            }
 
-            picUrlList.forEach(picUrl -> {
+            for (String picUrl : picUrlList) {
                 String picFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
+                String picSubModel = picFullName.substring(0, picFullName.lastIndexOf("."));
+                String picSuffix = picFullName.substring(picFullName.lastIndexOf("."));
                 try {
-                    FileCopyUtils.copy(new File(picUrl), new File(materialDir + File.separator + picFullName));
+                    //纭畾鐗╂枡鐨勫叿浣撳瀷鍙峰拰缂栫爜
+                    String subModel = null;
+                    String subCode = null;
+                    for (ProductBom bom : bomList) {
+                        String bomSubMode = bom.getSubModel();
+                        if ((bomSubMode + "-bom").toUpperCase().equals(picSubModel.toUpperCase())) {
+                            subModel = bomSubMode;
+                            subCode = bom.getSubCode();
+                            break;
+                        }
+                    }
+                    File picFile;
+                    if (subModel != null) {
+                        picFile = new File(materialDir + File.separator + subCode + "-" + subModel + File.separator + picSubModel + "_" + dateStr + picSuffix);
+                        File picDir = new File(materialDir + File.separator + subCode + "-" + subModel);
+                        if(!picDir.exists()){
+                            picDir.mkdirs();
+                        }
+                    } else {
+                        picFile = new File(materialDir + File.separator + picSubModel + "_" + dateStr + picSuffix);
+                    }
+                    if (!picFile.exists()) {
+                        FileCopyUtils.copy(new File(picUrl), picFile);
+                    }
                 } catch (IOException e) {
                     e.printStackTrace();
                 }
-            });
+            }
 
             //鐗╂枡琛ㄤ腑涓嶅瓨鍦ㄧ殑(渚濇嵁:鐗╂枡缂栫爜+鐗╂枡鍨嬪彿),鍒欐坊鍔犲埌鐗╂枡琛ㄤ腑鍘�(鍖呭惈product杩欎釜鐗╂枡)
+            //鏇存柊鍥剧焊鍜屽浘鐗�
             List<Material> materialExistList = mService.getListByCodeAndModelList2(bomList);
             //List<String> subCodeList = materialExistList.stream().map(Material::getSubCode).collect(Collectors.toList());
             List<String> subCodeList = materialExistList.stream().map(material -> material.getSubCode()+"/"+material.getSubModel()).collect(Collectors.toList());
-            List<Material> materialList = new LinkedList<>();
-            bomList.forEach(bom -> {
-                if (!subCodeList.contains(bom.getSubCode()+"/"+bom.getSubModel())) {
+            //闇�瑕佹洿鏂板埌鐗╂枡琛ㄤ腑鐨勭墿鏂�(瀛樺湪鍥剧焊鎴栬�呭浘鐗�)
+            List<MaterialHistory> materialHistoryList = new LinkedList<>();
+            //鏂扮墿鏂�
+            List<Material> newMaterialList = new LinkedList<>();
+            //鍒ゆ柇鐗╂枡鏄惁宸茬粡瀛樺湪浜庣墿鏂欒〃涓�
+            List<Material> materialUpdateList = new LinkedList<>();
+            for (ProductBom bom : bomList) {
+                if (!subCodeList.contains(bom.getSubCode() + "/" + bom.getSubModel())) {
                     Material material = new Material();
-                    material.setCategory(bom.getCategory());
-                    material.setCreateDate(bom.getCreateDate());
+                    material.setCreateDate(date);
                     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.setUpUserId(userId);
 
-                    materialList.add(material);
+                    newMaterialList.add(material);
+                } else { //鐗╂枡宸茬粡瀛樺湪鐨�
+                    // 鐗╂枡鍘嗗彶琛ㄦ槸涓轰簡瀛樺偍鐗╂枡鐨勫巻鍙插浘鐗囧拰dwg鍥剧焊
+                    Material material = new Material();
+                    if (bom.getPictureUrl() != null) {
+                        material.setPictureUrl(bom.getPictureUrl());
+                    }
+                    if (bom.getDwgUrl() != null) {
+                        material.setDwgUrl(bom.getDwgUrl());
+                    }
+                    if (material.getPictureUrl() != null || material.getDwgUrl() != null) {
+                        material.setSubCode(bom.getSubCode());
+                        material.setSubModel(bom.getSubModel());
+                        materialUpdateList.add(material);
+                    }
                 }
-            });
+            }
+            //瀵规柊澧炲埌鐗╂枡琛ㄤ腑鐨勭墿鏂�,鏍规嵁 鐗╂枡缂栫爜+鐗╂枡鍨嬪彿 杩涜鍘婚噸澶勭悊
+            newMaterialList = newMaterialList.stream().filter(distinctByKey(m->m.getSubCode()+"/"+m.getSubModel())).collect(Collectors.toList());
+
             //姣嶆枡鏄惁瀛樺湪
-            Material materialDB = mService.getByCodeAndModel(product.getParentCode(), product.getParentModel());
+            Material materialDB = mService.getByCodeAndModel(product.getParentCode(), product.getParentModel(),true);
             if (materialDB == null) {
                 Material material = new Material();
                 material.setSubCode(product.getParentCode());
                 material.setSubName(product.getParentName());
                 material.setSubModel(product.getParentModel());
+                material.setCreateDate(date);
                 material.setStatus(1);
+                material.setUpUserId(userId);
 
-                materialList.add(material);
+                newMaterialList.add(material);
             }
-            if(materialList.size()!=0) {
-                mService.insertBatch(materialList);
+            if(newMaterialList.size()!=0) {
+                mService.insertBatch(newMaterialList);
+            }
+            if(materialUpdateList.size()!=0) {
+                mService.updateDwgUrlAndPicUrl(materialUpdateList);
             }
             //鏇存柊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);
+            //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());
@@ -622,12 +992,13 @@
             productHistory.setVersion(nextVersion);
             //鐗堟湰鏂板,鍒濆bom瀛愪欢鐗堟湰涓�1
             productHistory.setSubVersionMax(1);
-            productHistory.setEnabled(1);
+
+            productHistory.setEnabled(-1);
             phService.insertAndUpdateEnabled(productHistory);
-            // -> product
+            // -> product 鐜版湁浜у搧鍜屼骇鍝乥om闇�瑕佹彃鍏�,version榛樿涓�-1,鍚屾椂瑕佸仛鍒犻櫎鍘熸潵鐨勬棫鐗堟湰
             product.setId(productHistory.getId());
             product.setCreateTime(date);
-            product.setVersion(nextVersion);
+            product.setVersion(-1);
             deleteAndInsert(product);
             // -> product_bom
             List<ProductBom> productBomList = new LinkedList<>();
@@ -636,6 +1007,13 @@
                 bom.setProductId(product.getId());
                 bom.setMaterialId(bomMaterial.getId());
                 bom.setQuantity(bomMaterial.getQuantity());
+                bom.setCategory(bomMaterial.getCategory());
+                bom.setMaterial(bomMaterial.getMaterial());
+                bom.setNotes(bomMaterial.getNotes());
+                bom.setProducer(bomMaterial.getProducer());
+                bom.setProducerSpecification(bomMaterial.getProducerSpecification());
+                bom.setSurfaceDetail(bomMaterial.getSurfaceDetail());
+                bom.setThickness(bomMaterial.getThickness());
                 bom.setSubVersion(1);
                 bom.setCreateDate(date);
 
@@ -649,6 +1027,13 @@
                 bomHistory.setProductId(productHistory.getId());
                 bomHistory.setMaterialId(bomMaterial.getId());
                 bomHistory.setQuantity(bomMaterial.getQuantity());
+                bomHistory.setCategory(bomMaterial.getCategory());
+                bomHistory.setMaterial(bomMaterial.getMaterial());
+                bomHistory.setNotes(bomMaterial.getNotes());
+                bomHistory.setProducer(bomMaterial.getProducer());
+                bomHistory.setProducerSpecification(bomMaterial.getProducerSpecification());
+                bomHistory.setSurfaceDetail(bomMaterial.getSurfaceDetail());
+                bomHistory.setThickness(bomMaterial.getThickness());
                 bomHistory.setSubSVersion(1);
                 bomHistory.setSubEVersion(1);
                 bomHistory.setCreateDate(date);
@@ -656,9 +1041,74 @@
                 bomHistoryList.add(bomHistory);
             });
             pbhService.insertBatch(bomHistoryList);
+            //鎻掑叆鍒扮墿鏂欏巻鍙茶〃鐨�,
+            // 鍖呭惈鏂扮墿鏂欏寘鍚浘绾稿浘鐗囩殑,
+            // 涔熷寘鍚棫鐗╂枡鍖呭惈鍥剧焊鍥剧墖鐨�
+            if(newMaterialList.size()>0){
+                for (Material material : newMaterialList) {
+                    //瀛樺湪鍥剧焊鎴栬�呭浘鐗�,灏辨彃鍏ュ巻鍙�
+                    if(material.getDwgUrl()!=null || material.getPictureUrl()!=null) {
+                        MaterialHistory materialHistory = new MaterialHistory();
+                        materialHistory.setPictureUrl(material.getPictureUrl());
+                        materialHistory.setProductId(productHistory.getId());
+                        materialHistory.setDwgUrl(material.getDwgUrl());
+                        materialHistory.setUpUserId(userId.intValue());
+                        materialHistory.setCreateTime(date);
+                        materialHistory.setMaterialId(material.getId());
+                        materialHistoryList.add(materialHistory);
+                    }
+                }
+            }
+            if(materialUpdateList.size()>0) {
+                //鏇存柊鐗╂枡鍥剧焊鍥剧墖鐨勫悓鏃�,娣诲姞鏂扮殑鍥剧焊鍥剧墖淇℃伅鍒扮墿鏂欏巻鍙茶〃涓�
+                for (Material material : materialUpdateList) {
+                    MaterialHistory materialHistory = new MaterialHistory();
+                    materialHistory.setPictureUrl(material.getPictureUrl());
+                    materialHistory.setProductId(productHistory.getId());
+                    materialHistory.setDwgUrl(material.getDwgUrl());
+                    materialHistory.setUpUserId(userId.intValue());
+                    materialHistory.setCreateTime(date);
+                    for (Material materialInDB : materialExistList) {
+                        if ((material.getSubCode() + "/" + material.getSubModel()).equals(materialInDB.getSubCode() + "/" + materialInDB.getSubModel())) {
+                            materialHistory.setMaterialId(materialInDB.getId());
+                            break;
+                        }
+                    }
+                    materialHistoryList.add(materialHistory);
+                }
+            }
+            if(materialHistoryList.size()>0) {
+                materialHistoryService.addBatch(materialHistoryList);
+            }
+            //濡傛灉鏂颁笂浼犵殑bom涓瓨鍦�0108銆�0109寮�澶寸殑鐗╂枡,(鑲畾浼氳璇嗗埆鎴愭柊鐗╂枡,涔嬪墠鐨勬搷浣滃凡缁忚鎻掑叆鍒拌〃涓�)
+            // 鍦ㄦ暟鎹簱瀛樺湪鐩稿悓鐨勭墿鏂欑紪鐮佸瓨鍦ㄤ笖涓嶅悓鐨勭墿鏂欏瀷鍙�,鍒欏皢鏁版嵁搴撴渶鏂扮殑鐗╂枡鐨勯檮浠跺鍒朵竴浠藉苟鐘舵�佸悓姝�,濉厖鍒版柊鐨勭墿鏂欒〃涓�
+            for (Material material : newMaterialList) { //鏂扮墿鏂�
+                String subCode = material.getSubCode();
+                String subModel = material.getSubModel();
+                if(subCode.startsWith("0108") || subCode.startsWith("0109")){
+                    Material materialWithSameCodeLatest = mService.getByCodeAndModel(subCode, subModel, false);
+                    if(materialWithSameCodeLatest!=null){
+                        //闄勪欢杞Щ骞惰缃�
+                        mService.transferCopiedAttachment(materialWithSameCodeLatest,material);
+                    }
+                }
+            }
 
         }
-        return new Response().setII(1,"鏂板瀹屾垚");
+        //娣诲姞鏂板鏃ュ織鍒皌b_product_lock_log琛�
+        ProductLockLog lockLog = new ProductLockLog();
+        lockLog.setParentCode(parentCode);
+        lockLog.setCustomCode(customCode);
+        lockLog.setVersion(nextVersion);
+        lockLog.setVersionTime(DateUtil.YYYY_MM_DD_HH_MM_SS.format(product.getVersionTime()));
+        lockLog.setReason("浜у搧bom涓婁紶");
+        lockLog.setOwner(ActionUtil.getUser().getName());
+        lockLog.setCreateTime(date);
+        //-1浠h〃鏃ュ織绫诲瀷涓�:浜у搧bom涓婁紶
+        lockLog.setLockFlag(-1);
+
+        productLockLogService.insert(lockLog);
+        return new Response().set(1,true,"鏂板瀹屾垚");
     }
 
     private void deleteAndInsert(Product product) {
@@ -668,6 +1118,14 @@
             pbService.deleteByProductId(productDB.getId());
         }
         mapper.insert(product);
+    }
+
+    private void delete(Product product) {
+        Product productDB = getByProductCodeAndCustomCode(product.getParentCode(), product.getCustomCode());
+        if(productDB!=null) {
+            mapper.deleteById(productDB.getId());
+            pbService.deleteByProductId(productDB.getId());
+        }
     }
 
     private Product getByProductCodeAndCustomCode(String parentCode, String customCode) {
@@ -686,4 +1144,27 @@
         List listProduct=mapper.selectListProduct(productId);
         return new Response().setIII(1,listMaterial.size()>0||listProduct.size()>0,listMaterial,listProduct,"");
     }
+
+    //鍙嶉绠$悊-鏌ヨ鎵�鏈夌殑浜у搧
+    public Response getFkProduct() {
+        //QueryWrapper wrapper=new QueryWrapper();
+        //wrapper.ne("version",-1);
+        List list=mapper.selectList(null);
+        return new Response().setII(1,list.size()>0,list,"鍙嶉绠$悊-鏌ヨ鎵�鏈夌殑浜у搧");
+    }
+
+    //浜у搧瀵规瘮涓嬫媺閫変腑
+    public Response getCompareProduct() {
+        List list=mapper.selectList(null);
+        return new Response().setII(1,list.size()>0,list,"浜у搧瀵规瘮涓嬫媺閫変腑-鏌ヨ褰撳墠浣跨敤鐨勬墍鏈夌殑浜у搧");
+    }
+    public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
+        Map<Object, Boolean> seen = new ConcurrentHashMap<>();
+        return object -> seen.putIfAbsent(keyExtractor.apply(object), Boolean.TRUE) == null;
+    }
+    //楠岃瘉姣嶆枡缂栫爜鏄惁瀛樺湪浜у搧涓�
+    public Response judgeParentCode(String parentCode,String customCode) {
+        int count = mapper.judgeParentCode(parentCode,customCode);
+        return  new Response().set(1,count>0,"楠岃瘉姣嶆枡缂栫爜鏄惁瀛樺湪浜у搧涓�");
+    }
 }

--
Gitblit v1.9.1