合并枚举类
This commit is contained in:
parent
035ba3b844
commit
9686122211
|
|
@ -1,39 +0,0 @@
|
|||
package org.jeecg.common.constant.enums;
|
||||
|
||||
/**
|
||||
* 文件类型说明枚举
|
||||
*/
|
||||
public enum WeatherDataTypeEnum {
|
||||
|
||||
|
||||
PANGU(0, "PANGU"),
|
||||
CRA40(1, "CRA40"),
|
||||
NCEP(2, "NCEP");
|
||||
|
||||
private Integer key;
|
||||
|
||||
private String value;
|
||||
|
||||
WeatherDataTypeEnum(Integer key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getKey(){
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public static WeatherDataTypeEnum getInfoByKey(int key) {
|
||||
for (WeatherDataTypeEnum info : WeatherDataTypeEnum.values()) {
|
||||
if (info.getKey() == key) {
|
||||
return info;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -75,12 +75,12 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
LocalDateTime targetTime = startTime.plusHours(hour);
|
||||
|
||||
try {
|
||||
if (WeatherDataTypeEnum.PANGU.getKey() == dataType) {
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataTypeEnum.PANGU);
|
||||
} else if (WeatherDataTypeEnum.CRA40.getKey() == dataType){
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataTypeEnum.CRA40);
|
||||
} else if (WeatherDataTypeEnum.NCEP.getKey() == dataType){
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataTypeEnum.NCEP);
|
||||
if (WeatherDataSourceEnum.PANGU.getKey() == dataType) {
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataSourceEnum.PANGU);
|
||||
} else if (WeatherDataSourceEnum.CRA40.getKey() == dataType){
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataSourceEnum.CRA40);
|
||||
} else if (WeatherDataSourceEnum.NCEP.getKey() == dataType){
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataSourceEnum.NCEP);
|
||||
}
|
||||
} catch (JeecgBootException e) {
|
||||
throw e;
|
||||
|
|
@ -104,12 +104,12 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
Integer dataType = weatherData.getDataSource();
|
||||
LocalDateTime targetTime = weatherData.getDataStartTime();
|
||||
try {
|
||||
if (WeatherDataTypeEnum.PANGU.getKey() == dataType) {
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataTypeEnum.PANGU);
|
||||
} else if (WeatherDataTypeEnum.CRA40.getKey() == dataType){
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataTypeEnum.CRA40);
|
||||
} else if (WeatherDataTypeEnum.NCEP.getKey() == dataType){
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataTypeEnum.NCEP);
|
||||
if (WeatherDataSourceEnum.PANGU.getKey() == dataType) {
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataSourceEnum.PANGU);
|
||||
} else if (WeatherDataSourceEnum.CRA40.getKey() == dataType){
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataSourceEnum.CRA40);
|
||||
} else if (WeatherDataSourceEnum.NCEP.getKey() == dataType){
|
||||
return processWeatherData(weatherType, targetTime, WeatherDataSourceEnum.NCEP);
|
||||
}
|
||||
} catch (JeecgBootException e) {
|
||||
throw e;
|
||||
|
|
@ -155,7 +155,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
try {
|
||||
String filePath = buildFilePath(currentTime,
|
||||
WeatherTypeEnum.TEMPERATURE.getKey(), // 使用温度作为基础类型
|
||||
WeatherDataTypeEnum.getInfoByKey(dataType));
|
||||
WeatherDataSourceEnum.getInfoByKey(dataType));
|
||||
|
||||
if (!isFileValid(filePath)) {
|
||||
log.warn("文件无效或不存在: {}", filePath);
|
||||
|
|
@ -483,7 +483,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
|
||||
// 使用与第一个方法相同的变量名获取方式
|
||||
Map<String, String> variables = getVariableNames(dataType);
|
||||
if(WeatherDataTypeEnum.PANGU.getKey() == dataType || WeatherDataTypeEnum.NCEP.getKey() == dataType){
|
||||
if(WeatherDataSourceEnum.PANGU.getKey() == dataType || WeatherDataSourceEnum.NCEP.getKey() == dataType){
|
||||
try (NetcdfFile ncFile = NetcdfFile.open(filePath)) {
|
||||
// 读取数据(使用通用NcUtil方法)
|
||||
List<List<Double>> tData = getVariableData(ncFile, variables.get("temperature"));
|
||||
|
|
@ -499,11 +499,11 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
}else {
|
||||
// 循环处理每个时间点的数据
|
||||
try {
|
||||
String tFilePath = buildFilePath(currentTime, WeatherTypeEnum.TEMPERATURE.getKey(), WeatherDataTypeEnum.getInfoByKey(dataType));
|
||||
String pFilePath = buildFilePath(currentTime, WeatherTypeEnum.PRESSURE.getKey(), WeatherDataTypeEnum.getInfoByKey(dataType));
|
||||
String hFilePath = buildFilePath(currentTime, WeatherTypeEnum.HUMIDITY.getKey(), WeatherDataTypeEnum.getInfoByKey(dataType));
|
||||
String uFilePath = buildFilePath(currentTime, WeatherTypeEnum.WIND.getKey(), WeatherDataTypeEnum.getInfoByKey(dataType));
|
||||
String vFilePath = buildFilePath(currentTime, WeatherTypeEnum.WIND.getKey() + 1, WeatherDataTypeEnum.getInfoByKey(dataType));
|
||||
String tFilePath = buildFilePath(currentTime, WeatherTypeEnum.TEMPERATURE.getKey(), WeatherDataSourceEnum.getInfoByKey(dataType));
|
||||
String pFilePath = buildFilePath(currentTime, WeatherTypeEnum.PRESSURE.getKey(), WeatherDataSourceEnum.getInfoByKey(dataType));
|
||||
String hFilePath = buildFilePath(currentTime, WeatherTypeEnum.HUMIDITY.getKey(), WeatherDataSourceEnum.getInfoByKey(dataType));
|
||||
String uFilePath = buildFilePath(currentTime, WeatherTypeEnum.WIND.getKey(), WeatherDataSourceEnum.getInfoByKey(dataType));
|
||||
String vFilePath = buildFilePath(currentTime, WeatherTypeEnum.WIND.getKey() + 1, WeatherDataSourceEnum.getInfoByKey(dataType));
|
||||
|
||||
List<List<Double>> tData = null;
|
||||
List<List<Double>> pData = null;
|
||||
|
|
@ -546,19 +546,19 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
*/
|
||||
private Map<String, String> getVariableNames(Integer dataType) {
|
||||
Map<String, String> variables = new HashMap<>();
|
||||
if (WeatherDataTypeEnum.PANGU.getKey() == dataType) {
|
||||
if (WeatherDataSourceEnum.PANGU.getKey() == dataType) {
|
||||
variables.put("temperature", WeatherVariableNameEnum.PANGU_T.getValue());
|
||||
variables.put("pressure", WeatherVariableNameEnum.PANGU_P.getValue());
|
||||
variables.put("humidity", WeatherVariableNameEnum.PANGU_H.getValue());
|
||||
variables.put("windU", WeatherVariableNameEnum.PANGU_U.getValue());
|
||||
variables.put("windV", WeatherVariableNameEnum.PANGU_V.getValue());
|
||||
} else if (WeatherDataTypeEnum.CRA40.getKey() == dataType){
|
||||
} else if (WeatherDataSourceEnum.CRA40.getKey() == dataType){
|
||||
variables.put("temperature", WeatherVariableNameEnum.CRA40_T.getValue());
|
||||
variables.put("pressure", WeatherVariableNameEnum.CRA40_P.getValue());
|
||||
variables.put("humidity", WeatherVariableNameEnum.CRA40_H.getValue());
|
||||
variables.put("windU", WeatherVariableNameEnum.CRA40_U.getValue());
|
||||
variables.put("windV", WeatherVariableNameEnum.CRA40_V.getValue());
|
||||
} else if (WeatherDataTypeEnum.NCEP.getKey() == dataType){
|
||||
} else if (WeatherDataSourceEnum.NCEP.getKey() == dataType){
|
||||
variables.put("temperature", WeatherVariableNameEnum.NCEP_T.getValue());
|
||||
variables.put("pressure", WeatherVariableNameEnum.NCEP_P.getValue());
|
||||
variables.put("humidity", WeatherVariableNameEnum.NCEP_H.getValue());
|
||||
|
|
@ -662,7 +662,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
/**
|
||||
* 处理天气数据
|
||||
*/
|
||||
private WeatherResultVO processWeatherData(Integer weatherType, LocalDateTime targetTime, WeatherDataTypeEnum dataTypeEnum) {
|
||||
private WeatherResultVO processWeatherData(Integer weatherType, LocalDateTime targetTime, WeatherDataSourceEnum dataTypeEnum) {
|
||||
WeatherResultVO weatherResultVO = new WeatherResultVO();
|
||||
|
||||
if (WeatherTypeEnum.WIND.getKey().equals(weatherType)) {
|
||||
|
|
@ -692,8 +692,8 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
* 处理风场数据
|
||||
*/
|
||||
private WeatherResultVO processWindData(Integer weatherType, LocalDateTime targetTime,
|
||||
WeatherDataTypeEnum dataTypeEnum, WeatherResultVO weatherResultVO) {
|
||||
if (WeatherDataTypeEnum.PANGU.equals(dataTypeEnum) || WeatherDataTypeEnum.NCEP.equals(dataTypeEnum)) {
|
||||
WeatherDataSourceEnum dataTypeEnum, WeatherResultVO weatherResultVO) {
|
||||
if (WeatherDataSourceEnum.PANGU.equals(dataTypeEnum) || WeatherDataSourceEnum.NCEP.equals(dataTypeEnum)) {
|
||||
String filePath = buildFilePath(targetTime, weatherType, dataTypeEnum);
|
||||
validateFile(filePath);
|
||||
|
||||
|
|
@ -780,19 +780,19 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
/**
|
||||
* 构建文件路径
|
||||
*/
|
||||
private String buildFilePath(LocalDateTime targetTime, Integer weatherType, WeatherDataTypeEnum dataTypeEnum) {
|
||||
private String buildFilePath(LocalDateTime targetTime, Integer weatherType, WeatherDataSourceEnum dataTypeEnum) {
|
||||
StringBuilder storagePath = new StringBuilder()
|
||||
.append(this.systemStorageProperties.getRootPath())
|
||||
.append(File.separator);
|
||||
|
||||
if (WeatherDataTypeEnum.PANGU.equals(dataTypeEnum)) {
|
||||
if (WeatherDataSourceEnum.PANGU.equals(dataTypeEnum)) {
|
||||
storagePath.append(systemStorageProperties.getPangu())
|
||||
.append(File.separator)
|
||||
.append(WeatherPrefixConstants.PANGU_PREFIX)
|
||||
.append(targetTime.format(DateTimeFormatter.ofPattern("yyyyMMddHH")))
|
||||
.append(".")
|
||||
.append(WeatherFileSuffixEnum.GRIB.getValue());
|
||||
} else if (WeatherDataTypeEnum.CRA40.equals(dataTypeEnum)) {
|
||||
} else if (WeatherDataSourceEnum.CRA40.equals(dataTypeEnum)) {
|
||||
storagePath.append(systemStorageProperties.getCra40())
|
||||
.append(File.separator)
|
||||
.append(WeatherPrefixConstants.CRA40_PREFIX)
|
||||
|
|
@ -802,7 +802,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
.append(WeatherSuffixConstants.CRA40_SUFFIX)
|
||||
.append(".")
|
||||
.append(WeatherFileSuffixEnum.GRIB2.getValue());
|
||||
} else if (WeatherDataTypeEnum.NCEP.equals(dataTypeEnum)) {
|
||||
} else if (WeatherDataSourceEnum.NCEP.equals(dataTypeEnum)) {
|
||||
storagePath.append(systemStorageProperties.getNcep())
|
||||
.append(File.separator)
|
||||
.append(targetTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmm")))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user