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/WorksheetMainService.java |  921 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 907 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/whyc/service/WorksheetMainService.java b/src/main/java/com/whyc/service/WorksheetMainService.java
index 0b1f223..246689d 100644
--- a/src/main/java/com/whyc/service/WorksheetMainService.java
+++ b/src/main/java/com/whyc/service/WorksheetMainService.java
@@ -1,12 +1,38 @@
 package com.whyc.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.whyc.config.EnumWorksheetType;
+import com.whyc.dto.MailDTO;
+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.WorksheetLink;
-import com.whyc.pojo.WorksheetMain;
+import com.whyc.pojo.*;
+import com.whyc.util.CommonUtil;
+import com.whyc.util.Word2PdfAsposeUtil;
+import com.whyc.util.WordUtil;
+import com.whyc.util.Zip4jUtil;
+import org.aspectj.util.FileUtil;
+import org.springframework.beans.BeanUtils;
+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 javax.mail.MessagingException;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class WorksheetMainService {
@@ -17,18 +43,885 @@
     @Resource
     private WorksheetLinkMapper linkMapper;
 
-    public void submit(WorksheetMain main) {
-        //鎻愪氦宸ュ崟涓昏〃
+    @Autowired
+    @Lazy
+    private WorksheetLinkService linkService;
+
+    @Resource
+    private DocUserMapper userMapper;
+
+    @Autowired
+    @Lazy
+    private ProductBomApprovingService approvingService;
+
+    @Autowired
+    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;
+
+    @Autowired
+    private MailService mailService;
+
+    @Autowired
+    private ProcedureDocApprovingService procedureDocApprovingService;
+
+    @Transactional
+    public boolean submit(WorksheetMain main, DocUser user) throws IOException {
+        main.setType(1);
+        ProductApproving productApproving = main.getProductApproving();
+        List<ProductBomApproving> bomList = productApproving.getBomApprovingList();
+        //鎻愪氦涓昏〃
+        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 false;
+        }
+        //浜у搧bom/鍥剧焊鍥剧墖鎻愪氦
+        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.setProductApprovingId(productApproving.getId());
+            bom.setUpUserId(user.getId());
+            bom.setCreateDate(new Date());
+            if(bom.getDwgUrl()==null){
+                bom.setDwgUrl("");
+            }else {
+                bom.setDwgUrl(bom.getDwgUrl());
+            }
+            if(bom.getFileUrl()==null){
+                bom.setFileUrl("");
+            }else {
+                bom.setFileUrl(bom.getFileUrl());
+            }
+            if(bom.getPictureUrl()==null){
+                bom.setPictureUrl("");
+            }else{
+                bom.setPictureUrl(bom.getPictureUrl());
+            }
+        });
+        approvingService.insert(bomList);
+        return true;
+    }
+
+    public boolean MaterialProductSubmit(WorksheetMainDTO mainDTO, DocUser user) {
+        List<MaterialProductApproving> approvingList = new LinkedList<>();
+        WorksheetMain main = mainDTO.getMain();
+        List<MaterialProductApproving> addedList = mainDTO.getAddedList();
+        //List<MaterialProductApproving> replacedList = mainDTO.getReplacedList();
+        List<MaterialProductApproving> removedList = mainDTO.getRemovedList();
+
+        main.setType(EnumWorksheetType.MaterialProduct.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 false;
+        }
+        //鐗╂枡-浜у搧瀹℃壒鎻愪氦
+        if(addedList!=null && addedList.size()!=0){
+            addedList.forEach(item->{
+                item.setMainId(main.getId());
+                item.setLinkType(1);
+            });
+            approvingList.addAll(addedList);
+        }
+        /*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());
+                item.setLinkType(-1);
+            });
+            approvingList.addAll(removedList);
+        }
+        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 parentFile = new File(filePath);
+        if (!parentFile.exists()) {
+            parentFile.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) {
+        return mainMapper.selectById(id);
+    }
+
+    public void updateStatusById(Integer id,Integer status) {
+        WorksheetMain main = new WorksheetMain();
+        main.setId(id);
+        main.setStatus(status);
+        mainMapper.updateById(main);
+    }
+
+    public void updateEndStatusById(Integer id,String endReason,Integer status) {
+        WorksheetMain main = new WorksheetMain();
+        main.setId(id);
+        main.setStatus(status);
+        main.setEndReason(endReason);
+        main.setEndTime(new Date());
+        mainMapper.updateById(main);
+    }
+
+    /**
+     * 鐢ㄦ埛瀵瑰簲鐨勫伐浣滃彴鏁版嵁鍒嗙被
+     * @param user
+     * @return*/
+    public Map<String, Integer> getStatusStatistic(DocUser user) {
+        Map<String,Integer> map = new HashMap<>();
+        switch (user.getRoleId()){
+            //鏅�氬憳宸�
+            case "1001":
+                {
+                    //鏈鐞�(瀹℃壒涓�)/宸查┏鍥�/宸插鎵�
+                    map.put("rejected",0);
+                    map.put("approving",0);
+                    map.put("approved",0);
+                    QueryWrapper<WorksheetMain> query = Wrappers.query();
+                    query.eq("create_user_id",user.getId());
+                    List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
+                    Map<Integer, List<WorksheetMain>> groupingList = worksheetMainList.stream().collect(Collectors.groupingBy(WorksheetMain::getStatus));
+                    groupingList.forEach((status,mainList)->{
+                        switch (status){
+                            case 0:{
+                                map.put("rejected",mainList.size());
+                            }break;
+                            case 1:
+                            case 2:{
+                                Integer addedMainCount= map.get("approving");
+                                if(addedMainCount ==0){
+                                    map.put("approving",mainList.size());
+                                }else{
+                                    map.put("approving",addedMainCount+mainList.size());
+                                }
+                            }break;
+                            case 5:{
+                                map.put("approved",mainList.size());
+                            }break;
+                        }
+                    });
+                }
+                break;
+            //椤圭洰缁忕悊
+            case "1002":
+                {
+                    //寰呭鐞�/宸插鐞�/灞炰簬鑷繁-瀹℃壒涓�/宸查┏鍥�/宸插鎵�
+                    //灞炰簬鑷繁-瀹℃壒涓�/宸查┏鍥�/宸插鎵�
+                    map.put("rejected",0);
+                    map.put("approving",0);
+                    map.put("approved",0);
+                    map.put("handling",0);
+                    map.put("handled",0);
+
+                    QueryWrapper<WorksheetMain> query = Wrappers.query();
+                    query.eq("create_user_id",user.getId());
+                    List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
+                    Map<Integer, List<WorksheetMain>> groupingList = worksheetMainList.stream().collect(Collectors.groupingBy(WorksheetMain::getStatus));
+                    groupingList.forEach((status,mainList)->{
+                        switch (status){
+                            case 0:{
+                                map.put("rejected",mainList.size());
+                            }break;
+                            case 2:{
+                                map.put("approving",mainList.size());
+                            }break;
+                            case 5:{
+                                map.put("approved",mainList.size());
+                            }break;
+                        }
+                    });
+                    //寰呭鐞�/宸插鐞�
+                    List<WorksheetLink> WorksheetLinkList = linkService.getInfoList(user.getId());
+                    Map<Integer, List<WorksheetLink>> groupingLinkList = WorksheetLinkList.stream().collect(Collectors.groupingBy(WorksheetLink::getLinkStatus));
+                    groupingLinkList.forEach((linkStatus,linkList)->{
+                        List<WorksheetMain> mainList = new LinkedList<>();
+                        linkList.forEach(link -> {mainList.add(link.getMain());});
+                        switch (linkStatus){
+                            case 0:{
+                                map.put("handling",mainList.size());
+                            }break;
+                            case 1:
+                            case 2:{
+                                Integer addedMainCount= map.get("handled");
+                                if(addedMainCount ==0){
+                                    map.put("handled",mainList.size());
+                                }else{
+                                    map.put("handled",addedMainCount+mainList.size());
+                                }
+                            }break;
+                        }
+                    });
+                }
+                break;
+            //鎬荤粡鐞�
+            case "1003":
+                {
+                    //寰呭鐞�/宸插鎵�
+                    map.put("handling",0);
+                    map.put("approved",0);
+                    List<WorksheetLink> WorksheetLinkList = linkService.getInfoList(user.getId());
+                    Map<Integer, List<WorksheetLink>> groupingLinkList = WorksheetLinkList.stream().collect(Collectors.groupingBy(WorksheetLink::getLinkStatus));
+                    groupingLinkList.forEach((linkStatus,linkList)->{
+                        List<WorksheetMain> mainList = new LinkedList<>();
+                        linkList.forEach(link -> {mainList.add(link.getMain());});
+                        switch (linkStatus){
+                            case 0:{
+                                map.put("handling",mainList.size());
+                            }break;
+                            case 1:
+                            case 2:{
+                                Integer addedMainCount= map.get("approved");
+                                if(addedMainCount ==0){
+                                    map.put("approved",mainList.size());
+                                }else{
+                                    map.put("approved",addedMainCount+mainList.size());
+                                }
+                            }break;
+                        }
+                    });
+                }
+                break;
+        }
+        //鏌ヨ鎴戠殑宸ュ崟鏁伴噺
+        QueryWrapper<WorksheetMain> query = Wrappers.query();
+        query.eq("create_user_id",user.getId());
+        Integer count = mainMapper.selectCount(query);
+        map.put("my",count);
+
+        return map;
+    }
+
+    public WorksheetMain getLinkList(int 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) {
+        PageHelper.startPage(pageNum,pageSize);
+        QueryWrapper<WorksheetMain> query = Wrappers.query();
+        query.eq("create_user_id",user.getId()).in("status",1,2).orderByDesc("id");
+        List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
+        //鏌ヨ涓昏〃鐘舵�佸搴旂殑瀛愯〃
+        worksheetMainList.forEach(main -> {
+            main.setApprovingUser(linkService.getApprovingUser(main.getId()));
+        });
+        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
+        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
+    }
+
+    public Response<PageInfo<WorksheetMain>> getRejectedListPage(DocUser user, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum,pageSize);
+        QueryWrapper<WorksheetMain> query = Wrappers.query();
+        query.eq("create_user_id",user.getId()).in("status",0).orderByDesc("id");
+        List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
+        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
+        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
+    }
+
+    public Response<PageInfo<WorksheetMain>> getApprovedListPage(DocUser user, int pageNum, int pageSize) {
+        Response<PageInfo<WorksheetMain>> response = new Response<>();
+        PageHelper.startPage(pageNum,pageSize);
+        List<WorksheetMain> worksheetMainList = null;
+        //鑷繁鐨勫伐鍗�
+        if(!user.getRoleId().equals("1003")){
+            QueryWrapper<WorksheetMain> query = Wrappers.query();
+            query.eq("create_user_id",user.getId()).in("status",5).orderByDesc("id");
+            worksheetMainList = mainMapper.selectList(query);
+
+        }else{
+            //鎬荤粡鐞�,鑺傜偣瀹℃壒浜轰负鑷繁
+            worksheetMainList = linkService.getInfoList2(user.getId(),1);
+        }
+        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
+        return response.set(1,pageInfo);
+    }
+
+    public Response<PageInfo<WorksheetMain>> getHandlingListPage(DocUser user, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum,pageSize);
+        List<WorksheetMain> worksheetMainList = linkService.getInfoList3(user.getId(),0);
+        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
+        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
+    }
+
+    public Response<PageInfo<WorksheetMain>> getHandledListPage(DocUser user, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum,pageSize);
+        List<WorksheetMain> worksheetMainList = linkService.getInfoList3(user.getId(),1);
+        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
+        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
+    }
+
+    public WorksheetMain getInfo(int id) {
+         return mainMapper.selectById(id);
+    }
+
+    public Response<PageInfo<WorksheetMain>> getMyList(int pageNum, int pageSize, DocUser user) {
+        PageHelper.startPage(pageNum,pageSize);
+        QueryWrapper<WorksheetMain> query = Wrappers.query();
+        query.eq("create_user_id",user.getId()).orderByDesc("id");
+        List<WorksheetMain> worksheetMainList = mainMapper.selectList(query);
+        PageInfo<WorksheetMain> pageInfo = new PageInfo<>(worksheetMainList);
+        return new Response<PageInfo<WorksheetMain>>().set(1,pageInfo);
+
+    }
+
+    public Response addProductProcedureAndSOP(ProcedureDocApproving approving, DocUser user) throws IOException, MessagingException {
+        WorksheetMain main = new WorksheetMain();
+         //瀛樺偍涓婁紶淇℃伅鍒颁富琛�,鑺傜偣琛�
+        //鏂囦欢淇濆瓨鍦�/doc_file/procedure_approving/xxx_鏃堕棿鎴�.doc
+        MultipartFile multipartFile = approving.getMultipartFile();
+        String originalFilename = multipartFile.getOriginalFilename();
+        String rootFile = CommonUtil.getRootFile();
+        Date date = new Date();
+        String filename = originalFilename.replace(".doc","_"+date.getTime()+".doc");
+        String suffixFilePath = "procedure_approving" + File.separator + filename;
+        String outFilePath = rootFile + suffixFilePath;
+        File outFile = new File(outFilePath);
+        multipartFile.transferTo(outFile);
+
+        main.setTitle(approving.getName());
+        main.setDescription(approving.getDescription());
+        main.setCreateUserId(user.getId());
+        main.setBeginTime(date);
+        main.setStatus(1);
+        if(approving.getType()==1){
+            main.setType(EnumWorksheetType.ProductProcedure.getType());
+        }else{
+            main.setType(EnumWorksheetType.SOP.getType());
+        }
         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);
