Selaa lähdekoodia

薪酬计提模板文件下载

zhouger 5 kuukautta sitten
vanhempi
säilyke
31b9474cd3

+ 61 - 0
src/main/java/fi/em/formPlugin/SalaryDownloadFilePlugin.java

@@ -0,0 +1,61 @@
+package fi.em.formPlugin;
+
+import kd.bos.form.events.AfterDoOperationEventArgs;
+import kd.bos.form.plugin.AbstractFormPlugin;
+import sys.sc.opplugin.utils.InterFaceImgUtils;
+import sys.sc.opplugin.utils.SftpClient;
+
+import javax.swing.filechooser.FileSystemView;
+import java.io.File;
+
+/**
+ * @author cjz
+ * @date 2024/11/7 20:35
+ * @description:点击按钮下载对应薪酬计提分录模板文件
+ */
+public class SalaryDownloadFilePlugin extends AbstractFormPlugin {
+
+    //获取文件上传接口配置信息
+    public InterFaceImgUtils interFaceImgUtils=new InterFaceImgUtils("downloadurl");
+    //端口号
+    int port= interFaceImgUtils.getPort();
+    //服务器地址
+    String serverurl= interFaceImgUtils.getServerName();
+    //用户
+    String user= interFaceImgUtils.getServerUser();
+    //密码
+    String password= interFaceImgUtils.getServerPassword();
+    //文件名
+    String filename= interFaceImgUtils.getFileName();
+    //获取文件路径
+    String fileurl= interFaceImgUtils.getServerUrl();
+
+    //获取sftp链接对象
+    public SftpClient sftpClient=new SftpClient(serverurl,user,password,port);
+
+    //点击按钮下载文件
+    @Override
+    public void afterDoOperation(AfterDoOperationEventArgs arg){
+        super.afterDoOperation(arg);
+        String operateKey = arg.getOperateKey();
+        //审核操作代码
+        String downloadBut="download";
+        if (downloadBut.equals(operateKey)) {
+            //获取桌面路径
+            String path = FileSystemView.getFileSystemView().getHomeDirectory().getPath();
+            this.getView().showMessage(path);
+            try {
+                //获取服务器链接
+                sftpClient.connect();
+                sftpClient.downloadFile(fileurl+ File.separator+filename,path);
+                this.getView().showMessage("文件生成成功,文件位置为:"+path);
+                sftpClient.disconnect();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+
+        }
+
+    }
+
+}

+ 6 - 0
src/main/java/sys/sc/opplugin/utils/SftpClient.java

@@ -9,6 +9,7 @@ import com.jcraft.jsch.ChannelSftp;
 import com.jcraft.jsch.JSch;
 import com.jcraft.jsch.JSch;
 import com.jcraft.jsch.Session;
 import com.jcraft.jsch.Session;
 import com.jcraft.jsch.SftpException;
 import com.jcraft.jsch.SftpException;
+import org.apache.commons.io.IOUtils;
 
 
 import java.io.FileOutputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.IOException;
@@ -64,6 +65,11 @@ public class SftpClient {
         }
         }
     }
     }
 
 
+    //下载文件到桌面
+    public void downloadFile(String url,String localpath) throws SftpException {
+        sftpChannel.get(url,localpath);
+    }
+
     public ChannelSftp getSftpChannel() {
     public ChannelSftp getSftpChannel() {
         return sftpChannel;
         return sftpChannel;
     }
     }