Explorar el Código

网格流量预报数据下载

hdc hace 2 años
padre
commit
cb203859da

+ 3 - 3
tongfei_river_data_collection/src/main/java/com/ublinkage/datacollection/ScheduledTaskConfig.java

@@ -102,13 +102,13 @@ public class ScheduledTaskConfig {
 
 
     public static String getLatestPublishTime(){
-        LocalDateTime localDateTime = getLocalDateTime();
+        LocalDateTime localDateTime = getLatestPublishLateTime();
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         return pattern.format(localDateTime);
     }
 
     @NotNull
-    private static LocalDateTime getLocalDateTime() {
+    private static LocalDateTime getLatestPublishLateTime() {
         //LocalDateTime now = LocalDateTime.of(2023, 6, 27, 1, 0);
         LocalDateTime now = LocalDateTime.now(Clock.systemUTC());
         long seconds = now.toEpochSecond(ZoneOffset.of("+8"));
@@ -120,7 +120,7 @@ public class ScheduledTaskConfig {
 
     public static String getPublishDt(){
         //LocalDateTime now = LocalDateTime.of(2023, 6, 27, 1, 0);
-        LocalDateTime localDateTime = getLocalDateTime();
+        LocalDateTime localDateTime = getLatestPublishLateTime();
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH_192");
         return pattern.format(localDateTime);
     }

+ 30 - 1
tongfei_river_data_collection/src/main/java/com/ublinkage/datacollection/controller/QxybController.java

@@ -1,11 +1,17 @@
 package com.ublinkage.datacollection.controller;
 
 import com.ublinkage.datacollection.service.QxybDataService;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.time.Clock;
+import java.time.LocalDateTime;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+
 @RestController
 @RequestMapping("/qxyb")
 public class QxybController {
@@ -15,9 +21,32 @@ public class QxybController {
     private QxybDataService qxybDataService;
 
     @RequestMapping("/download")
-    public String download(@RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
+    public String download(@RequestParam(value = "startTime", required = false) String startTime,
+                           @RequestParam(value = "endTime", required = false) String endTime) {
+        if (startTime == null || endTime == null) {
+            startTime = getLatestPublishTime();
+            endTime = getLatestPublishTime();
+        }
         qxybDataService.downloadQxybData(startTime, endTime);
         return "OK";
     }
 
+    public static String getLatestPublishTime() {
+        LocalDateTime localDateTime = getLatestPublishLateTime();
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        return pattern.format(localDateTime);
+    }
+
+    @NotNull
+    private static LocalDateTime getLatestPublishLateTime() {
+        //LocalDateTime now = LocalDateTime.of(2023, 6, 27, 1, 0);
+        LocalDateTime now = LocalDateTime.now(Clock.systemUTC());
+        long seconds = now.toEpochSecond(ZoneOffset.of("+8"));
+        long hours = seconds / (60 * 60);
+        long newHours = (hours / 6) * 6;
+        LocalDateTime localDateTime = LocalDateTime.ofEpochSecond(newHours * (60 * 60), 0, ZoneOffset.UTC);
+        return localDateTime;
+    }
+
+
 }

+ 31 - 7
tongfei_river_data_collection/src/main/java/com/ublinkage/datacollection/service/QxybDataService.java

@@ -44,9 +44,9 @@ public class QxybDataService {
     private String snowQzkFile;
 
     protected static OkHttpClient client = new OkHttpClient().newBuilder()
-            .connectTimeout(60, TimeUnit.SECONDS)
-            .readTimeout(600, TimeUnit.SECONDS)
-            .writeTimeout(180, TimeUnit.SECONDS)
+            .connectTimeout(10, TimeUnit.SECONDS)
+            .readTimeout(10, TimeUnit.SECONDS)
+            .writeTimeout(10, TimeUnit.SECONDS)
             .build();
     protected static String RDField = "LCJDomain";
     protected static String domain = "domain02";
@@ -428,6 +428,30 @@ public class QxybDataService {
                 }
             });
 
+            hoursForGridRain.forEach(hour -> {//网格流量与网格降水预报预见期一样
+                try {
+                    String dt1 = hour.format(DATE_TIME_FORMATTER1);
+                    String url2 = BASE_URL + "/getForecastHydroMatrixByWrfRDField?RDField=" + RDField + "&publishDT="
+                            + publishInfo.getPublishDT() + "&ensemble="
+                            + publishInfo.getEnsemble() + "&domain="
+                            + domain + "&content=2mTC&DT1="
+                            + dt1 + "&step=" + 1;
+                    log.info("下载网格流量预报数据(小时尺度):{}", url2);
+                    String result = getResult(url2);
+                    writeFile(result, downloadFilePath + "FlowGrid," + publishInfo.getPublishDT()
+                            + "," + dt1 + "," + 1 + "," + ensemble + ","
+                            + System.currentTimeMillis() + ".json");
+                    log.info("下载成功");
+                } catch (Exception e) {
+                    log.warn("下载失败", e);
+                }
+                try {
+                    Thread.sleep(100);
+                } catch (InterruptedException e) {
+                    // ignore...
+                }
+            });
+
 
         }
 
@@ -454,12 +478,12 @@ public class QxybDataService {
             response = client.newCall(request).execute();
             result = response.body().string();
             JSONObject json = JSONObject.parseObject(result);
-            String data = json.getString("data");
-            if (data == null || "[]".equals(data) || "{}".equals(data)) {
-                throw new RuntimeException("无有效数据");
-            }
             Integer code = json.getInteger("code");
             if (code != null && code == 200) {
+                String data = json.getString("data");
+                if (data == null || "[]".equals(data) || "{}".equals(data)) {
+                    throw new RuntimeException("无有效数据");
+                }
                 return result;
             } else {
                 throw new RuntimeException(result);

+ 1 - 1
tongfei_river_data_collection/src/main/java/com/ublinkage/datacollection/service/SatelliteRadarImageDataService.java

@@ -369,7 +369,7 @@ public class SatelliteRadarImageDataService {
      * @param urlList
      * @param path
      */
-    public static void downloadPicture(String urlList, String path) {
+    private static void downloadPicture(String urlList, String path) {
         URL url;
         try {
             urlList = urlList.replace("medium/", "");