Browse Source

1.重复解析云端预测文件会删除以往数据保留最新数据
2.有过期文件删除后跳过后面解析逻辑而不是跳出循环

tl 5 months ago
parent
commit
53ee1d7099

+ 22 - 12
cpp-admin/src/main/java/com/cpp/web/service/datafactory/CloudFileParsing.java

@@ -1,5 +1,6 @@
 package com.cpp.web.service.datafactory;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.cpp.common.utils.StringUtils;
 import com.cpp.web.domain.BaseForecastCloudEntity;
 import com.cpp.web.domain.BaseForecastEntity;
@@ -102,7 +103,7 @@ public class CloudFileParsing {
                 if (!fileName.contains(dayStr)) {
                     file.delete();
                     log.warn(fileName + "不是当天的文件,删除!");
-                    break;
+                    continue;
                 }
                 // 如果文件名长度符合规则
                 if (fileName.length() < 31) {
@@ -116,10 +117,16 @@ public class CloudFileParsing {
                                 parsingLog.setFileType(FileTypeEnum.dq);
                                 // 解析短期文件
                                 List<BaseForecastCloudEntity> listDq = new ArrayList<>();
-                                listDq.addAll(fileAnalysisShortTerm(file, new Date(currentDate)));
+                                listDq.addAll(fileAnalysisShortTerm(file, new Date(currentDate),stationCode));
                                 if (!listDq.isEmpty()) {
                                     try {
                                         parsingLog.setStationCode(stationCode);
+                                        BaseForecastCloudEntity base = listDq.get(0);
+                                        Date createTime  = base.getCreateTime();
+                                        String forecastModel = base.getForecastModel();
+
+                                        QueryWrapper queryWrapper = new QueryWrapper<ForecastPowerShortTermCloud>().between("create_time",DateTimeUtil.getDayStartTime(createTime.getTime()),DateTimeUtil.getDayLastTime(createTime.getTime())).eq("station_code",stationCode).eq("forecast_model",forecastModel);
+                                        forecastPowerShortTermCloudService.remove(queryWrapper);
                                         forecastPowerShortTermCloudService.saveBatch(overhaulPlanService.getCorrectionData(listDq, FileTypeEnum.dq.name(), fileName, stationCode));
                                         flag = true;
                                     } catch (Exception e) {
@@ -149,10 +156,18 @@ public class CloudFileParsing {
 
                             try {
                                 parsingLog.setFileType(FileTypeEnum.nwp);
-                                List<NwpCloud> listNwp = fileAnalysisNwp(file, new Date(currentDate));
+                                List<NwpCloud> listNwp = fileAnalysisNwp(file, new Date(currentDate), stationCode);
                                 if (!listNwp.isEmpty()) {
                                     try {
-                                        parsingLog.setStationCode(listNwp.get(0).getStationCode());
+                                        parsingLog.setStationCode(stationCode);
+                                        NwpCloud nwpCloud = listNwp.get(0);
+                                        Date createTime  = nwpCloud.getCreateTime();
+                                        String forecastModel = nwpCloud.getForecastModel();
+
+                                        QueryWrapper queryWrapper = new QueryWrapper<NwpCloud>().between("create_time",DateTimeUtil.getDayStartTime(createTime.getTime()),DateTimeUtil.getDayLastTime(createTime.getTime())).eq("station_code",stationCode).eq("forecast_model",forecastModel);
+
+                                        nwpCloudService.remove(queryWrapper);
+
                                         nwpCloudService.saveBatch(listNwp);
                                         flag = true;
                                     } catch (Exception e) {
@@ -206,7 +221,7 @@ public class CloudFileParsing {
      * @param file 文件路径
      * @return 样例集合
      */
-    private List<NwpCloud> fileAnalysisNwp(File file, Date currentDate) {
+    private List<NwpCloud> fileAnalysisNwp(File file, Date currentDate,String stationCode) {
         List<NwpCloud> listNwp = new ArrayList<>();
         if (file.renameTo(file)) {
             InputStreamReader readNwp = null;
@@ -219,8 +234,6 @@ public class CloudFileParsing {
                 BigDecimal nwpDirectRadiation = new BigDecimal("0.7"); //直接辐射
                 BigDecimal nwpDiffuseRadiation = new BigDecimal("0.3"); //散接辐射
 
-
-                String stationCode = "";
                 String forecastModel = "";
 
 
@@ -229,7 +242,6 @@ public class CloudFileParsing {
                     String[] datas = lineTxt.split("\t");
 
                     if (datas[0].startsWith("<集中")) {
-                        stationCode = ParsingUtil.splitLineWithSpace(datas[0])[1].split("'")[1];
                         // 使用单引号分割字符串
                         forecastModel = ParsingUtil.splitLineWithSpace(datas[0])[2].split("'")[1];
                     }
@@ -367,7 +379,8 @@ public class CloudFileParsing {
      */
     private List<ForecastPowerShortTermCloud> fileAnalysisShortTerm(
             File file,
-            Date currentDate
+            Date currentDate,
+            String stationCode
     ) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         List<ForecastPowerShortTermCloud> forecastPowerShortTerm = new ArrayList<>();
@@ -381,7 +394,6 @@ public class CloudFileParsing {
                 read = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);
                 bufferedReader = new BufferedReader(read);
 
-                String stationCode = "";
                 String forecastModel = "";
 
                 // 循环解析文件
@@ -389,8 +401,6 @@ public class CloudFileParsing {
 
                     String[] string_arr = stringLine.split("\t");
                     if (string_arr[0].startsWith("<集中")) {
-                        stationCode = ParsingUtil.splitLineWithSpace(string_arr[0])[1].split("'")[1];
-                        // 使用单引号分割字符串
                         forecastModel = ParsingUtil.splitLineWithSpace(string_arr[0])[2].split("'")[1];
                     }