From a8be0ccb35828ec333d5a88ff125db53739ba4ae Mon Sep 17 00:00:00 2001 From: RuoYi Date: Sat, 3 Dec 2022 13:20:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DLog=E6=B3=A8=E8=A7=A3GET?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=AE=B0=E5=BD=95=E4=B8=8D=E5=88=B0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/core/utils/ServletUtils.java | 31 +++++++++++++++++++ .../common/core/web/domain/AjaxResult.java | 8 ++--- .../ruoyi/common/log/aspect/LogAspect.java | 6 +++- .../com/ruoyi/gateway/filter/XssFilter.java | 3 +- .../service/impl/SysDeptServiceImpl.java | 6 +--- .../service/impl/SysMenuServiceImpl.java | 6 +--- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java index da36707..cda3716 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/ServletUtils.java @@ -4,8 +4,11 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.net.URLEncoder; +import java.util.Collections; import java.util.Enumeration; +import java.util.HashMap; import java.util.Map; +import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; @@ -79,6 +82,34 @@ public class ServletUtils return Convert.toBool(getRequest().getParameter(name), defaultValue); } + /** + * 获得所有请求参数 + * + * @param request 请求对象{@link ServletRequest} + * @return Map + */ + public static Map getParams(ServletRequest request) + { + final Map map = request.getParameterMap(); + return Collections.unmodifiableMap(map); + } + + /** + * 获得所有请求参数 + * + * @param request 请求对象{@link ServletRequest} + * @return Map + */ + public static Map getParamMap(ServletRequest request) + { + Map params = new HashMap<>(); + for (Map.Entry entry : getParams(request).entrySet()) + { + params.put(entry.getKey(), StringUtils.join(entry.getValue(), ",")); + } + return params; + } + /** * 获取request */ diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/AjaxResult.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/AjaxResult.java index c1e4b82..583d35e 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/AjaxResult.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/web/domain/AjaxResult.java @@ -128,7 +128,7 @@ public class AjaxResult extends HashMap /** * 返回错误消息 * - * @return + * @return 错误消息 */ public static AjaxResult error() { @@ -139,7 +139,7 @@ public class AjaxResult extends HashMap * 返回错误消息 * * @param msg 返回内容 - * @return 警告消息 + * @return 错误消息 */ public static AjaxResult error(String msg) { @@ -151,7 +151,7 @@ public class AjaxResult extends HashMap * * @param msg 返回内容 * @param data 数据对象 - * @return 警告消息 + * @return 错误消息 */ public static AjaxResult error(String msg, Object data) { @@ -163,7 +163,7 @@ public class AjaxResult extends HashMap * * @param code 状态码 * @param msg 返回内容 - * @return 警告消息 + * @return 错误消息 */ public static AjaxResult error(int code, String msg) { 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 45cf106..f6b3a32 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 @@ -102,7 +102,6 @@ public class LogAspect catch (Exception exp) { // 记录本地异常日志 - log.error("==前置通知异常=="); log.error("异常信息:{}", exp.getMessage()); exp.printStackTrace(); } @@ -150,6 +149,11 @@ public class LogAspect String params = argsArrayToString(joinPoint.getArgs()); operLog.setOperParam(StringUtils.substring(params, 0, 2000)); } + else + { + Map paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); + operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter()), 0, 2000)); + } } /** diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/XssFilter.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/XssFilter.java index 76792ee..66e8d40 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/XssFilter.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/XssFilter.java @@ -43,7 +43,8 @@ public class XssFilter implements GlobalFilter, Ordered { ServerHttpRequest request = exchange.getRequest(); // xss开关未开启 或 通过nacos关闭,不过滤 - if(!xss.getEnabled()){ + if (!xss.getEnabled()) + { return chain.filter(exchange); } // GET DELETE 不过滤 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 5aca64b..08eaf72 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -71,11 +71,7 @@ public class SysDeptServiceImpl implements ISysDeptService public List buildDeptTree(List depts) { List returnList = new ArrayList(); - List tempList = new ArrayList(); - for (SysDept dept : depts) - { - tempList.add(dept.getDeptId()); - } + List tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); for (SysDept dept : depts) { // 如果是顶级节点, 遍历该父节点的所有子节点 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index c6e8029..1e70003 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -223,11 +223,7 @@ public class SysMenuServiceImpl implements ISysMenuService public List buildMenuTree(List menus) { List returnList = new ArrayList(); - List tempList = new ArrayList(); - for (SysMenu dept : menus) - { - tempList.add(dept.getMenuId()); - } + List tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList()); for (Iterator iterator = menus.iterator(); iterator.hasNext();) { SysMenu menu = (SysMenu) iterator.next();