zhouger il y a 7 mois
Parent
commit
2ee075a387

+ 8 - 7
src/main/java/sys/sc/formplugin/CreatDatPlugin.java

@@ -78,7 +78,6 @@ public class CreatDatPlugin extends AbstractListPlugin {
                 }
                 this.getView().showMessage("创建成功"+filePath);
             }
-
             //分割符号
             String spiltsign=jkdataDy.getString("nckd_split");
             //结束符号
@@ -91,9 +90,6 @@ 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 {
                 //临时文件
                 File localFile = File.createTempFile(tablenumber, ".dat");
@@ -101,18 +97,23 @@ public class CreatDatPlugin extends AbstractListPlugin {
                 DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,localFile.getAbsolutePath(),spiltsign,endsign);
                 //生成dat文件到本地
                 datFileCreatUtils.creatDatFile();
+                //上传文件到服务器中
+                SftpClient sftpClient=new SftpClient(host,username,password,port);
+                //获取服务器连接
+                sftpClient.connect();
                 //从本地传文件到服务器
                 sftpClient.fileCreat(localFile.getAbsolutePath(), nckd_url);
                 //上传后删除临时文件
                 localFile.delete();
+                //关闭连接
+                sftpClient.disconnect();
             } catch (IOException e) {
                 throw new RuntimeException(e);
             } catch (SftpException e) {
                 throw new RuntimeException(e);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
             }
-
-            //关闭连接
-            sftpClient.disconnect();
         }
         if (name.equals("uploadfile"))
         {

+ 26 - 20
src/main/java/sys/sc/task/CreatDatDailyTask.java

@@ -2,6 +2,7 @@ package sys.sc.task;
 
 import com.alibaba.druid.support.logging.Log;
 import com.alibaba.druid.support.logging.LogFactory;
+import com.jcraft.jsch.SftpException;
 import kd.bos.context.RequestContext;
 import kd.bos.dataentity.entity.DynamicObject;
 import kd.bos.dataentity.entity.DynamicObjectCollection;
@@ -17,6 +18,7 @@ import sys.sc.opplugin.utils.DatFileCreatUtils;
 import sys.sc.opplugin.utils.SftpClient;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -69,22 +71,15 @@ public class CreatDatDailyTask extends AbstractTask {
                     "id,number,name,nckd_servername" +
                             ",nckd_port,nckd_url,nckd_filename,nckd_user" +
                             ",nckd_password,nckd_split,nckd_endsign",new QFilter[]{qFilter});
-            //文件名
-            String filename=tablenumber+".dat";
             //服务器路径
             String nckd_url=jkdataDy.getString("nckd_url");
             if (nckd_url.equals("/var/appstatic/")) {
                 nckd_url="/home/kingdee/cosmic/nginx-appstatic/store/appstatic/";
             }
-            //生成文件的路径
-            String filePath=nckd_url+"/"+filename;
             //分割符号
             String spiltsign=jkdataDy.getString("nckd_split");
             //结束符号
             String endsign=jkdataDy.getString("nckd_endsign");
-            //文件生成到本地路径
-            DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,filePath,spiltsign,endsign);
-
             //上传文件到服务器中
             //服务器端口
             String host=jkdataDy.getString("nckd_servername");
@@ -95,19 +90,30 @@ public class CreatDatDailyTask extends AbstractTask {
             //服务器路径
             //服务器端口号
             int port=jkdataDy.getInt("nckd_port");
-            //生成dat文件到本地
-            datFileCreatUtils.creatDatFile();
-//            SftpClient sftpClient=new SftpClient(host,username,password,port);
-//            //获取服务器连接
-//            try {
-//                sftpClient.connect();
-//                //上传文件到服务器指定路径
-//                sftpClient.fileCreat(filePath,nckd_url+filename);
-//                //关闭连接
-//                sftpClient.disconnect();
-//            } catch (Exception e) {
-//                throw new RuntimeException(e);
-//            }
+            try {
+                //临时文件
+                File localFile = File.createTempFile(tablenumber, ".dat");
+                //文件写入
+                DatFileCreatUtils datFileCreatUtils=new DatFileCreatUtils(tablenumber,bizappnum,fileList,localFile.getAbsolutePath(),spiltsign,endsign);
+                //生成dat文件到本地
+                datFileCreatUtils.creatDatFile();
+                //上传文件到服务器中
+                SftpClient sftpClient=new SftpClient(host,username,password,port);
+                //获取服务器连接
+                sftpClient.connect();
+                //从本地传文件到服务器
+                sftpClient.fileCreat(localFile.getAbsolutePath(), nckd_url);
+                //上传后删除临时文件
+                localFile.delete();
+                //关闭连接
+                sftpClient.disconnect();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            } catch (SftpException e) {
+                throw new RuntimeException(e);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
         }
     }