From b848451e8889fea12ce40b7818c1b8d84b50ea02 Mon Sep 17 00:00:00 2001
From: lxw <810412026@qq.com>
Date: 星期四, 01 九月 2022 13:41:07 +0800
Subject: [PATCH] 权限管理组合操作

---
 src/main/java/com/whyc/service/WorksheetMainService.java |  349 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 325 insertions(+), 24 deletions(-)

diff --git a/src/main/java/com/whyc/service/WorksheetMainService.java b/src/main/java/com/whyc/service/WorksheetMainService.java
index 955b24b..51b4873 100644
--- a/src/main/java/com/whyc/service/WorksheetMainService.java
+++ b/src/main/java/com/whyc/service/WorksheetMainService.java
@@ -7,16 +7,24 @@
 import com.whyc.config.EnumWorksheetType;
 import com.whyc.dto.Response;
 import com.whyc.dto.WorksheetMainDTO;
+import com.whyc.dto.WorksheetMainDTO2;
 import com.whyc.mapper.DocUserMapper;
 import com.whyc.mapper.WorksheetLinkMapper;
 import com.whyc.mapper.WorksheetMainMapper;
 import com.whyc.pojo.*;
+import com.whyc.util.CommonUtil;
+import com.whyc.util.Zip4jUtil;
+import org.aspectj.util.FileUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -41,13 +49,40 @@
     private ProductBomApprovingService approvingService;
 
     @Autowired
-    private ComponentProductApprovingService cpApprovingService;
+    private ProductApprovingService paService;
+
+    @Autowired
+    private MaterialProductApprovingService cpApprovingService;
+
+    @Autowired
+    private MaterialApprovingService mApprovingService;
+
+    @Autowired
+    private MaterialService mService;
+
+    @Autowired
+    private ProductBomService pbService;
+
+    @Autowired
+    private MaterialProductHistoryService cphService;
+
+    @Autowired
+    private ProductSoftwareApprovingService psaService;
+
+    @Autowired
+    private ProductSoftwareService productSoftwareService;
+
+    @Autowired
+    private ProductService productService;
+
+    @Autowired
+    private ProductHistoryService productHistoryService;
 
     @Transactional
-    public boolean submit(WorksheetMain main, DocUser user) {
+    public boolean submit(WorksheetMain main, DocUser user) throws IOException {
         main.setType(1);
-        List<ProductBomApproving> bomList = main.getApprovingBomList();
-        int rejectVersion=-1;
+        ProductApproving productApproving = main.getProductApproving();
+        List<ProductBomApproving> bomList = productApproving.getBomApprovingList();
         //鎻愪氦涓昏〃
         main.setCreateUserId(user.getId());
         //鎻愪氦浜鸿鑹叉潵鍒ゆ柇宸ヤ綔娴佸眰绾�
@@ -56,8 +91,6 @@
                 main.setLevel(2);
                 main.setStatus(1);
                 mainMapper.insert(main);
-            }else {
-                rejectVersion = approvingService.getRejectVersion(main.getId());
             }
             //鎻愪氦瀛愯〃
             WorksheetLink link =new WorksheetLink();
@@ -68,7 +101,6 @@
             link.setDealDesc(main.getDealDesc());
             link.setLinkStatus(0);
             link.setEnableArchive(0);
-            link.setRejectVersion(rejectVersion+1);
             linkMapper.insert(link);
         }
         else if(user.getRoleId().equals("1002")){
@@ -76,8 +108,6 @@
                 main.setLevel(1);
                 main.setStatus(2);
                 mainMapper.insert(main);
-            }else {
-                rejectVersion = approvingService.getRejectVersion(main.getId());
             }
             //鎻愪氦瀛愯〃
             WorksheetLink link =new WorksheetLink();
@@ -88,7 +118,6 @@
             link.setDealDesc(main.getDealDesc());
             link.setLinkStatus(0);
             link.setEnableArchive(1);
-            link.setRejectVersion(rejectVersion+1);
             linkMapper.insert(link);
         }
         else if(user.getRoleId().equals("1003")){
@@ -99,12 +128,49 @@
             return false;
         }
         //浜у搧bom/鍥剧焊鍥剧墖鎻愪氦
