From 665e1a6665efb8eda2789f96b3391b250e309028 Mon Sep 17 00:00:00 2001 From: zhangqinbin <181961702@qq.com> Date: Fri, 22 Dec 2023 09:57:06 +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 --- .../ebtp/extend/wps/controller/WpsController.java | 1 + .../extend/wps/service/impl/WpsServiceImpl.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 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 d0b4a1e..7322d01 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 @@ -314,6 +314,7 @@ public class WpsController { } if(uploadB){ buf = this.wpsService.uploadTempFile(fileId[0]); + fileLength = String.valueOf(buf.length); //Optional op=attachmentClient.upload(fileId[0],fileName,buf); } 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 09ef024..06f3bbe 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 @@ -38,6 +38,8 @@ import com.chinaunicom.mall.ebtp.extend.wps.vo.*; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.wp.usermodel.CharacterRun; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; @@ -722,19 +724,27 @@ public class WpsServiceImpl implements WpsService { } @Override public byte[] uploadTempFile(String fileExtension){ - String text = " "; + String text = "1111"; byte buf[] = text.getBytes(); File tempFile = null; try { tempFile = File.createTempFile("tempDoc", "."+fileExtension); + tempFile.deleteOnExit(); // 在程序退出时删除临时文件 + + byte[] b = "2222".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); }catch (Exception e){ log.error("读取异常",e); CommonExceptionEnum.FRAME_EXCEPTION_COMMON_DATA_OTHER_ERROR.customValidName("模板文件读取异常",true); }finally { if(tempFile!=null) { - tempFile.delete(); + tempFile.deleteOnExit(); } } return buf;