From 103160279885c466e835420564dc17fc5aba99f4 Mon Sep 17 00:00:00 2001 From: longyvfengyun <496960745@qq.com> Date: 星期五, 22 七月 2022 11:33:31 +0800 Subject: [PATCH] Merge branch 'master' of http://118.89.139.230:10101/r/~whyclxw/CadDrawManager --- src/main/java/com/whyc/service/ProductBomService.java | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/whyc/service/ProductBomService.java b/src/main/java/com/whyc/service/ProductBomService.java index a9ad87c..bf655f1 100644 --- a/src/main/java/com/whyc/service/ProductBomService.java +++ b/src/main/java/com/whyc/service/ProductBomService.java @@ -2,12 +2,19 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import com.whyc.dto.FileDirPath; import com.whyc.dto.Response; +import com.whyc.dto.ZipUtils; import com.whyc.mapper.ProductBomMapper; import com.whyc.pojo.ProductBom; +import com.whyc.util.ActionUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.util.Date; import java.util.List; @Service @@ -22,4 +29,34 @@ PageInfo pageInfo=new PageInfo(list); return new Response().setII(1,list.size()>0?true:false,pageInfo,"鏁版嵁杩斿洖"); } + //鍥剧焊鏂囦欢涓嬭浇 + public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp) { + String fileDirName = FileDirPath.getFileDirName(); + String rootFace=fileDirName+ File.separator+"face"; + 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(); + } catch (FileNotFoundException | UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } } -- Gitblit v1.9.1