From eb0b30fbedbed2918f14b35459a0eb0e4e95a2d2 Mon Sep 17 00:00:00 2001 From: zengwei <1439370432@qq.com> Date: Wed, 31 Mar 2021 16:24:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8E=A5=E5=8F=A3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 9026022b491e97fb5ac9cf4355bee91a3de00329 --- .../controller/sys/BusiAttachmentsController.java | 12 ++++++------ .../main/java/com/xjy/ai/common/utils/FileUtils.java | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) mode change 100644 => 100755 share-api/src/main/java/com/xjy/ai/api/controller/sys/BusiAttachmentsController.java diff --git a/share-api/src/main/java/com/xjy/ai/api/controller/sys/BusiAttachmentsController.java b/share-api/src/main/java/com/xjy/ai/api/controller/sys/BusiAttachmentsController.java old mode 100644 new mode 100755 index ae6a2fc..108008f --- a/share-api/src/main/java/com/xjy/ai/api/controller/sys/BusiAttachmentsController.java +++ b/share-api/src/main/java/com/xjy/ai/api/controller/sys/BusiAttachmentsController.java @@ -49,7 +49,6 @@ public class BusiAttachmentsController { BusiAttachments busiAttachment = new BusiAttachments(); String fileName = file.getOriginalFilename(); String suffix = fileName.substring(fileName.lastIndexOf(".")); - File tempFile = File.createTempFile("attachment", suffix, new File(tempPath)); String filePath = fileUtils.upload(file); if (filePath.equals("")) { return DataPacketUtil.errorJsonResult(Constants.UPLOAD_FILE + Constants.FAIL_MSG); @@ -63,7 +62,7 @@ public class BusiAttachmentsController { switch (suffix) { case ".doc": case ".docx": - filePath = fileUtils.docToPDFAndUpload(tempFile.getPath()); + filePath = fileUtils.docToPDFAndUpload(filePath); if (filePath.equals("")) { return DataPacketUtil.errorJsonResult(Constants.UPLOAD_FILE + Constants.FAIL_MSG); } @@ -71,7 +70,7 @@ public class BusiAttachmentsController { break; case ".xls": case ".xlsx": - filePath = fileUtils.ExcelToPDFAndUpload(tempFile.getPath()); + filePath = fileUtils.ExcelToPDFAndUpload(filePath); if (filePath.equals("")) { return DataPacketUtil.errorJsonResult(Constants.UPLOAD_FILE + Constants.FAIL_MSG); } @@ -104,13 +103,14 @@ public class BusiAttachmentsController { @ApiOperation("预览文件") @RequestMapping(value = "/view/{id}", method = RequestMethod.GET) - public String viewFile(HttpServletResponse response, @PathVariable Integer id) { + public ResponseData viewFile(HttpServletResponse response, @PathVariable Integer id) { try { fileUtils.viewFile(response, busiAttachmentsService.selectByPrimaryKey(id).getFileViewPath()); } catch (IOException e) { - return "sdsdfsdsdf"; + e.printStackTrace(); + return DataPacketUtil.jsonFailResult(); } - return "1111111"; + return DataPacketUtil.jsonSuccessResult(); } @ApiOperation("下载文件") diff --git a/share-common/src/main/java/com/xjy/ai/common/utils/FileUtils.java b/share-common/src/main/java/com/xjy/ai/common/utils/FileUtils.java index c467323..6abe36c 100644 --- a/share-common/src/main/java/com/xjy/ai/common/utils/FileUtils.java +++ b/share-common/src/main/java/com/xjy/ai/common/utils/FileUtils.java @@ -118,8 +118,6 @@ public class FileUtils { public String docToPDFAndUpload(String filePath) { String pdfFilePathAndName = this.getNewFilePathAndName("test.pdf"); File pdfFile = new File(pdfFilePathAndName); - System.out.println("============>"); - System.out.println(pdfFilePathAndName); if (!this.createFile(pdfFile)) { return ""; } @@ -145,7 +143,7 @@ public class FileUtils { **/ public String ExcelToPDFAndUpload(String filePath){ String pdfFilePathAndName = this.getNewFilePathAndName("test.pdf"); - File pdfFile = new File(this.getNewFilePathAndName("test.pdf")); + File pdfFile = new File(pdfFilePathAndName); if (!this.createFile(pdfFile)) { return ""; } @@ -153,7 +151,7 @@ public class FileUtils { FileOutputStream os = new FileOutputStream(pdfFile); Workbook wb = new Workbook(filePath); wb.save(os, com.aspose.cells.SaveFormat.PDF); - os.close(); +// os.close(); return pdfFilePathAndName; } catch (Exception e) { logger.info("excel转pdf失败");