From 670ee80190ce5493206f8d0963c3940b8be051cc Mon Sep 17 00:00:00 2001
From: chenlu <1320612696@qq.com>
Date: 星期三, 22 十月 2025 08:50:54 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10105/r/ERP_override
---
north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java | 79 ++++++++++++++++++++++++++++++++++++++-
1 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java b/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
index bdee6f6..c4c586a 100644
--- a/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
+++ b/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
@@ -1,6 +1,6 @@
package com.example.erp.controller.pp;
-import cn.dev33.satoken.annotation.SaCheckPermission;
+import org.springframework.core.io.InputStreamResource;
import com.example.erp.common.Constants;
import com.example.erp.common.Result;
import com.example.erp.entity.pp.LayoutsData;
@@ -10,7 +10,6 @@
import com.example.erp.service.pp.JsonToOptConverter;
import com.example.erp.service.userInfo.UserService;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,7 +18,11 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.sql.Date;
import java.util.Map;
@@ -335,6 +338,78 @@
}
+ @CrossOrigin(origins = "*")
+ @ApiOperation("PDF鏂囦欢涓嬭浇鎺ュ彛")
+ @GetMapping("/reports/pdf")
+ public ResponseEntity<InputStreamResource> downloadPdf(@RequestParam String filePath) {
+ try {
+ String decodedPath = java.net.URLDecoder.decode(filePath, "UTF-8");
+ System.out.println("鎺ユ敹鍒扮殑鏂囦欢璺緞: " + decodedPath);
+
+ // 鏀惧楠岃瘉鏉′欢锛屼粎妫�鏌ュ繀瑕佹潯浠�
+ if (decodedPath == null || decodedPath.trim().isEmpty()) {
+ System.out.println("鏂囦欢璺緞涓虹┖");
+ return ResponseEntity.badRequest().build();
+ }
+
+ // 妫�鏌ユ槸鍚︿负PDF鏂囦欢锛堜笉涓ユ牸妫�鏌ュ紑澶达級
+ if (!decodedPath.trim().toLowerCase().endsWith(".pdf")) {
+ System.out.println("鏂囦欢涓嶆槸PDF鏍煎紡: " + decodedPath);
+ return ResponseEntity.badRequest().build();
+ }
+
+ // 澶勭悊璺緞锛屾纭鐞哤indows缃戠粶璺緞
+ String processedPath = decodedPath.trim();
+ // 纭繚缃戠粶璺緞鏍煎紡姝g‘
+ if (processedPath.startsWith("\\\\")) {
+ // 宸茬粡鏄纭殑缃戠粶璺緞鏍煎紡
+ System.out.println("妫�娴嬪埌Windows缃戠粶璺緞: " + processedPath);
+ } else if (processedPath.startsWith("\\")) {
+ // 琛ュ叏缃戠粶璺緞
+ processedPath = "\\" + processedPath;
+ System.out.println("琛ュ叏缃戠粶璺緞涓�: " + processedPath);
+ }
+
+ System.out.println("澶勭悊鍚庣殑鏂囦欢璺緞: " + processedPath);
+
+ // 鏋勯�犳枃浠惰矾寰�
+ File file = new File(processedPath);
+ System.out.println("鏋勯�犵殑鏂囦欢缁濆璺緞: " + file.getAbsolutePath());
+ System.out.println("鏂囦欢瑙勮寖璺緞: " + file.getCanonicalPath());
+
+ // 妫�鏌ユ枃浠舵槸鍚﹀瓨鍦�
+ if (!file.exists()) {
+ System.out.println("鏂囦欢涓嶅瓨鍦�: " + file.getAbsolutePath());
+ return ResponseEntity.notFound().build();
+ }
+
+ // 妫�鏌ユ槸鍚︿负鏂囦欢锛堣�岄潪鐩綍锛�
+ if (!file.isFile()) {
+ System.out.println("璺緞涓嶆槸鏂囦欢: " + file.getAbsolutePath());
+ return ResponseEntity.badRequest().build();
+ }
+
+ // 鍒涘缓Resource
+ InputStreamResource resource = new InputStreamResource(new FileInputStream(file));
+
+ // 璁剧疆鍝嶅簲澶�
+ HttpHeaders headers = new HttpHeaders();
+ headers.add(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + file.getName() + "\"");
+ headers.add(HttpHeaders.CONTENT_TYPE, "application/pdf");
+ headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length()));
+ headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
+
+ return ResponseEntity.ok()
+ .headers(headers)
+ .contentType(org.springframework.http.MediaType.APPLICATION_PDF)
+ .body(resource);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
+ }
+ }
+
--
Gitblit v1.8.0