Procházet zdrojové kódy

2022年12月22日13:46:41

黄洋 před 2 roky
rodič
revize
a201f47284

+ 0 - 1
tongfei_river_data_collection/src/main/java/com/ublinkage/datacollection/Application.java

@@ -14,7 +14,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
  */
 @SpringBootApplication
 @EnableScheduling
-@EnableAsync
 public class Application {
     private static final Logger logger = LoggerFactory.getLogger(Application.class);
 

+ 67 - 13
tongfei_river_data_collection/src/main/java/com/ublinkage/datacollection/service/QxybDataCollectionTask.java

@@ -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();
+    }
 }

+ 7 - 9
tongfei_river_data_collection/src/main/java/com/ublinkage/datacollection/service/SatelliteRadarImageCollectionTask.java

@@ -19,6 +19,8 @@ import java.net.URL;
 @Slf4j
 @Service
 public class SatelliteRadarImageCollectionTask {
+    @Value("${yb.fixedTime}")
+    private Boolean ybFixedTime;
     /**
      * 下载路径
      */
@@ -26,20 +28,16 @@ public class SatelliteRadarImageCollectionTask {
     private String downloadFilePath;
 
     /**
-     * 分钟一次
+     * 50分钟一次
      */
-    @Scheduled(cron = "0 0/3 * * * ? ")
+    @Scheduled(cron = "0 0/50 * * * ? ")
     public void download1() {
+        if (ybFixedTime) {
+            return;
+        }
         this.FY4Ainfrared();
         this.FY4AWaterVapour();
         this.radarChinaAll();
-    }
-
-    /**
-     * 30分钟一次
-     */
-    @Scheduled(cron = "0 0/30 * * * ? ")
-    public void download2() {
         this.watervapor();
     }
 

+ 5 - 0
tongfei_river_data_collection/src/main/java/com/ublinkage/datacollection/service/WeatherDataCollectionTask.java

@@ -19,6 +19,8 @@ import java.util.List;
 @Slf4j
 @Service
 public class WeatherDataCollectionTask {
+    @Value("${yb.fixedTime}")
+    private Boolean ybFixedTime;
     /**
      * 下载路径
      */
@@ -75,6 +77,9 @@ public class WeatherDataCollectionTask {
      */
     @Scheduled(cron = "0 0 0/2 * * ? ")
     public void getWeatherData() {
+        if (ybFixedTime) {
+            return;
+        }
         for (Position position : list) {
             JSONObject json = new JSONObject();
             json.put("lat", position.getLat());

+ 2 - 2
tongfei_river_data_collection/src/main/resources/application.properties

@@ -8,8 +8,8 @@ download.file.path=/Users/ocean/Downloads/qxyb/
 
 
 
-yb.startTime=2022-12-01 00:00:00
-yb.endTime=2022-12-08 00:00:00
+yb.startTime=2022_12_15_00_00_00
+yb.endTime=2022_12_16_00_00_00
 
 yb.fixedTime=true
 

+ 1 - 1
tongfei_river_data_collection/src/test/java/com/ublinkage/datacollection/TongfeiRiverDataCollectionApplicationTests.java

@@ -18,7 +18,7 @@ class TongfeiRiverDataCollectionApplicationTests {
 
     @Test
     void test1() {
-        qxybDataCollectionTask.getQxybData();
+        qxybDataCollectionTask.getQxybDataManual();
     }
 
     @Test

+ 13 - 0
tongfei_river_data_collection/数据采集.bat

@@ -0,0 +1,13 @@
+:: 固定下载一个时间段的数据,和yb.startTime与yb.endTime配合使用
+set ybfixedTime=false
+
+set ybStartTime=2022-12-01 00:00:00
+set ybEndTime=2022-12-08 00:00:00
+
+set downloadFilePath=D:/
+
+set snowcdfile=/Users/ocean/Downloads/demo/SnowCoverPrediction/cd/predict.csv
+set snowqzkfile=/Users/ocean/Downloads/demo/SnowCoverPrediction/qzk/predict.csv
+
+:: 程序启动命令,不用修改。
+start jre1.8.0_171/bin/java  -Xms1g -Xmx1g -jar -Dyb.fixedTime=%ybfixedTime% -Dyb.startTime=%ybStartTime% -Dyb.endTime=%ybEndTime%  -Ddownload.file.path=%downloadFilePath% -Dsnow.cd.file=%snowcdfile% -Dsnow.qzk.file=%snowqzkfile% river_data_transfer.jar

+ 11 - 2
tongfei_river_data_transfer/src/main/java/com/ublinkage/transfer/backup/BackupHandlerTask.java

@@ -12,6 +12,7 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.time.Duration;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.Date;
@@ -31,24 +32,32 @@ public class BackupHandlerTask {
      * 备份天数
      */
     @Value("${send.backup-day}")
-    private String backupDay;
+    private Integer backupDay;
     /**
      * 备份路径
      */
     @Value("${send.backup-path}")
     private String backupPath;
 
+    @Value("${send.need-backup}")
+    private boolean needBackup;
+
     /**
      * 每天凌晨1点检查过期文件
      */
     @Scheduled(cron = "0 0 1 * * ? ")
     public void handlerBackup() {
+        if (!needBackup) {
+            return;
+        }
         try (Stream<Path> paths = Files.walk(Paths.get(backupPath))) {
             List<Path> fileNames = paths.filter(Files::isRegularFile).collect(Collectors.toList());
             for (Path file : fileNames) {
                 LocalDateTime startTime = FileUtil.lastModifiedTime(file.toFile()).toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
                 LocalDateTime endTime = LocalDateTime.now();
-                if (startTime.isAfter(endTime)) {
+
+                //计算时间差距
+                if (Duration.between(startTime, endTime).toDays() > backupDay) {
                     FileUtil.del(file.toFile());
                 }
             }

+ 6 - 9
tongfei_river_data_transfer/src/main/resources/application.yml

@@ -1,31 +1,28 @@
 server:
   port: 4000
 
-
 #-------发送端的验证
 compress:
   #启动压缩,如果启动
-  enable: false
+  enable: true
   #需要压缩的文件目录,可以填多个,用逗号分隔
-  file-path: /Users/ocean/Downloads/temp1/
+  file-path: /Users/ocean/Downloads/qxyb/
   #压缩完成的zip目录
-  zip-path: /Users/ocean/Downloads/temp1/
-
+  zip-path: /Users/ocean/Downloads/senzip/
 
 #发送路径
 send:
   #是否启用发送功能
   enable: true
   #目标IP地址
-  to-addr: 10.165.7.1:4000
-  file-path: /Users/ocean/Downloads/qxyb/
+  to-addr: 192.168.1.6:4000
+  file-path: /Users/ocean/Downloads/senzip/
   #发送成功后需要备份到备份目录
-  need-backup: true
+  need-backup: false
   #备份时长天数
   backup-day: 30
   backup-path: /Users/ocean/Downloads/back/
 
-
 #-------接收端的配置
 #服务端地址
 receive:

+ 31 - 0
tongfei_river_data_transfer/压缩、发送、接收.bat

@@ -0,0 +1,31 @@
+:: 压缩相关------------------
+:: 是否启动压缩
+set compress_enable=false
+:: 需要压缩的目录
+set compress_path=xxx
+:: 压缩文件存放目录
+set compress_zip=xxx
+
+:: 发送相关------------------
+:: 启动发送
+set send_enable=false
+:: IP和端口
+set send_to-addr=10.165.7.1:4000
+:: 发送目录文件
+set send_file-path=xxx
+:: 发送成功后需要备份到备份目录
+set send_need-backup=true
+:: 备份路径
+set send_backup-path=xxxx
+:: 备份天数
+set send_backup-day=10000
+
+
+:: 接收相关------------------
+:: 监听的端口
+set server_port=4000
+:: 接收目录
+set receive_file_path=D:/
+
+:: 程序启动命令,不用修改。
+start jre1.8.0_171/bin/java  -Xms1g -Xmx1g -jar -Dcompress.enable=%compress_enable% -Dcompress.file-path=%compress_path% -Dcompress.zip-path=%compress_zip%  -Dsend.enable=%send_enable% -Dsend.to-addr=%send_to-addr% -Dsend.file-path=%send_file-path% -Dsend.need-backup=%send_need-backup% -Dsend.backup-day=%send_backup-day% -Dsend.backup-path=%send_backup-path% -Dserver.port=%server_port% -Dreceive.file.path=%receive_file_path% river_data_transfer.jar