From 0a5b2316601eb43efcc5d3fe9198f2845f918ee4 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Thu, 4 Jul 2024 17:03:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=A1=E5=88=9B=E5=AE=A1=E6=A0=B8=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20=E9=A2=84=E8=A7=88=E6=96=87=E4=BB=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hz/pm/api/projectdeclared/controller/PurchaseController.java | 3 ++- .../com/hz/pm/api/projectdeclared/helper/MhXchxFileHelper.java | 7 ++++--- .../java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java index 0427b25..0e02910 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/controller/PurchaseController.java @@ -23,6 +23,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import java.io.UnsupportedEncodingException; import java.util.List; /** @@ -153,7 +154,7 @@ public class PurchaseController { @GetMapping("/exportXcfhFile/{code}") @ApiOperation("直接导出信创文件") - public void exportXcfhFile(@PathVariable String code,HttpServletResponse response) { + public void exportXcfhFile(@PathVariable String code,HttpServletResponse response) throws UnsupportedEncodingException { purchaseManage.exportXcfhFile(code,response); } diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXchxFileHelper.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXchxFileHelper.java index 5cef003..e00f9a1 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXchxFileHelper.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/helper/MhXchxFileHelper.java @@ -18,6 +18,7 @@ import org.springframework.stereotype.Component; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.*; +import java.net.URLEncoder; import java.nio.file.Files; /** @@ -67,15 +68,15 @@ public class MhXchxFileHelper { return JSONUtil.toJsonStr(retFileInfo); } - public void exportReport(String reportFile, HttpServletResponse response){ + public void exportReport(String reportFile, HttpServletResponse response) throws UnsupportedEncodingException { if (StrUtils.isBlank(reportFile)) { throw BizException.wrap("信创报告文件不能为空"); } File file = mhFileClient.downloadToTmpFile(reportFile); // 设置响应的内容类型和头信息 - response.setContentType("application/octet-stream"); - response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\""); + response.setContentType("application/pdf"); + response.setHeader("Content-Disposition", "attachment;filename=\"" + URLEncoder.encode(file.getName(),"utf-8") + "\""); // 使用ServletOutputStream写文件内容 try (InputStream in = Files.newInputStream(file.toPath()); diff --git a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java index 870f805..e08fd6b 100644 --- a/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java +++ b/hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/manage/PurchaseManage.java @@ -80,6 +80,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDateTime; @@ -755,7 +756,7 @@ public class PurchaseManage { return mhXchxFileHelper.getXchxFile(code, null); } - public void exportXcfhFile(String code,HttpServletResponse response) { + public void exportXcfhFile(String code,HttpServletResponse response) throws UnsupportedEncodingException { mhXchxFileHelper.exportReport(code, response); } }