气象预览

This commit is contained in:
hekaiyu 2025-10-24 14:41:46 +08:00
parent c4679d4c2b
commit c9072c0ae6
3 changed files with 47 additions and 5 deletions

View File

@ -81,10 +81,22 @@ public class WeatherDataController {
@Operation(summary = "气象预测-气象数据查询")
@GetMapping(value = "getWeatherData")
public Result<?> getWeatherData(Integer dataType,
Integer type,
Integer weatherType,
LocalDateTime startTime,
int hour) {
return Result.OK(weatherDataService.getWeatherData(dataType, type, startTime, hour));
return Result.OK(weatherDataService.getWeatherData(dataType, weatherType, startTime, hour));
}
/**
* 气象预览
* @return
*/
@AutoLog(value = "气象预测-气象预览")
@Operation(summary = "气象预测-气象预览")
@GetMapping(value = "getWeatherData")
public Result<?> getWeatherDataPreview(String weatherId,
@RequestParam(required = false, defaultValue = "0")Integer weatherType) {
return Result.OK(weatherDataService.getWeatherDataPreview(weatherId, weatherType));
}
/**

View File

@ -15,7 +15,8 @@ import java.util.Map;
public interface WeatherDataService {
WeatherResultVO getWeatherData(Integer dataType, Integer type, LocalDateTime startTime, int hour);
WeatherResultVO getWeatherData(Integer dataType, Integer weatherType, LocalDateTime startTime, int hour);
WeatherResultVO getWeatherDataPreview(String weatherId, Integer weatherType);
Map<String, List<String>> getDataLine(Integer dataType, LocalDateTime startTime, LocalDateTime endTime, double longitude, double latitude);
/**

View File

@ -91,6 +91,35 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
throw new JeecgBootException("没有该类型的气象数据!");
}
/**
* 根据类型和小时数获取天气数据
* @param weatherId 气象数据id
* @param weatherType 天气类型
* @return 天气数据列表
*/
@Override
public WeatherResultVO getWeatherDataPreview(String weatherId, Integer weatherType) {
Objects.requireNonNull(weatherId, "天气数据ID不能为空");
WeatherData weatherData = this.baseMapper.selectById(weatherId);
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);
}
} catch (JeecgBootException e) {
throw e;
} catch (Exception e) {
log.error("处理天气数据失败", e);
throw new JeecgBootException("处理天气数据失败", e);
}
throw new JeecgBootException("没有该类型的气象数据!");
}
/**
* 获取时间序列天气数据
* @param dataType 气象数据类型
@ -454,7 +483,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
// 使用与第一个方法相同的变量名获取方式
Map<String, String> variables = getVariableNames(dataType);
if(WeatherDataTypeEnum.PANGU.getKey() == dataType){
if(WeatherDataTypeEnum.PANGU.getKey() == dataType || WeatherDataTypeEnum.NCEP.getKey() == dataType){
try (NetcdfFile ncFile = NetcdfFile.open(filePath)) {
// 读取数据使用通用NcUtil方法
List<List<Double>> tData = getVariableData(ncFile, variables.get("temperature"));
@ -664,7 +693,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
*/
private WeatherResultVO processWindData(Integer weatherType, LocalDateTime targetTime,
WeatherDataTypeEnum dataTypeEnum, WeatherResultVO weatherResultVO) {
if (WeatherDataTypeEnum.PANGU.equals(dataTypeEnum)) {
if (WeatherDataTypeEnum.PANGU.equals(dataTypeEnum) || WeatherDataTypeEnum.NCEP.equals(dataTypeEnum)) {
String filePath = buildFilePath(targetTime, weatherType, dataTypeEnum);
validateFile(filePath);