From b306d1106b915bb13fd7a02217ae9c65de2fd03d Mon Sep 17 00:00:00 2001
From: ws183 <1143478319@qq.com>
Date: 星期一, 28 四月 2025 17:19:52 +0800
Subject: [PATCH] 新增质检页面附件上传

---
 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