lxw
2022-08-03 efb9455b7f2a41ca162164de20649e47a8b6ee36
产品下载后需要删除文件夹和压缩包
2个文件已修改
30 ■■■■■ 已修改文件
src/main/java/com/whyc/dto/ZipUtils.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/ProductBomService.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/dto/ZipUtils.java
@@ -160,7 +160,7 @@
                    }
                }
                //删除最后的文件夹
                //Files.delete(dirPath);
                Files.delete(dirPath);
            }
        } catch (Exception e) {
            System.out.println("删除目录失败,path = {}"+path);
src/main/java/com/whyc/service/ProductBomService.java
@@ -60,7 +60,7 @@
                String picUrl=pictureUrls.get(i);
                pictureName+=picUrl.substring(picUrl.lastIndexOf("\\")+1)+",";
                File sourceFile=new File(fileDirName+ File.separator+picUrl);
                copyFile(sourceFile,rootFace,i);
                copyFile(sourceFile,rootFace);
            }
        }
        String timeStr= ActionUtil.sdfwithFTP.format(new Date());
@@ -83,6 +83,7 @@
            in.close();
            out.close();
            file.delete();//删除压缩文件
            ZipUtils.delDir(rootFace);
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
@@ -151,16 +152,16 @@
    }
    //将选中的文件存入指定目录下
    public void copyFile(File source,String dest,int i ){
    public void copyFile(File source,String dest ){
        //创建目的地文件夹
        File destfile = new File(dest);
        if(!destfile.exists()) {
            destfile.mkdir();
        }else{
        }/*else{
            if(i==0){
                ZipUtils.delDir(dest);
            }
        }
        }*/
        //source是文件,则用字节输入输出流复制文件
        try {
            if(source.isFile()){
@@ -213,12 +214,12 @@
        wrapper.eq("parent_model",parentModel);
        List<ProductBom> list=mapper.selectList(wrapper);
        //生成excel并将dwg文件放在同一报下压缩
        creatBomExcel(req,resp,list,wb,parentModel);
        creatBomExcel(req,resp,list,wb);
    }
    //根据产品信息创建excel表格并存放在指定目录
    public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List<ProductBom> list, HSSFWorkbook wb, String parentModel){
    public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List<ProductBom> list, HSSFWorkbook wb){
        String fileDirName = FileDirPath.getFileDirName();
        String rootFace=fileDirName+ File.separator+parentModel;
        String rootFace="";
        String pictureName="";
        String excelName="";
        //创建单个sheet
@@ -249,11 +250,18 @@
            for (int i=0;i<list.size();i++) {
                ProductBom bom=list.get(i);
                String dwgUrl=bom.getDwgUrl();
                excelName=bom.getParentCode();
                if(i==0){
                    excelName=bom.getParentCode();
                    rootFace=fileDirName+File.separator+excelName;
                    File destfile = new File(rootFace);
                    if(!destfile.exists()) {
                        destfile.mkdir();
                    }
                }
                if((dwgUrl!=null)&&(!dwgUrl.isEmpty())){
                    pictureName+=dwgUrl.substring(dwgUrl.lastIndexOf("\\")+1)+",";
                    File sourceFile=new File(fileDirName+ File.separator+dwgUrl);
                    copyFile(sourceFile,rootFace,i);
                    copyFile(sourceFile,rootFace);
                }
                Row row=sheet.createRow(rownum+i+1);
                row.setHeight((short)(1500));
@@ -332,11 +340,11 @@
            in.close();
            out.close();
            file.delete();
            ZipUtils.delDir(rootFace);
        } catch (FileNotFoundException | UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}