1. 定义日志切面以及注解,统一输出controller层日志;2. 修改经纬度校验范围,限定在中国区域(0-55N, 70-140E); 3. info日志和error日志分开存储;

download
shiyi 11 months ago
parent 7fc28bba7b
commit 20c4a6ca41

@ -1,9 +0,0 @@
package com.htfp.weather.web.config;
/**
* @Author : shiyi
* @Date : 2024/6/12 14:12
* @Description :
*/
public class LogAspect {
}

@ -0,0 +1,16 @@
package com.htfp.weather.web.config.aspect;
import java.lang.annotation.*;
/**
* @Author : shiyi
* @Date : 2024/7/15 16:01
* @Description :
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ControllerLog {
String info(); // 调用接口的简要信息
boolean isSaveToDatabase() default false; //该条操作日志是否需要持久化存储, 当前未配置数据库, 默认为false
}

@ -0,0 +1,131 @@
package com.htfp.weather.web.config.aspect;
import com.htfp.weather.web.pojo.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.*;
/**
* @Author : shiyi
* @Date : 2024/6/12 14:12
* @Description :
*/
@Aspect
@Component
@Order(1)
@Slf4j
public class ControllerLogAspect {
/**定义切点指定controller包下面的公共方法且被ControllerLog注解修饰*/
@Pointcut("execution(public * com.htfp.weather.web.controller.*.*(..))" +
"&& @annotation(com.htfp.weather.web.config.aspect.ControllerLog)"
)
public void logPointCut() {
}
// @Before(value = "logPointCut()&& @annotation(controllerLog)")
// public void doBefore(JoinPoint joinPoint, ControllerLog controllerLog) {
// log.info("[controllerLog] {} start: {}", controllerLog.info(), joinPoint.getSignature().toShortString());
// }
//
// @AfterReturning(value = "logPointCut()&& @annotation(controllerLog)", returning = "ret")
// public void doAfterReturning(JoinPoint joinPoint, Object ret, ControllerLog controllerLog) {
// log.info("[controllerLog] {} finished: {}, return: {}", controllerLog.info(), joinPoint.getSignature().toShortString(), ret);
// }
@AfterThrowing(value = "logPointCut()&& @annotation(controllerLog)", throwing = "cause")
public void doAfterThrowing(JoinPoint joinPoint, Throwable cause, ControllerLog controllerLog){
log.info("[controllerLog] {} failed: {}, errorMsg: {}", controllerLog.info(), joinPoint.getSignature().toShortString(), cause.getMessage());
}
@Around(value = "logPointCut()&& @annotation(controllerLog)")
public Object doAround(ProceedingJoinPoint joinPoint, ControllerLog controllerLog) throws Throwable {
//获取当前请求对象
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if (attributes == null) {
return Result.error(new RuntimeException("切点处理异常: " + this.getClass().getName()));
}
HttpServletRequest request = attributes.getRequest();
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
//记录请求信息
Object parameter = getParameter(method, joinPoint.getArgs());
log.info("[controllerLog] {} start: {}, request params: {}", controllerLog.info(), signature.toShortString(), parameter);
long startTime = System.currentTimeMillis();
// 调用目标切点方法
Object result = joinPoint.proceed();
long endTime = System.currentTimeMillis();
int timeCost = (int) (endTime - startTime);
if (controllerLog.isSaveToDatabase()) {
WebLog webLog = new WebLog();
webLog.setDescription(controllerLog.info());
webLog.setIp(request.getRemoteUser());
webLog.setRequestMethod(request.getMethod());
webLog.setParameter(parameter);
webLog.setResult(result);
webLog.setTimeCost(timeCost);
webLog.setStartTime(startTime);
webLog.setUri(request.getRequestURI());
webLog.setUrl(request.getRequestURL().toString());
}
log.debug("[controllerLog] {} finished ({}ms): {}, return: {}", controllerLog.info(), timeCost, signature.toShortString(), result);
log.info("[controllerLog] {} finished ({}ms): {}", controllerLog.info(), timeCost, signature.toShortString());
// 返回值将由controller返回
return result;
}
/**
*
*/
private Object getParameter(Method method, Object[] args) {
List<Object> argList = new ArrayList<>();
Parameter[] parameters = method.getParameters();
for (int i = 0; i < parameters.length; i++) {
//将RequestBody注解修饰的参数作为请求参数
RequestBody requestBody = parameters[i].getAnnotation(RequestBody.class);
if (requestBody != null) {
argList.add(args[i]);
}
//将RequestParam注解修饰的参数作为请求参数
RequestParam requestParam = parameters[i].getAnnotation(RequestParam.class);
if (requestParam != null) {
Map<String, Object> map = new HashMap<>();
String key = parameters[i].getName();
if (!StringUtils.isEmpty(requestParam.value())) {
key = requestParam.value();
}
map.put(key, args[i]);
argList.add(map);
}
// else {
// argList.add(args[i]);
// }
}
if (argList.isEmpty()) {
return null;
} else if (argList.size() == 1) {
return argList.get(0);
} else {
return argList;
}
}
}

