From 933ee70c42092a600696428cefd178de805d0439 Mon Sep 17 00:00:00 2001
From: wanghc <2466022993@qq.com>
Date: Tue, 27 Jun 2023 12:46:38 +0800
Subject: [PATCH] 打包方式修改为lib,添加启动脚本
---
cmci-pfcs-gateway/src/main/java/com/jttech/pfcs/services/impl/BillServiceImpl.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/cmci-pfcs-gateway/src/main/java/com/jttech/pfcs/services/impl/BillServiceImpl.java b/cmci-pfcs-gateway/src/main/java/com/jttech/pfcs/services/impl/BillServiceImpl.java
index 79d9963..d68cff3 100644
--- a/cmci-pfcs-gateway/src/main/java/com/jttech/pfcs/services/impl/BillServiceImpl.java
+++ b/cmci-pfcs-gateway/src/main/java/com/jttech/pfcs/services/impl/BillServiceImpl.java
@@ -1,9 +1,15 @@
package com.jttech.pfcs.services.impl;
+import java.io.File;
import java.util.concurrent.TimeUnit;
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.Session;
+import com.jttech.pfcs.util.SftpUtil;
+import com.jttech.pfcs.vo.req.bill.FtpServerParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
@@ -13,6 +19,7 @@
import com.jttech.pfcs.vo.resp.bill.BillApiRespVo;
import okhttp3.*;
+import org.springframework.web.multipart.MultipartFile;
/**
* 账单服务
@@ -62,4 +69,47 @@
return ResponseVo.fail(-999, errMsg);
}
}
+
+ /**
+ * 文件上传
+ *
+ * @param files
+ * @param ftpServer
+ * @return
+ */
+ @Override
+ public ResponseVo fileUpload(MultipartFile[] files, FtpServerParam ftpServer) {
+ Session session = null;
+ ChannelSftp sftpChannel = null;
+ try {
+ session = SftpUtil.getSession(ftpServer.getIp(), ftpServer.getUser(), ftpServer.getPwd(), ftpServer.getPort());
+ sftpChannel = SftpUtil.openChannel(session);
+ //文件目录没有就需要创建
+ String saveDirPath = ftpServer.getSaveDirPath();
+ File targetDirFile = new File(saveDirPath);
+ if (!targetDirFile.exists()) {
+ if (!targetDirFile.mkdirs()) {
+ // 创建处理目录失败
+ throw new Exception("创建文件目录失败");
+ }
+ }
+ SftpUtil.cd(sftpChannel, saveDirPath);
+ for (MultipartFile file : files) {
+ String fileName = file.getOriginalFilename();
+ //放入文件
+ SftpUtil.put(sftpChannel, file.getBytes(), fileName);
+ }
+ } catch (Exception e) {
+ mLogger.error("BillServiceImpl.fileUpload err={} server={}", e, ftpServer);
+ throw new RuntimeException(e.getMessage());
+ } finally {
+ if (null != sftpChannel) {
+ sftpChannel.disconnect();
+ }
+ if (null != session) {
+ session.disconnect();
+ }
+ }
+ return ResponseVo.ok();
+ }
}
--
Gitblit v1.8.0