文件接口修改
Former-commit-id: 9026022b491e97fb5ac9cf4355bee91a3de00329
This commit is contained in:
parent
84aa126ce2
commit
eb0b30fbed
12
share-api/src/main/java/com/xjy/ai/api/controller/sys/BusiAttachmentsController.java
Normal file → Executable file
12
share-api/src/main/java/com/xjy/ai/api/controller/sys/BusiAttachmentsController.java
Normal file → Executable file
|
|
@ -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("下载文件")
|
||||
|
|
|
|||
|
|
@ -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失败");
|
||||
|
|
|
|||
Loading…
Reference in New Issue