@ -0,0 +1,35 @@
package com.htfp.weather.web.config.aspect;
import lombok.Data;
/**
* @Author : shiyi
* @Date : 2024/7/15 15:44
* @Description :
*/
@Data
public class WebLog {
private String description; // 操作简介
private String username;
private Long startTime;
private Integer timeCost;
private String basePath;
private String uri;
private String url;
private String requestMethod;
private String ip;
private Object parameter;
private Object result;
}

@ -28,9 +28,9 @@ public class InterfaceInterceptor implements HandlerInterceptor {
String servletPath = request.getServletPath(); String servletPath = request.getServletPath();
// log.info("InterfaceInterceptor.preHandle >> 进入拦截, {}, {}", servletPath, handler.getClass().getName()); // log.info("InterfaceInterceptor.preHandle >> 进入拦截, {}, {}", servletPath, handler.getClass().getName());
// ip 校验 // ip 校验
// if (checkIp(request)) { if (checkIp(request)) {
// return true; return true;
// } }
// 签名校验 // 签名校验
final String signature = request.getHeader("signature"); final String signature = request.getHeader("signature");
final String timestamp = String.valueOf(request.getHeader("timestamp")); final String timestamp = String.valueOf(request.getHeader("timestamp"));

@ -7,6 +7,7 @@ import com.htfp.weather.griddata.operation.GfsDataImport;
import com.htfp.weather.griddata.operation.GfsDataImport.ImportFileInfo; import com.htfp.weather.griddata.operation.GfsDataImport.ImportFileInfo;
import com.htfp.weather.info.Constant; import com.htfp.weather.info.Constant;
import com.htfp.weather.utils.DateTimeUtils; import com.htfp.weather.utils.DateTimeUtils;
import com.htfp.weather.web.config.aspect.ControllerLog;
import com.htfp.weather.web.exception.AppException; 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.request.GfsConfigUpdate; import com.htfp.weather.web.pojo.request.GfsConfigUpdate;
@ -63,6 +64,7 @@ public class ConfigController {
* tablestore * tablestore
*/ */
@RequestMapping("/queryDatabaseConfig") @RequestMapping("/queryDatabaseConfig")
@ControllerLog(info = "查询tablestore数据库配置")
public Result queryDatabaseConfig() { public Result queryDatabaseConfig() {
return Result.success(tableConfig); return Result.success(tableConfig);
} }
@ -71,6 +73,7 @@ public class ConfigController {
* tablestore * tablestore
*/ */
@PostMapping("/updateDatabaseConfig") @PostMapping("/updateDatabaseConfig")
@ControllerLog(info = "更新tablestore数据库配置")
public Result updateDatabaseConfig(@RequestBody TableConfigUpdate request) { public Result updateDatabaseConfig(@RequestBody TableConfigUpdate request) {
String secret = request.getSecret(); String secret = request.getSecret();
TableConfig updateConfig = request.getConfig(); TableConfig updateConfig = request.getConfig();
@ -91,6 +94,7 @@ public class ConfigController {
* GFS * GFS
*/ */
@RequestMapping("/queryDataSourceConfig") @RequestMapping("/queryDataSourceConfig")
@ControllerLog(info = "查询GFS下载配置")
public Result queryDataSourceConfig() { public Result queryDataSourceConfig() {
return Result.success(gfsDataConfig); return Result.success(gfsDataConfig);
} }
@ -99,6 +103,7 @@ public class ConfigController {
* GFS * GFS
*/ */
@PostMapping("/updateDataSourceConfig") @PostMapping("/updateDataSourceConfig")
@ControllerLog(info = "更新GFS下载配置")
public Result updateDataSourceConfig(@Validated @RequestBody GfsConfigUpdate request) { public Result updateDataSourceConfig(@Validated @RequestBody GfsConfigUpdate request) {
String secret = request.getSecret(); String secret = request.getSecret();
GfsDataConfig updateConfig = request.getConfig(); GfsDataConfig updateConfig = request.getConfig();
@ -119,6 +124,7 @@ public class ConfigController {
* 24 * 24
*/ */
@PostMapping("/downloadAllFiles") @PostMapping("/downloadAllFiles")
@ControllerLog(info = "下载当前时刻未来24小时的数据文件")
public Result downloadAllFiles(@RequestBody Map<String, String> params) { public Result downloadAllFiles(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); validSecret(secret);
@ -140,6 +146,7 @@ public class ConfigController {
* *
*/ */
@PostMapping("/downloadSingleFile") @PostMapping("/downloadSingleFile")
@ControllerLog(info = "下载指定时刻文件")
public Result downloadSingleFile(@RequestBody Map<String, String> params) { public Result downloadSingleFile(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); validSecret(secret);
@ -152,6 +159,7 @@ public class ConfigController {
* *
*/ */
@PostMapping("/importToTablestoreByReferenceTime") @PostMapping("/importToTablestoreByReferenceTime")
@ControllerLog(info = "根据起报时间将数据导入数据库")
public Result importData(@RequestBody Map<String, String> params) { public Result importData(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); validSecret(secret);
@ -163,10 +171,11 @@ public class ConfigController {
* *
*/ */
@PostMapping("/downloadAndImport") @PostMapping("/downloadAndImport")
@ControllerLog(info = "下载并导入")
public Result downloadAndImport(@RequestBody Map<String, String> params) { public Result downloadAndImport(@RequestBody Map<String, String> params) {
Result downloadResponse = downloadAllFiles(params); Result downloadResponse = downloadAllFiles(params);
if (downloadResponse.isSuccess()) { if (downloadResponse.isSuccess()) {
DownloadResult data = (DownloadResult)downloadResponse.getData(); DownloadResult data = (DownloadResult) downloadResponse.getData();
String refTimeStr = data.getSuccessList().get(0).getRefTimeStr(); String refTimeStr = data.getSuccessList().get(0).getRefTimeStr();
OffsetDateTime time = OffsetDateTime.of(LocalDateTime.parse(refTimeStr, DateTimeFormatter.ofPattern(Constant.UTC_TIME_STRING)), ZoneOffset.UTC); OffsetDateTime time = OffsetDateTime.of(LocalDateTime.parse(refTimeStr, DateTimeFormatter.ofPattern(Constant.UTC_TIME_STRING)), ZoneOffset.UTC);
return getImportResponse(time); return getImportResponse(time);
@ -193,6 +202,7 @@ public class ConfigController {
} }
@PostMapping("queryAllDataDir") @PostMapping("queryAllDataDir")
@ControllerLog(info = "查询所有数据文件夹")
public Result queryAllDataDir(@RequestBody Map<String, String> params) { public Result queryAllDataDir(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); validSecret(secret);
@ -200,10 +210,12 @@ public class ConfigController {
List<String> subDirList = fileService.getSubDirList(dataRoot); List<String> subDirList = fileService.getSubDirList(dataRoot);
return Result.success(subDirList); return Result.success(subDirList);
} }
/** /**
* *
*/ */
@PostMapping("/queryAllFileByReferenceTime") @PostMapping("/queryAllFileByReferenceTime")
@ControllerLog(info = "查询指定起报时间文件夹中的所有文件名")
public Result queryAllFileByReferenceTime(@RequestBody Map<String, String> params) { public Result queryAllFileByReferenceTime(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); validSecret(secret);
@ -220,6 +232,7 @@ public class ConfigController {
* *
*/ */
@PostMapping("/deleteDirByReferenceTime") @PostMapping("/deleteDirByReferenceTime")
@ControllerLog(info = "删除指定起报时间对应的文件夹")
public Result deleteDirByReferenceTime(@RequestBody Map<String, String> params) { public Result deleteDirByReferenceTime(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); validSecret(secret);
@ -241,6 +254,7 @@ public class ConfigController {
* *
*/ */
@PostMapping("/deleteTargetFile") @PostMapping("/deleteTargetFile")
@ControllerLog(info = "删除指定文件")
public Result deleteTargetFile(@RequestBody Map<String, String> params) { public Result deleteTargetFile(@RequestBody Map<String, String> params) {
String secret = params.get("secret"); String secret = params.get("secret");
validSecret(secret); validSecret(secret);

@ -1,5 +1,6 @@
package com.htfp.weather.web.controller; package com.htfp.weather.web.controller;
import com.htfp.weather.web.config.aspect.ControllerLog;
import com.htfp.weather.web.pojo.hefeng.HeFengWarningResponse; import com.htfp.weather.web.pojo.hefeng.HeFengWarningResponse;
import com.htfp.weather.web.pojo.request.Position2D; import com.htfp.weather.web.pojo.request.Position2D;
import com.htfp.weather.web.pojo.response.NowWeatherStatus; import com.htfp.weather.web.pojo.response.NowWeatherStatus;
@ -24,7 +25,8 @@ import java.util.List;
* @Description : * @Description :
*/ */
@CrossOrigin @CrossOrigin
@RestController @Slf4j @RestController
@Slf4j
@RequestMapping("/htfp/weather/surface/") @RequestMapping("/htfp/weather/surface/")
public class SurfaceWeatherController { public class SurfaceWeatherController {
@Resource(name = "hefeng") @Resource(name = "hefeng")
@ -32,48 +34,40 @@ public class SurfaceWeatherController {
@Resource @Resource
CmaServiceImpl cmaService; CmaServiceImpl cmaService;
@PostMapping("/querySurfaceNowWeather") @PostMapping("/querySurfaceNowWeather")
@ControllerLog(info = "地面实时气象信息查询")
public Result queryNowWeather(@Validated @RequestBody Position2D position2D) throws Exception { public Result queryNowWeather(@Validated @RequestBody Position2D position2D) throws Exception {
double lat = position2D.getLatitude(); double lat = position2D.getLatitude();
double lon = position2D.getLongitude(); double lon = position2D.getLongitude();
log.info("[data-server] 地面实时气象信息查询 start: param={}", position2D);
try { NowWeatherStatus nowWeatherStatus = surfaceDataService.getNowSurfaceWeatherStatus(lat, lon);
NowWeatherStatus nowWeatherStatus = surfaceDataService.getNowSurfaceWeatherStatus(lat, lon); nowWeatherStatus.setLatitude(lat);
nowWeatherStatus.setLatitude(lat); nowWeatherStatus.setLongitude(lon);
nowWeatherStatus.setLongitude(lon); return Result.success(nowWeatherStatus);
return Result.success(nowWeatherStatus);
} finally {
log.info("[data-server] 地面实时气象信息查询 end");
}
} }
@PostMapping("/querySurfaceForecast") @PostMapping("/querySurfaceForecast")
@ControllerLog(info = "地面24小时预报结果查询")
public Result querySurfaceForecast(@Validated @RequestBody Position2D position2D) throws Exception { public Result querySurfaceForecast(@Validated @RequestBody Position2D position2D) throws Exception {
double lat = position2D.getLatitude(); double lat = position2D.getLatitude();
double lon = position2D.getLongitude(); double lon = position2D.getLongitude();
log.info("[data-server] 地面24小时预报结果查询 start: param={}", position2D);
try { TimeSeriesDataset forecastSeries = surfaceDataService.getForecastSeries(lat, lon);
TimeSeriesDataset forecastSeries = surfaceDataService.getForecastSeries(lat, lon); forecastSeries.setLatitude(lat);
forecastSeries.setLatitude(lat); forecastSeries.setLongitude(lon);
forecastSeries.setLongitude(lon); return Result.success(forecastSeries);
return Result.success(forecastSeries);
} finally {
log.info("[data-server] 地面24小时预报结果查询");
}
} }
@PostMapping ("/queryWeatherWarning") @PostMapping("/queryWeatherWarning")
@ControllerLog(info = "地面气象预警信息查询")
public Result queryWeatherWarning(@Validated @RequestBody Position2D position2D) throws Exception { public Result queryWeatherWarning(@Validated @RequestBody Position2D position2D) throws Exception {
double lat = position2D.getLatitude(); double lat = position2D.getLatitude();
double lon = position2D.getLongitude(); double lon = position2D.getLongitude();
log.info("[data-server] 地面气象预警信息查询 start: param={}", position2D);
try { // List<SurfaceWeatherWarning> warning = surfaceDataService.getSurfaceWarning(lat, lon);
// List<SurfaceWeatherWarning> warning = surfaceDataService.getSurfaceWarning(lat, lon); List<SurfaceWeatherWarning> warning = cmaService.getSurfaceWarning(lat, lon);
List<SurfaceWeatherWarning> warning = cmaService.getSurfaceWarning(lat, lon); return Result.success(warning);
return Result.success(warning);
} finally {
log.info("[data-server] 地面气象预警信息查询 end");
}
} }
} }

@ -1,6 +1,7 @@
package com.htfp.weather.web.controller; package com.htfp.weather.web.controller;
import com.htfp.weather.utils.DateTimeUtils; import com.htfp.weather.utils.DateTimeUtils;
import com.htfp.weather.web.config.aspect.ControllerLog;
import com.htfp.weather.web.exception.AppException; 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.request.*; import com.htfp.weather.web.pojo.request.*;
@ -21,7 +22,8 @@ import java.util.List;
* @Description : * @Description :
*/ */
@CrossOrigin @CrossOrigin
@RestController @Slf4j @RestController
@Slf4j
@RequestMapping("/htfp/weather/upper/") @RequestMapping("/htfp/weather/upper/")
public class UpperWeatherController { public class UpperWeatherController {
@ -29,17 +31,17 @@ public class UpperWeatherController {
GfsDataServiceImpl gfsDataService; GfsDataServiceImpl gfsDataService;
@PostMapping("/queryUpperNowWeather") @PostMapping("/queryUpperNowWeather")
@ControllerLog(info = "高空实时气象信息查询")
public Result queryUpperNowWeather(@Validated @RequestBody Position3D position3D) { public Result queryUpperNowWeather(@Validated @RequestBody Position3D position3D) {
double latitude = position3D.getLatitude(); double latitude = position3D.getLatitude();
double longitude = position3D.getLongitude(); double longitude = position3D.getLongitude();
int level = position3D.getLevel(); int level = position3D.getLevel();
log.info("[data-server] 高空实时气象信息查询 start: param={}", position3D);
NowWeatherStatus nowWeather = gfsDataService.getNowWeather(level, latitude, longitude); NowWeatherStatus nowWeather = gfsDataService.getNowWeather(level, latitude, longitude);
log.info("[data-server] 高空实时气象信息查询 end");
return Result.success(nowWeather); return Result.success(nowWeather);
} }
@PostMapping("/queryUpperNowWeatherInMultiPoints") @PostMapping("/queryUpperNowWeatherInMultiPoints")
@ControllerLog(info = "高空航点实时气象信息查询")
public Result queryUpperNowWeatherInMultiPoints(@Validated @RequestBody MultiPointsRequest multiPointsRequest) { public Result queryUpperNowWeatherInMultiPoints(@Validated @RequestBody MultiPointsRequest multiPointsRequest) {
List<Double> latitudeList = new ArrayList<>(); List<Double> latitudeList = new ArrayList<>();
List<Double> longitudeList = new ArrayList<>(); List<Double> longitudeList = new ArrayList<>();
@ -54,24 +56,22 @@ public class UpperWeatherController {
} }
} }
int level = multiPointsRequest.getLevel().intValue(); int level = multiPointsRequest.getLevel().intValue();
log.info("[data-server] 高空航点实时气象信息查询 start: param={}", multiPointsRequest);
List<NowWeatherStatus> nowWeatherByMultiPoint = gfsDataService.getNowWeatherByMultiPoint(level, latitudeList, longitudeList); List<NowWeatherStatus> nowWeatherByMultiPoint = gfsDataService.getNowWeatherByMultiPoint(level, latitudeList, longitudeList);
log.info("[data-server] 高空航点实时气象信息查询 end");
return Result.success(nowWeatherByMultiPoint); return Result.success(nowWeatherByMultiPoint);
} }
@PostMapping("/queryUpperForecast") @PostMapping("/queryUpperForecast")
@ControllerLog(info = "高空24小时预报结果查询")
public Result queryUpperForecast(@Validated @RequestBody Position3D position3D) { public Result queryUpperForecast(@Validated @RequestBody Position3D position3D) {
double latitude = position3D.getLatitude(); double latitude = position3D.getLatitude();
double longitude = position3D.getLongitude(); double longitude = position3D.getLongitude();
int level = position3D.getLevel(); int level = position3D.getLevel();
log.info("[data-server] 高空24小时预报结果查询 start: param={}", position3D);
TimeSeriesDataset forecastSeries = gfsDataService.getForecastSeries(level, latitude, longitude); TimeSeriesDataset forecastSeries = gfsDataService.getForecastSeries(level, latitude, longitude);
log.info("[data-server] 高空24小时预报结果查询 end");
return Result.success(forecastSeries); return Result.success(forecastSeries);
} }
@PostMapping("/queryUpperForecastInMultiPoints") @PostMapping("/queryUpperForecastInMultiPoints")
@ControllerLog(info = "高空航点24小时预报结果查询")
public Result queryUpperForecastInMultiPoints(@Validated @RequestBody MultiPointsRequest multiPointsRequest) { public Result queryUpperForecastInMultiPoints(@Validated @RequestBody MultiPointsRequest multiPointsRequest) {
List<Double> latitudeList = new ArrayList<>(); List<Double> latitudeList = new ArrayList<>();
List<Double> longitudeList = new ArrayList<>(); List<Double> longitudeList = new ArrayList<>();
@ -86,77 +86,76 @@ public class UpperWeatherController {
} }
} }
int level = multiPointsRequest.getLevel().intValue(); int level = multiPointsRequest.getLevel().intValue();
log.info("[data-server] 高空航点24小时预报结果查询 start: param={}", multiPointsRequest);
List<TimeSeriesDataset> nowWeatherByMultiPoint = gfsDataService.getForecastSeriesByMultiPoint(latitudeList, longitudeList, level); List<TimeSeriesDataset> nowWeatherByMultiPoint = gfsDataService.getForecastSeriesByMultiPoint(latitudeList, longitudeList, level);
log.info("[data-server] 高空航点24小时预报结果查询 end");
return Result.success(nowWeatherByMultiPoint); return Result.success(nowWeatherByMultiPoint);
} }
/**查询指定变量随气压的分布*/ /**
*
*/
@RequestMapping("/queryProfileByVariableAndPressure") @RequestMapping("/queryProfileByVariableAndPressure")
@ControllerLog(info = "指定变量高度廓线(气压坐标)查询")
public Result queryProfileByVariableAndPressure(@Validated @RequestBody ProfileRequest profileRequest) { public Result queryProfileByVariableAndPressure(@Validated @RequestBody ProfileRequest profileRequest) {
OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime()); OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime());
OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time); OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time);
String variableName = profileRequest.getVariableName(); String variableName = profileRequest.getVariableName();
double latitude = profileRequest.getLatitude(); double latitude = profileRequest.getLatitude();
double longitude = profileRequest.getLongitude(); double longitude = profileRequest.getLongitude();
try {
log.info("[data-server] 高度廓线(气压坐标)查询 start: param={}", profileRequest); ProfileResponse profileResponse = gfsDataService.getProfileByVariableAndPressure(variableName, utcDateTime, latitude, longitude);
ProfileResponse profileResponse = gfsDataService.getProfileByVariableAndPressure(variableName, utcDateTime, latitude, longitude); return Result.success(profileResponse);
return Result.success(profileResponse);
} finally {
log.info("[data-server] 高度廓线(气压坐标)查询 end");
}
} }
/**查询全部变量随气压的分布*/ /**
*
*/
@RequestMapping("/queryProfileByPressure") @RequestMapping("/queryProfileByPressure")
@ControllerLog(info = "全部变量高度廓线(气压坐标)查询")
public Result queryProfileByAndPressure(@Validated @RequestBody ProfileRequest profileRequest) { public Result queryProfileByAndPressure(@Validated @RequestBody ProfileRequest profileRequest) {
OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime()); OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime());
OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time); OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time);
double latitude = profileRequest.getLatitude(); double latitude = profileRequest.getLatitude();
double longitude = profileRequest.getLongitude(); double longitude = profileRequest.getLongitude();
try {
log.info("[data-server] 高度廓线(气压坐标)查询 start: param={}", profileRequest); ProfileDataset profile = gfsDataService.getProfileByPressure(utcDateTime, latitude, longitude);
ProfileDataset profile = gfsDataService.getProfileByPressure(utcDateTime, latitude, longitude); return Result.success(profile);
return Result.success(profile);
} finally {
log.info("[data-server] 高度廓线(气压坐标)查询 end");
}
} }
/**查询全部近地面变量随高度的分布*/
/**
*
*/
@RequestMapping("/queryProfileByVariableAndNearSurfaceHeight") @RequestMapping("/queryProfileByVariableAndNearSurfaceHeight")
@ControllerLog(info = "指定变量高度廓线(近地面高度坐标)查询")
public Result queryProfileByVariableAndNearSurfaceHeight(@Validated @RequestBody ProfileRequest profileRequest) { public Result queryProfileByVariableAndNearSurfaceHeight(@Validated @RequestBody ProfileRequest profileRequest) {
OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime()); OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime());
OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time); OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time);
String variableName = profileRequest.getVariableName(); String variableName = profileRequest.getVariableName();
double latitude = profileRequest.getLatitude(); double latitude = profileRequest.getLatitude();
double longitude = profileRequest.getLongitude(); double longitude = profileRequest.getLongitude();
try {
log.info("[data-server] 高度廓线(近地面高度坐标)查询 start: param={}", profileRequest); ProfileResponse profile = gfsDataService.getProfileByVariableAndNearSurfaceHeight(variableName, utcDateTime, latitude, longitude);
ProfileResponse profile = gfsDataService.getProfileByVariableAndNearSurfaceHeight(variableName, utcDateTime, latitude, longitude); return Result.success(profile);
return Result.success(profile);
} finally {
log.info("[data-server] 高度廓线(近地面高度坐标)查询 end");
}
} }
/**查询全部近地面变量随高度的分布*/
/**
*
*/
@RequestMapping("/queryProfileByNearSurfaceHeight") @RequestMapping("/queryProfileByNearSurfaceHeight")
@ControllerLog(info = "全部变量高度廓线(近地面高度坐标)查询")
public Result queryProfileByNearSurfaceHeight(@Validated @RequestBody ProfileRequest profileRequest) { public Result queryProfileByNearSurfaceHeight(@Validated @RequestBody ProfileRequest profileRequest) {
OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime()); OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime());
OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time); OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time);
double latitude = profileRequest.getLatitude(); double latitude = profileRequest.getLatitude();
double longitude = profileRequest.getLongitude(); double longitude = profileRequest.getLongitude();
try {
log.info("[data-server] 高度廓线(近地面高度坐标)查询 start: param={}", profileRequest); log.info("[data-server] 高度廓线(近地面高度坐标)查询 start: param={}", profileRequest);
ProfileDataset profile = gfsDataService.getProfileByNearSurfaceHeight(utcDateTime, latitude, longitude); ProfileDataset profile = gfsDataService.getProfileByNearSurfaceHeight(utcDateTime, latitude, longitude);
return Result.success(profile); return Result.success(profile);
} finally {
log.info("[data-server] 高度廓线(近地面高度坐标)查询 end");
}
} }
@PostMapping("/queryPlaneGrid") @PostMapping("/queryPlaneGrid")
@ControllerLog(info = "平面网格数据查询")
public Result queryPlaneGrid(@Validated @RequestBody PlaneRequest planeRequest) { public Result queryPlaneGrid(@Validated @RequestBody PlaneRequest planeRequest) {
planeRequest.valid(); planeRequest.valid();
String variableName = planeRequest.getVariableName(); String variableName = planeRequest.getVariableName();
@ -167,9 +166,8 @@ public class UpperWeatherController {
double maxLat = planeRequest.getMaxLatitude(); double maxLat = planeRequest.getMaxLatitude();
double minLon = planeRequest.getMinLongitude(); double minLon = planeRequest.getMinLongitude();
double maxLon = planeRequest.getMaxLongitude(); double maxLon = planeRequest.getMaxLongitude();
log.info("[data-server] 平面网格数据查询 start: param={}", planeRequest);
PlaneResponse forecastSeries = gfsDataService.getPlane(utcDateTime, variableName, level, minLat, maxLat, minLon, maxLon); PlaneResponse forecastSeries = gfsDataService.getPlane(utcDateTime, variableName, level, minLat, maxLat, minLon, maxLon);
log.info("[data-server] 平面网格数据查询 end");
return Result.success(forecastSeries); return Result.success(forecastSeries);
} }

@ -12,10 +12,11 @@ public class AppException extends RuntimeException{
return errorCode; return errorCode;
} }
public AppException(ErrorCode errorCode) { public AppException(ErrorCode errorCode) {
super(errorCode.getMsg());
this.errorCode = errorCode; this.errorCode = errorCode;
} }
public AppException(ErrorCode errorCode, String message) { public AppException(ErrorCode errorCode, String message) {
super(message); super(errorCode.getMsg()+ ", " +message);
this.errorCode = errorCode; this.errorCode = errorCode;
} }
public AppException(ErrorCode errorCode, Throwable e) { public AppException(ErrorCode errorCode, Throwable e) {

@ -1,5 +1,7 @@
package com.htfp.weather.web.pojo.request; package com.htfp.weather.web.pojo.request;
import com.htfp.weather.download.gfs.GfsLevelsEnum;
import com.htfp.weather.web.valid.EnumValid;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@ -14,5 +16,6 @@ import java.util.List;
public class MultiPointsRequest { public class MultiPointsRequest {
List<Position2D> pointList; List<Position2D> pointList;
@NotNull(message = "高度层次 (level) 不能为空") @NotNull(message = "高度层次 (level) 不能为空")
@EnumValid(message = "高度层次 (level) 不存在", enumClass = GfsLevelsEnum.class)
Integer level; Integer level;
} }

@ -14,13 +14,13 @@ import javax.validation.constraints.NotNull;
@Data @Data
public class Position2D { public class Position2D {
@NotNull(message = "纬度 (latitude) 不能为空") @NotNull(message = "纬度 (latitude) 不能为空")
@Min(value = -90, message = "纬度 (latitude) 最小值为-90南纬9") @Min(value = 0, message = "纬度 (latitude) 最小值为0")
@Max(value = 90, message = "纬度 (latitude) 最大值为90北纬90°)") @Max(value = 55, message = "纬度 (latitude) 最大值为55北纬55°)")
Double latitude; Double latitude;
@NotNull(message = "经度 (longitude) 不能为空") @NotNull(message = "经度 (longitude) 不能为空")
@Min(value = -180, message = "经度 (longitude) 最小值为-180西经18") @Min(value = 70, message = "经度 (longitude) 最小值为 70东经 7")
@Max(value = 180, message = "经度 (longitude) 最大值为180东经18") @Max(value = 140, message = "经度 (longitude) 最大值为 140东经 14")
Double longitude; Double longitude;
} }

@ -4,6 +4,8 @@ import javax.validation.constraints.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import com.htfp.weather.download.gfs.GfsLevelsEnum;
import com.htfp.weather.web.valid.EnumValid;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -16,5 +18,6 @@ import lombok.EqualsAndHashCode;
@Data @Data
public class Position3D extends Position2D { public class Position3D extends Position2D {
@NotNull(message = "高度层次 (level) 不能为空") @NotNull(message = "高度层次 (level) 不能为空")
@EnumValid(message = "高度层次 (level) 不存在", enumClass = GfsLevelsEnum.class)
Integer level; Integer level;
} }

@ -37,7 +37,7 @@ public class Result {
return new Result(false, error.getCode(), error.getMsg(), null); return new Result(false, error.getCode(), error.getMsg(), null);
} }
public static Result error(ErrorCode error, String msg) { public static Result error(ErrorCode error, String msg) {
return new Result(false, error.getCode(), error.getMsg() + msg, null); return new Result(false, error.getCode(), msg, null);
} }
public static Result error(Throwable cause) { public static Result error(Throwable cause) {

@ -1,11 +0,0 @@
{
"duration" : 30,
"minLon" : 70.0,
"maxLon" : 140.0,
"minLat" : 0.0,
"maxLat" : 55.0,
"resolution" : 0.25,
"variables" : [ "DZDT", "RH", "TMP", "UGRD", "VGRD", "TCDC" ,"GUST", "PRATE"],
"pressureLevels" : [400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 925, 950, 975, 1000],
"saveRoot" : "./GFSData"
}

@ -1,12 +0,0 @@
{
"dataTableName" : "gfs_data_table",
"metaTableName" : "gfs_meta_table",
"dataIndexName" : "gfs_data_index",
"metaIndexName" : "gfs_meta_table_index",
"dataDir" : "D:/HTFP/weather/GFSData/",
"variableList" : [ "temp", "cloud", "wind360", "windSpeed"],
"lonSize" : 281,
"latSize" : 221,
"levSize" : 10,
"timeToLive" : 2
}

@ -12,13 +12,13 @@
</filter> </filter>
</appender> </appender>
<!-- 按照每天生成日志文件 --> <!-- 以天为单位生成INFO日志文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <appender name="fileInfo" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的目录及文件名--> <!--日志文件输出的目录及文件名-->
<FileNamePattern>./log/%d{yyyy-MM-dd}.%i.log</FileNamePattern> <FileNamePattern>./logInfo/info-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数--> <!--日志文件保留天数-->
<MaxHistory>30</MaxHistory> <MaxHistory>15</MaxHistory>
<MaxFileSize>10MB</MaxFileSize> <MaxFileSize>10MB</MaxFileSize>
</rollingPolicy> </rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
@ -27,12 +27,49 @@
<pattern>%-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{50} - %msg%n</pattern> <pattern>%-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <charset>UTF-8</charset>
</encoder> </encoder>
<!-- 此日志文件只记录info级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- 以天为单位生成ERROR级别日志文件 -->
<appender name="fileError" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!--日志文件输出的目录及文件名-->
<FileNamePattern>./logError/error-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
<!--日志文件保留天数-->
<MaxHistory>15</MaxHistory>
<MaxFileSize>10MB</MaxFileSize>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期%thread表示线程名%-5level级别从左显示5个字符宽度%msg日志消息%n是换行符-->
<pattern>%highlight(%-5level) %d{HH:mm:ss.SSS} %magenta([%thread]) %cyan(%logger{36}) - %msg%n</pattern>
<pattern>%-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
<!-- 此日志文件只记录warn以上的 -->
<!-- 允许打印警告日志到文件的过滤器 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>NEUTRAL</onMismatch>
</filter>
<!-- 允许打印错误日志到文件的过滤器 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- onMatch,onMismatch取值及含义 -->
<!-- DENY:日志将立即被抛弃不再经过其他过滤器,最后一个filter的onMismatch使用 -->
<!-- NEUTRAL:有序列表里的下个过滤器过接着处理日志,非最后一个filter的onMismatch使用 -->
<!-- ACCEPT:日志会被立即处理,不再经过剩余过滤器,所有filter的onMatch使用 -->
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender> </appender>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="FILE"/>
</root>
<!-- 定义某个包的日志级别 --> <!-- 定义某个包的日志级别 -->
<!-- <logger name="com.htfp.gcsplugin" level="debug" additivity="false"> &lt;!&ndash; 添加控制台输出 &ndash;&gt;--> <!-- <logger name="com.htfp.gcsplugin" level="debug" additivity="false"> &lt;!&ndash; 添加控制台输出 &ndash;&gt;-->
<!-- <appender-ref ref="console"/>--> <!-- <appender-ref ref="console"/>-->
@ -40,6 +77,12 @@
<!-- </logger>--> <!-- </logger>-->
<logger name="com.alicloud.openservices" level="WARN"/> <logger name="com.alicloud.openservices" level="WARN"/>
<logger name="com.aliyun.ots" level="WARN"/> <logger name="com.aliyun.ots" level="WARN"/>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="fileInfo"/>
<appender-ref ref="fileError"/>
</root>
</configuration> </configuration>

Loading…
Cancel
Save