src/main/java/com/whyc/controller/ProductBomApprovingController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/controller/ProductBomController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/FtpService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/ProductBomApprovingService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/service/ProductBomService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/whyc/util/DwgToPdfUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/whyc/controller/ProductBomApprovingController.java
@@ -8,10 +8,7 @@ import io.swagger.annotations.ApiOperation; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; @@ -51,5 +48,10 @@ return service.zipParse(file); } @GetMapping("dwgReview") @ApiOperation("dwg文件预览") public Response dwgReview(@RequestParam String dwgUrl) throws IOException { return service.dwgReview(dwgUrl); } } 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/ProductBomApprovingService.java
@@ -6,10 +6,7 @@ import com.whyc.pojo.DocUser; import com.whyc.pojo.ProductBomApproving; import com.whyc.pojo.WorksheetMain; import com.whyc.util.ActionUtil; import com.whyc.util.CommonUtil; import com.whyc.util.FileUtil; import com.whyc.util.Zip4jUtil; import com.whyc.util.*; import io.swagger.models.auth.In; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; @@ -258,12 +255,14 @@ return list; } public static void main(String[] args) throws IOException, InvalidFormatException { String a = "C:\\Users\\29550\\Desktop\\当前项目\\202207泰州平台\\49泰州数据库备份-服务器从windows切换到Ubuntu时的数据库备份\\db_alarm.sql"; String substring = a.substring(a.lastIndexOf(File.separator)+1); String s2 = (a.substring(a.lastIndexOf("当前项目"+File.separator+"202207泰州平台"))); public Response dwgReview(String dwgUrl) throws IOException { //绝对路径xxx/doc_file String rootFile = CommonUtil.getRootFile(); String dwgSubFilePath = dwgUrl.substring(dwgUrl.indexOf("doc_file")+8); String dwgSubFileDirPath = dwgSubFilePath.substring(0,dwgSubFilePath.lastIndexOf(File.separator)); File dwgFile = new File(rootFile + dwgSubFilePath); String pdfFileName = DwgToPdfUtil.dwg2Pdf(dwgFile); System.out.println(substring); System.out.println(s2); return new Response().set(1,"doc_file"+dwgSubFileDirPath+File.separator+pdfFileName); } } 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(); } } } src/main/java/com/whyc/util/DwgToPdfUtil.java
@@ -15,7 +15,7 @@ @Slf4j public class DwgToPdfUtil { public static File Dwg2Pdf(File dwgFile) throws IOException { public static String dwg2Pdf(File dwgFile) throws IOException { FileInputStream fileInputStream; //将dwg文件转换成InputStream输入流 fileInputStream = new FileInputStream(dwgFile); @@ -36,7 +36,7 @@ pdfOptions.setVectorRasterizationOptions(rasterizationOptions); //输出文件 File outputFile = new File(dwgFile.getName().substring(0,dwgFile.getName().lastIndexOf("."))+".pdf"); File outputFile = new File(dwgFile.getParent()+File.separator+dwgFile.getName().substring(0,dwgFile.getName().lastIndexOf("."))+"-dwg.pdf"); //存放地址 try { objImage.save(outputFile.getPath(), pdfOptions); @@ -47,17 +47,9 @@ fileInputStream.close(); } log.info("文件转换成功{}",dwgFile.getName()); return outputFile; return outputFile.getName(); } public static void main(String[] args) throws IOException { long l = System.currentTimeMillis(); File file = new File("C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\IDCE-6006NT(5ST3010+接触器替换5ST3040)(双天线)结构件_A09(2022-7-5)\\IDCE-6006NT(5ST3010+接触器替换5ST3040) PCBA专用结构件BOM表_A08(2022-6-10)\\IDCE2415CT-701(2016-3-8).dwg"); File file1 = Dwg2Pdf(file); System.out.println(file1.getAbsolutePath()); long l1 = System.currentTimeMillis(); System.out.println((l1-l)/1000); } }