智慧保安后台管理-外网
Administrator
2022-04-27 dd899673f3ff75ad59ae43afd124ef8ef0fc0180
src/main/java/org/springblade/modules/FTP/Monitor.java
@@ -21,8 +21,6 @@
@Component
public class Monitor {
   /**
    * 读取文件(对象)
    * @param uuid 随机数
@@ -85,6 +83,10 @@
                     //返回
                     return new Result(202,null,result.getMsg(),null);
                  }
                  if (result.getCode()==203) {
                     //返回
                     return new Result(203,null,result.getMsg(),null);
                  }
               }
            }
            return new Result(400,null,"未读取到对应的文件",null);
@@ -105,10 +107,10 @@
   }
   /**
    * 读取文件
    * 读取内外推送的文件,每30秒读取一次
    * @return
    */
   //   @Scheduled(cron = "*/30 * * * * ?")
   @Scheduled(cron = "*/30 * * * * ?")
   public static boolean isFTPFileExist() {
      FTPClient ftp = new FTPClient();
      try {
@@ -140,8 +142,11 @@
            for (FTPFile file : files){
               String fileName = file.getName();
               InputStream is = ftp.retrieveFileStream(new String(fileName.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
               String substring1 = fileName.substring(0, 1);
               if (substring1.equals("n")){
               if (null == is) {
                  return false;
               } else {
                  String substring1 = fileName.substring(0, 4);
                  if (substring1.equals("nsql")) {
                  //把文件下载到本地
                  FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
                  //
@@ -166,81 +171,30 @@
                        MysqlCenlint.delete(sqls);
                     }
                  }
                  //删除本地文件
                  //MysqlCenlint.deletes(fileName);
                     //删除本地服务器文件
                  MysqlCenlint.deletess(fileName);
                     //删除 ftp 服务器文件
                  FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName);
                  }
                  //关闭流
                  is.close();
                  ftp.completePendingCommand();
               }
            }
            return true;
         }
         //InputStream is = ftp.retrieveFileStream(new String(file.getBytes("GBK"), FTP.DEFAULT_CONTROL_ENCODING));
//         if (is == null || ftp.getReplyCode() == FTPReply.FILE_UNAVAILABLE) {
//            return false;
//
//         }
//
//         if (is != null) {
//            //把文件下载到本地
//            FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, ftpPort, ftpPath, localPath, fileName);
//            //
//            String s = OutJson.TestJson();
//            //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.delete();
//            FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, "anbao/", "nsql.json");
//            is.close();
//            ftp.completePendingCommand();
//
//         }
         }
      } catch (Exception e) {
         System.out.println("ftp连接失败");
         e.printStackTrace();
      } finally {
         if (ftp != null) {
            try {
               ftp.disconnect();
            } catch (IOException e) {
               e.printStackTrace();
            }
         }
      }
      return false;
   }
}