|
@@ -1,4 +1,4 @@
|
|
|
-package com.cpp.web.service.cloud;
|
|
|
+package com.cpp.web.service.datafactory;
|
|
|
|
|
|
import com.cpp.common.utils.StringUtils;
|
|
|
import com.cpp.web.domain.BaseForecastEntity;
|
|
@@ -9,6 +9,8 @@ import com.cpp.web.domain.datafactory.enums.FileTypeEnum;
|
|
|
import com.cpp.web.domain.enums.AlarmEnum;
|
|
|
import com.cpp.web.domain.enums.DataSourcesEnum;
|
|
|
import com.cpp.web.service.alarm.AbnormalAlarmService;
|
|
|
+import com.cpp.web.service.cloud.ForecastPowerShortTermCloudService;
|
|
|
+import com.cpp.web.service.cloud.NwpCloudService;
|
|
|
import com.cpp.web.service.datafactory.ParsingLogService;
|
|
|
import com.cpp.web.service.overhaulplan.OverhaulPlanService;
|
|
|
import com.cpp.web.utils.*;
|
|
@@ -28,6 +30,8 @@ import java.nio.file.Files;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* ftp文件解析
|
|
@@ -41,15 +45,10 @@ import java.util.*;
|
|
|
public class CloudFileParsing {
|
|
|
|
|
|
private final ParsingLogService parsingLogService;
|
|
|
-
|
|
|
private final ForecastPowerShortTermCloudService forecastPowerShortTermCloudService;
|
|
|
private final NwpCloudService nwpCloudService;
|
|
|
-
|
|
|
private final File fileNewDir = ParsingFileUtil.checkGetPath(ParsingFileUtil.getOutDownload() + File.separator + "new");
|
|
|
-
|
|
|
private final ThreadPoolTaskExecutor executor;
|
|
|
-
|
|
|
-
|
|
|
private final OverhaulPlanService overhaulPlanService;
|
|
|
|
|
|
/**
|
|
@@ -98,77 +97,94 @@ public class CloudFileParsing {
|
|
|
parsingLog.setParsingTime(new Date());
|
|
|
parsingLog.setFileName(fileName);
|
|
|
|
|
|
- // 如果文件不是当然的,删除文件
|
|
|
+ // 如果文件不是当天的,删除文件
|
|
|
if (!fileName.contains(dayStr)) {
|
|
|
file.delete();
|
|
|
log.warn(fileName + "不是当天的文件,删除!");
|
|
|
break;
|
|
|
}
|
|
|
// 如果文件名长度符合规则
|
|
|
- if (fileName.length() < 30) {
|
|
|
+ if (fileName.length() < 31) {
|
|
|
// 如果是短期文件
|
|
|
if (file.getName().startsWith("DQ")) {
|
|
|
- try {
|
|
|
- parsingLog.setFileType(FileTypeEnum.dq);
|
|
|
- // 解析短期文件
|
|
|
- List<BaseForecastEntity> listDq = new ArrayList<>();
|
|
|
- listDq.addAll(fileAnalysisShortTerm(file, new Date(currentDate)));
|
|
|
- if (!listDq.isEmpty()) {
|
|
|
- try {
|
|
|
- String stationCode = listDq.get(0).getStationCode();
|
|
|
- parsingLog.setStationCode(stationCode);
|
|
|
- forecastPowerShortTermCloudService.saveBatch(overhaulPlanService.getCorrectionData(listDq, FileTypeEnum.dq.name(), fileName, stationCode));
|
|
|
- flag = true;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("保存短期数据报错:" + fileName, e);
|
|
|
- parsingLog.setParsingDescribe("保存短期数据报错:" + fileName);
|
|
|
- LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "保存短期数据报错:" + fileName, null);
|
|
|
+ String stationCode = findStationCode(fileName);
|
|
|
+ if (!stationCode.equals("null")) {
|
|
|
+ try {
|
|
|
+ //标准格式DQ_J01100_202410170118030.RB
|
|
|
+ parsingLog.setFileType(FileTypeEnum.dq);
|
|
|
+ // 解析短期文件
|
|
|
+ List<BaseForecastEntity> listDq = new ArrayList<>();
|
|
|
+ listDq.addAll(fileAnalysisShortTerm(file, new Date(currentDate)));
|
|
|
+ if (!listDq.isEmpty()) {
|
|
|
+ try {
|
|
|
+ parsingLog.setStationCode(stationCode);
|
|
|
+ forecastPowerShortTermCloudService.saveBatch(overhaulPlanService.getCorrectionData(listDq, FileTypeEnum.dq.name(), fileName, stationCode));
|
|
|
+ flag = true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("保存短期数据报错:" + fileName, e);
|
|
|
+ parsingLog.setParsingDescribe("保存短期数据报错:" + fileName);
|
|
|
+ LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "保存短期数据报错:" + fileName, null);
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info(file.getName() + "文件数据内容为空、不能正常解析 、移除该文件:" + fileName);
|
|
|
+ parsingLog.setParsingDescribe("文件数据内容为空、不能正常解析 、移除该文件:" + fileName);
|
|
|
+ LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "文件数据内容为空、不能正常解析 、移除该文件::" + fileName, null);
|
|
|
flag = false;
|
|
|
}
|
|
|
- } else {
|
|
|
- log.info(file.getName() + "文件数据内容为空、不能正常解析 、移除该文件:" + fileName);
|
|
|
- parsingLog.setParsingDescribe("文件数据内容为空、不能正常解析 、移除该文件:" + fileName);
|
|
|
- LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "文件数据内容为空、不能正常解析 、移除该文件::" + fileName, null);
|
|
|
- flag = false;
|
|
|
- }
|
|
|
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
+ flag = false;
|
|
|
+ parsingLog.setParsingDescribe("解析DQ文件异常:" + fileName);
|
|
|
+ LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "解析DQ文件失败:" + fileName, null);
|
|
|
+ log.error("解析DQ文件失败:" + fileName, e);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
flag = false;
|
|
|
- parsingLog.setParsingDescribe("解析DQ文件异常:" + fileName);
|
|
|
- LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "解析DQ文件失败:" + fileName, null);
|
|
|
- log.error("解析DQ文件失败:" + fileName, e);
|
|
|
+ parsingLog.setParsingDescribe("解析DQ文件异常:" + fileName + "==无法获取场站编码");
|
|
|
+ LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "解析DQ文件失败:" + fileName + "==无法获取场站编码", null);
|
|
|
+ log.error("解析DQ文件失败:" + fileName + "==无法获取场站编码");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if (file.getName().startsWith("NWP")) {
|
|
|
- try {
|
|
|
- parsingLog.setFileType(FileTypeEnum.nwp);
|
|
|
- List<NwpCloud> listNwp = fileAnalysisNwp(file, new Date(currentDate));
|
|
|
- if (!listNwp.isEmpty()) {
|
|
|
- try {
|
|
|
- parsingLog.setStationCode(listNwp.get(0).getStationCode());
|
|
|
- nwpCloudService.saveBatch(listNwp);
|
|
|
- flag = true;
|
|
|
- } catch (Exception e) {
|
|
|
- LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "保存NWP数据报错:" + fileName, null);
|
|
|
- log.error("保存NWP数据报错:" + fileName, e);
|
|
|
- parsingLog.setParsingDescribe("保存NWP数据报错:" + fileName);
|
|
|
+ String stationCode = findStationCode(fileName);
|
|
|
+ if (!stationCode.equals("null")) {
|
|
|
+ try {
|
|
|
+ parsingLog.setFileType(FileTypeEnum.nwp);
|
|
|
+ List<NwpCloud> listNwp = fileAnalysisNwp(file, new Date(currentDate));
|
|
|
+ if (!listNwp.isEmpty()) {
|
|
|
+ try {
|
|
|
+ parsingLog.setStationCode(listNwp.get(0).getStationCode());
|
|
|
+ nwpCloudService.saveBatch(listNwp);
|
|
|
+ flag = true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "保存NWP数据报错:" + fileName, null);
|
|
|
+ log.error("保存NWP数据报错:" + fileName, e);
|
|
|
+ parsingLog.setParsingDescribe("保存NWP数据报错:" + fileName);
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "文件数据内容为空、不能正常解析 、移除该文件:" + fileName, null);
|
|
|
+ parsingLog.setParsingDescribe("文件数据内容为空、不能正常解析 、移除该文件:" + fileName);
|
|
|
+ log.info(file.getName() + "文件数据内容为空、不能正常解析 、移除该文件");
|
|
|
flag = false;
|
|
|
}
|
|
|
- } else {
|
|
|
- LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "文件数据内容为空、不能正常解析 、移除该文件:" + fileName, null);
|
|
|
- parsingLog.setParsingDescribe("文件数据内容为空、不能正常解析 、移除该文件:" + fileName);
|
|
|
- log.info(file.getName() + "文件数据内容为空、不能正常解析 、移除该文件");
|
|
|
+ } catch (Exception e) {
|
|
|
+ LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "解析NWP文件失败:" + fileName, null);
|
|
|
+ log.error("解析NWP文件失败:" + fileName, e);
|
|
|
+ parsingLog.setParsingDescribe("解析NWP文件失败:" + fileName);
|
|
|
flag = false;
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "解析NWP文件失败:" + fileName, null);
|
|
|
- log.error("解析NWP文件失败:" + fileName, e);
|
|
|
- parsingLog.setParsingDescribe("解析NWP文件失败:" + fileName);
|
|
|
+ } else {
|
|
|
flag = false;
|
|
|
+ LogUtil.info(DataSourcesEnum.E2, AlarmEnum.E4, "解析NWP文件失败:" + fileName + "==无法获取场站编码", null);
|
|
|
+ log.error("解析NWP文件失败:" + fileName + "==无法获取场站编码");
|
|
|
+ parsingLog.setParsingDescribe("解析NWP文件失败:" + fileName + "==无法获取场站编码");
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -360,7 +376,10 @@ public class CloudFileParsing {
|
|
|
* @param currentDate 当前时间
|
|
|
* @return 样例集合
|
|
|
*/
|
|
|
- private List<ForecastPowerShortTermCloud> fileAnalysisShortTerm(File file, Date currentDate) {
|
|
|
+ private List<ForecastPowerShortTermCloud> fileAnalysisShortTerm(
|
|
|
+ File file,
|
|
|
+ Date currentDate
|
|
|
+ ) {
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
List<ForecastPowerShortTermCloud> forecastPowerShortTerm = new ArrayList<>();
|
|
|
// 当文件未被使用时,进行解析上报
|
|
@@ -552,4 +571,18 @@ public class CloudFileParsing {
|
|
|
log.error(file.getName() + "文件解析失败", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public String findStationCode(String fileName) {
|
|
|
+ String regex = "_([^_]+)_"; // 匹配两个下划线之间的内容
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
+ Matcher matcher = pattern.matcher(fileName);
|
|
|
+
|
|
|
+ if (matcher.find()) {
|
|
|
+ String result = matcher.group(1); // 获取第一个捕获组的内容
|
|
|
+ return result;
|
|
|
+ } else {
|
|
|
+ return "null";
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|