+
+        List<WorksheetLink> links = new LinkedList<>();
+        WorksheetLink baseLink = new WorksheetLink();
+        WorksheetLink linkFzr = new WorksheetLink();
+        WorksheetLink linkBz = new WorksheetLink();
+        WorksheetLink linkZz = new WorksheetLink();
+        WorksheetLink linkPb = new WorksheetLink();
+
+        baseLink.setMainId(main.getId());
+        baseLink.setLinkStatus(0);
+        baseLink.setCreateTime(date);
+
+        BeanUtils.copyProperties(baseLink,linkFzr);
+        BeanUtils.copyProperties(baseLink,linkBz);
+        BeanUtils.copyProperties(baseLink,linkZz);
+        BeanUtils.copyProperties(baseLink,linkPb);
+
+        linkFzr.setDealUserId(approving.getFzr());
+        linkBz.setDealUserId(approving.getBz());
+        linkZz.setDealUserId(approving.getZz());
+        linkPb.setDealUserId(approving.getPb());
+        links.add(linkFzr);
+        links.add(linkBz);
+        links.add(linkZz);
+        links.add(linkPb);
+        linkMapper.insertBatchSomeColumn(links);
+
+        //娴佺▼鏂囨。瀹℃壒瀛愯〃瀛樺叆
+        approving.setFile("doc_file"+ File.separator + suffixFilePath);
+        approving.setMainId(main.getId());
+        procedureDocApprovingService.insert(approving);
+        //鍙戦�侀偖浠剁粰鍥涗釜纭浜�
+        QueryWrapper<DocUser> query = Wrappers.query();
+        query.select("mail").in("id",approving.getFzr(),approving.getBz(),approving.getZz(),approving.getPb());
+        List<DocUser> docUsers = userMapper.selectList(query);
+        List<String> userMailList = docUsers.stream().map(DocUser::getMail).collect(Collectors.toList());
+
+        MailDTO mailDTO = new MailDTO();
+        mailDTO.setMailList(userMailList);
+        if(approving.getType()==1){
+            mailDTO.setTitle("銆愭祦绋嬪崱纭銆�"+main.getTitle());
+            mailDTO.setContent(user.getName()+"鍦ㄦ枃妗g鐞嗗钩鍙颁笂浼犱簡浜у搧娴佺▼鍗�,璇峰強鏃剁‘璁�");
+        }else{
+            mailDTO.setTitle("銆怱OP纭銆�"+main.getTitle());
+            mailDTO.setContent(user.getName()+"鍦ㄦ枃妗g鐞嗗钩鍙颁笂浼犱簡SOP,璇峰強鏃剁‘璁�");
+        }
+        mailService.sendMail(mailDTO);
+
+        return new Response().setII(1,"涓婁紶瀹屾垚");
+    }
+
+    /**
+     * 缁熻鏁伴噺:
+     *  鎴戠殑鎻愪氦
+     *  寰呭鐞�
+     *  宸插鐞�
+     * @param user
+     * @return
+     */
+    public Map<String, Integer> getProcedureDocApprovingStatusStatistic(DocUser user) {
+        Map<String,Integer> map = new HashMap<>();
+
+        //鎴戠殑鎻愪氦
+        QueryWrapper<WorksheetMain> query = Wrappers.query();
+        query.eq("create_user_id",user.getId()).in("type",EnumWorksheetType.ProductProcedure.getType(),EnumWorksheetType.SOP.getType());
+        List<WorksheetMain> worksheetMains = mainMapper.selectList(query);
+        map.put("mySubmit",worksheetMains.size());
+        //寰呭鐞唡宸插鐞�
+        int handlingCount = 0;
+        int handledCount = 0;
+        List<WorksheetLink> links = linkMapper.getProcedureDocApprovingByUserId(user.getId());
+        for (WorksheetLink link : links) {
+            //dealType鐨勫�间负涓昏〃鐨勭姸鎬�
+            if(link.getDealType() == 1 && link.getLinkStatus() == 0){ //鏈鐞嗕笖瀹℃壒鏈粨鏉�
+                handlingCount++;
+            }else if(link.getLinkStatus() == 1 || link.getLinkStatus() ==2){ //宸茬‘璁ゆ垨宸叉嫆缁�
+                handledCount++;
+            }
+        }
+        map.put("handling",handlingCount);
+        map.put("handled",handledCount);
+        return map;
+    }
+
+    public Response procedurePreview(HttpServletResponse response, int mainId) throws IOException {
+        //鏌ヨ褰撳墠鍗曟嵁瀹℃壒浜虹殑纭鐘舵��
+        ProcedureDocApproving approving = procedureDocApprovingService.getByMainId(mainId);
+        List<WorksheetLink> linkList = linkMapper.getList(mainId);
+        String fzr = linkList.get(0).getLinkStatus() == 1 ? linkList.get(0).getDealUsername():"";
+        String bz = linkList.get(1).getLinkStatus() == 1 ? linkList.get(1).getDealUsername():"";
+        String zz = linkList.get(2).getLinkStatus() == 1 ? linkList.get(2).getDealUsername():"";
+        String pb = linkList.get(3).getLinkStatus() == 1 ? linkList.get(3).getDealUsername():"";
+        List<String> list = new LinkedList();
+        list.add(fzr);
+        list.add(bz);
+        list.add(zz);
+        list.add(pb);
+        //鑾峰彇word妯℃澘鍏蜂綋鏂囦欢
+
+        long currentTimeMillis = System.currentTimeMillis();
+        String projectDir = CommonUtil.getProjectDir();
+        String fileRelativePath = approving.getFile();
+        String inFilePath = projectDir + File.separator + fileRelativePath;
+        String outFilePath = inFilePath.replace(".doc","_"+currentTimeMillis+".doc");
+        WordUtil.fillValue(inFilePath,outFilePath,list);
+        //pdf甯︽按鍗扮殑鍦板潃 /doc_file/procedure_approving/xxx.doc
+        String suffixOutPdfFilePath = "doc_file" + File.separator + "procedure_approving" + File.separator + outFilePath.substring(outFilePath.lastIndexOf(File.separator)+1,outFilePath.lastIndexOf(".")) + ".pdf";
+        String outPdfFilePath = projectDir + File.separator + suffixOutPdfFilePath;
+        Word2PdfAsposeUtil.doc2pdfWithWaterMark(outFilePath,outPdfFilePath,true);
+        return new Response().setII(1,suffixOutPdfFilePath);
+        /*try {
+            // 杞爜闃叉涔辩爜
+            //resp.addHeader("Content-Disposition", "attachment;filename=" + new String(softwareName.getBytes("UTF-8"), "ISO8859-1"));
+            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( fileRelativePath.substring(fileRelativePath.lastIndexOf(File.separator+1)), "utf-8"));
+            OutputStream out = response.getOutputStream();
+            FileInputStream in = new FileInputStream(outFilePath);
+            int len=0;
+            byte[] buffer =new byte[1024];
+            //7. 灏嗙紦鍐插尯涓殑鏁版嵁杈撳嚭
+            while ((len=in.read(buffer))>0){
+                out.write(buffer,0,len);
+            }
+            in.close();
+            out.close();
+        } catch (FileNotFoundException | UnsupportedEncodingException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }*/
+    }
+
+    /**
+     * 鏌ヨ鎵�鏈夌殑宸ュ崟,鎵�鏈変汉鍙
+     * @param param
+     * @return
+     */
+    public Response getAllPage(WorksheetMain param) {
+        Integer pageNum = param.getPageNum();
+        Integer pageSize = param.getPageSize();
+        PageHelper.startPage(pageNum,pageSize);
+
+        int createUserId = param.getCreateUserId().intValue();
+        Date beginTime = param.getBeginTime();
+        Date endTime = param.getEndTime();
+        Integer type = param.getType();
+        QueryWrapper<WorksheetMain> query = Wrappers.query();
+        if(createUserId>0){
+            query.eq("create_user_id",createUserId);
+        }
+        query.ge("begin_time",beginTime);
+        query.le("begin_time",endTime);
+        if(type!=null && type>=0){
+            query.eq("type",type);
+        }
+        List<WorksheetMain> worksheetMains = mainMapper.selectList(query);
+        PageInfo pageInfo = new PageInfo(worksheetMains);
+        return new Response().set(1,pageInfo);
     }
 }

--
Gitblit v1.9.1