From 20c4a6ca41615515d29426091410d224f52abb49 Mon Sep 17 00:00:00 2001 From: shiyi Date: Tue, 16 Jul 2024 15:19:26 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E5=AE=9A=E4=B9=89=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E5=88=87=E9=9D=A2=E4=BB=A5=E5=8F=8A=E6=B3=A8=E8=A7=A3=EF=BC=8C?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=BE=93=E5=87=BAcontroller=E5=B1=82?= =?UTF-8?q?=E6=97=A5=E5=BF=97=EF=BC=9B2.=20=E4=BF=AE=E6=94=B9=E7=BB=8F?= =?UTF-8?q?=E7=BA=AC=E5=BA=A6=E6=A0=A1=E9=AA=8C=E8=8C=83=E5=9B=B4=EF=BC=8C?= =?UTF-8?q?=E9=99=90=E5=AE=9A=E5=9C=A8=E4=B8=AD=E5=9B=BD=E5=8C=BA=E5=9F=9F?= =?UTF-8?q?=EF=BC=880-55N,=2070-140E=EF=BC=89;=203.=20info=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E5=92=8Cerror=E6=97=A5=E5=BF=97=E5=88=86=E5=BC=80?= =?UTF-8?q?=E5=AD=98=E5=82=A8=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../htfp/weather/web/config/LogAspect.java | 9 -- .../web/config/aspect/ControllerLog.java | 16 +++ .../config/aspect/ControllerLogAspect.java | 131 ++++++++++++++++++ .../weather/web/config/aspect/WebLog.java | 35 +++++ .../interceptor/InterfaceInterceptor.java | 6 +- .../web/controller/ConfigController.java | 16 ++- .../controller/SurfaceWeatherController.java | 50 +++---- .../controller/UpperWeatherController.java | 84 ++++++----- .../weather/web/exception/AppException.java | 3 +- .../web/pojo/request/MultiPointsRequest.java | 3 + .../weather/web/pojo/request/Position2D.java | 8 +- .../weather/web/pojo/request/Position3D.java | 3 + .../weather/web/pojo/response/Result.java | 2 +- .../main/resources/config/gfsDataConfig.json | 11 -- .../src/main/resources/config/tableConf.json | 12 -- .../src/main/resources/logback.xml | 59 ++++++-- 16 files changed, 327 insertions(+), 121 deletions(-) delete mode 100644 weather-service/src/main/java/com/htfp/weather/web/config/LogAspect.java create mode 100644 weather-service/src/main/java/com/htfp/weather/web/config/aspect/ControllerLog.java create mode 100644 weather-service/src/main/java/com/htfp/weather/web/config/aspect/ControllerLogAspect.java create mode 100644 weather-service/src/main/java/com/htfp/weather/web/config/aspect/WebLog.java delete mode 100644 weather-service/src/main/resources/config/gfsDataConfig.json delete mode 100644 weather-service/src/main/resources/config/tableConf.json diff --git a/weather-service/src/main/java/com/htfp/weather/web/config/LogAspect.java b/weather-service/src/main/java/com/htfp/weather/web/config/LogAspect.java deleted file mode 100644 index 4f1dcda..0000000 --- a/weather-service/src/main/java/com/htfp/weather/web/config/LogAspect.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.htfp.weather.web.config; - -/** - * @Author : shiyi - * @Date : 2024/6/12 14:12 - * @Description : 日志切面 - */ -public class LogAspect { -} diff --git a/weather-service/src/main/java/com/htfp/weather/web/config/aspect/ControllerLog.java b/weather-service/src/main/java/com/htfp/weather/web/config/aspect/ControllerLog.java new file mode 100644 index 0000000..9b2e80c --- /dev/null +++ b/weather-service/src/main/java/com/htfp/weather/web/config/aspect/ControllerLog.java @@ -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 +} diff --git a/weather-service/src/main/java/com/htfp/weather/web/config/aspect/ControllerLogAspect.java b/weather-service/src/main/java/com/htfp/weather/web/config/aspect/ControllerLogAspect.java new file mode 100644 index 0000000..dbe889a --- /dev/null +++ b/weather-service/src/main/java/com/htfp/weather/web/config/aspect/ControllerLogAspect.java @@ -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 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 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; + } + } +} diff --git a/weather-service/src/main/java/com/htfp/weather/web/config/aspect/WebLog.java b/weather-service/src/main/java/com/htfp/weather/web/config/aspect/WebLog.java new file mode 100644 index 0000000..3205f91 --- /dev/null +++ b/weather-service/src/main/java/com/htfp/weather/web/config/aspect/WebLog.java @@ -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; + +} diff --git a/weather-service/src/main/java/com/htfp/weather/web/config/interceptor/InterfaceInterceptor.java b/weather-service/src/main/java/com/htfp/weather/web/config/interceptor/InterfaceInterceptor.java index 8522ea7..8a694d7 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/config/interceptor/InterfaceInterceptor.java +++ b/weather-service/src/main/java/com/htfp/weather/web/config/interceptor/InterfaceInterceptor.java @@ -28,9 +28,9 @@ public class InterfaceInterceptor implements HandlerInterceptor { String servletPath = request.getServletPath(); // log.info("InterfaceInterceptor.preHandle >> 进入拦截, {}, {}", servletPath, handler.getClass().getName()); // ip 校验 - // if (checkIp(request)) { - // return true; - // } + if (checkIp(request)) { + return true; + } // 签名校验 final String signature = request.getHeader("signature"); final String timestamp = String.valueOf(request.getHeader("timestamp")); diff --git a/weather-service/src/main/java/com/htfp/weather/web/controller/ConfigController.java b/weather-service/src/main/java/com/htfp/weather/web/controller/ConfigController.java index 212cc12..0dc07fc 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/controller/ConfigController.java +++ b/weather-service/src/main/java/com/htfp/weather/web/controller/ConfigController.java @@ -7,6 +7,7 @@ import com.htfp.weather.griddata.operation.GfsDataImport; import com.htfp.weather.griddata.operation.GfsDataImport.ImportFileInfo; import com.htfp.weather.info.Constant; 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.ErrorCode; import com.htfp.weather.web.pojo.request.GfsConfigUpdate; @@ -63,6 +64,7 @@ public class ConfigController { * 查询tablestore数据库配置 */ @RequestMapping("/queryDatabaseConfig") + @ControllerLog(info = "查询tablestore数据库配置") public Result queryDatabaseConfig() { return Result.success(tableConfig); } @@ -71,6 +73,7 @@ public class ConfigController { * 更新tablestore数据库配置 */ @PostMapping("/updateDatabaseConfig") + @ControllerLog(info = "更新tablestore数据库配置") public Result updateDatabaseConfig(@RequestBody TableConfigUpdate request) { String secret = request.getSecret(); TableConfig updateConfig = request.getConfig(); @@ -91,6 +94,7 @@ public class ConfigController { * 查询GFS下载配置 */ @RequestMapping("/queryDataSourceConfig") + @ControllerLog(info = "查询GFS下载配置") public Result queryDataSourceConfig() { return Result.success(gfsDataConfig); } @@ -99,6 +103,7 @@ public class ConfigController { * 更新GFS下载配置 */ @PostMapping("/updateDataSourceConfig") + @ControllerLog(info = "更新GFS下载配置") public Result updateDataSourceConfig(@Validated @RequestBody GfsConfigUpdate request) { String secret = request.getSecret(); GfsDataConfig updateConfig = request.getConfig(); @@ -119,6 +124,7 @@ public class ConfigController { * 下载当前时刻未来24小时的数据文件 */ @PostMapping("/downloadAllFiles") + @ControllerLog(info = "下载当前时刻未来24小时的数据文件") public Result downloadAllFiles(@RequestBody Map params) { String secret = params.get("secret"); validSecret(secret); @@ -140,6 +146,7 @@ public class ConfigController { * 下载指定时刻文件 */ @PostMapping("/downloadSingleFile") + @ControllerLog(info = "下载指定时刻文件") public Result downloadSingleFile(@RequestBody Map params) { String secret = params.get("secret"); validSecret(secret); @@ -152,6 +159,7 @@ public class ConfigController { * 根据起报时间将数据导入数据库 */ @PostMapping("/importToTablestoreByReferenceTime") + @ControllerLog(info = "根据起报时间将数据导入数据库") public Result importData(@RequestBody Map params) { String secret = params.get("secret"); validSecret(secret); @@ -163,10 +171,11 @@ public class ConfigController { * 下载并导入 */ @PostMapping("/downloadAndImport") + @ControllerLog(info = "下载并导入") public Result downloadAndImport(@RequestBody Map params) { Result downloadResponse = downloadAllFiles(params); if (downloadResponse.isSuccess()) { - DownloadResult data = (DownloadResult)downloadResponse.getData(); + DownloadResult data = (DownloadResult) downloadResponse.getData(); String refTimeStr = data.getSuccessList().get(0).getRefTimeStr(); OffsetDateTime time = OffsetDateTime.of(LocalDateTime.parse(refTimeStr, DateTimeFormatter.ofPattern(Constant.UTC_TIME_STRING)), ZoneOffset.UTC); return getImportResponse(time); @@ -193,6 +202,7 @@ public class ConfigController { } @PostMapping("queryAllDataDir") + @ControllerLog(info = "查询所有数据文件夹") public Result queryAllDataDir(@RequestBody Map params) { String secret = params.get("secret"); validSecret(secret); @@ -200,10 +210,12 @@ public class ConfigController { List subDirList = fileService.getSubDirList(dataRoot); return Result.success(subDirList); } + /** * 查询指定起报时间文件夹中的所有文件名 */ @PostMapping("/queryAllFileByReferenceTime") + @ControllerLog(info = "查询指定起报时间文件夹中的所有文件名") public Result queryAllFileByReferenceTime(@RequestBody Map params) { String secret = params.get("secret"); validSecret(secret); @@ -220,6 +232,7 @@ public class ConfigController { * 删除指定起报时间对应的文件夹 */ @PostMapping("/deleteDirByReferenceTime") + @ControllerLog(info = "删除指定起报时间对应的文件夹") public Result deleteDirByReferenceTime(@RequestBody Map params) { String secret = params.get("secret"); validSecret(secret); @@ -241,6 +254,7 @@ public class ConfigController { * 删除指定文件 */ @PostMapping("/deleteTargetFile") + @ControllerLog(info = "删除指定文件") public Result deleteTargetFile(@RequestBody Map params) { String secret = params.get("secret"); validSecret(secret); diff --git a/weather-service/src/main/java/com/htfp/weather/web/controller/SurfaceWeatherController.java b/weather-service/src/main/java/com/htfp/weather/web/controller/SurfaceWeatherController.java index 520bd4b..302fcfe 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/controller/SurfaceWeatherController.java +++ b/weather-service/src/main/java/com/htfp/weather/web/controller/SurfaceWeatherController.java @@ -1,5 +1,6 @@ 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.request.Position2D; import com.htfp.weather.web.pojo.response.NowWeatherStatus; @@ -24,7 +25,8 @@ import java.util.List; * @Description : 地面天气状态 */ @CrossOrigin -@RestController @Slf4j +@RestController +@Slf4j @RequestMapping("/htfp/weather/surface/") public class SurfaceWeatherController { @Resource(name = "hefeng") @@ -32,48 +34,40 @@ public class SurfaceWeatherController { @Resource CmaServiceImpl cmaService; + @PostMapping("/querySurfaceNowWeather") + @ControllerLog(info = "地面实时气象信息查询") public Result queryNowWeather(@Validated @RequestBody Position2D position2D) throws Exception { double lat = position2D.getLatitude(); double lon = position2D.getLongitude(); - log.info("[data-server] 地面实时气象信息查询 start: param={}", position2D); - try { - NowWeatherStatus nowWeatherStatus = surfaceDataService.getNowSurfaceWeatherStatus(lat, lon); - nowWeatherStatus.setLatitude(lat); - nowWeatherStatus.setLongitude(lon); - return Result.success(nowWeatherStatus); - } finally { - log.info("[data-server] 地面实时气象信息查询 end"); - } + + NowWeatherStatus nowWeatherStatus = surfaceDataService.getNowSurfaceWeatherStatus(lat, lon); + nowWeatherStatus.setLatitude(lat); + nowWeatherStatus.setLongitude(lon); + return Result.success(nowWeatherStatus); } @PostMapping("/querySurfaceForecast") + @ControllerLog(info = "地面24小时预报结果查询") public Result querySurfaceForecast(@Validated @RequestBody Position2D position2D) throws Exception { double lat = position2D.getLatitude(); double lon = position2D.getLongitude(); - log.info("[data-server] 地面24小时预报结果查询 start: param={}", position2D); - try { - TimeSeriesDataset forecastSeries = surfaceDataService.getForecastSeries(lat, lon); - forecastSeries.setLatitude(lat); - forecastSeries.setLongitude(lon); - return Result.success(forecastSeries); - } finally { - log.info("[data-server] 地面24小时预报结果查询"); - } + + TimeSeriesDataset forecastSeries = surfaceDataService.getForecastSeries(lat, lon); + forecastSeries.setLatitude(lat); + forecastSeries.setLongitude(lon); + return Result.success(forecastSeries); } - @PostMapping ("/queryWeatherWarning") + @PostMapping("/queryWeatherWarning") + @ControllerLog(info = "地面气象预警信息查询") public Result queryWeatherWarning(@Validated @RequestBody Position2D position2D) throws Exception { double lat = position2D.getLatitude(); double lon = position2D.getLongitude(); - log.info("[data-server] 地面气象预警信息查询 start: param={}", position2D); - try { - // List warning = surfaceDataService.getSurfaceWarning(lat, lon); - List warning = cmaService.getSurfaceWarning(lat, lon); - return Result.success(warning); - } finally { - log.info("[data-server] 地面气象预警信息查询 end"); - } + + // List warning = surfaceDataService.getSurfaceWarning(lat, lon); + List warning = cmaService.getSurfaceWarning(lat, lon); + return Result.success(warning); } } diff --git a/weather-service/src/main/java/com/htfp/weather/web/controller/UpperWeatherController.java b/weather-service/src/main/java/com/htfp/weather/web/controller/UpperWeatherController.java index 8123fb7..8577279 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/controller/UpperWeatherController.java +++ b/weather-service/src/main/java/com/htfp/weather/web/controller/UpperWeatherController.java @@ -1,6 +1,7 @@ package com.htfp.weather.web.controller; 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.ErrorCode; import com.htfp.weather.web.pojo.request.*; @@ -21,7 +22,8 @@ import java.util.List; * @Description : 高空天气查询接口 */ @CrossOrigin -@RestController @Slf4j +@RestController +@Slf4j @RequestMapping("/htfp/weather/upper/") public class UpperWeatherController { @@ -29,17 +31,17 @@ public class UpperWeatherController { GfsDataServiceImpl gfsDataService; @PostMapping("/queryUpperNowWeather") + @ControllerLog(info = "高空实时气象信息查询") public Result queryUpperNowWeather(@Validated @RequestBody Position3D position3D) { double latitude = position3D.getLatitude(); double longitude = position3D.getLongitude(); int level = position3D.getLevel(); - log.info("[data-server] 高空实时气象信息查询 start: param={}", position3D); NowWeatherStatus nowWeather = gfsDataService.getNowWeather(level, latitude, longitude); - log.info("[data-server] 高空实时气象信息查询 end"); return Result.success(nowWeather); } @PostMapping("/queryUpperNowWeatherInMultiPoints") + @ControllerLog(info = "高空航点实时气象信息查询") public Result queryUpperNowWeatherInMultiPoints(@Validated @RequestBody MultiPointsRequest multiPointsRequest) { List latitudeList = new ArrayList<>(); List longitudeList = new ArrayList<>(); @@ -54,24 +56,22 @@ public class UpperWeatherController { } } int level = multiPointsRequest.getLevel().intValue(); - log.info("[data-server] 高空航点实时气象信息查询 start: param={}", multiPointsRequest); List nowWeatherByMultiPoint = gfsDataService.getNowWeatherByMultiPoint(level, latitudeList, longitudeList); - log.info("[data-server] 高空航点实时气象信息查询 end"); return Result.success(nowWeatherByMultiPoint); } @PostMapping("/queryUpperForecast") + @ControllerLog(info = "高空24小时预报结果查询") public Result queryUpperForecast(@Validated @RequestBody Position3D position3D) { double latitude = position3D.getLatitude(); double longitude = position3D.getLongitude(); int level = position3D.getLevel(); - log.info("[data-server] 高空24小时预报结果查询 start: param={}", position3D); TimeSeriesDataset forecastSeries = gfsDataService.getForecastSeries(level, latitude, longitude); - log.info("[data-server] 高空24小时预报结果查询 end"); return Result.success(forecastSeries); } @PostMapping("/queryUpperForecastInMultiPoints") + @ControllerLog(info = "高空航点24小时预报结果查询") public Result queryUpperForecastInMultiPoints(@Validated @RequestBody MultiPointsRequest multiPointsRequest) { List latitudeList = new ArrayList<>(); List longitudeList = new ArrayList<>(); @@ -86,77 +86,76 @@ public class UpperWeatherController { } } int level = multiPointsRequest.getLevel().intValue(); - log.info("[data-server] 高空航点24小时预报结果查询 start: param={}", multiPointsRequest); List nowWeatherByMultiPoint = gfsDataService.getForecastSeriesByMultiPoint(latitudeList, longitudeList, level); - log.info("[data-server] 高空航点24小时预报结果查询 end"); return Result.success(nowWeatherByMultiPoint); } - /**查询指定变量随气压的分布*/ + /** + * 查询指定变量随气压的分布 + */ @RequestMapping("/queryProfileByVariableAndPressure") + @ControllerLog(info = "指定变量高度廓线(气压坐标)查询") public Result queryProfileByVariableAndPressure(@Validated @RequestBody ProfileRequest profileRequest) { OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime()); OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time); String variableName = profileRequest.getVariableName(); double latitude = profileRequest.getLatitude(); double longitude = profileRequest.getLongitude(); - try { - log.info("[data-server] 高度廓线(气压坐标)查询 start: param={}", profileRequest); - ProfileResponse profileResponse = gfsDataService.getProfileByVariableAndPressure(variableName, utcDateTime, latitude, longitude); - return Result.success(profileResponse); - } finally { - log.info("[data-server] 高度廓线(气压坐标)查询 end"); - } + + ProfileResponse profileResponse = gfsDataService.getProfileByVariableAndPressure(variableName, utcDateTime, latitude, longitude); + return Result.success(profileResponse); } - /**查询全部变量随气压的分布*/ + /** + * 查询全部变量随气压的分布 + */ @RequestMapping("/queryProfileByPressure") + @ControllerLog(info = "全部变量高度廓线(气压坐标)查询") public Result queryProfileByAndPressure(@Validated @RequestBody ProfileRequest profileRequest) { OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime()); OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time); double latitude = profileRequest.getLatitude(); double longitude = profileRequest.getLongitude(); - try { - log.info("[data-server] 高度廓线(气压坐标)查询 start: param={}", profileRequest); - ProfileDataset profile = gfsDataService.getProfileByPressure(utcDateTime, latitude, longitude); - return Result.success(profile); - } finally { - log.info("[data-server] 高度廓线(气压坐标)查询 end"); - } + + ProfileDataset profile = gfsDataService.getProfileByPressure(utcDateTime, latitude, longitude); + return Result.success(profile); } - /**查询全部近地面变量随高度的分布*/ + + /** + * 查询指定近地面变量随高度的分布 + */ @RequestMapping("/queryProfileByVariableAndNearSurfaceHeight") + @ControllerLog(info = "指定变量高度廓线(近地面高度坐标)查询") public Result queryProfileByVariableAndNearSurfaceHeight(@Validated @RequestBody ProfileRequest profileRequest) { OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime()); OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time); String variableName = profileRequest.getVariableName(); double latitude = profileRequest.getLatitude(); double longitude = profileRequest.getLongitude(); - try { - log.info("[data-server] 高度廓线(近地面高度坐标)查询 start: param={}", profileRequest); - ProfileResponse profile = gfsDataService.getProfileByVariableAndNearSurfaceHeight(variableName, utcDateTime, latitude, longitude); - return Result.success(profile); - } finally { - log.info("[data-server] 高度廓线(近地面高度坐标)查询 end"); - } + + ProfileResponse profile = gfsDataService.getProfileByVariableAndNearSurfaceHeight(variableName, utcDateTime, latitude, longitude); + return Result.success(profile); } - /**查询全部近地面变量随高度的分布*/ + + /** + * 查询全部近地面变量随高度的分布 + */ @RequestMapping("/queryProfileByNearSurfaceHeight") + @ControllerLog(info = "全部变量高度廓线(近地面高度坐标)查询") public Result queryProfileByNearSurfaceHeight(@Validated @RequestBody ProfileRequest profileRequest) { OffsetDateTime time = OffsetDateTime.parse(profileRequest.getTime()); OffsetDateTime utcDateTime = DateTimeUtils.getUTCDateTime(time); double latitude = profileRequest.getLatitude(); double longitude = profileRequest.getLongitude(); - try { - log.info("[data-server] 高度廓线(近地面高度坐标)查询 start: param={}", profileRequest); - ProfileDataset profile = gfsDataService.getProfileByNearSurfaceHeight(utcDateTime, latitude, longitude); - return Result.success(profile); - } finally { - log.info("[data-server] 高度廓线(近地面高度坐标)查询 end"); - } + + log.info("[data-server] 高度廓线(近地面高度坐标)查询 start: param={}", profileRequest); + ProfileDataset profile = gfsDataService.getProfileByNearSurfaceHeight(utcDateTime, latitude, longitude); + return Result.success(profile); } + @PostMapping("/queryPlaneGrid") + @ControllerLog(info = "平面网格数据查询") public Result queryPlaneGrid(@Validated @RequestBody PlaneRequest planeRequest) { planeRequest.valid(); String variableName = planeRequest.getVariableName(); @@ -167,9 +166,8 @@ public class UpperWeatherController { double maxLat = planeRequest.getMaxLatitude(); double minLon = planeRequest.getMinLongitude(); double maxLon = planeRequest.getMaxLongitude(); - log.info("[data-server] 平面网格数据查询 start: param={}", planeRequest); + PlaneResponse forecastSeries = gfsDataService.getPlane(utcDateTime, variableName, level, minLat, maxLat, minLon, maxLon); - log.info("[data-server] 平面网格数据查询 end"); return Result.success(forecastSeries); } diff --git a/weather-service/src/main/java/com/htfp/weather/web/exception/AppException.java b/weather-service/src/main/java/com/htfp/weather/web/exception/AppException.java index 27697bd..660a188 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/exception/AppException.java +++ b/weather-service/src/main/java/com/htfp/weather/web/exception/AppException.java @@ -12,10 +12,11 @@ public class AppException extends RuntimeException{ return errorCode; } public AppException(ErrorCode errorCode) { + super(errorCode.getMsg()); this.errorCode = errorCode; } public AppException(ErrorCode errorCode, String message) { - super(message); + super(errorCode.getMsg()+ ", " +message); this.errorCode = errorCode; } public AppException(ErrorCode errorCode, Throwable e) { diff --git a/weather-service/src/main/java/com/htfp/weather/web/pojo/request/MultiPointsRequest.java b/weather-service/src/main/java/com/htfp/weather/web/pojo/request/MultiPointsRequest.java index 02f09c1..b99a4e9 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/pojo/request/MultiPointsRequest.java +++ b/weather-service/src/main/java/com/htfp/weather/web/pojo/request/MultiPointsRequest.java @@ -1,5 +1,7 @@ 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 javax.validation.constraints.NotNull; @@ -14,5 +16,6 @@ import java.util.List; public class MultiPointsRequest { List pointList; @NotNull(message = "高度层次 (level) 不能为空") + @EnumValid(message = "高度层次 (level) 不存在", enumClass = GfsLevelsEnum.class) Integer level; } diff --git a/weather-service/src/main/java/com/htfp/weather/web/pojo/request/Position2D.java b/weather-service/src/main/java/com/htfp/weather/web/pojo/request/Position2D.java index 958b41c..a011833 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/pojo/request/Position2D.java +++ b/weather-service/src/main/java/com/htfp/weather/web/pojo/request/Position2D.java @@ -14,13 +14,13 @@ import javax.validation.constraints.NotNull; @Data public class Position2D { @NotNull(message = "纬度 (latitude) 不能为空") - @Min(value = -90, message = "纬度 (latitude) 最小值为-90(南纬90°)") - @Max(value = 90, message = "纬度 (latitude) 最大值为90(北纬90°)") + @Min(value = 0, message = "纬度 (latitude) 最小值为0(0°)") + @Max(value = 55, message = "纬度 (latitude) 最大值为55(北纬55°)") Double latitude; @NotNull(message = "经度 (longitude) 不能为空") - @Min(value = -180, message = "经度 (longitude) 最小值为-180(西经180°)") - @Max(value = 180, message = "经度 (longitude) 最大值为180(东经180°)") + @Min(value = 70, message = "经度 (longitude) 最小值为 70(东经 70°)") + @Max(value = 140, message = "经度 (longitude) 最大值为 140(东经 140°)") Double longitude; } diff --git a/weather-service/src/main/java/com/htfp/weather/web/pojo/request/Position3D.java b/weather-service/src/main/java/com/htfp/weather/web/pojo/request/Position3D.java index 6d278d7..f559326 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/pojo/request/Position3D.java +++ b/weather-service/src/main/java/com/htfp/weather/web/pojo/request/Position3D.java @@ -4,6 +4,8 @@ import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; +import com.htfp.weather.download.gfs.GfsLevelsEnum; +import com.htfp.weather.web.valid.EnumValid; import lombok.Data; import lombok.EqualsAndHashCode; @@ -16,5 +18,6 @@ import lombok.EqualsAndHashCode; @Data public class Position3D extends Position2D { @NotNull(message = "高度层次 (level) 不能为空") + @EnumValid(message = "高度层次 (level) 不存在", enumClass = GfsLevelsEnum.class) Integer level; } diff --git a/weather-service/src/main/java/com/htfp/weather/web/pojo/response/Result.java b/weather-service/src/main/java/com/htfp/weather/web/pojo/response/Result.java index 620f5ad..83f5ded 100644 --- a/weather-service/src/main/java/com/htfp/weather/web/pojo/response/Result.java +++ b/weather-service/src/main/java/com/htfp/weather/web/pojo/response/Result.java @@ -37,7 +37,7 @@ public class Result { return new Result(false, error.getCode(), error.getMsg(), null); } 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) { diff --git a/weather-service/src/main/resources/config/gfsDataConfig.json b/weather-service/src/main/resources/config/gfsDataConfig.json deleted file mode 100644 index 964d18b..0000000 --- a/weather-service/src/main/resources/config/gfsDataConfig.json +++ /dev/null @@ -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" -} \ No newline at end of file diff --git a/weather-service/src/main/resources/config/tableConf.json b/weather-service/src/main/resources/config/tableConf.json deleted file mode 100644 index 2bb5d5b..0000000 --- a/weather-service/src/main/resources/config/tableConf.json +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/weather-service/src/main/resources/logback.xml b/weather-service/src/main/resources/logback.xml index 9f9102b..eec5a1c 100644 --- a/weather-service/src/main/resources/logback.xml +++ b/weather-service/src/main/resources/logback.xml @@ -12,13 +12,13 @@ - - + + - ./log/%d{yyyy-MM-dd}.%i.log + ./logInfo/info-%d{yyyy-MM-dd}.%i.log - 30 + 15 10MB @@ -27,12 +27,49 @@ %-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{50} - %msg%n UTF-8 + + + INFO + ACCEPT + DENY + + + + + + + + ./logError/error-%d{yyyy-MM-dd}.%i.log + + 15 + 10MB + + + + %highlight(%-5level) %d{HH:mm:ss.SSS} %magenta([%thread]) %cyan(%logger{36}) - %msg%n + %-5level %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %logger{50} - %msg%n + UTF-8 + + + + + + WARN + ACCEPT + NEUTRAL + + + + + + + + ERROR + ACCEPT + DENY + - - - - @@ -40,6 +77,12 @@ + + + + + +