|
|
|
@ -20,7 +20,7 @@ import com.htfp.weather.web.exception.AppException;
|
|
|
|
|
import com.htfp.weather.web.exception.ErrorCode;
|
|
|
|
|
import com.htfp.weather.web.pojo.response.*;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import ucar.ma2.Array;
|
|
|
|
|
import ucar.ma2.Index4D;
|
|
|
|
@ -125,8 +125,10 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
nowWeatherStatus.setLatitude(latitude);
|
|
|
|
|
nowWeatherStatus.setLongitude(longitude);
|
|
|
|
|
return nowWeatherStatus;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -162,8 +164,10 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
nowWeatherStatusList.add(nowWeatherStatus);
|
|
|
|
|
}
|
|
|
|
|
return nowWeatherStatusList;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -189,8 +193,10 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
);
|
|
|
|
|
final GfsLevelsEnum levelFlag = GfsLevelsEnum.getByCode(level);
|
|
|
|
|
return buildTimeSeriesDatasetInTargetPoint(gridDataSet, level, latitude, longitude, levelFlag);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -223,8 +229,10 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
timeSeriesDatasetList.add(timeSeriesDataset);
|
|
|
|
|
}
|
|
|
|
|
return timeSeriesDatasetList;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -243,22 +251,29 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
throw new AppException(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
int[] pressureLevels = tableConfig.getPressureList();
|
|
|
|
|
Array array = gfsDataFetcher.getProfileByVariableAndPressure(targetVariable, targetTime, latitude, longitude);
|
|
|
|
|
float[] values = (float[]) array.copyTo1DJavaArray();
|
|
|
|
|
ProfileResponse profileResponse = new ProfileResponse(pressureLevels, values);
|
|
|
|
|
GridDataSet gridDataSet = gfsDataFetcher.getProfileByPressure(Collections.singletonList(targetVariable), targetTime, latitude, longitude);
|
|
|
|
|
float[] values = (float[]) gridDataSet.getVariables().get(targetVariable).toArray().copyTo1DJavaArray();
|
|
|
|
|
ProfileResponse profileResponse = new ProfileResponse();
|
|
|
|
|
profileResponse.setPressureLevels(tableConfig.getPressureList());
|
|
|
|
|
profileResponse.setHeightLevels(tableConfig.getPressureHeightList());
|
|
|
|
|
profileResponse.setValues(values);
|
|
|
|
|
profileResponse.setLatitude(latitude);
|
|
|
|
|
profileResponse.setLongitude(longitude);
|
|
|
|
|
return profileResponse;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 获取全部变量随气压变化的廓线 (推荐) */
|
|
|
|
|
public ProfileDataset getProfileByPressure(OffsetDateTime targetTime, double latitude, double longitude) {
|
|
|
|
|
try {
|
|
|
|
|
List<String> variableNames = getVariableNamesInDatabase(GfsLevelsEnum.UPPER.getCode());
|
|
|
|
|
GfsLevelsEnum levelFlag = GfsLevelsEnum.UPPER;
|
|
|
|
|
List<String> variableNames = getVariableNamesInDatabase(levelFlag.getCode());
|
|
|
|
|
GridDataSet gridDataSet = gfsDataFetcher.getProfileByPressure(variableNames, targetTime, latitude, longitude);
|
|
|
|
|
ProfileDataset profile = buildProfileDataset(gridDataSet, GfsLevelsEnum.UPPER);
|
|
|
|
|
ProfileDataset profile = buildProfileDataset(gridDataSet, levelFlag);
|
|
|
|
|
profile.setLatitude(latitude);
|
|
|
|
|
profile.setLongitude(longitude);
|
|
|
|
|
return profile;
|
|
|
|
@ -269,6 +284,48 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 获取指定变量随高度变化的廓线, 目前只支持风速风向*/
|
|
|
|
|
public ProfileResponse getProfileByVariableAndNearSurfaceHeight(String variableName, OffsetDateTime targetTime, double latitude, double longitude) {
|
|
|
|
|
String targetVariable = GfsVariableHeightEnum.getGfsVariableName(variableName);
|
|
|
|
|
if (targetVariable == null) {
|
|
|
|
|
throw new AppException(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
int[] heightLevels = tableConfig.getHeightList();
|
|
|
|
|
GridDataSet gridDataSet = gfsDataFetcher.getProfileByNearSurfaceHeight(Collections.singletonList(targetVariable), targetTime, latitude, longitude);
|
|
|
|
|
float[] values = (float[]) gridDataSet.getVariables().get(targetVariable).toArray().copyTo1DJavaArray();
|
|
|
|
|
ProfileResponse profileResponse = new ProfileResponse();
|
|
|
|
|
profileResponse.setValues(values);
|
|
|
|
|
profileResponse.setHeightLevels(Arrays.copyOfRange(heightLevels, 1, heightLevels.length));
|
|
|
|
|
profileResponse.setLatitude(latitude);
|
|
|
|
|
profileResponse.setLongitude(longitude);
|
|
|
|
|
return profileResponse;
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 获取全部变量随高度变化的廓线, 目前只支持风速风向*/
|
|
|
|
|
public ProfileDataset getProfileByNearSurfaceHeight(OffsetDateTime targetTime, double latitude, double longitude) {
|
|
|
|
|
try {
|
|
|
|
|
GfsLevelsEnum levelFlag = GfsLevelsEnum.SURFACE;
|
|
|
|
|
List<String> variableNames = new ArrayList<>();
|
|
|
|
|
variableNames.add(GfsVariableHeightEnum.getGfsVariableName("windSpeed"));
|
|
|
|
|
variableNames.add(GfsVariableHeightEnum.getGfsVariableName("wind360"));
|
|
|
|
|
GridDataSet gridDataSet = gfsDataFetcher.getProfileByNearSurfaceHeight(variableNames, targetTime, latitude, longitude);
|
|
|
|
|
ProfileDataset profile = buildProfileDataset(gridDataSet, levelFlag);
|
|
|
|
|
profile.setHeightLevel(Arrays.copyOfRange(tableConfig.getHeightList(), 1, tableConfig.getHeightList().length));
|
|
|
|
|
profile.setLatitude(latitude);
|
|
|
|
|
profile.setLongitude(longitude);
|
|
|
|
|
return profile;
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取指定变量、时间、高度的二维数组数据
|
|
|
|
@ -305,8 +362,10 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
variableNames, timeRange, levRange, latRange, lonRange
|
|
|
|
|
).getVariable(targetVariable).toArray();
|
|
|
|
|
return buildPlane(array, minLat, maxLat, minLon, maxLon);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
} catch (AppException e) {
|
|
|
|
|
throw e;
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
throw new AppException(ErrorCode.TABLESTORE_QUERY_ERROR, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -499,7 +558,12 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
throw new AppException(ErrorCode.RESPONSE_DATA_BUILD_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
result.setPressureLevels(tableConfig.getPressureList());
|
|
|
|
|
if (levelFlag == GfsLevelsEnum.UPPER) {
|
|
|
|
|
result.setPressureLevels(tableConfig.getPressureList());
|
|
|
|
|
result.setHeightLevel(tableConfig.getPressureHeightList());
|
|
|
|
|
} else {
|
|
|
|
|
result.setHeightLevel(tableConfig.getHeightList());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|