From 74131764317f69d5b122342f1593c74de9761d45 Mon Sep 17 00:00:00 2001 From: zhangqinbin <181961702@qq.com> Date: Fri, 22 Dec 2023 10:57:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=BF=E4=BC=81WPS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../extend/wps/controller/WpsController.java | 2 +- .../ebtp/extend/wps/service/WpsService.java | 2 - .../wps/service/impl/WpsServiceImpl.java | 39 ++++++++----------- 3 files changed, 18 insertions(+), 25 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 bad26ef..e780cd7 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 @@ -318,7 +318,7 @@ public class WpsController { businessIdList2.add(tempDocFileId); Optional optional2 = attachmentClient.findByBusinessId(businessIdList2); AttachmentDetail detail = optional2.get(); - List entityList = detail.get(fileId[0]); + List entityList = detail.get(tempDocFileId); Optional optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId()); if(optional1!=null&&optional1.isPresent()) { fileLength = String.valueOf(optional1.get().length); diff --git a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/WpsService.java b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/WpsService.java index 69f7839..351fad2 100644 --- a/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/WpsService.java +++ b/src/main/java/com/chinaunicom/mall/ebtp/extend/wps/service/WpsService.java @@ -29,6 +29,4 @@ public interface WpsService{ String downloadDecrypt(String key); Map saveKSFile(KingSoftFileSaveVo vo); - - public byte[] uploadTempFile(String fileExtension); } 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 7b5445b..2ce460c 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 @@ -130,6 +130,8 @@ public class WpsServiceImpl implements WpsService { private String kswpsurl; @Value("${KingSoftWps.kswpsurl-preview}") private String kswpsurl_preview; + @Value("${KingSoftWps.tempDocFileId}") + private String tempDocFileId; @Resource private RedisTemplate redisTemplate; @@ -716,37 +718,30 @@ public class WpsServiceImpl implements WpsService { } } } + //没有文件 上传模板一份 if(uploadB){ - buf = uploadTempFile(fileExtension); + log.info(" 没有文件 上传模板一份 "+id+" | "+fileName+" | "+fileExtension); + uploadTempFile(id,fileName,fileExtension); + log.info(" 没有文件 上传模板一份 成功"); } return buf; } - @Override - public byte[] uploadTempFile(String fileExtension){ - String text = "1111"; - byte buf[] = text.getBytes(); - File tempFile = null; + private void uploadTempFile(String fileid,String fileName,String fileExtension){ try { - tempFile = File.createTempFile("tempDoc", "."+fileExtension); - tempFile.deleteOnExit(); // 在程序退出时删除临时文件 - - byte[] b = " ".getBytes(); - OutputStream out = new FileOutputStream(tempFile); - out.write(b); - out.close(); - - BufferedInputStream bis = new BufferedInputStream(new FileInputStream(tempFile)); - buf = IOUtils.toByteArray(bis); - log.info("buf:"+buf.length); + List businessIdList2 = new ArrayList<>(); + businessIdList2.add(tempDocFileId); + Optional optional2 = attachmentClient.findByBusinessId(businessIdList2); + AttachmentDetail detail = optional2.get(); + List entityList = detail.get(tempDocFileId); + Optional optional1 = attachmentClient.downloadFileByObjectId(entityList.get(0).getId()); + if(optional1!=null&&optional1.isPresent()) { + byte buf[] = optional1.get(); + Optional op=attachmentClient.upload(fileid,fileName+"."+fileExtension,buf); + } }catch (Exception e){ log.error("读取异常",e); CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("模板文件读取异常",true); - }finally { - if(tempFile!=null) { - tempFile.deleteOnExit(); - } } - return buf; } @Override