From 930d29f39d115fe76c305af4320c2acbcb30c445 Mon Sep 17 00:00:00 2001
From: czt <czt18638530771@163.com>
Date: 星期四, 12 六月 2025 10:37:37 +0800
Subject: [PATCH] 优化SQL
---
igds-basic/src/main/java/com/ld/igds/basic/controller/FileController.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/igds-basic/src/main/java/com/ld/igds/basic/controller/FileController.java b/igds-basic/src/main/java/com/ld/igds/basic/controller/FileController.java
index 1ce6b66..95d231d 100644
--- a/igds-basic/src/main/java/com/ld/igds/basic/controller/FileController.java
+++ b/igds-basic/src/main/java/com/ld/igds/basic/controller/FileController.java
@@ -5,6 +5,8 @@
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -13,11 +15,13 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
+import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
+import java.util.Date;
/**
* 鏂囦欢涓婁紶鎺ュ彛
@@ -170,4 +174,46 @@
}
}
+ /**
+ * PDF鏂囦欢棰勮
+ * @param response
+ */
+ @RequestMapping("/show-pdf")
+ public void showFile(String fileTime, String fileName, String filePathType, HttpServletResponse response) throws Exception {
+
+ if (!fileName.endsWith(".pdf")) {
+ return;
+ }
+ Date time = DateUtils.parseDate(fileTime, new String[]{"yy-MM-dd HH:mm:ss"});
+
+ String filePath = fileManager.getPathByType(filePathType, time);
+ if(StringUtils.isEmpty(filePath)){
+ return;
+ }
+
+ File file = new File(filePath, fileName);
+ try {
+ response.setHeader("Content-Disposition", "inline; filename*=UTF-8''" + URLEncoder.encode(file.getName(), "UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ ServletOutputStream os = null;
+ try {
+ os = response.getOutputStream();
+ os.write(FileUtils.readFileToByteArray(file));
+ os.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ if (os != null) {
+ try {
+ os.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
}
--
Gitblit v1.9.3