From ae8f85ec49f410a376d703e403d742bede9e92ee Mon Sep 17 00:00:00 2001 From: zhangqinbin <181961702@qq.com> Date: Mon, 11 Dec 2023 17:35:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=AC=E5=91=8A=E7=BB=93=E6=9E=84=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../extend/wps/controller/WpsController.java | 20 +++++++++++++------ .../wps/service/impl/WpsServiceImpl.java | 12 +++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/controller/WpsController.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/controller/WpsController.java index db83784..3ed0db0 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/controller/WpsController.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/controller/WpsController.java @@ -210,20 +210,28 @@ public class WpsController { Optional optional = attachmentClient.findByBusinessId(businessIdList); - AttachmentDetail detail = optional.get(); + String fileLength = "10"; + String fileName = fileId; + byte buf[] = new byte[0]; - List entityList = detail.get(fileId); + if(optional!=null&&optional.get()!=null){ + AttachmentDetail detail = optional.get(); - Optional optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId()); + List entityList = detail.get(fileId); + Optional optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId()); + fileLength = String.valueOf(optional1.get().length); + fileName = entityList.get(0).getFilename(); + buf = optional1.get(); + } try{ // 设置响应的头信息,告诉浏览器文件的大小和下载方式 response.setCharacterEncoding("UTF-8"); - response.setHeader("Content-Length", String.valueOf(optional1.get().length)); - response.setHeader("Content-Disposition", "attachment; filename=".concat(new String(entityList.get(0).getFilename().getBytes(StandardCharsets.UTF_8), "ISO8859-1"))); + response.setHeader("Content-Length", fileLength); + response.setHeader("Content-Disposition", "attachment; filename=".concat(new String(fileName.getBytes(StandardCharsets.UTF_8), "ISO8859-1"))); - InputStream word = new ByteArrayInputStream(optional1.get()); + InputStream word = new ByteArrayInputStream(buf); // 创建输入输出流 BufferedInputStream inStream = new BufferedInputStream(word); BufferedOutputStream outStream = new BufferedOutputStream(response.getOutputStream()); diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java index 464b9cb..29bbc53 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/impl/WpsServiceImpl.java @@ -630,12 +630,16 @@ public class WpsServiceImpl implements WpsService { Optional optional = attachmentClient.findByBusinessId(businessIdList); - AttachmentDetail detail = optional.get(); + if(optional!=null&&optional.get()!=null) { - List entityList = detail.get(id); + AttachmentDetail detail = optional.get(); - Optional optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId()); - return optional1.get(); + List entityList = detail.get(id); + + Optional optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId()); + return optional1.get(); + } + return new byte[0]; } @Override