From 61cfb19a3864e70cedaa8de38f4caf032f528455 Mon Sep 17 00:00:00 2001
From: 钟日健 <5689795+arsn@user.noreply.gitee.com>
Date: Fri, 06 May 2022 09:35:54 +0800
Subject: [PATCH] 新增查询保安员证编号,新增 ftp 读取
---
src/main/java/org/springblade/modules/FTP/FtpUtil.java | 143 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 136 insertions(+), 7 deletions(-)
diff --git a/src/main/java/org/springblade/modules/FTP/FtpUtil.java b/src/main/java/org/springblade/modules/FTP/FtpUtil.java
index c5c19ea..201a824 100644
--- a/src/main/java/org/springblade/modules/FTP/FtpUtil.java
+++ b/src/main/java/org/springblade/modules/FTP/FtpUtil.java
@@ -6,13 +6,16 @@
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
+import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.net.SocketException;
import java.util.Date;
+import java.util.Map;
-import static org.springblade.common.constant.FtpConstant.*;
-import static org.springblade.common.constant.FtpConstant.ftpPath;
+import net.lingala.zip4j.core.ZipFile;
+
+import static org.springblade.common.config.FtpConfig.*;
/**
* ftp工具类
@@ -50,7 +53,7 @@
logger.info("未连接到FTP,用户名或密码错误。");
ftpClient.disconnect();
} else {
- logger.info("FTP连接成功。");
+// logger.info("FTP连接成功。");
}
} catch (SocketException e) {
e.printStackTrace();
@@ -287,12 +290,83 @@
}
}
}
+
+ /**
+ *
+ * 解压zip 包
+ * @author panchaoyuan
+ * @param srcFile Unzipped file
+ * @param destDirPath Unzipped destination folder
+ * @throws RuntimeException
+ * @throws IOException
+ */
+ public static void unZip(MultipartFile srcFile, String destDirPath, String savePath) throws RuntimeException, IOException {
+ File file = null;
+ InputStream ins = srcFile.getInputStream();
+ String savaPaths = savePath+srcFile.getOriginalFilename();
+ file=new File(savaPaths);
+ inputStreamToFile(ins, file);
+
+ if (!file.exists()) {
+ throw new RuntimeException(file.getPath() + ",file is not found");
+ }
+ ZipFile zipFile = null;
+ try {
+ zipFile = new ZipFile(file);
+// zipFile.setFileNameCharset("utf-8");
+ zipFile.setFileNameCharset("gbk");
+ //解压到 destDirPath
+ zipFile.extractAll(destDirPath);
+ }catch(Exception e) {
+ throw new RuntimeException("unzip error from FileUtil", e);
+ }
+ }
+
+
+ /**
+ * 输入流转换为文件
+ * @author panchaoyuan
+ * @return
+ */
+ private static void inputStreamToFile(InputStream ins, File file) {
+ try {
+ OutputStream os = new FileOutputStream(file);
+ int bytesRead = 0;
+ byte[] buffer = new byte[8192];
+ while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+ os.close();
+ ins.close();
+ }catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
/**
* 执行sql 上传
- * @param s1 sql
+ * @param obj sql
*/
- public static void sqlFileUpload(String s1){
- String json1 = JSON.toJSONString(s1);
+ public static void sqlFileUpload(String obj){
+ String json1 = JSON.toJSONString(obj);
+ String response1 = String.valueOf((new Date()).getTime());
+ OutJson.createJsonFile(json1, localPath, "nsql"+response1);
+ FileInputStream in1 = null;
+ try {
+ in1 = new FileInputStream(new File(localPath + "nsql"+response1+".json"));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "nsql"+response1+".json", in1);
+ MysqlCenlint.deletess("nsql"+response1+".json");
+ }
+
+ /**
+ * 执行 对象数据(用户,报名对象信息等) 上传
+ * @param obj 对象信息
+ */
+ public static void objectFileUpload(Object obj){
+ String json1 = JSON.toJSONString(obj);
String response1 = String.valueOf((new Date()).getTime());
OutJson.createJsonFile(json1, localPath, "n"+response1);
FileInputStream in1 = null;
@@ -301,7 +375,62 @@
} catch (FileNotFoundException e) {
e.printStackTrace();
}
- FtpUtil.uploadFile(ftpHost_dev, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "n"+response1+".json", in1);
+ FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "n"+response1+".json", in1);
+ MysqlCenlint.deletess("n"+response1+".json");
}
+
+ /**
+ * 执行 对象数据(用户,报名对象信息等) 上传
+ * @param obj 对象信息
+ */
+ public static void objectFileUploadList(Object obj){
+ String json1 = JSON.toJSONString(obj);
+ String response1 = String.valueOf((new Date()).getTime());
+ OutJson.createJsonFile(json1, localPath, "nl"+response1);
+ FileInputStream in1 = null;
+ try {
+ in1 = new FileInputStream(new File(localPath + "nl"+response1+".json"));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "nl"+response1+".json", in1);
+ MysqlCenlint.deletess("nl"+response1+".json");
+ }
+
+ /**
+ * 返回报名信息结果
+ * @param obj
+ */
+ public static void objectFileUploadListTrain(Object obj){
+ String json1 = JSON.toJSONString(obj);
+ String response1 = String.valueOf((new Date()).getTime());
+ OutJson.createJsonFile(json1, localPath, "nt"+response1);
+ FileInputStream in1 = null;
+ try {
+ in1 = new FileInputStream(new File(localPath + "nt"+response1+".json"));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "nt"+response1+".json", in1);
+ MysqlCenlint.deletess("nt"+response1+".json");
+ }
+
+ /**
+ * 向外网发送保安员证编号位数数据
+ * @param map1
+ */
+ public static void objectFileUploadSecurityNumberCount(Object obj){
+ String json1 = JSON.toJSONString(obj);
+ String response1 = String.valueOf((new Date()).getTime());
+ OutJson.createJsonFile(json1, localPath, "ns"+response1);
+ FileInputStream in1 = null;
+ try {
+ in1 = new FileInputStream(new File(localPath + "ns"+response1+".json"));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ FtpUtil.uploadFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, "/", "ns"+response1+".json", in1);
+ MysqlCenlint.deletess("ns"+response1+".json");
+ }
}
--
Gitblit v1.9.3