lxw
2022-08-03 ec7196276592289acbf6f20415b1aaea73977852
产品下载后需要删除文件夹和压缩包
2个文件已修改
31 ■■■■ 已修改文件
src/main/java/com/whyc/dto/ZipUtils.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductBomService.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/ZipUtils.java
@@ -155,12 +155,12 @@
                for (File file : files) {
                    if(file.isDirectory()){  //先判断是不是文件夹
                        delDir(file.getPath());
                    }
                    else{   //这样就覆盖到了删除失效的软链接情况
                    }else{   //这样就覆盖到了删除失效的软链接情况
                        file.delete();
                    }
                }
                Files.delete(dirPath);
                //删除最后的文件夹
                //Files.delete(dirPath);
            }
        } catch (Exception e) {
            System.out.println("删除目录失败,path = {}"+path);
@@ -178,6 +178,6 @@
        fileList.add(new File("D:/Java/jdk1.7.0_45_64bit/bin/java.exe"));
        FileOutputStream fos2 = new FileOutputStream(new File("c:/mytest02.zip"));
        ZipUtils.toZip(fileList, fos2);*/
        delDir("D:\\IDEAWorkSpace\\CadDrawManager\\target\\downLoad");
        delDir("D:\\IDEAWorkSpace\\CadDrawManager\\target\\IDCE-6006NTpro");
    }
}
src/main/java/com/whyc/service/ProductBomService.java
@@ -56,10 +56,11 @@
        String pictureName="";
        //将选中的文件存入指定目录下打包下载
        if(pictureUrls!=null&&pictureUrls.size()>0){
            for (String picUrl:pictureUrls) {
            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);
                copyFile(sourceFile,rootFace,i);
            }
        }
        String timeStr= ActionUtil.sdfwithFTP.format(new Date());
@@ -82,7 +83,6 @@
            in.close();
            out.close();
            file.delete();//删除压缩文件
            ZipUtils.delDir(rootFace);//删除文件夹
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
@@ -151,11 +151,15 @@
    }
    //将选中的文件存入指定目录下
    public void copyFile(File source,String dest ){
    public void copyFile(File source,String dest,int i ){
        //创建目的地文件夹
        File destfile = new File(dest);
        if(!destfile.exists()) {
            destfile.mkdir();
        }else{
            if(i==0){
                ZipUtils.delDir(dest);
            }
        }
        //source是文件,则用字节输入输出流复制文件
        try {
@@ -209,12 +213,12 @@
        wrapper.eq("parent_model",parentModel);
        List<ProductBom> list=mapper.selectList(wrapper);
        //生成excel并将dwg文件放在同一报下压缩
        creatBomExcel(req,resp,list,wb);
        creatBomExcel(req,resp,list,wb,parentModel);
    }
    //根据产品信息创建excel表格并存放在指定目录
    public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List<ProductBom> list, HSSFWorkbook wb){
    public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List<ProductBom> list, HSSFWorkbook wb, String parentModel){
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace=fileDirName+ File.separator+"downLoad";
        String rootFace=fileDirName+ File.separator+parentModel;
        String pictureName="";
        String excelName="";
        //创建单个sheet
@@ -249,7 +253,7 @@
                if((dwgUrl!=null)&&(!dwgUrl.isEmpty())){
                    pictureName+=dwgUrl.substring(dwgUrl.lastIndexOf("\\")+1)+",";
                    File sourceFile=new File(fileDirName+ File.separator+dwgUrl);
                    copyFile(sourceFile,rootFace);
                    copyFile(sourceFile,rootFace,i);
                }
                Row row=sheet.createRow(rownum+i+1);
                row.setHeight((short)(1500));
@@ -309,7 +313,7 @@
                }
            }
        }
        try {
       try {
            File file=new File(rootFace+".zip");
            FileOutputStream forootFace = new FileOutputStream(file);
            ZipUtils.toZip(rootFace, forootFace,true);
@@ -328,7 +332,6 @@
            in.close();
            out.close();
            file.delete();
            ZipUtils.delDir(rootFace);
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {