|
@@ -2,12 +2,13 @@ package cc.uncarbon.module.sys.aspect;
|
|
|
|
|
|
|
|
import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
import cc.uncarbon.framework.core.context.UserContextHolder;
|
|
|
import cc.uncarbon.module.sys.annotation.SysLog;
|
|
import cc.uncarbon.module.sys.annotation.SysLog;
|
|
|
|
|
+import cc.uncarbon.module.sys.constant.SysConstant;
|
|
|
import cc.uncarbon.module.sys.entity.SysLogEntity;
|
|
import cc.uncarbon.module.sys.entity.SysLogEntity;
|
|
|
import cc.uncarbon.module.sys.enums.SysLogStatusEnum;
|
|
import cc.uncarbon.module.sys.enums.SysLogStatusEnum;
|
|
|
import cc.uncarbon.module.sys.service.SysLogService;
|
|
import cc.uncarbon.module.sys.service.SysLogService;
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
+import cn.hutool.core.bean.copier.CopyOptions;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
@@ -18,8 +19,13 @@ import org.aspectj.lang.reflect.MethodSignature;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * SysLog切面实现类
|
|
|
|
|
|
|
+ * SysLog 切面实现类
|
|
|
|
|
+ *
|
|
|
* @author Uncarbon
|
|
* @author Uncarbon
|
|
|
*/
|
|
*/
|
|
|
@Aspect
|
|
@Aspect
|
|
@@ -29,7 +35,13 @@ import org.springframework.stereotype.Component;
|
|
|
public class SysLogAspect {
|
|
public class SysLogAspect {
|
|
|
|
|
|
|
|
private final SysLogService sysLogService;
|
|
private final SysLogService sysLogService;
|
|
|
|
|
+ // Bean 属性复制配置项
|
|
|
|
|
+ private static final CopyOptions copyOptions4MaskingArgs = new CopyOptions();
|
|
|
|
|
|
|
|
|
|
+ static {
|
|
|
|
|
+ copyOptions4MaskingArgs.setIgnoreNullValue(false);
|
|
|
|
|
+ copyOptions4MaskingArgs.setIgnoreProperties(SysConstant.SENSITIVE_FIELDS);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Pointcut("@annotation(cc.uncarbon.module.sys.annotation.SysLog)")
|
|
@Pointcut("@annotation(cc.uncarbon.module.sys.annotation.SysLog)")
|
|
|
public void sysLogPointcut() {
|
|
public void sysLogPointcut() {
|
|
@@ -48,21 +60,31 @@ public class SysLogAspect {
|
|
|
.setUsername(UserContextHolder.getUserName())
|
|
.setUsername(UserContextHolder.getUserName())
|
|
|
;
|
|
;
|
|
|
|
|
|
|
|
- // 请求方法
|
|
|
|
|
|
|
+ // 记录请求方法
|
|
|
MethodSignature methodSignature = (MethodSignature) point.getSignature();
|
|
MethodSignature methodSignature = (MethodSignature) point.getSignature();
|
|
|
sysLogEntity.setMethod(methodSignature.toString());
|
|
sysLogEntity.setMethod(methodSignature.toString());
|
|
|
|
|
|
|
|
- // 操作内容
|
|
|
|
|
|
|
+ // 记录操作内容
|
|
|
SysLog sysLogAnnotation = methodSignature.getMethod().getAnnotation(SysLog.class);
|
|
SysLog sysLogAnnotation = methodSignature.getMethod().getAnnotation(SysLog.class);
|
|
|
sysLogEntity.setOperation(sysLogAnnotation.value());
|
|
sysLogEntity.setOperation(sysLogAnnotation.value());
|
|
|
|
|
|
|
|
- // 请求参数
|
|
|
|
|
- sysLogEntity.setParams(Arrays.stream(point.getArgs()).map(JSONUtil::toJsonStr).collect(Collectors.joining(",")));
|
|
|
|
|
-
|
|
|
|
|
- // IP地址
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ 记录请求参数
|
|
|
|
|
+ */
|
|
|
|
|
+ HashMap<Object, Object> afterMasked = new HashMap<>();
|
|
|
|
|
+ sysLogEntity.setParams(Arrays.stream(point.getArgs()).map(
|
|
|
|
|
+ each -> {
|
|
|
|
|
+ // 先去除敏感字段后再入库
|
|
|
|
|
+ afterMasked.clear();
|
|
|
|
|
+ BeanUtil.copyProperties(each, afterMasked, copyOptions4MaskingArgs);
|
|
|
|
|
+ return JSONUtil.toJsonStr(afterMasked);
|
|
|
|
|
+ }
|
|
|
|
|
+ ).collect(Collectors.joining(",")));
|
|
|
|
|
+
|
|
|
|
|
+ // 记录IP地址
|
|
|
sysLogEntity.setIp(UserContextHolder.getClientIP());
|
|
sysLogEntity.setIp(UserContextHolder.getClientIP());
|
|
|
|
|
|
|
|
- // 状态
|
|
|
|
|
|
|
+ // 记录状态
|
|
|
sysLogEntity.setStatus(SysLogStatusEnum.SUCCESS);
|
|
sysLogEntity.setStatus(SysLogStatusEnum.SUCCESS);
|
|
|
|
|
|
|
|
this.callSysLogServiceSave(sysLogEntity);
|
|
this.callSysLogServiceSave(sysLogEntity);
|