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失败");