whycxzp
2022-08-15 6eda8b2ff2b6748376670e84a14a8656cc1094c6
src/main/java/com/whyc/service/ProductBomService.java
@@ -50,48 +50,18 @@
        return  new Response().setII(1,list.size()>0?true:false,pageInfo,"数据返回");
    }
    //图纸文件下载
    public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp, ArrayList<String> pictureUrls) {
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace=fileDirName+ File.separator+"downLoad";
        String pictureName="";
        //将选中的文件存入指定目录下打包下载
        if(pictureUrls!=null&&pictureUrls.size()>0){
            for (int i=0;i<pictureUrls.size();i++) {
                String picUrl=pictureUrls.get(i);
                pictureName+=picUrl.substring(picUrl.lastIndexOf("\\")+1)+",";
                File sourceFile=new File(fileDirName+ File.separator+picUrl);
                copyFile(sourceFile,rootFace);
            }
        }
        String timeStr= ActionUtil.sdfwithFTP.format(new Date());
        try {
            File file=new File(rootFace+".zip");
            FileOutputStream forootFace = new FileOutputStream(file);
            ZipUtils.toZip(rootFace, forootFace,true);
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(timeStr.getBytes("UTF-8"), "ISO8859-1")
                    + ".zip");
            OutputStream out = resp.getOutputStream();
            FileInputStream in = new FileInputStream(rootFace+".zip");
            int len=0;
            byte[] buffer =new byte[1024];
            //7. 将缓冲区中的数据输出
            while ((len=in.read(buffer))>0){
                out.write(buffer,0,len);
            }
            in.close();
            out.close();
            file.delete();//删除压缩文件
            ZipUtils.delDir(rootFace);
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp, List<ProductBom> boms) {
        HSSFWorkbook wb = new HSSFWorkbook();
        //字体格式-加粗
        HSSFCellStyle cellStyle = wb.createCellStyle();
        HSSFFont font = wb.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        cellStyle.setFont(font);
        //生成excel并将dwg文件放在同一报下压缩
        creatBomExcel(req,resp,boms,wb,"pic");
        //记录日志
        DocUser docUser= ActionUtil.getUser();
        String operationDetail="具体图纸为:"+pictureName.substring(0,pictureName.lastIndexOf(","));
        String operationDetail="具体图纸为数量:"+boms.size();
        String opreationMsg="执行了文件打包下载操作";
        String terminalIp=req.getRemoteAddr();
        logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail);
@@ -235,7 +205,7 @@
            }
        }
        //生成excel并将dwg文件放在同一报下压缩
        creatBomExcel(req,resp,list,wb);
        creatBomExcel(req,resp,list,wb,"bom");
        //记录日志
        DocUser docUser= ActionUtil.getUser();
        String operationDetail="具体产品母料型号为:"+parentModel;
@@ -244,10 +214,9 @@
        logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail);
    }
    //根据产品信息创建excel表格并存放在指定目录
    public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List list, HSSFWorkbook wb){
    public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List list, HSSFWorkbook wb,String type){
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace="";
        String pictureName="";
        String excelName="";
        //创建单个sheet
        HSSFSheet sheet = wb.createSheet("bom信息");
@@ -288,6 +257,10 @@
                String dwgUrl=bom.getDwgUrl();
                if(i==0){
                    excelName=bom.getParentCode()+"_"+bom.getParentModel();
                    String timeStr= ActionUtil.sdfwithFTP.format(new Date());
                    if(type.equals("pic")){
                        excelName=timeStr;
                    }
                    rootFace=fileDirName+File.separator+excelName;
                    File destfile = new File(rootFace);
                    if(!destfile.exists()) {
@@ -295,7 +268,6 @@
                    }
                }
                if((dwgUrl!=null)&&(!dwgUrl.isEmpty())){
                    pictureName+=dwgUrl.substring(dwgUrl.lastIndexOf("\\")+1)+",";
                    File sourceFile=new File(fileDirName+ File.separator+dwgUrl);
                    copyFile(sourceFile,rootFace);
                }
@@ -365,6 +337,7 @@
            File file=new File(rootFace+".zip");
            FileOutputStream forootFace = new FileOutputStream(file);
            ZipUtils.toZip(rootFace, forootFace,true);
            // 转码防止乱码
            resp.addHeader("Content-Disposition", "attachment;filename="
                    + new String(excelName.getBytes("UTF-8"), "ISO8859-1")