whycxzp
2024-01-03 66db1d15cf5d4b51a346a42b66f0505bd7f31ce0
src/main/java/com/whyc/service/ProductBomHistoryService.java
@@ -19,12 +19,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;
@@ -206,7 +208,8 @@
        return new Response().setIIII(1,list.size()>0,list,listsoft,fIleSilkLock,"返回物料信息及关联物料");
    }
    //历史产品下载(产品id和版本<下载的版本>)
    public void downloadProductHistory(HttpServletRequest req, HttpServletResponse resp, int productId, int version) {
    public void downloadProductHistory(HttpServletRequest req, HttpServletResponse resp, int productId, int version
            ,  String oprateReason,  String oprateInfo) {
        //读取产品信息
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("id",productId);
@@ -246,16 +249,11 @@
            withOutDwg+=File.separator+"standard"+File.separator+version;
        }
        //生成excel并将dwg文件放在同一报下压缩
        creatBomHsitoryExcel(req,resp,pHistory,endList,withOutDwg);
        //记录日志
        DocUser docUser= ActionUtil.getUser();
        String operationDetail="具体产品为:"+pHistory.toString();
        String opreationMsg="执行了"+pHistory.getVersion()+"版本产品的下载操作";
        String terminalIp=req.getRemoteAddr();
        logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail);
        creatBomHsitoryExcel(req,resp,pHistory,endList,withOutDwg,oprateReason,oprateInfo,ActionUtil.sdfwithALL.format(pHistory.getVersionTime()));
    }
    //根据产品信息创建excel表格并存放在指定目录
    public void creatBomHsitoryExcel(HttpServletRequest req, HttpServletResponse resp,ProductHistory pHistory,List<ProductBomHistory> list,String withOutDwg){
    public void creatBomHsitoryExcel(HttpServletRequest req, HttpServletResponse resp,ProductHistory pHistory,List<ProductBomHistory> list,String withOutDwg
            ,  String oprateReason,  String oprateInfo,String oprateVersion){
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace="";
        String excelName="";
@@ -445,9 +443,10 @@
            FileOutputStream forootFace = new FileOutputStream(file);
            ZipUtils.toZip(rootFace, forootFace,true);
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
            /*resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")
                    + ".zip");
                    + ".zip");*/
            resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode ( excelName+".zip", "utf-8"));
            OutputStream out = resp.getOutputStream();
            FileInputStream in = new FileInputStream(rootFace+".zip");
            int len=0;
@@ -465,6 +464,9 @@
        } catch (IOException e) {
            e.printStackTrace();
        }
        //记录日志
        logService.recordOperationLogDownLoad(ActionUtil.getUser().getId(),ActionUtil.getUser().getName(), UserOperation.TYPE_DOWNLOAD_PRODUCT.getType(),new Date(),req.getRemoteAddr()
                ,excelName+".zip",rootFace+".zip",oprateReason,oprateInfo,oprateVersion);
    }
    //将物料存放为一个bomHistory为下载做准备
@@ -667,7 +669,7 @@
    }
    //根据产品母料型号,定制单号,版本下载原始压缩包文件
    public Response getOriginalZip(String parentModel, String customCode, int version) {
    public Response getOriginalZip(String parentCode,String parentModel, String customCode, int version) {
        String fileDirName = FileDirPath.getFileDirName();
        String withOutDwg=fileDirName+File.separator+"doc_file"+File.separator+"product"+File.separator+parentModel;
        if(customCode!=null&&!customCode.isEmpty()){
@@ -683,9 +685,10 @@
        String[] filePath = file.list();//获取该文件夹下的所有文件以及目录的名字
        if(filePath!=null&&filePath.length>0){
            for (String tmp:filePath) {
                if(tmp.contains(".zip")){
                if((tmp.contains(parentCode)||tmp.contains(parentModel))&&tmp.contains(".zip")){
                    bl=true;
                    withOutDwg=withOutDwg+File.separator+tmp;
                    break;
                }
            }
        }