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