From 00b43011dc4aa059731f7f9c8553ec9b1b728dfe Mon Sep 17 00:00:00 2001
From: tangzy <tangzy123456>
Date: Sat, 21 Aug 2021 16:23:12 +0800
Subject: [PATCH] 1.ftp

---
 src/main/java/org/springblade/modules/FTP/monitor.java |   37 ++++++++++++++++++++++++++++++++-----
 1 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/springblade/modules/FTP/monitor.java b/src/main/java/org/springblade/modules/FTP/monitor.java
index 324a9e7..b2d61eb 100644
--- a/src/main/java/org/springblade/modules/FTP/monitor.java
+++ b/src/main/java/org/springblade/modules/FTP/monitor.java
@@ -8,6 +8,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+
 @Component
 public class monitor {
 	//ftp服务器IP地址
@@ -19,9 +20,14 @@
 	//ftp服务器密码
 	private static String ftpPassword = "Yly@123";
 	//ftp服务器路径
-	private static String ftpPath = "anbao/sql.json";
+	private static String ftpPath = "anbao/nsql.json";
+	//本地路径
+	private static String localPath = "D:\\anbao";
+	//文件名
+	private static String fileName = "nsql.json";
 
-	@Scheduled(cron = "*/5 * * * * ?")
+
+	@Scheduled(cron = "*/30 * * * * ?")
 	public static boolean isFTPFileExist() {
 
 		FTPClient ftp = new FTPClient();
@@ -73,15 +79,36 @@
 			InputStream is = ftp.retrieveFileStream(new String(file.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
 
 			if (is == null || ftp.getReplyCode() == FTPReply.FILE_UNAVAILABLE) {
-				System.out.println(false);
 				return false;
 
 			}
 
 			if (is != null) {
-				System.out.println(true);
-				is.close();
+				//把文件下载到本地
+				FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
+				//
+				String s = OutJson.TestJson();
+				//sql语句
+				String sql = OutJson.stringReplace(s);
+				//判断是否是新增,删除,修改
+				String substring = sql.substring(0, 2);
+				//新增
+				if (substring.equals("in")){
+					//运行sql语句
+					MysqlCenlint.inster(sql);
+				}
+				//修改
+				else if (substring.equals("up")){
 
+				}
+				//删除
+				else {
+
+				}
+				//删除本地文件
+				MysqlCenlint.delete();
+				FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "nsql.json");
+				is.close();
 				ftp.completePendingCommand();
 
 			}

--
Gitblit v1.9.3