From 2ed0b62cfcc024c759d54a6ba6a62ca6bba36d12 Mon Sep 17 00:00:00 2001 From: imlam Date: Sun, 11 Jun 2023 13:09:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E8=AF=8D=E6=8B=BC?= =?UTF-8?q?=E5=86=99=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...erLogEvent.java => OperationLogEvent.java} | 2 +- .../ruoyi/framework/aspectj/LogAspect.java | 48 +++++++++---------- .../framework/manager/EncryptorManager.java | 6 +-- .../service/impl/SysOperLogServiceImpl.java | 8 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) rename ruoyi-common/src/main/java/com/ruoyi/common/core/domain/event/{OperLogEvent.java => OperationLogEvent.java} (96%) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/event/OperLogEvent.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/event/OperationLogEvent.java similarity index 96% rename from ruoyi-common/src/main/java/com/ruoyi/common/core/domain/event/OperLogEvent.java rename to ruoyi-common/src/main/java/com/ruoyi/common/core/domain/event/OperationLogEvent.java index 3a2997810..8710345f4 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/event/OperLogEvent.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/event/OperationLogEvent.java @@ -12,7 +12,7 @@ import java.util.Date; */ @Data -public class OperLogEvent implements Serializable { +public class OperationLogEvent implements Serializable { private static final long serialVersionUID = 1L; 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 00918327b..90cf41837 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 @@ -4,7 +4,7 @@ import cn.hutool.core.lang.Dict; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import com.ruoyi.common.annotation.Log; -import com.ruoyi.common.core.domain.event.OperLogEvent; +import com.ruoyi.common.core.domain.event.OperationLogEvent; import com.ruoyi.common.enums.BusinessStatus; import com.ruoyi.common.enums.HttpMethod; import com.ruoyi.common.helper.LoginHelper; @@ -66,28 +66,28 @@ public class LogAspect { try { // *========数据库日志=========*// - OperLogEvent operLog = new OperLogEvent(); - operLog.setStatus(BusinessStatus.SUCCESS.ordinal()); + OperationLogEvent operationLog = new OperationLogEvent(); + operationLog.setStatus(BusinessStatus.SUCCESS.ordinal()); // 请求的地址 String ip = ServletUtils.getClientIP(); - operLog.setOperIp(ip); - operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)); - operLog.setOperName(LoginHelper.getUsername()); + operationLog.setOperIp(ip); + operationLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255)); + operationLog.setOperName(LoginHelper.getUsername()); if (e != null) { - operLog.setStatus(BusinessStatus.FAIL.ordinal()); - operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); + operationLog.setStatus(BusinessStatus.FAIL.ordinal()); + operationLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000)); } // 设置方法名称 String className = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); - operLog.setMethod(className + "." + methodName + "()"); + operationLog.setMethod(className + "." + methodName + "()"); // 设置请求方式 - operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); + operationLog.setRequestMethod(ServletUtils.getRequest().getMethod()); // 处理设置注解上的参数 - getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); + getControllerMethodDescription(joinPoint, controllerLog, operationLog, jsonResult); // 发布事件保存数据库 - SpringUtils.context().publishEvent(operLog); + SpringUtils.context().publishEvent(operationLog); } catch (Exception exp) { // 记录本地异常日志 log.error("异常信息:{}", exp.getMessage()); @@ -99,44 +99,44 @@ public class LogAspect { * 获取注解中对方法的描述信息 用于Controller层注解 * * @param log 日志 - * @param operLog 操作日志 + * @param operationLog 操作日志 * @throws Exception */ - public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperLogEvent operLog, Object jsonResult) throws Exception { + public void getControllerMethodDescription(JoinPoint joinPoint, Log log, OperationLogEvent operationLog, Object jsonResult) throws Exception { // 设置action动作 - operLog.setBusinessType(log.businessType().ordinal()); + operationLog.setBusinessType(log.businessType().ordinal()); // 设置标题 - operLog.setTitle(log.title()); + operationLog.setTitle(log.title()); // 设置操作人类别 - operLog.setOperatorType(log.operatorType().ordinal()); + operationLog.setOperatorType(log.operatorType().ordinal()); // 是否需要保存request,参数和值 if (log.isSaveRequestData()) { // 获取参数的信息,传入到数据库中。 - setRequestValue(joinPoint, operLog, log.excludeParamNames()); + setRequestValue(joinPoint, operationLog, log.excludeParamNames()); } // 是否需要保存response,参数和值 if (log.isSaveResponseData() && ObjectUtil.isNotNull(jsonResult)) { - operLog.setJsonResult(StringUtils.substring(JsonUtils.toJsonString(jsonResult), 0, 2000)); + operationLog.setJsonResult(StringUtils.substring(JsonUtils.toJsonString(jsonResult), 0, 2000)); } } /** * 获取请求的参数,放到log中 * - * @param operLog 操作日志 + * @param operationLog 操作日志 * @throws Exception 异常 */ - private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog, String[] excludeParamNames) throws Exception { + private void setRequestValue(JoinPoint joinPoint, OperationLogEvent operationLog, String[] excludeParamNames) throws Exception { Map paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest()); - String requestMethod = operLog.getRequestMethod(); + String requestMethod = operationLog.getRequestMethod(); 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)); + operationLog.setOperParam(StringUtils.substring(params, 0, 2000)); } else { MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES); MapUtil.removeAny(paramsMap, excludeParamNames); - operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 2000)); + operationLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 2000)); } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/EncryptorManager.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/EncryptorManager.java index 94515aab4..69017b915 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/EncryptorManager.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/manager/EncryptorManager.java @@ -53,7 +53,7 @@ public class EncryptorManager { * * @param encryptContext 加密执行者需要的相关配置参数 */ - public IEncryptor registAndGetEncryptor(EncryptContext encryptContext) { + public IEncryptor registerAndGetEncryptor(EncryptContext encryptContext) { if (encryptorMap.containsKey(encryptContext)) { return encryptorMap.get(encryptContext); } @@ -78,7 +78,7 @@ public class EncryptorManager { * @param encryptContext 加密相关的配置信息 */ public String encrypt(String value, EncryptContext encryptContext) { - IEncryptor encryptor = this.registAndGetEncryptor(encryptContext); + IEncryptor encryptor = this.registerAndGetEncryptor(encryptContext); return encryptor.encrypt(value, encryptContext.getEncode()); } @@ -89,7 +89,7 @@ public class EncryptorManager { * @param encryptContext 加密相关的配置信息 */ public String decrypt(String value, EncryptContext encryptContext) { - IEncryptor encryptor = this.registAndGetEncryptor(encryptContext); + IEncryptor encryptor = this.registerAndGetEncryptor(encryptContext); return encryptor.decrypt(value); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java index 28ac34cba..f088f767d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysOperLogServiceImpl.java @@ -5,7 +5,7 @@ import cn.hutool.core.util.ArrayUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.core.domain.PageQuery; -import com.ruoyi.common.core.domain.event.OperLogEvent; +import com.ruoyi.common.core.domain.event.OperationLogEvent; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.ip.AddressUtils; @@ -36,12 +36,12 @@ public class SysOperLogServiceImpl implements ISysOperLogService { /** * 操作日志记录 * - * @param operLogEvent 操作日志事件 + * @param operationLogEvent 操作日志事件 */ @Async @EventListener - public void recordOper(OperLogEvent operLogEvent) { - SysOperLog operLog = BeanUtil.toBean(operLogEvent, SysOperLog.class); + public void recordOper(OperationLogEvent operationLogEvent) { + SysOperLog operLog = BeanUtil.toBean(operationLogEvent, SysOperLog.class); // 远程查询操作地点 operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp())); insertOperlog(operLog);