| | |
| | | import org.aspectj.lang.annotation.AfterReturning;
|
| | | import org.aspectj.lang.annotation.AfterThrowing;
|
| | | import org.aspectj.lang.annotation.Aspect;
|
| | | import org.aspectj.lang.annotation.Before;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.core.NamedThreadLocal;
|
| | | import org.springframework.stereotype.Component;
|
| | | import org.springframework.validation.BindingResult;
|
| | | import org.springframework.web.multipart.MultipartFile;
|
| | | import org.springframework.web.servlet.HandlerMapping;
|
| | | import com.alibaba.fastjson2.JSON;
|
| | | import com.ruoyi.common.enums.HttpMethod;
|
| | | import com.ruoyi.common.filter.PropertyPreExcludeFilter;
|
| | |
| | |
|
| | | /** 排除敏感属性字段 */
|
| | | public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
|
| | |
|
| | | /** 计算操作消耗时间 */
|
| | | private static final ThreadLocal<Long> TIME_THREADLOCAL = new NamedThreadLocal<Long>("Cost Time");
|
| | |
|
| | | /**
|
| | | * 处理请求前执行
|
| | | */
|
| | | @Before(value = "@annotation(controllerLog)")
|
| | | public void boBefore(JoinPoint joinPoint, Log controllerLog)
|
| | | {
|
| | | TIME_THREADLOCAL.set(System.currentTimeMillis());
|
| | | }
|
| | |
|
| | | /**
|
| | | * 处理完请求后执行
|
| | |
| | | operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
|
| | | // 处理设置注解上的参数
|
| | | getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
|
| | | // 设置消耗时间
|
| | | operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get());
|
| | | // 保存数据库
|
| | | AsyncManager.me().execute(AsyncFactory.recordOper(operLog));
|
| | | }
|
| | | catch (Exception exp)
|
| | | {
|
| | | // 记录本地异常日志
|
| | | log.error("==前置通知异常==");
|
| | | log.error("异常信息:{}", exp.getMessage());
|
| | | exp.printStackTrace();
|
| | | }
|
| | | finally
|
| | | {
|
| | | TIME_THREADLOCAL.remove();
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | Map<?, ?> paramsMap = (Map<?, ?>) ServletUtils.getRequest().getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
|
| | | operLog.setOperParam(StringUtils.substring(paramsMap.toString(), 0, 2000));
|
| | | Map<?, ?> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
|
| | | operLog.setOperParam(StringUtils.substring(JSON.toJSONString(paramsMap, excludePropertyPreFilter()), 0, 2000));
|
| | | }
|
| | | }
|
| | |
|