| | |
| | | @Component |
| | | public class Monitor { |
| | | |
| | | |
| | | |
| | | /** |
| | | * 读取文件(对象) |
| | | * @param uuid 随机数 |
| | |
| | | //返回 |
| | | 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); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 读取文件 |
| | | * 读取内外推送的文件,每30秒读取一次 |
| | | * @return |
| | | */ |
| | | // @Scheduled(cron = "*/30 * * * * ?") |
| | | @Scheduled(cron = "*/30 * * * * ?") |
| | | public static boolean isFTPFileExist() { |
| | | FTPClient ftp = new FTPClient(); |
| | | try { |
| | |
| | | return false; |
| | | } |
| | | else { |
| | | for (FTPFile file : files){ |
| | | 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")){ |
| | | //把文件下载到本地 |
| | | FtpUtil.downloadFtpFile(ftpHost, ftpUserName, ftpPassword, 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); |
| | | 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); |
| | | // |
| | | 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); |
| | | } |
| | | } |
| | | //修改 |
| | | else if (substring.equals("up")) { |
| | | MysqlCenlint.update(sqls); |
| | | } |
| | | //删除 |
| | | else { |
| | | MysqlCenlint.delete(sqls); |
| | | } |
| | | //删除本地服务器文件 |
| | | MysqlCenlint.deletess(fileName); |
| | | //删除 ftp 服务器文件 |
| | | FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName); |
| | | } |
| | | //删除本地文件 |
| | | //MysqlCenlint.deletes(fileName); |
| | | MysqlCenlint.deletess(fileName); |
| | | FtpUtil.deleteFile(ftpHost, ftpPort, ftpUserName, ftpPassword, ftpPath, fileName); |
| | | //关闭流 |
| | | is.close(); |
| | | ftp.completePendingCommand(); |
| | | } |
| | | return true; |
| | | } |
| | | 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; |
| | | |
| | | } |
| | | } |