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/WorksheetLinkService.java |  415 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 223 insertions(+), 192 deletions(-)

diff --git a/src/main/java/com/whyc/service/WorksheetLinkService.java b/src/main/java/com/whyc/service/WorksheetLinkService.java
index 3a35c0d..a93f1d8 100644
--- a/src/main/java/com/whyc/service/WorksheetLinkService.java
+++ b/src/main/java/com/whyc/service/WorksheetLinkService.java
@@ -3,11 +3,13 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.whyc.config.EnumWorksheetType;
+import com.whyc.dto.Response;
 import com.whyc.mapper.ProductBomApprovingMapper;
 import com.whyc.mapper.WorksheetLinkMapper;
 import com.whyc.pojo.*;
 import com.whyc.util.CommonUtil;
 import com.whyc.util.FileUtil;
+import com.whyc.util.WordUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -15,6 +17,7 @@
 
 import javax.annotation.Resource;
 import java.io.File;
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -47,7 +50,7 @@
     private ProductBomApprovingService pbaService;
 
     @Autowired
-    private MaterialProductHistoryService cphService;
+    private MaterialProductHistoryService mphService;
 
     @Autowired
     private MaterialProductApprovingService cpAService;
@@ -66,6 +69,12 @@
 
     @Autowired
     private ProductHistoryService phService;
+
+    @Autowired
+    private ProcedureDocApprovingService procedureDocApprovingService;
+
+    @Autowired
+    private ProcedureDocService procedureDocService;
 
     @Transactional
     public void audit(WorksheetLink link) {
@@ -144,12 +153,30 @@
                 String parentModel = productApproving.getParentModel();
                 String parentCode = productApproving.getParentCode();
                 String customCode = productApproving.getCustomCode();
-                Product product = productService.getVersion(parentCode, customCode);
+                ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode);
+                ProductHistory enabledProduct = phService.getEnabledByParentCodeAndCustomCode(parentCode, customCode);
                 int currentVersion = 0;
-                if (product != null) {
-                    currentVersion = product.getVersion();
+                if (latestProduct != null) {
+                    currentVersion = latestProduct.getVersion();
                 }
                 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);
+                    }
+                }
+
                 //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞
                 //鏂囦欢杞Щ,鏈窡瀛愪欢鎸傞挬鐨勬墍鏈夊浘绾稿浘鐗囪浆绉诲埌浜у搧鐗堟湰涓�:doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/
                 //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/
@@ -164,9 +191,7 @@
                 //瀛樹簬浜у搧涓�,bom鍐呮病瀵瑰簲
                 List<String> productUrlList = new LinkedList<>();
 
-                List<String> productUrlNameList = new LinkedList<>();
-                List<String> materialUrlNameList = new LinkedList<>();
-                List<String> picUrlNameList = new LinkedList<>();
+                List<Material> materialDwgUrlNameList = new LinkedList<>();
 
                 fileUrlList = FileUtil.getStaticFilePath(file,fileUrlList);
                 //鍥剧焊dwg 瀛愪欢/浜у搧
@@ -177,9 +202,16 @@
                     boolean existFlag = false;
                     for (ProductBomApproving approving :approvingList){
                         String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4);
+                        String fileFullName = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1);
                         if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){
                             materialUrlList.add(dwgUrl);
                             existFlag = true;
+
+                            Material temp = new Material();
+                            temp.setSubModel(approving.getSubModel());
+                            temp.setNotes("doc_file" + File.separator + "material"
+                                    + File.separator + fileFullName);
+                            materialDwgUrlNameList.add(temp);
                             break;
                         }
                     }
@@ -192,8 +224,10 @@
                 picUrlList.forEach(picUrl->{
                     for (ProductBomApproving approving :approvingList){
                         String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.length() - 4);
+                        String fileFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1);
                         if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){
-                            picUrlNameList.add(picUrl);
+                            approving.setPictureUrl("doc_file" + File.separator + "material"
+                            + File.separator + fileFullName);
                             break;
                         }
                     }
@@ -204,10 +238,10 @@
                 //doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/
                 //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/
                 String customCodeString = null;
