src/main/java/com/whyc/controller/ProductBomController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/FtpService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/ProductBomService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/whyc/controller/ProductBomController.java
@@ -8,6 +8,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @Api(tags = "图纸管理") @RestController @RequestMapping("productBom") @@ -17,8 +20,14 @@ @ApiOperation("图纸查询分类检索") @PostMapping("searchCadDrawer") private Response searchCadDrawer(@RequestBody ProductBom productBom, @RequestParam int pageCurr, @RequestParam int pageSize){ public Response searchCadDrawer(@RequestBody ProductBom productBom, @RequestParam int pageCurr, @RequestParam int pageSize){ return service.searchCadDrawer(productBom,pageCurr,pageSize); } @ApiOperation("图纸文件下载") @GetMapping("downloadCadDrawer") public void downloadCadDrawer(HttpServletRequest req, HttpServletResponse resp){ service.downloadCadDrawer(req,resp); } } src/main/java/com/whyc/service/FtpService.java
@@ -29,11 +29,13 @@ ZipUtils.toZip(rootFace, forootFace,true); File filerootFace = new File(rootFace+".zip"); ftp.uploadFile(filerootFace, timeStr+"/face.zip"); filerootFace.delete(); FileOutputStream forootDoc = new FileOutputStream(new File(rootDoc+".zip")); ZipUtils.toZip(rootDoc, forootDoc,true); File filerootDoc = new File(rootDoc+".zip"); ftp.uploadFile(filerootDoc, timeStr+"/doc_file.zip"); filerootDoc.delete(); } catch (Exception e) { e.printStackTrace(); } 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,33 @@ 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(); } catch (FileNotFoundException | UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }