From 95df5e1ec6c5685bdbceba23a3e99d3f16e09f5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=B9=8F?= <845871400@qq.com> Date: Sat, 26 Oct 2024 21:01:54 +0800 Subject: [PATCH] =?UTF-8?q?add=20SAP=E7=B3=BB=E7=BB=9F=20=E6=A0=B8?= =?UTF-8?q?=E9=94=80=E6=8E=A5=E5=8F=A3=E5=AE=A2=E6=88=B7=E7=AB=AF=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shkd/fi/fi/task/impl/OAInvoiceImpl.java | 23 ++++++++++++++----- .../java/shkd/fi/fi/util/SFTPConnectUtil.java | 6 ++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/task/impl/OAInvoiceImpl.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/task/impl/OAInvoiceImpl.java index fc485b9..8504d7f 100644 --- a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/task/impl/OAInvoiceImpl.java +++ b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/task/impl/OAInvoiceImpl.java @@ -26,10 +26,7 @@ import shkd.fi.fi.util.LogBillUtils; import shkd.fi.fi.util.ParamsUtils; import shkd.fi.fi.util.SFTPConnectUtil; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; +import java.io.*; import java.net.URLDecoder; import java.net.URLEncoder; import java.rmi.RemoteException; @@ -109,8 +106,18 @@ public class OAInvoiceImpl { path = URLDecoder.decode(path,"UTF-8"); path = FilePathUtil.dealPath(path,"attach"); InputStream inputStream = FileServiceFactory.getAttachmentFileService().getInputStream(path); - FileInputStream fileInputStream = (FileInputStream) inputStream; - boolean flag = SFTPConnectUtil.uploadFile("/usr/local/nginx/html/", fileInputStream, filename, sftp); + String suffix = filename.substring(filename.lastIndexOf(".")); + File tempFile = File.createTempFile(filename,suffix); + tempFile.deleteOnExit(); + try (FileOutputStream outputStream = new FileOutputStream(tempFile)) { + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); + } + } + + boolean flag = SFTPConnectUtil.uploadFile("/usr/local/nginx/html/", tempFile, sftp,filename); if(flag){ String filenameEn = URLEncoder.encode(filename); @@ -120,6 +127,10 @@ public class OAInvoiceImpl { log.info("url参数转义后:"+url); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); } } diff --git a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/SFTPConnectUtil.java b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/SFTPConnectUtil.java index c2018e6..dd1002e 100644 --- a/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/SFTPConnectUtil.java +++ b/fi/shkd-fi-fi/src/main/java/shkd/fi/fi/util/SFTPConnectUtil.java @@ -88,11 +88,11 @@ public class SFTPConnectUtil { * @return boolean */ public static boolean uploadFile(String directory, File uploadFile, - ChannelSftp sftp) { + ChannelSftp sftp,String fileName) { try { // 进入指定目录 sftp.cd(directory); - sftp.put(new FileInputStream(uploadFile), uploadFile.getName()); + sftp.put(new FileInputStream(uploadFile), fileName); } catch (FileNotFoundException e) { logger.error("uploadFile -- FileNotFoundException:" + e.toString()); return false; @@ -292,7 +292,7 @@ public class SFTPConnectUtil { /** * 判断对象是否为空 * - * @param str + * @param * @return boolean */ public static boolean isEmpty(Object obj) {