From b367ef20f7fb5be71610dd89b18bde7d99a2647d Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Thu, 09 Jun 2022 12:21:36 +0800
Subject: [PATCH] 调整删除文件逻辑
---
src/main/java/org/springblade/modules/FTP/Monitor.java | 167 ++++++++++---------------------------------------------
1 files changed, 30 insertions(+), 137 deletions(-)
diff --git a/src/main/java/org/springblade/modules/FTP/Monitor.java b/src/main/java/org/springblade/modules/FTP/Monitor.java
index 8c463f6..469aa7f 100644
--- a/src/main/java/org/springblade/modules/FTP/Monitor.java
+++ b/src/main/java/org/springblade/modules/FTP/Monitor.java
@@ -68,50 +68,35 @@
if (files.length==0){
return new Result(400,null,"未读取到文件",null);
} else {
+ boolean flag = false;
for (FTPFile file : files){
String fileName = file.getName();
if (fileName.contains("ni")){
System.out.println("-------接收到内网回传的文件: " + fileName);
- //把文件下载到本地
+ //把文件下载到本地
FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName);
// 解析数据
String s = OutJson.TestJson(fileName);
//数据处理
Result result = DataHandler.handler(s,uuid);
- if (result.getCode()==400){
-// return new Result(400,null,"uuid 不匹配",null);
- break;
- }else {
+ //匹配上了删除文件
+ if (result.getCode()==200) {
+ flag = true;
//删除本地文件
MysqlCenlint.deletess(fileName);
-// ftp.dele(fileName);
+ //删除 ftp 文件
FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName);
- ftp.completePendingCommand();
- ftp.logout();
- if (result.getCode() == 200) {
- //返回
- return new Result(200, null, "新增成功", null);
- }
- if (result.getCode() == 201) {
- //返回
- return new Result(201, null, "修改成功", null);
- }
- if (result.getCode() == 202) {
- //返回
- return new Result(202, null, result.getMsg(), null);
- }
- if (result.getCode() == 203) {
- //返回
- return new Result(203, null, result.getMsg(), null);
- }
- if (result.getCode() == 205) {
- //返回
- return new Result(202, null, "新增失败,找不到该用户", null);
- }
+// ftp.dele(fileName);
+ //返回
+ return result;
}
+ ftp.completePendingCommand();
+ ftp.logout();
}
}
- System.out.println("未读取到对应的文件");
+// if (!flag){
+// ftp.logout();
+// }
return new Result(400,null,"未读取到对应的文件",null);
}
} catch (Exception e) {
@@ -188,16 +173,16 @@
//删除 ftp 文件
FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName);
// ftp.dele(fileName);
- ftp.completePendingCommand();
- ftp.logout();
//返回
return result;
}
+ ftp.completePendingCommand();
+ ftp.logout();
}
}
- if (!flag){
- ftp.logout();
- }
+// if (!flag){
+// ftp.logout();
+// }
return new Result(400,null,"未读取到对应的文件",null);
}
} catch (Exception e) {
@@ -274,16 +259,16 @@
//删除 ftp 文件
// ftp.dele(fileName);
FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName);
- ftp.completePendingCommand();
- ftp.logout();
//返回
return result;
}
+ ftp.completePendingCommand();
+ ftp.logout();
}
}
- if (!flag){
- ftp.logout();
- }
+// if (!flag){
+// ftp.logout();
+// }
return new Result(400,null,"未读取到对应的文件",null);
}
} catch (Exception e) {
@@ -299,99 +284,6 @@
}
}
return new Result(400,null,"失败",null);
- }
-
- /**
- * 读取内外推送的文件,每30秒读取一次
- * @return
- */
-// @Scheduled(cron = "*/30 * * * * ?")
- public static boolean isFTPFileExist() {
- FTPClient ftp = new FTPClient();
- try {
- //设置超时时间
- ftp.setDataTimeout(60000);
- //连接超时为60秒
- ftp.setConnectTimeout(60000);
- //连接
- ftp.connect(ftpHost, ftpPort);
- // 登陆
- ftp.login(ftpUserNameIn, ftpPasswordIn);
- // 检验登陆操作的返回码是否正确
- if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {
- ftp.disconnect();
- return false;
- }
-
- ftp.enterLocalActiveMode();
-
- // 设置文件类型为二进制,与ASCII有区别
- ftp.setFileType(FTP.BINARY_FILE_TYPE);
-
- // 设置编码格式
- ftp.setControlEncoding("GBK");
-
- // 检验文件是否存在
- ftp.changeWorkingDirectory(ftpPath);
-
- // Use passive mode as default
- ftp.enterLocalPassiveMode();
-
- FTPFile[] files = ftp.listFiles();
- if (files.length==0){
- return false;
- }
- else {
- for (FTPFile file : files) {
- String fileName = file.getName();
- if (fileName.contains("nq")) {
- //把文件下载到本地
- FtpUtil.downloadFtpFile(ftpHost, ftpUserNameIn, ftpPasswordIn, ftpPort, ftpPath, localPath, fileName);
- //
- String s = OutJson.TestJson(fileName);
- //sql语句
- String sql = OutJson.stringReplace(s);
- String[] split = sql.split(";");//以逗号分割
- for (String sqls : split) {
- //判断是否是新增,删除,修改
- String substring = sqls.substring(0, 2);
- //新增
- if (substring.equals("in")) {
- //运行sql语句
- MysqlCenlint.inster(sqls);
- }
- //修改
- else if (substring.equals("up")) {
- MysqlCenlint.update(sqls);
- }
- //删除
- else {
- MysqlCenlint.delete(sqls);
- }
- }
- //删除本地服务器文件
- MysqlCenlint.deletess(fileName);
- //删除 ftp 服务器文件
-// ftp.dele(fileName);
- FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName);
- }
- ftp.completePendingCommand();
- ftp.logout();
- }
- }
- } catch (Exception e) {
- System.out.println("ftp连接失败");
- e.printStackTrace();
- } finally {
- if (ftp.isConnected()) {
- try {
- ftp.disconnect();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- return false;
}
/**
@@ -453,16 +345,17 @@
//删除 ftp 文件
// ftp.dele(fileName);
FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserNameIn, ftpPasswordIn, ftpPath, fileName);
- ftp.completePendingCommand();
- ftp.logout();
+
//返回
return result;
}
+ ftp.completePendingCommand();
+ ftp.logout();
}
}
- if (!flag){
- ftp.logout();
- }
+// if (!flag){
+// ftp.logout();
+// }
return new Result(400,null,"未读取到对应的文件",null);
}
} catch (Exception e) {
--
Gitblit v1.9.3