-                if(customCode==null) {
-                    customCodeString = "standard";
-                }else{
+                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;
@@ -222,7 +256,7 @@
                 }
                 productUrlList.forEach(productUrl->{
                     String dwgName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1, productUrl.length() - 4);
-                    productUrlNameList.add(dwgName);
+
                     try {
                         FileCopyUtils.copy(new File(productUrl),new File(productDir+File.separator+dwgName+".dwg"));
                     } catch (IOException e) {
@@ -232,9 +266,17 @@
 
                 materialUrlList.forEach(materialUrl->{
                     String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4);
-                    materialUrlNameList.add(dwgName);
                     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();
                     }
@@ -245,15 +287,26 @@
                 ProductHistory productHistory = new ProductHistory();
                 productHistory.setParentCode(parentCode);
                 productHistory.setParentName(productApproving.getParentName());
-                productApproving.setParentModel(parentModel);
+                productHistory.setParentModel(parentModel);
                 productHistory.setNotes(productApproving.getNotes());
                 productHistory.setCustomCode(customCode);
                 productHistory.setCreateTime(new Date());
                 productHistory.setVersion(nextVersion);
                 productHistory.setEnabled(1);
 
+                Product productNew = new Product();
+                productNew.setParentCode(parentCode);
+                productNew.setParentName(productApproving.getParentName());
+                productNew.setParentModel(parentModel);
+                productNew.setNotes(productApproving.getNotes());
+                productNew.setCustomCode(customCode);
+                productNew.setCreateTime(new Date());
+                productNew.setVersion(nextVersion);
+
+                //瀹為檯鐢熸晥鐨勫彧鏈塱nsert,鍥犱负鐘舵�佽缃负鏈惎鐢ㄥ凡缁忓湪鎻愪氦瀹℃壒鏃跺彉鏇翠簡
                 phService.insertAndUpdateEnabled(productHistory);
-                int productId = productService.updateVersion(parentCode,customCode,nextVersion);
+
+                productService.insert(productNew);
 
                 List<ProductBomHistory> productBomHistoryList = new LinkedList<>();
                 List<ProductBom> productBomList = new LinkedList<>();
@@ -261,7 +314,7 @@
                     ProductBomHistory bomHistory = new ProductBomHistory();
                     ProductBom bom = new ProductBom();
 
-                    bom.setProductId(productId);
+                    bom.setProductId(productNew.getId());
                     bom.setCategory(approving.getCategory());
                     bom.setCreateDate(new Date());
                     bom.setDwgUrl(approving.getDwgUrl());
@@ -278,7 +331,7 @@
                     bom.setThickness(approving.getThickness());
                     bom.setType(approving.getType());
                     bom.setUnit(approving.getUnit());
-                    bom.setUpUserId(approving.getUpUserId());
+                    //bom.setUpUserId(approving.getUpUserId());
                     bom.setVersion(nextVersion);
 
                     bomHistory.setProductId(productHistory.getId());
@@ -298,7 +351,7 @@
                     bomHistory.setThickness(approving.getThickness());
                     bomHistory.setType(approving.getType());
                     bomHistory.setUnit(approving.getUnit());
-                    bomHistory.setUpUserId(approving.getUpUserId());
+                    //bomHistory.setUpUserId(approving.getUpUserId());
                     bomHistory.setVersion(nextVersion);
 
                     productBomHistoryList.add(bomHistory);
@@ -314,30 +367,34 @@
                 approvingList.forEach(approving->{
                     if(!existCodeList.contains(approving.getSubCode())){ //杩欎釜瀹℃壒bom涓殑鐗╂枡涓嶅湪鐗╂枡绠$悊鍐�
                         Material temp = new Material();
-                        temp.setCategory(approving.getCategory());
+                        //temp.setCategory(approving.getCategory());
                         temp.setCreateDate(new Date());
                         temp.setDwgUrl(approving.getDwgUrl());
                         temp.setFileUrl(approving.getFileUrl());
-                        temp.setMaterial(approving.getMaterial());
+                        //temp.setMaterial(approving.getMaterial());
                         temp.setNotes(approving.getNotes());
                         temp.setPictureUrl(approving.getPictureUrl());
-                        temp.setProducer(approving.getProducer());
-                        temp.setQuantity(approving.getQuantity());
+                        //temp.setProducer(approving.getProducer());
+                        //TODO quantity
+                        //temp.setQuantity(approving.getQuantity());
                         temp.setStatus(1);
                         temp.setSubCode(approving.getSubCode());
                         temp.setSubModel(approving.getSubModel());
                         temp.setSubName(approving.getSubName());
-                        temp.setSurfaceDetail(approving.getSurfaceDetail());
-                        temp.setThickness(approving.getThickness());
+                        //temp.setSurfaceDetail(approving.getSurfaceDetail());
+                        //temp.setThickness(approving.getThickness());
                         temp.setType(approving.getType());
                         temp.setUnit(approving.getUnit());
                         materialList.add(temp);
                     }
                 });
-                mService.insertBatch(materialList);
-
-                //灏哾wg鍥剧焊鍜宲ic鍥剧墖,鍏ㄩ儴鏇存柊鍒板搴旂殑璁板綍url涓� TODO
-
+                if(materialList.size()!=0) {
+                    mService.insertBatch(materialList);
+                }
+                //灏哾wg鍥剧焊,鍏ㄩ儴鏇存柊鍒板搴旂殑璁板綍url涓�
+                if(materialDwgUrlNameList.size()!=0) {
+                    mService.updateDwgUrl(materialDwgUrlNameList);
+                }
                 /*List<ProductBomApproving> fileBomApprovingList = approvingList.stream()
                         .filter(productBomApproving ->
                                 productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null
@@ -376,29 +433,77 @@
             }
             else if(type.intValue() == EnumWorksheetType.Material.getType()){ //鐗╂枡
                 List<MaterialApproving> approvingList = mAService.getListByMainId(link.getMainId());
-                List<Material> MaterialList = new LinkedList<>();
+                List<Material> materialList = new LinkedList<>();
                 //鍖哄垎鏄柊澧炶繕鏄垹闄�
-                Integer MaterialId = approvingList.get(0).getMaterialId();
-                if(MaterialId==null) { //鏂板
+                Integer materialId = approvingList.get(0).getMaterialId();
+                if(materialId==null) { //鏂板
+                    String fileUrl = approvingList.get(0).getFileUrl();
+                    File file = new File(fileUrl);
+
+                    List<String> fileUrlList = new LinkedList<>();
+                    List<String> dwgUrlList = null;
+                    List<String> materialUrlList = new LinkedList<>();
+                    List<Material> materialDwgUrlNameList = new LinkedList<>();
+
+                    fileUrlList = FileUtil.getStaticFilePath(file,fileUrlList);
+                    dwgUrlList = fileUrlList.stream().filter(url->url.contains(".dwg")).collect(Collectors.toList());
+                    //鍥剧焊涓庣墿鏂檓odel瀵瑰簲,鍒欏浘绾搁渶瑕佷繚鐣欏苟杞Щ鍒版寮忔枃浠跺す
+                    //鍚屾椂,淇濈暀鍥剧焊瀵瑰簲鐨勭墿鏂檓odel鍜屾寮忔枃浠跺す涓殑http url
+                    dwgUrlList.forEach(dwgUrl-> {
+                        approvingList.forEach(approving -> {
+                            String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4);
+                            String fileFullName = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1);
+                            if (approving.getSubModel().toUpperCase().equals(filename.toUpperCase())) {
+                                materialUrlList.add(dwgUrl);
+
+                                Material temp = new Material();
+                                temp.setSubModel(approving.getSubModel());
+                                temp.setNotes("doc_file" + File.separator + "material"
+                                        + File.separator + fileFullName);
+                                materialDwgUrlNameList.add(temp);
+                            }
+                        });
+                    });
+                    String projectDir = CommonUtil.getProjectDir();
+                    String materialDir = projectDir + File.separator + "doc_file" + File.separator + "material";
+                    File materialFile = new File(materialDir);
+                    if(!materialFile.exists()){
+                        materialFile.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();
+                        }
+                    });
                     //灏嗙墿鏂欎粠瀹℃壒琛ㄤ腑杞Щ鍒版寮忚〃
                     approvingList.forEach(approve -> {
                         Material material = new Material();
-                        material.setCategory(approve.getCategory());
+                        //material.setCategory(approve.getCategory());
                         material.setSubCode(approve.getSubCode());
                         material.setSubName(approve.getSubName());
                         material.setSubModel(approve.getSubModel());
                         material.setUnit(approve.getUnit());
-                        material.setQuantity(approve.getQuantity());
-                        material.setProducer(approve.getProducer());
+                        //TODO quantity
+                        //material.setQuantity(approve.getQuantity());
+                        //material.setProducer(approve.getProducer());
                         material.setNotes(approve.getNotes());
                         material.setCreateDate(new Date());
                         material.setStatus(1);
-                        MaterialList.add(material);
+                        materialDwgUrlNameList.forEach(materialDwgUrlName->{
+                            if(materialDwgUrlName.getSubModel().equals(approve.getSubModel())){
+                                material.setDwgUrl(materialDwgUrlName.getDwgUrl());
+                            }
+                        });
+                        materialList.add(material);
                     });
-                    mService.insertBatch(MaterialList);
+                    mService.insertBatch(materialList);
                 }else{ //鍒犻櫎
-                    List<Integer> MaterialIdList = approvingList.stream().map(MaterialApproving::getMaterialId).collect(Collectors.toList());
-                    mService.deleteBatch(MaterialIdList);
+                    List<Integer> materialIdList = approvingList.stream().map(MaterialApproving::getMaterialId).collect(Collectors.toList());
+                    mService.deleteBatch(materialIdList);
                 }
                 //鏇存柊鐗╂枡瀹℃壒瀛愯〃涓璽ype涓哄畬缁�
                 mAService.endStatus(link.getMainId());
@@ -406,170 +511,39 @@
             else if(type.intValue() == EnumWorksheetType.MaterialProduct.getType()){ //鏇存柊鐗╂枡-浜у搧鍏崇郴
                 //鏌ユ壘鍒板搴旂殑鐗╂枡-浜у搧鍏崇郴鏁版嵁
                 List<MaterialProductApproving> cpAList = cpAService.getListByMainId(link.getMainId());
-                //鏌ヨ閮ㄤ欢鏈�鏂扮殑鐗堟湰鍙�
-                //lxw淇敼
-                //ProductBom product = bomService.getProduct(cpAList.get(0).getParentModel());
-                ProductBom product=new ProductBom();
-                int currentVersion = -1;
-                if (product != null) {
-                    currentVersion = product.getVersion();
-                }
-                Integer nextVersion = currentVersion + 1;
-                //鍏宠仈/鎺ヨЕ鍏宠仈,鏇存柊鐗堟湰
-                //鏇挎崲,鏇存柊鐗堟湰,鍚屾椂bom琛ㄥ巻鍙蹭腑瀵瑰簲鐨剆ubName 鐗堟湰鍙蜂笉鍙�(鎺掗櫎鏇存柊)
+                //褰撳墠鐗堟湰
+                int version = cpAList.get(0).getVersion();
+                //鏂板鍏宠仈/绉婚櫎鍏宠仈
                 Map<Integer, List<MaterialProductApproving>> linkTypeMap = cpAList.stream().collect(Collectors.groupingBy(MaterialProductApproving::getLinkType));
-                List<MaterialProductApproving> addedList = new LinkedList<>();
-                List<MaterialProductApproving> replacedList = new LinkedList<>();
+                List<MaterialProductHistory> addedList = new LinkedList<>();
                 List<MaterialProductApproving> removedList = new LinkedList<>();
                 linkTypeMap.forEach((linkType,list)->{
                     if(linkType == 1){
-                        addedList.addAll(list);
-                    }else if(linkType == 2){
-                        replacedList.addAll(list);
+                        list.forEach(approving->{
+                            MaterialProductHistory his = new MaterialProductHistory();
+                            his.setParentCode(approving.getParentCode());
+                            his.setCustomCode(approving.getCustomCode());
+                            his.setSVersion(approving.getVersion());
+                            his.setEVersion(approving.getVersion());
+                            his.setSubMaterialId(approving.getSubMaterialId());
+                            his.setQuantity(approving.getQuantity());
+                            his.setMaterialId(approving.getMaterialId());
+                            his.setCreateTime(new Date());
+
+                            addedList.add(his);
+                        });
                     }else{
                         removedList.addAll(list);
                     }
                 });
-                List<MaterialProductHistory> newHistoryList = new LinkedList<>();
-                //鏌ヨ鏈�鏂扮増鏈敓鏁堢殑鐩稿叧鐗╂枡
-                //lxw娉ㄩ噴
-                //List<MaterialProductHistory> nowHistoryList = cphService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion);
-                List<MaterialProductHistory> nowHistoryList =new ArrayList<>();
-                //鏌ヨ鍘嗗彶涓渶鏂扮増鏈敓鏁堢殑bom
-                //List<ProductBomHistory> nowBomHistoryList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion);
-                List<ProductBomHistory> nowBomHistoryList = new ArrayList<>();
-                /*
-                瀵逛簬鍏宠仈鐨�,鍒ゆ柇褰撳墠鐗堟湰涓槸鍚﹀瓨鍦ㄦ浛鎹㈠叧绯�,瀛樺湪,鍒欑洿鎺ヤ笅涓増鏈彃鍏ュ叧鑱�;
-                鍚屾椂,鍏朵粬褰撳墠鐗堟湰鐨勭浉鍏崇墿鏂�-浜у搧璁板綍鏇存柊鐗堟湰,鎺掗櫎瀛樺湪鐨勬浛鎹㈠叧绯�
-                */
-
-                /*
-                瀵逛簬鏇挎崲鐨�,鍒ゆ柇褰撳墠鐗堟湰涓槸鍚﹀瓨鍦ㄥ叧鑱斿叧绯�,瀛樺湪,鐩存帴涓嬩釜鐗堟湰鏇挎崲,璁板綍鎻掑叆;
-                鍚屾椂,褰撳墠鐗堟湰鐨勭浉鍏崇墿鏂�-浜у搧璁板綍鏇存柊鐗堟湰,鎺掗櫎瀛樺湪鐨勫叧鑱斿叧绯�;
-                鍚屾椂,bom琛ㄦ洿鏂板埌涓嬩釜鐗堟湰鏃�,鎺掗櫎琚浛鎹欢
-                */
-
-                //瀵逛簬瑙i櫎鍏宠仈鐨�,褰撳墠鐗堟湰鐨勭浉鍏崇墿鏂�-浜у搧璁板綍鏇存柊鐗堟湰,鎺掗櫎瑙i櫎鍏宠仈鐨勮褰�
-                //澶勭悊鎬濊矾:鍏堣В闄ゅ叧鑱�,鍐嶆浛鎹�,鍐嶅叧鑱�
-                if(removedList.size()!=0){
-                    removedList.forEach(remove -> {
-                        /*nowHistoryList.forEach(nowHistory -> {
-                            if (remove.getMaterialId().intValue() == nowHistory.getMaterialId()) {
-                                nowHistoryList.remove(nowHistory);
-                            }
-                        });*/
-                        Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator();
-                        while (iterator.hasNext()){
-                            MaterialProductHistory next = iterator.next();
-                            //lxw娉ㄩ噴
-                            /*if(remove.getMaterialId().intValue() == next.getMaterialId()
-                                &&remove.getSubName().equals(next.getSubName())
-                            ){
-                                iterator.remove();
-                                break;
-                            }*/
-                        }
-                    });
+                //鏂板鍏宠仈
+                if(addedList.size()!=0) {
+                    mphService.insertBatch(addedList);
                 }
-
-                //澶勭悊鏇挎崲
-                if(replacedList.size()!=0){
-                    replacedList.forEach(replace -> {
-                        //褰撳墠鐢熸晥鐨勭墿鏂�-浜у搧鍒楄〃
-                        /*nowHistoryList.forEach(nowHistory -> {
-                            if (replace.getMaterialId().intValue() == nowHistory.getMaterialId()) {
-                                nowHistoryList.remove(nowHistory);
-                            }
-                        });*/
-                        if(nowHistoryList.size()!=0) {
-                            Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator();
-                            while (iterator.hasNext()) {
-                                MaterialProductHistory next = iterator.next();
-                                //lxw娉ㄩ噴
-                                /*if (replace.getMaterialId().intValue() == next.getMaterialId()
-                                        && replace.getSubName().equals(next.getSubName())
-                                ) {
-                                    iterator.remove();
-                                    break;
-                                }*/
-                            }
-                        }
-                        //涓嬩釜鐗堟湰鏂板鏇挎崲鐨勭墿鏂�-浜у搧鍒楄〃
-                        MaterialProductHistory newHistory = new MaterialProductHistory();
-                        newHistory.setMaterialId(replace.getMaterialId());
-                        //lxw娉ㄩ噴
-                        //newHistory.setParentModel(replace.getParentModel());
-                        //newHistory.setSubName(replace.getSubName());
-                        newHistory.setQuantity(replace.getQuantity());
-                        newHistory.setCreateTime(new Date());
-                        newHistory.setLinkType(2);
-                        //newHistory.setSVersion(nextVersion);
-                        //newHistory.setEVersion(nextVersion);
-                        newHistoryList.add(newHistory);
-                        //褰撳墠鐢熸晥鐨刡om鍒楄〃
-                        /*nowBomHistoryList.forEach(nowBomHistory->{
-                            if(replace.getSubName().equals(nowBomHistory.getSubName())){
-                                nowBomHistoryList.remove(nowBomHistory);
-                            }
-                        });*/
-                        Iterator<ProductBomHistory> iterator1 = nowBomHistoryList.iterator();
-                        while (iterator1.hasNext()){
-                            //lxw娉ㄩ噴
-                            /*if(replace.getSubName().equals(iterator1.next().getSubName())){
-                                iterator1.remove();
-                                break;
-                            }*/
-                        }
-                    });
+                //绉婚櫎鍏宠仈
+                if(removedList.size()!=0) {
+                    mphService.updateVersionSubtractBatch(removedList);
                 }
-
-                //澶勭悊鍏宠仈
-                addedList.forEach(add -> {
-                    /*nowHistoryList.forEach(nowHistory -> {
-                        if (add.getMaterialId().intValue() == nowHistory.getMaterialId()) {
-                            nowHistoryList.remove(nowHistory);
-                        }
-                    });*/
-                    if(nowHistoryList.size()!=0) {
-                        Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator();
-                        while (iterator.hasNext()) {
-                            MaterialProductHistory next = iterator.next();
-                            //lxw娉ㄩ噴
-                            /*if (add.getMaterialId().intValue() == next.getMaterialId()
-                                    && add.getSubName().equals(next.getSubName())
-                            ) {
-                                iterator.remove();
-                                break;
-                            }*/
-                        }
-                    }
-
-                    MaterialProductHistory newHistory = new MaterialProductHistory();
-                    newHistory.setMaterialId(add.getMaterialId());
-                    //newHistory.setParentModel(add.getParentModel());
-                    //newHistory.setSubName(add.getSubName());
-                    newHistory.setQuantity(add.getQuantity());
-                    newHistory.setCreateTime(new Date());
-                    newHistory.setLinkType(1);
-                    //newHistory.setSVersion(nextVersion);
-                    //newHistory.setEVersion(nextVersion);
-                    newHistoryList.add(newHistory);
-
-                });
-
-                //澶勭悊瀹屾垚,杩涜琛ㄥ崟鏁版嵁鏇存柊,鍒嗕负nowHistoryList,newHistoryList,nowBomHistoryList
-                //nowHistoryList.forEach(nowHis->nowHis.setEVersion(nextVersion));
-                //lxw娉ㄩ噴
-                //if(newHistoryList.size()!=0){newHistoryList.forEach(newHis->{newHis.setEVersion(nextVersion);newHis.setSVersion(nextVersion);});}
-                //if(nowBomHistoryList.size()!=0){nowBomHistoryList.forEach(nowBomHis->nowBomHis.setEVersion(nextVersion));}
-
-                if(nowHistoryList.size()!=0){cphService.updateVersionBatch(nowHistoryList);}
-                if(newHistoryList.size()!=0){cphService.insertBatch(newHistoryList);}
-                if(nowBomHistoryList.size()!=0){historyService.updateVersionBatch(nowBomHistoryList);}
-                //鏇存柊ProductBom
-                //lxw娉ㄩ噴
-                //List<ProductBomHistory> newBomList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), nextVersion);
-                //bomService.updateNewBom(newBomList);
             }
             else if(type.intValue() == EnumWorksheetType.ProductSoftware.getType()){ //杞欢涓嬭浇
                 //杞Щ璁板綍鍒版寮忚〃
@@ -618,4 +592,61 @@
     public DocUser getApprovingUser(Integer mainId) {
         return linkMapper.getApprovingUser(mainId);
     }
+
+    @Transactional
+    public Response confirmProductProcedureAndSOP(WorksheetLink link) throws IOException {
+        Integer mainId = linkMapper.selectById(link.getId()).getMainId();
+        //鏇存柊瀛愯〃
+        linkMapper.updateById(link);
+        if(link.getLinkStatus() ==1){
+            //鏌ヨ褰撳墠鍗曟嵁瀛愯〃鏄惁宸茬粡鍏ㄩ儴鍚屾剰
+            QueryWrapper<WorksheetLink> query = Wrappers.query();
+            query.eq("main_id",mainId);
+            List<WorksheetLink> linkList = linkMapper.selectList(query);
+            List<WorksheetLink> rejectList = linkList.stream().filter(linkFilter -> linkFilter.getLinkStatus() != 1).collect(Collectors.toList());
+            if(rejectList == null){
+                //閮戒负1,宸茬‘璁�
+                mainService.updateEndStatusById(mainId,"宸茬‘璁�",5);
+                //鏂囦欢杞Щ鍒板鎵瑰畬鎴愬悗鐨勬寮忚矾寰� 鏂囦欢淇濆瓨鍦�/doc_file/procedure/xxx.doc
+                ProcedureDocApproving approving = procedureDocApprovingService.getByMainId(mainId);
+                String fileRelativePath = approving.getFile();
+                String projectDir = CommonUtil.getProjectDir();
+                String inFilePath = projectDir + File.separator + fileRelativePath;
+                String outFilePath = (projectDir + File.separator + fileRelativePath).replace("_approving","");
+                WordUtil.fillValue(inFilePath,outFilePath,Arrays.asList(approving.getFzr(),approving.getBz(),approving.getZz(),approving.getPb()));
+                //鍒犻櫎涔嬪墠棰勮浜х敓鐨勪腑闂存枃浠�
+                String filename = fileRelativePath.substring(fileRelativePath.lastIndexOf(File.separator)+1,fileRelativePath.lastIndexOf("."));
+                File approvingDir = new File(projectDir + File.separator + "procedure_approving");
+                FilenameFilter filenameFilter = new FilenameFilter() {
+                    @Override
+                    public boolean accept(File dir, String name) {
+                        name = name.substring(0,name.lastIndexOf("."));
+                        if(name.contains(filename) && !name.equals(filename)){
+                            return true;
+                        }
+                        return false;
+                    }
+                };
+                File[] files = approvingDir.listFiles(filenameFilter);
+                for (File file : files) {
+                    file.delete();
+                }
+
+                //娴佺▼鏂囦欢鏁版嵁杞Щ
+                ProcedureDoc procedureDoc = new ProcedureDoc();
+                procedureDoc.setName(approving.getName());
+                procedureDoc.setDescription(approving.getDescription());
+                procedureDoc.setVersion(approving.getVersion());
+                procedureDoc.setFzr(approving.getFzr());
+                procedureDoc.setBz(approving.getBz());
+                procedureDoc.setType(approving.getType());
+                procedureDoc.setCreateTime(new Date());
+                procedureDoc.setFile(fileRelativePath.replace("_approving",""));
+                procedureDocService.insert(procedureDoc);
+            }
+        }else{
+            mainService.updateEndStatusById(mainId,"宸查┏鍥�",0);
+        }
+        return new Response().set(1);
+    }
 }

--
Gitblit v1.9.1