From 1af35600ad339dabb4ae31acd7e6e882efffd189 Mon Sep 17 00:00:00 2001 From: lxw <810412026@qq.com> Date: 星期六, 13 八月 2022 16:30:08 +0800 Subject: [PATCH] 图纸打包下载 --- src/main/java/com/whyc/service/ProductBomService.java | 52 ++++++++++------------------------------------------ 1 files changed, 10 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/whyc/service/ProductBomService.java b/src/main/java/com/whyc/service/ProductBomService.java index 1883964..5c2bc7c 100644 --- a/src/main/java/com/whyc/service/ProductBomService.java +++ b/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); //璁板綍鏃ュ織 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); @@ -247,7 +217,6 @@ public void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,List list, HSSFWorkbook wb){ String fileDirName = FileDirPath.getFileDirName(); String rootFace=""; - String pictureName=""; String excelName=""; //鍒涘缓鍗曚釜sheet HSSFSheet sheet = wb.createSheet("bom淇℃伅"); @@ -295,7 +264,6 @@ } } if((dwgUrl!=null)&&(!dwgUrl.isEmpty())){ - pictureName+=dwgUrl.substring(dwgUrl.lastIndexOf("\\")+1)+","; File sourceFile=new File(fileDirName+ File.separator+dwgUrl); copyFile(sourceFile,rootFace); } -- Gitblit v1.9.1