From 856f0767b4ada087e9e2cb33f373e23dbcf39b85 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期二, 07 三月 2023 17:56:59 +0800 Subject: [PATCH] update 同步 ruoyi * update element-ui 2.15.10 => 2.15.12 * update 优化 tagsView右选框,首页不应该存在关闭左侧选项 * update copyright 2023 * update 优化 监控页面图标显示 * update 优化 日志注解支持排除指定的请求参数 * update 优化 业务校验优化代码 * fix 修复 优化文件下载出现的异常 * fix 修复 修改密码日志存储明文问题 * add 新增 操作日志消耗时间属性 * update 优化 日志管理使用索引提升查询性能 * update 优化 框架时间检索使用时间默认值 00:00:00 - 23:59:59 --- ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java | 40 ++++++++++++++++++++++++++++++++++------ 1 files changed, 34 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java index d85d152..4aba4ec 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/aspect/LogAspect.java @@ -3,6 +3,7 @@ import cn.hutool.core.lang.Dict; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.ttl.TransmittableThreadLocal; import com.ruoyi.common.core.utils.ServletUtils; import com.ruoyi.common.core.utils.SpringUtils; import com.ruoyi.common.core.utils.StringUtils; @@ -14,10 +15,12 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.time.StopWatch; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.http.HttpMethod; import org.springframework.validation.BindingResult; @@ -40,6 +43,22 @@ * 鎺掗櫎鏁忔劅灞炴�у瓧娈� */ public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" }; + + + /** + * 璁$畻鎿嶄綔娑堣�楁椂闂� + */ + private static final ThreadLocal<StopWatch> TIME_THREADLOCAL = new TransmittableThreadLocal<>(); + + /** + * 澶勭悊璇锋眰鍓嶆墽琛� + */ + @Before(value = "@annotation(controllerLog)") + public void boBefore(JoinPoint joinPoint, Log controllerLog) { + StopWatch stopWatch = new StopWatch(); + TIME_THREADLOCAL.set(stopWatch); + stopWatch.start(); + } /** * 澶勭悊瀹岃姹傚悗鎵ц @@ -87,12 +106,18 @@ operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); // 澶勭悊璁剧疆娉ㄨВ涓婄殑鍙傛暟 getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); + // 璁剧疆娑堣�楁椂闂� + StopWatch stopWatch = TIME_THREADLOCAL.get(); + stopWatch.stop(); + operLog.setCostTime(stopWatch.getTime()); // 鍙戝竷浜嬩欢淇濆瓨鏁版嵁搴� SpringUtils.context().publishEvent(operLog); } catch (Exception exp) { // 璁板綍鏈湴寮傚父鏃ュ織 log.error("寮傚父淇℃伅:{}", exp.getMessage()); exp.printStackTrace(); + } finally { + TIME_THREADLOCAL.remove(); } } @@ -113,7 +138,7 @@ // 鏄惁闇�瑕佷繚瀛榬equest锛屽弬鏁板拰鍊� if (log.isSaveRequestData()) { // 鑾峰彇鍙傛暟鐨勪俊鎭紝浼犲叆鍒版暟鎹簱涓�� - setRequestValue(joinPoint, operLog); + setRequestValue(joinPoint, operLog, log.excludeParamNames()); } // 鏄惁闇�瑕佷繚瀛榬esponse锛屽弬鏁板拰鍊� if (log.isSaveResponseData() && ObjectUtil.isNotNull(jsonResult)) { @@ -127,14 +152,16 @@ * @param operLog 鎿嶄綔鏃ュ織 * @throws Exception 寮傚父 */ - private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog) throws Exception { + private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog, String[] excludeParamNames) throws Exception { + Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); String requestMethod = operLog.getRequestMethod(); - if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) { - String params = argsArrayToString(joinPoint.getArgs()); + if (MapUtil.isEmpty(paramsMap) + && HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) { + String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames); operLog.setOperParam(StringUtils.substring(params, 0, 2000)); } else { - Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES); + MapUtil.removeAny(paramsMap, excludeParamNames); operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 2000)); } } @@ -142,7 +169,7 @@ /** * 鍙傛暟鎷艰 */ - private String argsArrayToString(Object[] paramsArray) { + private String argsArrayToString(Object[] paramsArray, String[] excludeParamNames) { StringBuilder params = new StringBuilder(); if (paramsArray != null && paramsArray.length > 0) { for (Object o : paramsArray) { @@ -152,6 +179,7 @@ Dict dict = JsonUtils.parseMap(str); if (MapUtil.isNotEmpty(dict)) { MapUtil.removeAny(dict, EXCLUDE_PROPERTIES); + MapUtil.removeAny(dict, excludeParamNames); str = JsonUtils.toJsonString(dict); } params.append(str).append(" "); -- Gitblit v1.9.3