From 256f9c48f2c52985a094a220b644d60d24cb6ed4 Mon Sep 17 00:00:00 2001 From: czt <czt18638530771@163.com> Date: 星期二, 14 十月 2025 09:49:32 +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