-        //鏌ヨ褰撳墠椹冲洖鐗堟湰
-        int nextRejectVersion = rejectVersion+1;
+        if(productApproving.getCustomCode()!=null && bomList.get(0).getId()!=null) { //涓庡墠绔害瀹� 瀹氬埗琛ㄥ崟鍙峰叧鑱斾骇鍝�,鍒欏叧鑱旂殑浜у搧id鍐欏叆id
+            Product product = productService.getById(bomList.get(0).getId());
+            List<ProductBom> productBomList = pbService.getBomByProductId(bomList.get(0).getId());
+            //product涓嬬殑鍥剧焊澶嶅埗鍒版柊鐨勫鎵硅矾寰�
+            String rootFile = CommonUtil.getRootFile();
+            String dateFormat = new SimpleDateFormat("YYYY-MM").format(new Date());
+            long timeStamp = System.currentTimeMillis();
+            String filePath = rootFile + "product_approving" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp;
+            String inFilePath = rootFile + "product" + File.separator + product.getParentModel() + File.separator + "standard"+ File.separator + product.getVersion();
+            File parentFile = new File(filePath);
+            //FileCopyUtils.copy(new File(inFilePath),parentFile);
+            FileUtil.copyDir(new File(inFilePath),parentFile);
+            productApproving.setFileUrl(filePath);
+            bomList.clear();
+            productBomList.forEach(bom->{
+                ProductBomApproving approving = new ProductBomApproving();
+                approving.setCategory(bom.getCategory());
+                approving.setSubCode(bom.getSubCode());
+                approving.setSubName(bom.getSubName());
+                approving.setSubModel(bom.getSubModel());
+                approving.setUnit(bom.getUnit());
+                approving.setQuantity(bom.getQuantity());
+                approving.setProducer(bom.getProducer());
+                approving.setMaterial(bom.getMaterial());
+                approving.setThickness(bom.getThickness());
+                approving.setSurfaceDetail(bom.getSurfaceDetail());
+                approving.setNotes(bom.getNotes());
+
+                bomList.add(approving);
+            });
+        }
+        //鍐荤粨(涓嶅惎鐢�)宸插瓨鍦ㄧ殑浜у搧缂栫爜+瀹氬埗淇濆崟鍙�
+        productService.deleteByParentCodeAndCustomCode(productApproving.getParentCode(),productApproving.getCustomCode());
+        productHistoryService.updateEnabledStatus(productApproving.getParentCode(),productApproving.getCustomCode(),0);
+
+        productApproving.setMainId(main.getId());
+        productApproving.setCreateTime(new Date());
+        paService.insert(productApproving);
+
         bomList.forEach(bom->{
-            bom.setMainId(main.getId());
+            //bom.setMainId(main.getId());
+            bom.setProductApprovingId(productApproving.getId());
             bom.setUpUserId(user.getId());
-            bom.setRejectVersion(nextRejectVersion);
             bom.setCreateDate(new Date());
             if(bom.getDwgUrl()==null){
                 bom.setDwgUrl("");
@@ -126,14 +192,14 @@
         return true;
     }
 
-    public boolean componentProductSubmit(WorksheetMainDTO mainDTO, DocUser user) {
-        List<ComponentProductApproving> approvingList = new LinkedList<>();
+    public boolean MaterialProductSubmit(WorksheetMainDTO mainDTO, DocUser user) {
+        List<MaterialProductApproving> approvingList = new LinkedList<>();
         WorksheetMain main = mainDTO.getMain();
-        List<ComponentProductApproving> addedList = mainDTO.getAddedList();
-        List<ComponentProductApproving> replacedList = mainDTO.getReplacedList();
-        List<ComponentProductApproving> removedList = mainDTO.getRemovedList();
+        List<MaterialProductApproving> addedList = mainDTO.getAddedList();
+        //List<MaterialProductApproving> replacedList = mainDTO.getReplacedList();
+        List<MaterialProductApproving> removedList = mainDTO.getRemovedList();
 
-        main.setType(EnumWorksheetType.ComponentProduct.getType());
+        main.setType(EnumWorksheetType.MaterialProduct.getType());
         //鎻愪氦涓昏〃
         main.setCreateUserId(user.getId());
         //鎻愪氦浜鸿鑹叉潵鍒ゆ柇宸ヤ綔娴佸眰绾�
@@ -178,7 +244,7 @@
         }else{
             return false;
         }
-        //鏁h浠�-浜у搧瀹℃壒鎻愪氦
+        //鐗╂枡-浜у搧瀹℃壒鎻愪氦
         if(addedList!=null && addedList.size()!=0){
             addedList.forEach(item->{
                 item.setMainId(main.getId());
@@ -186,13 +252,13 @@
             });
             approvingList.addAll(addedList);
         }
-        if(replacedList!=null && replacedList.size()!=0){
+        /*if(replacedList!=null && replacedList.size()!=0){
             replacedList.forEach(item->{
                 item.setMainId(main.getId());
                 item.setLinkType(2);
             });
             approvingList.addAll(replacedList);
-        }
+        }*/
         if(removedList!=null && removedList.size()!=0){
             removedList.forEach(item->{
                 item.setMainId(main.getId());
@@ -202,6 +268,230 @@
         }
         cpApprovingService.insert(approvingList);
         return true;
+    }
+
+    public Response materialSubmit(WorksheetMain main, DocUser user) {
+        Response<Object> response = new Response<>();
+        List<MaterialApproving> mApprovingList = main.getMApprovingList();
+        //鍒ゆ柇鏄柊澧炶繕鏄垹闄�
+        boolean isAdded = mApprovingList.get(0).getSubName()!=null;
+        if(isAdded) { //鏂板
+            //鏌ヨ鏄惁鏈� 宸茬敓鏁堟垨鑰呭凡鎻愪氦瀹℃壒鐨� 鐩稿悓鐨勭墿鏂�
+            List<Material> existMaterialList = new LinkedList<>();
+            List<MaterialApproving> existCAList = new LinkedList<>();
+
+            List<Material> materialList = mService.getList();
+            List<MaterialApproving> cAList = mApprovingService.getListByStatus(1);
+            for (int i = 0; i < mApprovingList.size(); i++) {
+                MaterialApproving materialApproving = mApprovingList.get(i);
+                for (int j = 0; j < materialList.size(); j++) {
+                    if (materialApproving.getSubCode().equals(materialList.get(j).getSubCode())
+                            && materialApproving.getSubName().equals(materialList.get(j).getSubName())
+                            && materialApproving.getSubModel().equals(materialList.get(j).getSubModel())
+                    ) {
+                        existMaterialList.add(materialList.get(j));
+                    }
+                }
+
+                for (int j = 0; j < cAList.size(); j++) {
+                    if (materialApproving.getSubCode().equals(cAList.get(j).getSubCode())
+                            && materialApproving.getSubName().equals(cAList.get(j).getSubName())
+                            && materialApproving.getSubModel().equals(cAList.get(j).getSubModel())
+                    ) {
+                        existCAList.add(cAList.get(j));
+                    }
+                }
+            }
+
+            int existCASize = existCAList.size();
+            int existMaterialSize = existMaterialList.size();
+            if (existCASize != 0) {
+                if (existMaterialSize != 0) {
+                    response.setII(21, existCAList, existMaterialList, "閲嶅鎻愪氦:鐜版湁鐗╂枡鍙婃鍦ㄨ繘琛屽鎵圭殑鐗╂枡涓�,瀛樺湪褰撳墠鎻愪氦涓婁紶鐨勭墿鏂�");
+                } else {
+                    response.set(22, existCAList, "閲嶅鎻愪氦:姝e湪杩涜瀹℃壒鐨勭墿鏂欎腑,瀛樺湪褰撳墠鎻愪氦涓婁紶鐨勭墿鏂�");
+                }
+                return response;
+            } else {
+                if (existMaterialSize != 0) {
+                    return response.setII(23, null, existMaterialList, "閲嶅鎻愪氦:鐜版湁鐗╂枡涓�,瀛樺湪褰撳墠鎻愪氦涓婁紶鐨勭墿鏂�");
+                }
+            }
+        }else{ //鍒犻櫎
+            //鍒ゆ柇鏄惁鍦ㄧ墿鏂欏鎵瑰垹闄や腑,鏄惁瀛樺湪浜у搧鍏宠仈鍙婂叧鑱斿鎵�
+            MaterialApproving deleteApproving = new MaterialApproving();
+            List<MaterialProductHistory> existMaterialProducts = new LinkedList<>();
+            List<MaterialProductApproving> existMaterialProductApprovingList = new LinkedList<>();
+            deleteApproving = mApprovingService.getListByMaterialId(mApprovingList.get(0).getMaterialId());
+
+            //鏌ョ湅浜у搧鍏宠仈
+            List<MaterialProductHistory> cphLatestExistList =  cphService.getLatestExistListByMaterialId(mApprovingList.get(0).getMaterialId());
+            //鏌ョ湅浜у搧鍏宠仈瀹℃壒
+            List<MaterialProductApproving> cpaLatestExistList = cpApprovingService.getLatestExistListByMaterialId(mApprovingList.get(0).getMaterialId());
+            if(deleteApproving!=null){
+                return response.set(31,deleteApproving,"鎷掔粷鏈鍒犻櫎鐢宠,褰撳墠鐗╂枡姝e湪杩涜鍒犻櫎瀹℃壒");
+            }
+            if(cphLatestExistList!=null && cphLatestExistList.size()!=0){
+                if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){
+                    return response.setII(32,cpaLatestExistList,cphLatestExistList,"鎷掔粷鏈鍒犻櫎鐢宠,褰撳墠鏁h宸茬粡鍏宠仈浜у搧鍙婂湪浜у搧鍏宠仈瀹℃壒");
+                }else{
+                    return response.setII(33,null,cphLatestExistList,"鎷掔粷鏈鍒犻櫎鐢宠,褰撳墠鐗╂枡鍦ㄤ骇鍝佸叧鑱斿鎵�");
+                }
+            }else{
+                if(cpaLatestExistList!=null && cpaLatestExistList.size()!=0){
+                    return response.set(34,cpaLatestExistList,"鎷掔粷鏈鍒犻櫎鐢宠,褰撳墠鐗╂枡宸茬粡鍏宠仈浜у搧");
+                }
+            }
+
+        }
+        main.setType(EnumWorksheetType.Material.getType());
+        //鎻愪氦涓昏〃
+        main.setCreateUserId(user.getId());
+        //鎻愪氦浜鸿鑹叉潵鍒ゆ柇宸ヤ綔娴佸眰绾�
+        if(user.getRoleId().equals("1001")){
+            if(main.getId()==null) {
+                main.setLevel(2);
+                main.setStatus(1);
+                mainMapper.insert(main);
+            }
+            //鎻愪氦瀛愯〃
+            WorksheetLink link =new WorksheetLink();
+            link.setMainId(main.getId());
+            link.setParentId(0);
+            link.setDealUserId(main.getNextUser());
+            link.setDealType(1);
+            link.setDealDesc(main.getDealDesc());
+            link.setLinkStatus(0);
+            link.setEnableArchive(0);
+            linkMapper.insert(link);
+        }
+        else if(user.getRoleId().equals("1002")){
+            if(main.getId()==null) {
+                main.setLevel(1);
+                main.setStatus(2);
+                mainMapper.insert(main);
+            }
+            //鎻愪氦瀛愯〃
+            WorksheetLink link =new WorksheetLink();
+            link.setMainId(main.getId());
+            link.setParentId(0);
+            link.setDealUserId(main.getNextUser());
+            link.setDealType(2);
+            link.setDealDesc(main.getDealDesc());
+            link.setLinkStatus(0);
+            link.setEnableArchive(1);
+            linkMapper.insert(link);
+        }
+        else if(user.getRoleId().equals("1003")){
+            main.setLevel(0);
+            main.setStatus(5);
+            mainMapper.insert(main);
+        }else{
+            return response.set(3);
+        }
+        //鐗╂枡-瀹℃壒鎻愪氦
+        mApprovingList.forEach(cApproving->{
+            cApproving.setCreateDate(new Date());
+            cApproving.setMainId(main.getId());
+            cApproving.setStatus(1);
+        });
+
+        mApprovingService.insert(mApprovingList);
+        return response.set(1);
+    }
+
+    public Response productSoftwareSubmit(MultipartFile file, WorksheetMainDTO2 mainDTO, DocUser user) throws IOException {
+        Response response = new Response();
+        WorksheetMain main = mainDTO.getMain();
+        ProductSoftwareApproving approving = mainDTO.getApproving();
+        //棣栧厛鏍¢獙鏂囦欢鍚嶆槸鍚﹀凡瀛樺湪
+        String filename = file.getOriginalFilename();
+        List<ProductSoftwareApproving> softwareApprovingList = psaService.getAll();
+        List<ProductSoftware> softwareList = productSoftwareService.getAll();
+        List<String> existApprovingList = softwareApprovingList.stream().map(ProductSoftwareApproving::getSoftwareName).collect(Collectors.toList());
+        List<String> existList = softwareList.stream().map(ProductSoftware::getSoftwareName).collect(Collectors.toList());
+
+        for (String existFilename:existList){
+            if(filename.equals(existFilename)){
+                return response.set(1,false,"杞欢鏂囦欢鍚嶅凡瀛樺湪");
+            }
+        }
+        for (String existFilename:existApprovingList){
+            if(filename.equals(existFilename)){
+                return response.set(1,false,"杞欢鏂囦欢鍚嶅湪瀹℃壒鍒楄〃涓凡瀛樺湪");
+            }
+        }
+
+        main.setType(1);
+        //鎻愪氦涓昏〃
+        main.setCreateUserId(user.getId());
+        //鎻愪氦浜鸿鑹叉潵鍒ゆ柇宸ヤ綔娴佸眰绾�
+        if(user.getRoleId().equals("1001")){
+            if(main.getId()==null) {
+                main.setLevel(2);
+                main.setStatus(1);
+                mainMapper.insert(main);
+            }
+            //鎻愪氦瀛愯〃
+            WorksheetLink link =new WorksheetLink();
+            link.setMainId(main.getId());
+            link.setParentId(0);
+            link.setDealUserId(main.getNextUser());
+            link.setDealType(1);
+            link.setDealDesc(main.getDealDesc());
+            link.setLinkStatus(0);
+            link.setEnableArchive(0);
+            linkMapper.insert(link);
+        }
+        else if(user.getRoleId().equals("1002")){
+            if(main.getId()==null) {
+                main.setLevel(1);
+                main.setStatus(2);
+                mainMapper.insert(main);
+            }
+            //鎻愪氦瀛愯〃
+            WorksheetLink link =new WorksheetLink();
+            link.setMainId(main.getId());
+            link.setParentId(0);
+            link.setDealUserId(main.getNextUser());
+            link.setDealType(2);
+            link.setDealDesc(main.getDealDesc());
+            link.setLinkStatus(0);
+            link.setEnableArchive(1);
+            linkMapper.insert(link);
+        }
+        else if(user.getRoleId().equals("1003")){
+            main.setLevel(0);
+            main.setStatus(5);
+            mainMapper.insert(main);
+        }else{
+            return response.set(1,false,"瑙掕壊鏃犳硶鎻愪氦瀹℃壒");
+        }
+        //杞寲涓哄鎵硅矾寰�
+        //妫�鏌ユ槸鍚︿负zip
+        boolean isZip = Zip4jUtil.checkZipFileParam(file);
+        if(!isZip){
+            return response.set(1,false,"涓婁紶鐨勬枃浠舵牸寮忎笉鏄痾ip");
+        }
+        //zip瀛樺偍璺緞:doc_file/product_approving/${username}/{dateFormat}/${timeStamp}
+        String rootFile = CommonUtil.getRootFile();
+        String dateFormat = new SimpleDateFormat("YYYY-MM").format(new Date());
+        long timeStamp = System.currentTimeMillis();
+        String productSoftwarePath =  File.separator + "product_software" + File.separator + user.getName() + File.separator + dateFormat+ File.separator + timeStamp;
+        String filePath = rootFile + productSoftwarePath;
+        String originalFilename = file.getOriginalFilename();
+        File zipFile = new File(filePath+File.separator+ originalFilename);
+        if(!zipFile.exists()){
+            zipFile.mkdirs();
+        }
+        file.transferTo(zipFile);
+        approving.setSoftwareUrl("doc_file"+productSoftwarePath+File.separator+ originalFilename);
+        approving.setSoftwareName(originalFilename);
+        approving.setCreateTime(new Date());
+        approving.setMainId(main.getId());
+        //浜у搧杞欢鎻愪氦
+        psaService.insert(approving);
+        return response.set(1,true, "鎻愪氦瀹屾垚");
     }
 
     public WorksheetMain getInfoById(Integer id) {
@@ -353,7 +643,18 @@
     }
 
     public WorksheetMain getLinkList(int id) {
-        return mainMapper.getLinkList(id);
+         //鍒ゆ柇鏄摢绉嶇被鍨嬬殑瀹℃壒,杩斿洖涓嶅悓鐨勭被鍨� 鍏蜂綋鏁版嵁
+        Integer type = getInfoById(id).getType();
+        if(type.intValue() == EnumWorksheetType.ProductBom.getType()) {
+            WorksheetMain main = mainMapper.getLinkList(id);
+            List<ProductBomApproving> pbaList = approvingService.getList(main.getProductApproving().getId());
+            main.getProductApproving().setBomApprovingList(pbaList);
+            return main;
+        }else if(type.intValue() == EnumWorksheetType.Material.getType()){
+            return mainMapper.getLinkListWithMaterials(id);
+        }else{ //鐗╂枡-浜у搧
+            return mainMapper.getLinkListWithMaterialProducts(id);
+        }
     }
 
     public Response<PageInfo<WorksheetMain>> getApprovingListPage(DocUser user, int pageNum, int pageSize) {

--
Gitblit v1.9.1