Commit 71409ae5 authored by Xuxiaodong's avatar Xuxiaodong

完成pullwenjian

parent f77b2a13
package com.jianju.di.task; package com.jianju.di.task;
import com.jianju.di.Manager.PostGISMannager;
import com.jianju.di.utils.FtpUtil; import com.jianju.di.utils.FtpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @author D
*/
@Component @Component
@Slf4j
public class PullFileTask { public class PullFileTask {
/** /**
...@@ -25,13 +33,15 @@ public class PullFileTask { ...@@ -25,13 +33,15 @@ public class PullFileTask {
private String password; private String password;
@Value("${ftp.remotepath}") @Value("${ftp.remotepath}")
private String remotePath; private String remotePath;
@Value("${ftp.localpath}")
private String localPath;
/** /**
* 数据库注入参数 * 数据库注入参数
*/ */
@Value("${postgis.host}") @Value("${postgis.host}")
private String dbHost; private String dbHost;
@Value("${postgis.prot}") @Value("${postgis.port}")
private String dbPort; private String dbPort;
@Value("${postgis.username}") @Value("${postgis.username}")
private String dbUserName; private String dbUserName;
...@@ -41,21 +51,36 @@ public class PullFileTask { ...@@ -41,21 +51,36 @@ public class PullFileTask {
private String dbName; private String dbName;
@Value("${postgis.tbname}") @Value("${postgis.tbname}")
private String tbName; private String tbName;
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("YYYYMMdd");
//每日0点与中午12点执行;
//@Scheduled(cron ="0 0 12,18 * * ?" )
@Scheduled(fixedRate = 10000) @Scheduled(fixedRate = 10000)
public void PullFileAndSendDi() throws Exception { public void PullFileAndSendDi() throws Exception {
FtpUtil.FtpConfig ftpConfig = new FtpUtil.FtpConfig().setHost(host).setPort(port).setUserName(userName).setPassword(password); FtpUtil.FtpConfig ftpConfig = new FtpUtil.FtpConfig().setHost(host).setPort(port).setUserName(userName).setPassword(password);
boolean b = FtpUtil.existFile(ftpConfig, remotePath, "b.html"); Calendar c = Calendar.getInstance();
if(b) c.setTime(new Date());
{ c.add(Calendar.DATE, -2);
boolean download = FtpUtil.download(ftpConfig, remotePath, "b.html", "E:/新建文件夹", System.currentTimeMillis() + ".html");
String fileName = "#"+dateFormat.format(c.getTime());
log.info("开始下载"+"#"+fileName);
boolean download = FtpUtil.download(ftpConfig, remotePath, fileName, localPath, fileName);
if(download) if(download)
{ {
log.info("下载成功");
// PostGISMannager postGIS = new PostGISMannager(dbHost, dbPort,
// dbName, tbName, dbUserName, dbPassword);
// postGIS.createTableGDAS("GODAS");
// postGIS.insertGodasToPG("GODAS", );
} }
} else
{
log.info("下载失败");
}
} }
} }
...@@ -6,7 +6,8 @@ ftp: ...@@ -6,7 +6,8 @@ ftp:
port: 21 port: 21
username: ncc username: ncc
password: ncc123 password: ncc123
remotepath: /NOAA/NCEP/noaa18_olr remotepath: /NOAA/NCEP/noaa18_olr/
localpath: C:\Users\D\Desktop\证书\
postgis: postgis:
host: 10.40.16.39 host: 10.40.16.39
port: 27088 port: 27088
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment