|
|
@ -13,7 +13,7 @@ import com.htfp.weather.info.Constant;
|
|
|
|
import com.htfp.weather.info.GfsLevelsEnum;
|
|
|
|
import com.htfp.weather.info.GfsLevelsEnum;
|
|
|
|
import com.htfp.weather.utils.DateTimeUtils;
|
|
|
|
import com.htfp.weather.utils.DateTimeUtils;
|
|
|
|
import com.htfp.weather.utils.NdArrayUtils;
|
|
|
|
import com.htfp.weather.utils.NdArrayUtils;
|
|
|
|
import com.htfp.weather.web.exception.AppExcpetion;
|
|
|
|
import com.htfp.weather.web.exception.AppException;
|
|
|
|
import com.htfp.weather.web.exception.ErrorCode;
|
|
|
|
import com.htfp.weather.web.exception.ErrorCode;
|
|
|
|
import com.htfp.weather.web.pojo.response.NowWeatherStatus;
|
|
|
|
import com.htfp.weather.web.pojo.response.NowWeatherStatus;
|
|
|
|
import com.htfp.weather.web.pojo.response.PlaneResponse;
|
|
|
|
import com.htfp.weather.web.pojo.response.PlaneResponse;
|
|
|
@ -65,14 +65,14 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
String targetVariable = GfsVariableIsobaricEnum.getGfsVariableName(variableName);
|
|
|
|
String targetVariable = GfsVariableIsobaricEnum.getGfsVariableName(variableName);
|
|
|
|
|
|
|
|
|
|
|
|
if (targetVariable == null) {
|
|
|
|
if (targetVariable == null) {
|
|
|
|
throw new AppExcpetion(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
|
throw new AppException(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GridDataSetMeta lastGridDataSetMeta = null;
|
|
|
|
GridDataSetMeta lastGridDataSetMeta = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
throw new AppException(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int iTime = getTargetTimeIndex(targetTime, lastGridDataSetMeta);
|
|
|
|
int iTime = getTargetTimeIndex(targetTime, lastGridDataSetMeta);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
@ -102,7 +102,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
throw new AppException(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map<String, List> params = getFutureTimeIndexList(lastGridDataSetMeta);
|
|
|
|
Map<String, List> params = getFutureTimeIndexList(lastGridDataSetMeta);
|
|
|
|
List<Integer> iTimeList = params.get("iTimeList");
|
|
|
|
List<Integer> iTimeList = params.get("iTimeList");
|
|
|
@ -141,7 +141,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": " + e.getMessage());
|
|
|
|
throw new AppException(ErrorCode.DATA_SET_EMPTY, ": " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int iTime = getTargetTimeIndex(OffsetDateTime.now(), lastGridDataSetMeta);
|
|
|
|
int iTime = getTargetTimeIndex(OffsetDateTime.now(), lastGridDataSetMeta);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
@ -176,10 +176,10 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": " + e.getMessage());
|
|
|
|
throw new AppException(ErrorCode.DATA_SET_EMPTY, ": " + e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (latitude.size() != longitude.size()) {
|
|
|
|
if (latitude.size() != longitude.size()) {
|
|
|
|
throw new AppExcpetion(ErrorCode.INDEX_SIZE_ERROR, ": 经纬度数组大小不一致");
|
|
|
|
throw new AppException(ErrorCode.INDEX_SIZE_ERROR, ": 经纬度数组大小不一致");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int pointSize = latitude.size();
|
|
|
|
int pointSize = latitude.size();
|
|
|
|
List<String> variableNames = getVariableNamesInDatabase(level);
|
|
|
|
List<String> variableNames = getVariableNamesInDatabase(level);
|
|
|
@ -264,13 +264,13 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (targetVariable == null) {
|
|
|
|
if (targetVariable == null) {
|
|
|
|
throw new AppExcpetion(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
|
throw new AppException(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GridDataSetMeta lastGridDataSetMeta = null;
|
|
|
|
GridDataSetMeta lastGridDataSetMeta = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
throw new AppException(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int iTime = getTargetTimeIndex(targetTime, lastGridDataSetMeta);
|
|
|
|
int iTime = getTargetTimeIndex(targetTime, lastGridDataSetMeta);
|
|
|
@ -388,7 +388,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
variableNameInApi = GfsVariableIsobaricEnum.getVariableNameInApi(variableNameInFile);
|
|
|
|
variableNameInApi = GfsVariableIsobaricEnum.getVariableNameInApi(variableNameInFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (variableNameInApi == null) {
|
|
|
|
if (variableNameInApi == null) {
|
|
|
|
throw new AppExcpetion(ErrorCode.NO_SUCH_VARIABLE);
|
|
|
|
throw new AppException(ErrorCode.NO_SUCH_VARIABLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Grid4D grid4D = entry.getValue(); Index4D index = new Index4D(grid4D.getShape());
|
|
|
|
Grid4D grid4D = entry.getValue(); Index4D index = new Index4D(grid4D.getShape());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -396,10 +396,10 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
Method method = aClass.getDeclaredMethod(setMethodName, aClass.getDeclaredField(variableNameInApi).getType());
|
|
|
|
Method method = aClass.getDeclaredMethod(setMethodName, aClass.getDeclaredField(variableNameInApi).getType());
|
|
|
|
method.invoke(result, grid4D.toArray().getFloat(index.set(0, iLevInGrid, iLatInGrid, iLonInGrid)));
|
|
|
|
method.invoke(result, grid4D.toArray().getFloat(index.set(0, iLevInGrid, iLatInGrid, iLonInGrid)));
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
} catch (ReflectiveOperationException e) {
|
|
|
|
throw new AppExcpetion(ErrorCode.NO_SUCH_VARIABLE, e);
|
|
|
|
throw new AppException(ErrorCode.NO_SUCH_VARIABLE, e);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
throw new AppExcpetion(ErrorCode.RESPONSE_DATA_BUILD_ERROR);
|
|
|
|
throw new AppException(ErrorCode.RESPONSE_DATA_BUILD_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
@ -409,13 +409,13 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
long milli = (long) lastGridDataSetMeta.getAttributes().get(AttributionEnum.REFERENCE_TIME.getName());
|
|
|
|
long milli = (long) lastGridDataSetMeta.getAttributes().get(AttributionEnum.REFERENCE_TIME.getName());
|
|
|
|
OffsetDateTime refTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneOffset.ofHours(0));
|
|
|
|
OffsetDateTime refTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneOffset.ofHours(0));
|
|
|
|
if (targetTime.isBefore(refTime)) {
|
|
|
|
if (targetTime.isBefore(refTime)) {
|
|
|
|
throw new AppExcpetion(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
throw new AppException(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<String> forecastHours = lastGridDataSetMeta.getForecastHours();
|
|
|
|
List<String> forecastHours = lastGridDataSetMeta.getForecastHours();
|
|
|
|
String targetHour = String.valueOf(getForecastHourFromTargetTime(targetTime, refTime));
|
|
|
|
String targetHour = String.valueOf(getForecastHourFromTargetTime(targetTime, refTime));
|
|
|
|
if (!forecastHours.contains(targetHour)) {
|
|
|
|
if (!forecastHours.contains(targetHour)) {
|
|
|
|
throw new AppExcpetion(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
throw new AppException(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int iTime = forecastHours.indexOf(targetHour);
|
|
|
|
int iTime = forecastHours.indexOf(targetHour);
|
|
|
|
return iTime;
|
|
|
|
return iTime;
|
|
|
@ -426,7 +426,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
OffsetDateTime refTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneOffset.ofHours(0));
|
|
|
|
OffsetDateTime refTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneOffset.ofHours(0));
|
|
|
|
OffsetDateTime currentTime = DateTimeUtils.getUTCDateTime(OffsetDateTime.now());
|
|
|
|
OffsetDateTime currentTime = DateTimeUtils.getUTCDateTime(OffsetDateTime.now());
|
|
|
|
if (currentTime.isBefore(refTime)) {
|
|
|
|
if (currentTime.isBefore(refTime)) {
|
|
|
|
throw new AppExcpetion(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
throw new AppException(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int startHour = getForecastHourFromTargetTime(currentTime, refTime);
|
|
|
|
int startHour = getForecastHourFromTargetTime(currentTime, refTime);
|
|
|
|
List<String> forecastHours = lastGridDataSetMeta.getForecastHours();
|
|
|
|
List<String> forecastHours = lastGridDataSetMeta.getForecastHours();
|
|
|
@ -446,7 +446,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CollectionUtils.isEmpty(iTimeList) || CollectionUtils.isEmpty(timeList)) {
|
|
|
|
if (CollectionUtils.isEmpty(iTimeList) || CollectionUtils.isEmpty(timeList)) {
|
|
|
|
throw new AppExcpetion(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
throw new AppException(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map<String, List> map = new HashMap<>(2);
|
|
|
|
Map<String, List> map = new HashMap<>(2);
|
|
|
|
map.put("iTimeList", iTimeList);
|
|
|
|
map.put("iTimeList", iTimeList);
|
|
|
@ -457,16 +457,16 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
private int getLongitudeIndex(double lon) {
|
|
|
|
private int getLongitudeIndex(double lon) {
|
|
|
|
double[] lonList = tableConfig.getLonList();
|
|
|
|
double[] lonList = tableConfig.getLonList();
|
|
|
|
if (lonList.length == 0) {
|
|
|
|
if (lonList.length == 0) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LONGITUDE_INDEX_ERROR, "经度列表为空, 无法查找索引");
|
|
|
|
throw new AppException(ErrorCode.LONGITUDE_INDEX_ERROR, "经度列表为空, 无法查找索引");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
double minLon = lonList[0];
|
|
|
|
double minLon = lonList[0];
|
|
|
|
double maxLon = lonList[lonList.length - 1];
|
|
|
|
double maxLon = lonList[lonList.length - 1];
|
|
|
|
if (minLon > lon || lon > maxLon) {
|
|
|
|
if (minLon > lon || lon > maxLon) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LONGITUDE_INDEX_ERROR, "经度不在有效范围内: " + minLon + " ~ " + maxLon);
|
|
|
|
throw new AppException(ErrorCode.LONGITUDE_INDEX_ERROR, "经度不在有效范围内: " + minLon + " ~ " + maxLon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int nearestIndex = NdArrayUtils.findNearestIndex(lonList, lon);
|
|
|
|
int nearestIndex = NdArrayUtils.findNearestIndex(lonList, lon);
|
|
|
|
if (nearestIndex == -1) {
|
|
|
|
if (nearestIndex == -1) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LONGITUDE_INDEX_ERROR, "找不到" + lon + "的经度索引");
|
|
|
|
throw new AppException(ErrorCode.LONGITUDE_INDEX_ERROR, "找不到" + lon + "的经度索引");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nearestIndex;
|
|
|
|
return nearestIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -474,17 +474,17 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
private int getLatitudeIndex(double lat) {
|
|
|
|
private int getLatitudeIndex(double lat) {
|
|
|
|
double[] latList = tableConfig.getLatList();
|
|
|
|
double[] latList = tableConfig.getLatList();
|
|
|
|
if (latList.length == 0) {
|
|
|
|
if (latList.length == 0) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LATITUDE_INDEX_ERROR, "纬度列表为空, 无法查找索引");
|
|
|
|
throw new AppException(ErrorCode.LATITUDE_INDEX_ERROR, "纬度列表为空, 无法查找索引");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
double minLat = latList[0];
|
|
|
|
double minLat = latList[0];
|
|
|
|
double maxLat = latList[latList.length - 1];
|
|
|
|
double maxLat = latList[latList.length - 1];
|
|
|
|
|
|
|
|
|
|
|
|
if (minLat > lat || lat > maxLat) {
|
|
|
|
if (minLat > lat || lat > maxLat) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LATITUDE_INDEX_ERROR, "纬度不在有效范围内: " + minLat + " ~ " + maxLat);
|
|
|
|
throw new AppException(ErrorCode.LATITUDE_INDEX_ERROR, "纬度不在有效范围内: " + minLat + " ~ " + maxLat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int nearestIndex = NdArrayUtils.findNearestIndex(latList, lat);
|
|
|
|
int nearestIndex = NdArrayUtils.findNearestIndex(latList, lat);
|
|
|
|
if (nearestIndex == -1) {
|
|
|
|
if (nearestIndex == -1) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LATITUDE_INDEX_ERROR, "找不到" + lat + "的纬度索引");
|
|
|
|
throw new AppException(ErrorCode.LATITUDE_INDEX_ERROR, "找不到" + lat + "的纬度索引");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nearestIndex;
|
|
|
|
return nearestIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -492,11 +492,11 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
private int getPressureIndex(int pressureLevel) {
|
|
|
|
private int getPressureIndex(int pressureLevel) {
|
|
|
|
List<Integer> levList = Arrays.stream(tableConfig.getPressureList()).boxed().collect(Collectors.toList());
|
|
|
|
List<Integer> levList = Arrays.stream(tableConfig.getPressureList()).boxed().collect(Collectors.toList());
|
|
|
|
if (CollectionUtils.isEmpty(levList)) {
|
|
|
|
if (CollectionUtils.isEmpty(levList)) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LEVEL_INDEX_ERROR, "气压列表为空, 无法查找索引");
|
|
|
|
throw new AppException(ErrorCode.LEVEL_INDEX_ERROR, "气压列表为空, 无法查找索引");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int index = levList.indexOf(pressureLevel);
|
|
|
|
int index = levList.indexOf(pressureLevel);
|
|
|
|
if (index == -1) {
|
|
|
|
if (index == -1) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LATITUDE_INDEX_ERROR, "找不到" + pressureLevel + "的气压高度索引");
|
|
|
|
throw new AppException(ErrorCode.LATITUDE_INDEX_ERROR, "找不到" + pressureLevel + "的气压高度索引");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|