|
@@ -2,13 +2,17 @@ package com.jiayue.ssi.aspectj;
|
|
|
|
|
|
import cn.hutool.core.util.DesensitizedUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.jiayue.ssi.annotation.OperateLog;
|
|
|
+import com.jiayue.ssi.backenum.AuditAblesEventEnum;
|
|
|
import com.jiayue.ssi.backenum.BusinessStatus;
|
|
|
import com.jiayue.ssi.backenum.HttpMethod;
|
|
|
import com.jiayue.ssi.entity.SysOperLog;
|
|
|
+import com.jiayue.ssi.entity.SysPolicy;
|
|
|
import com.jiayue.ssi.entity.SysUser;
|
|
|
import com.jiayue.ssi.factory.OperateLogFactory;
|
|
|
import com.jiayue.ssi.filter.PropertyPreExcludeFilter;
|
|
|
+import com.jiayue.ssi.service.SysPolicyService;
|
|
|
import com.jiayue.ssi.util.IPUtils;
|
|
|
import com.jiayue.ssi.util.RyStringUtils;
|
|
|
import com.jiayue.ssi.util.SecurityContextUtil;
|
|
@@ -22,6 +26,7 @@ import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.core.NamedThreadLocal;
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
import org.springframework.stereotype.Component;
|
|
@@ -58,6 +63,9 @@ public class OperateLogAspect {
|
|
|
*/
|
|
|
private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
|
|
|
|
|
+ @Autowired
|
|
|
+ SysPolicyService sysPolicyService;
|
|
|
+
|
|
|
/**
|
|
|
* 处理请求前执行
|
|
|
*/
|
|
@@ -89,37 +97,57 @@ public class OperateLogAspect {
|
|
|
|
|
|
protected void handleLog(final JoinPoint joinPoint, OperateLog controllerLog, final Exception e, Object jsonResult) {
|
|
|
try {
|
|
|
- // 获取当前的用户
|
|
|
- SysUser sysUser = SecurityContextUtil.getSysUser();
|
|
|
+ String visitUrl = StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255);
|
|
|
+ // 对审计策略配置过滤
|
|
|
+ SysPolicy sysPolicy = sysPolicyService.getOne(new QueryWrapper<>());
|
|
|
+ String auditableEvent = sysPolicy.getAuditableEvent();
|
|
|
|
|
|
- // *========数据库日志=========*//
|
|
|
- SysOperLog operLog = new SysOperLog();
|
|
|
- operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
|
|
- // 请求的地址
|
|
|
- String ip = IPUtils.getIpAddr();
|
|
|
- operLog.setOperIp(ip);
|
|
|
- operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
|
|
|
- if (sysUser != null) {
|
|
|
- operLog.setOperName(sysUser.getUsername());
|
|
|
+ boolean executeAudit = true;
|
|
|
+ if (auditableEvent!=null){
|
|
|
+ String[] auditables = auditableEvent.split(",");
|
|
|
+ for (int i=0;i<auditables.length;i++){
|
|
|
+ // 0-NWP;1-DQ
|
|
|
+ if (visitUrl.equals(AuditAblesEventEnum.getByCode(Integer.parseInt(auditables[i])).getMessage())){
|
|
|
+ // 遇到短期或者nwp不加入审计
|
|
|
+ executeAudit = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (e != null) {
|
|
|
- operLog.setStatus(BusinessStatus.FAIL.ordinal());
|
|
|
- operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
|
|
|
+ if (executeAudit){
|
|
|
+ // 获取当前的用户
|
|
|
+ SysUser sysUser = SecurityContextUtil.getSysUser();
|
|
|
+
|
|
|
+ // *========数据库日志=========*//
|
|
|
+ SysOperLog operLog = new SysOperLog();
|
|
|
+ operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
|
|
|
+ // 请求的地址
|
|
|
+ String ip = IPUtils.getIpAddr();
|
|
|
+ operLog.setOperIp(ip);
|
|
|
+ operLog.setOperUrl(visitUrl);
|
|
|
+ if (sysUser != null) {
|
|
|
+ operLog.setOperName(sysUser.getUsername());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (e != null) {
|
|
|
+ operLog.setStatus(BusinessStatus.FAIL.ordinal());
|
|
|
+ operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
|
|
|
+ }
|
|
|
+ // 设置方法名称
|
|
|
+ String className = joinPoint.getTarget().getClass().getName();
|
|
|
+ String methodName = joinPoint.getSignature().getName();
|
|
|
+ operLog.setMethod(className + "." + methodName + "()");
|
|
|
+ // 设置请求方式
|
|
|
+ operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
|
|
+ // 处理设置注解上的参数
|
|
|
+ getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
|
|
+ // 设置消耗时间
|
|
|
+ operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
|
|
|
+ operLog.setCreateBy(sysUser.getUsername());
|
|
|
+ // 保存数据库
|
|
|
+ OperateLogFactory.recordOper(operLog);
|
|
|
}
|
|
|
- // 设置方法名称
|
|
|
- String className = joinPoint.getTarget().getClass().getName();
|
|
|
- String methodName = joinPoint.getSignature().getName();
|
|
|
- operLog.setMethod(className + "." + methodName + "()");
|
|
|
- // 设置请求方式
|
|
|
- operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
|
|
- // 处理设置注解上的参数
|
|
|
- getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
|
|
- // 设置消耗时间
|
|
|
- operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
|
|
|
- operLog.setCreateBy(sysUser.getUsername());
|
|
|
- // 保存数据库
|
|
|
- OperateLogFactory.recordOper(operLog);
|
|
|
} catch (Exception exp) {
|
|
|
// 记录本地异常日志
|
|
|
log.error("异常信息:{}", exp.getMessage());
|