Commit 999bce9e authored by Xuxiaodong's avatar Xuxiaodong

完成oisstv2定时任务编写

parent 12f456f6
...@@ -13,6 +13,7 @@ import org.springframework.scheduling.annotation.Scheduled; ...@@ -13,6 +13,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -86,7 +87,63 @@ public class PullFileTask { ...@@ -86,7 +87,63 @@ public class PullFileTask {
private static final SimpleDateFormat yearDateFormat = new SimpleDateFormat("yyyy"); private static final SimpleDateFormat yearDateFormat = new SimpleDateFormat("yyyy");
private static final SimpleDateFormat yearMonthDateFormat = new SimpleDateFormat("MM"); private static final SimpleDateFormat yearMonthDateFormat = new SimpleDateFormat("MM");
private final FtpUtil.FtpConfig ftpConfig = new FtpUtil.FtpConfig().setHost(host).setPort(port).setUserName(userName).setPassword(password); /**
* Monthly数据入库以及发送di
* 暂定为每晚八点20运行获取上一个月的数据
*/
// @Scheduled(cron = "0 0 20 20 * ?") 目前ftp数据还未准备好,所以暂时先不进行运行
public void pullSstvGodasFileAndSendDi() throws Exception
{
FtpUtil.FtpConfig ftpConfig = new FtpUtil.FtpConfig().setHost(host).setPort(port).setUserName(userName).setPassword(password);
Calendar c = Calendar.getInstance();
c.setTime(new Date());
//上一个月
c.add(Calendar.MONTH, -1);
String fileName = "godas.M." + yearMonthDateFormat.format(c.getTime())+".grb";
log.info("开始下载----" + fileName);
long beforeDown = System.currentTimeMillis();
boolean download = FtpUtil.download(ftpConfig, godasMonthlyRemotePath, fileName, localPath, fileName);
long afterDown;
if (download) {
log.info("下载成功" + fileName);
PostGISMannager postGIS = new PostGISMannager(dbHost, dbPort,
dbName, godasMonthlyTbName, dbUserName, dbPassword);
if (postGIS.insertGodasToPGMonth(godasMonthlyTbName, localPath + fileName) > 0) {
// 发送Di
afterDown = System.currentTimeMillis();
Date start = new Date(beforeDown);
long fileSize = new File(localPath,fileName).length();
String diJson = sendDi("godas-monthly数据入库","K.0436.0001.6666",c.getTime(), new Date(beforeDown), new Date(afterDown), fileName, "1",fileSize);
OkHttpClient httpClient = new OkHttpClient();
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), diJson);
Request request = new Request.Builder()
.url(diUrl)
.post(requestBody)
.build();
//发送请求获取响应
try {
Response response = httpClient.newCall(request).execute();
//判断请求是否成功
if (response.isSuccessful()) {
//打印服务端返回结果
log.info("请求代理返回结果==========:" + response.body().string());
log.info("请求di的Json=========" + diJson);
}
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
log.info("下载失败" + fileName);
}
}
/** /**
* Monthly数据入库以及发送di * Monthly数据入库以及发送di
...@@ -95,6 +152,7 @@ public class PullFileTask { ...@@ -95,6 +152,7 @@ public class PullFileTask {
// @Scheduled(cron = "0 0 20 15 * ?") 目前ftp数据还未准备好,所以暂时先不进行运行 // @Scheduled(cron = "0 0 20 15 * ?") 目前ftp数据还未准备好,所以暂时先不进行运行
public void pullMonthlyGodasFileAndSendDi() throws Exception public void pullMonthlyGodasFileAndSendDi() throws Exception
{ {
FtpUtil.FtpConfig ftpConfig = new FtpUtil.FtpConfig().setHost(host).setPort(port).setUserName(userName).setPassword(password);
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.setTime(new Date()); c.setTime(new Date());
//上一个月 //上一个月
...@@ -152,6 +210,7 @@ public class PullFileTask { ...@@ -152,6 +210,7 @@ public class PullFileTask {
*/ */
// @Scheduled(cron = "0 0 20 * * ?") 目前ftp数据还未准备好,所以暂时先不进行运行 // @Scheduled(cron = "0 0 20 * * ?") 目前ftp数据还未准备好,所以暂时先不进行运行
public void pullPentadGodasFileAndSendDi() throws Exception { public void pullPentadGodasFileAndSendDi() throws Exception {
FtpUtil.FtpConfig ftpConfig = new FtpUtil.FtpConfig().setHost(host).setPort(port).setUserName(userName).setPassword(password);
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.setTime(new Date()); c.setTime(new Date());
// -2 为ftp上传文件延迟的时间 // -2 为ftp上传文件延迟的时间
...@@ -211,6 +270,7 @@ public class PullFileTask { ...@@ -211,6 +270,7 @@ public class PullFileTask {
*/ */
@Scheduled(cron = "0 10 20 * * ?") @Scheduled(cron = "0 10 20 * * ?")
public void pullOlrFileAndSendDi() throws Exception { public void pullOlrFileAndSendDi() throws Exception {
FtpUtil.FtpConfig ftpConfig = new FtpUtil.FtpConfig().setHost(host).setPort(port).setUserName(userName).setPassword(password);
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
c.setTime(new Date()); c.setTime(new Date());
c.add(Calendar.DATE, -2); c.add(Calendar.DATE, -2);
...@@ -298,11 +358,11 @@ public class PullFileTask { ...@@ -298,11 +358,11 @@ public class PullFileTask {
* *
* @throws Exception * @throws Exception
*/ */
// @PostConstruct @PostConstruct
public void a() throws Exception { public void a() 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);
Date dateStart = dateFormat.parse("20200325"); Date dateStart = dateFormat.parse("20200405");
Date dateEnd = dateFormat.parse("20200325"); Date dateEnd = dateFormat.parse("20200405");
Calendar c = Calendar.getInstance(); Calendar c = Calendar.getInstance();
PostGISMannager postGIS = new PostGISMannager(dbHost, dbPort, PostGISMannager postGIS = new PostGISMannager(dbHost, dbPort,
dbName, olrTbName, dbUserName, dbPassword); dbName, olrTbName, dbUserName, dbPassword);
...@@ -322,7 +382,7 @@ public class PullFileTask { ...@@ -322,7 +382,7 @@ public class PullFileTask {
} else { } else {
log.info(fileName + "========入库失败"); log.info(fileName + "========入库失败");
} }
} }else
{ {
log.info(fileName + "========下载失败"); log.info(fileName + "========下载失败");
break; break;
......
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