|
|
@@ -1,11 +1,13 @@
|
|
|
package com.ublinkage.datacollection.service;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ublinkage.datacollection.entity.PublishInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.InitializingBean;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -23,7 +25,7 @@ import java.util.List;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class QxybDataCollectionTask {
|
|
|
+public class QxybDataCollectionTask implements InitializingBean {
|
|
|
|
|
|
/**
|
|
|
* 下载路径
|
|
|
@@ -46,7 +48,7 @@ public class QxybDataCollectionTask {
|
|
|
private Boolean ybFixedTime;
|
|
|
|
|
|
String RDField = "LCJDomain";
|
|
|
- String domain = "domain03";
|
|
|
+ String domain = "domain02";
|
|
|
String ensemble = "mp3_cu3";
|
|
|
|
|
|
|
|
|
@@ -54,7 +56,35 @@ public class QxybDataCollectionTask {
|
|
|
* 获取预报批次数据列表,每天下午3点同步
|
|
|
*/
|
|
|
@Scheduled(cron = "0 0 13 * * ? ")
|
|
|
- public void getQxybData() {
|
|
|
+ public void getQxybDataAudo() {
|
|
|
+ //固定时间就不执行自动任务
|
|
|
+ if (ybFixedTime) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ log.info("开始下载:{}到{}的预报数据.", this.getYbStartTime(), this.getYbEndTime());
|
|
|
+ //下载分区雨量
|
|
|
+ this.getForecast15Data();
|
|
|
+
|
|
|
+ this.getForecast29Data();
|
|
|
+
|
|
|
+ this.getDomainTempAndRain();
|
|
|
+
|
|
|
+ //获取网格数据,包含温度网格,降雨网格
|
|
|
+ this.getGridData();
|
|
|
+
|
|
|
+ //下载温度站点
|
|
|
+ this.getForeTempData();
|
|
|
+ log.info("结束下载:{}到{}的预报数据.", this.getYbStartTime(), this.getYbEndTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手动雨欣
|
|
|
+ */
|
|
|
+ public void getQxybDataManual() {
|
|
|
+ //固定时间就不执行自动任务
|
|
|
+ if (!ybFixedTime) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
log.info("开始下载:{}到{}的预报数据.", this.getYbStartTime(), this.getYbEndTime());
|
|
|
//下载分区雨量
|
|
|
this.getForecast15Data();
|
|
|
@@ -225,12 +255,14 @@ public class QxybDataCollectionTask {
|
|
|
JSONObject json = JSONObject.parseObject(batchResult);
|
|
|
Integer code = json.getInteger("code");
|
|
|
if (code == 200) {
|
|
|
- FileUtil.writeUtf8String(batchResult, downloadFilePath + "TempSiteBatch," + this.getYbStartTime() + "," + this.getYbEndTime() + "," + ensemble + "," + System.currentTimeMillis() + ".json");
|
|
|
+ FileUtil.writeUtf8String(batchResult, downloadFilePath + "TempSiteBatch," + this.toyyyy_MM_dd_HH_mm_ss(this.getYbStartTime()) + "," + this.toyyyy_MM_dd_HH_mm_ss(this.getYbEndTime()) + "," + ensemble + "," + System.currentTimeMillis() + ".json");
|
|
|
List<PublishInfo> publishList = json.getJSONArray("data").toJavaList(PublishInfo.class);
|
|
|
try {
|
|
|
for (PublishInfo publishInfo : publishList) {
|
|
|
int hour = 1;
|
|
|
- String result = HttpUtil.get("http://111.198.2.202:6657/getForeTempData?publishDT=" + publishInfo.getPublishDT() + "&RDField=" + RDField + "&ensemble=" + ensemble);
|
|
|
+ String getForeTempUrl = "http://111.198.2.202:6657/getForeTempData?publishDT=" + publishInfo.getPublishDT() + "&RDField=" + RDField + "&ensemble=" + ensemble;
|
|
|
+ log.info("下载温度站点数据请求地址:{}", getForeTempUrl);
|
|
|
+ String result = HttpUtil.get(getForeTempUrl);
|
|
|
FileUtil.writeUtf8String(result, downloadFilePath + "TempSiteData," + publishInfo.getPublishDT() + "," + hour + "," + ensemble + "," + System.currentTimeMillis() + ".json");
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -246,18 +278,21 @@ public class QxybDataCollectionTask {
|
|
|
*/
|
|
|
private void getGridData() {
|
|
|
String url = "http://111.198.2.202:6657/getForecastBaseInfo?RDField=" + RDField + "&domain=" + domain + "&ensemble=" + ensemble + "&startTime=" + this.getYbStartTime() + "&endTime=" + this.getYbEndTime();
|
|
|
+ log.info("getGridData的URL:{}", url);
|
|
|
String batchResult = HttpUtil.get(url);
|
|
|
JSONObject json = JSONObject.parseObject(batchResult);
|
|
|
Integer code = json.getInteger("code");
|
|
|
if (code == 200) {
|
|
|
- FileUtil.writeUtf8String(batchResult, downloadFilePath + "GridBatch," + this.getYbStartTime() + "," + this.getYbEndTime() + "," + ensemble + "," + System.currentTimeMillis() + ".json");
|
|
|
+ FileUtil.writeUtf8String(batchResult, downloadFilePath + "GridBatch," + this.toyyyy_MM_dd_HH_mm_ss(this.getYbStartTime()) + "," + this.toyyyy_MM_dd_HH_mm_ss(this.getYbEndTime()) + "," + ensemble + "," + System.currentTimeMillis() + ".json");
|
|
|
List<PublishInfo> publishInfoList = json.getJSONObject("data").getJSONArray("publishInfoList").toJavaList(PublishInfo.class);
|
|
|
//查询1小时的降雨和温度
|
|
|
for (PublishInfo publishInfo : publishInfoList) {
|
|
|
//获取这个批次的每个时间点数据,根据publishTime的次日0时开始算192个小时
|
|
|
int duration = Integer.parseInt(publishInfo.getPublishDT().split("_")[2]);
|
|
|
LocalDateTime publishTime = LocalDateTime.parse(publishInfo.getPublishTime(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
- LocalDateTime st = publishTime.plusHours(12);
|
|
|
+// LocalDateTime st = publishTime.plusHours(12);
|
|
|
+ //网格降水和温度都是从次日1时开始
|
|
|
+ LocalDateTime st = LocalDateTime.of(publishTime.getYear(), publishTime.getMonthValue(), publishTime.getDayOfMonth(), 1, 0, 0).plusDays(1);
|
|
|
|
|
|
try {
|
|
|
//1小时雨量
|
|
|
@@ -304,17 +339,27 @@ public class QxybDataCollectionTask {
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
- log.error("获取到预报批次数据异常:{}", code);
|
|
|
+ log.error("获取到预报批次数据异常:{}", batchResult);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 转换格式
|
|
|
+ *
|
|
|
+ * @param str
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String toyyyy_MM_dd_HH_mm_ss(String str) {
|
|
|
+ return str.replace("-", "_").replace(":", "_").replace(" ", "_");
|
|
|
+ }
|
|
|
|
|
|
public String getYbStartTime() {
|
|
|
if (ybFixedTime) {
|
|
|
- return ybStartTime;
|
|
|
+ DateTime date = DateUtil.parse(ybStartTime, "yyyy_MM_dd_HH_mm_ss");
|
|
|
+ return DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
|
|
|
} else {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
- LocalDateTime st = LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 0, 0, 0);
|
|
|
+ LocalDateTime st = LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 0, 0, 0).minusDays(3);
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
return df.format(st);
|
|
|
}
|
|
|
@@ -322,14 +367,23 @@ public class QxybDataCollectionTask {
|
|
|
|
|
|
public String getYbEndTime() {
|
|
|
if (ybFixedTime) {
|
|
|
- return ybEndTime;
|
|
|
+ DateTime date = DateUtil.parse(ybEndTime, "yyyy_MM_dd_HH_mm_ss");
|
|
|
+ return DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
|
|
|
} else {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
- LocalDateTime st = LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 0, 0, 0).plusDays(1);
|
|
|
+ LocalDateTime st = LocalDateTime.of(now.getYear(), now.getMonthValue(), now.getDayOfMonth(), 0, 0, 0).minusDays(2);
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
return df.format(st);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 系统启动后马上执行下载
|
|
|
+ *
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void afterPropertiesSet() throws Exception {
|
|
|
+ this.getQxybDataManual();
|
|
|
+ }
|
|
|
}
|