zhouger 7 ماه پیش
والد
کامیت
9153a7cf8c

+ 30 - 25
src/main/java/sys/sc/formplugin/CreatDatPlugin.java

@@ -1,6 +1,7 @@
 package sys.sc.formplugin;
 
 import com.alipay.api.kms.aliyun.utils.BackoffUtils;
+import com.jcraft.jsch.SftpException;
 import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.dataentity.entity.DynamicObjectCollection;
 import kd.bos.form.events.AfterDoOperationEventArgs;
@@ -77,15 +78,11 @@ public class CreatDatPlugin extends AbstractListPlugin {
                 }
                 this.getView().showMessage("创建成功"+filePath);
             }
+
             //分割符号
             String spiltsign=jkdataDy.getString("nckd_split");
             //结束符号
             String endsign=jkdataDy.getString("nckd_endsign");
-            //文件生成到本地路径
-            DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,filePath,spiltsign,endsign);
-            //生成dat文件到本地
-            datFileCreatUtils.creatDatFile();
-            //上传文件到服务器中
             //服务器端口
             String host=jkdataDy.getString("nckd_servername");
             //服务器用户名
@@ -94,35 +91,43 @@ public class CreatDatPlugin extends AbstractListPlugin {
             String password=jkdataDy.getString("nckd_password");
             //服务器端口号
             int port=jkdataDy.getInt("nckd_port");
+
+            //上传文件到服务器中
             SftpClient sftpClient=new SftpClient(host,username,password,port);
-            //获取服务器连接
             try {
-                sftpClient.connect();
-                //上传文件到服务器指定路径
-                sftpClient.fileCreat(filePath,nckd_url+filename);
-            } catch (Exception e) {
+                //临时文件
+                Path localFile = Files.createTempFile(tablenumber, ".dat");
+                //文件生成到本地路径
+                DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,localFile.toString(),spiltsign,endsign);
+                //生成dat文件到本地
+                datFileCreatUtils.creatDatFile();
+                sftpClient.fileCreat(String.valueOf(localFile),nckd_url);
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            } catch (SftpException e) {
                 throw new RuntimeException(e);
             }
+
             //关闭连接
             sftpClient.disconnect();
         }
         if (name.equals("uploadfile"))
         {
-            String remoteFilePath="/home/kingdee/cosmic/nginx-appstatic/store/appstatic/";
-            SftpClient sftpClient=new SftpClient("192.168.10.69","root","Kd@86262007",22);
-            try {
-                sftpClient.connect();
-                // 创建一个新的远程文件并写入内容
-                Path localFile = Files.createTempFile("tempfile", ".txt");
-                Files.write(localFile, Collections.singleton("Hello, SFTP!"));
-                sftpClient.fileCreat(localFile.toString(),remoteFilePath);  // 清理临时文件
-                Files.delete(localFile);
-            } catch (IOException e) {
-                throw new RuntimeException(e);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-            sftpClient.disconnect();
+//            String remoteFilePath="/home/kingdee/cosmic/nginx-appstatic/store/appstatic/";
+//            SftpClient sftpClient=new SftpClient("192.168.10.69","root","Kd@86262007",22);
+//
+//            try {
+////                sftpClient.connect();
+////                DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,filePath,spiltsign,endsign);
+////                Files.write(localFile, Collections.singleton("Hello, SFTP!"));
+////                sftpClient.fileCreat(localFile.toString(),remoteFilePath);  // 清理临时文件
+////                Files.delete(localFile);
+//            } catch (IOException e) {
+//                throw new RuntimeException(e);
+//            } catch (Exception e) {
+//                throw new RuntimeException(e);
+//            }
+//            sftpClient.disconnect();
         }
 
     }

+ 7 - 0
src/main/java/sys/sc/opplugin/utils/DatFileCreatUtils.java

@@ -1,6 +1,7 @@
 package sys.sc.opplugin.utils;
 
 import com.grapecity.documents.excel.Q;
+import com.jcraft.jsch.SftpException;
 import kd.bos.algo.DataSet;
 
 import kd.bos.algo.Row;
@@ -16,7 +17,10 @@ import kd.bos.servicehelper.BusinessDataServiceHelper;
 import kd.scm.bid.formplugin.report.biddetailquery.QingFiledContent;
 
 import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -84,8 +88,11 @@ public class DatFileCreatUtils {
                     writer.newLine();
                 }
             }
+
         } catch (IOException ex) {
             ex.printStackTrace();
+        }  catch (Exception e) {
+            throw new RuntimeException(e);
         }
     }
 }

+ 11 - 10
src/main/java/sys/sc/task/CreatDatDailyTask.java

@@ -84,18 +84,19 @@ public class CreatDatDailyTask extends AbstractTask {
             String endsign=jkdataDy.getString("nckd_endsign");
             //文件生成到本地路径
             DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,filePath,spiltsign,endsign);
+
+            //上传文件到服务器中
+            //服务器端口
+            String host=jkdataDy.getString("nckd_servername");
+            //服务器用户名
+            String username=jkdataDy.getString("nckd_user");
+            //服务器密码
+            String password=jkdataDy.getString("nckd_password");
+            //服务器路径
+            //服务器端口号
+            int port=jkdataDy.getInt("nckd_port");
             //生成dat文件到本地
             datFileCreatUtils.creatDatFile();
-            //上传文件到服务器中
-//            //服务器端口
-//            String host=jkdataDy.getString("nckd_servername");
-//            //服务器用户名
-//            String username=jkdataDy.getString("nckd_user");
-//            //服务器密码
-//            String password=jkdataDy.getString("nckd_password");
-//            //服务器路径
-//            //服务器端口号
-//            int port=jkdataDy.getInt("nckd_port");
 //            SftpClient sftpClient=new SftpClient(host,username,password,port);
 //            //获取服务器连接
 //            try {