From c638d33343d42e58541243cd2d72f3439361b02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=AE=87=E5=A5=87?= Date: Mon, 24 Nov 2025 18:51:56 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/framework/aspectj/LogAspect.java | 2 +- .../web/exception/GlobalExceptionHandler.java | 54 ++++++++++++------- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java index ef6b37174..cdb8092c4 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java @@ -116,7 +116,7 @@ public class LogAspect // 保存数据库 // AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); // 输出到日志文件 - log.info("【接口请求日志】{}", operLog); + log.info("【接口日志】{}", operLog); } catch (Exception exp) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java index dd54dfc56..296beb155 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/exception/GlobalExceptionHandler.java @@ -2,6 +2,7 @@ package com.ruoyi.framework.web.exception; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.core.domain.AjaxResult; @@ -11,6 +12,7 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.html.EscapeUtil; +import com.ruoyi.common.utils.http.HttpHelper; import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.framework.aspectj.LogAspect; @@ -186,7 +188,7 @@ public class GlobalExceptionHandler * @param optLog */ private void sendExceptionMsg(SysOperLog optLog) { - log.info("【异常请求日志】{}", optLog); + log.info("【异常日志】{}", optLog); SpringUtils.getBean(FsNotice.class).sendException2MonitorChat(optLog); } @@ -210,29 +212,41 @@ public class GlobalExceptionHandler * @param request * @return */ - private Map getParamsMap(HttpServletRequest request) { + private Map getParamsMap(HttpServletRequest request) { + Map params = new HashMap<>(); Map requestParams = request.getParameterMap(); - if (MapUtil.isEmpty(requestParams)) { - return MapUtil.empty(); - } - Map params = new HashMap<>(); - for (Map.Entry entry : requestParams.entrySet()) { - String name = entry.getKey(); - if (ArrayUtil.contains(LogAspect.EXCLUDE_PROPERTIES, name)) { - //敏感信息不记入日志 - continue; - } - String[] values = entry.getValue(); - StringBuilder valueStrBuilder = new StringBuilder(); - if (values != null) { - for (int i = 0; i < values.length; i++) { - valueStrBuilder.append(values[i]); - if (i != values.length - 1) { - valueStrBuilder.append(","); + if (MapUtil.isNotEmpty(requestParams)) { + for (Map.Entry entry : requestParams.entrySet()) { + String name = entry.getKey(); + if (ArrayUtil.contains(LogAspect.EXCLUDE_PROPERTIES, name)) { + //敏感信息不记入日志 + continue; + } + String[] values = entry.getValue(); + StringBuilder valueStrBuilder = new StringBuilder(); + if (values != null) { + for (int i = 0; i < values.length; i++) { + valueStrBuilder.append(values[i]); + if (i != values.length - 1) { + valueStrBuilder.append(","); + } } } + params.put(name, valueStrBuilder.toString()); + } + } + String requestBodyStr = HttpHelper.getBodyString(request); + if (JSONUtil.isTypeJSONObject(requestBodyStr)) { + JSONObject requestBody = JSONUtil.parseObj(requestBodyStr); + for (Map.Entry entry : requestBody.entrySet()) { + String name = entry.getKey(); + if (ArrayUtil.contains(LogAspect.EXCLUDE_PROPERTIES, name)) { + //敏感信息不记入日志 + continue; + } + Object value = entry.getValue(); + params.put(name, value); } - params.put(name, valueStrBuilder.toString()); } return params; }