mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-21 18:45:57 +08:00
Pre Merge pull request !371 from burningimlam/dev
This commit is contained in:
commit
abfeced6eb
@ -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;
|
||||
|
||||
@ -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<String, String> 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user