package com.zy.common.config;
|
|
/**
|
* @author pang.jiabao
|
* @description
|
* @createDate 2024/10/25 16:18
|
*/
|
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Aspect;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Component;
|
|
@Aspect
|
@Component
|
public class SqlExecutionTimeAspect {
|
|
private static final Logger logger = LoggerFactory.getLogger(SqlExecutionTimeAspect.class);
|
|
@Around("execution(* com.zy.asrs.mapper..*(..))") // 替换为你的Mapper包路径
|
public Object logSqlExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
long startTime = System.currentTimeMillis();
|
Object result = joinPoint.proceed();
|
long duration = System.currentTimeMillis() - startTime;
|
|
if (duration > 500) { // 设置阈值
|
logger.error("慢SQL: {},执行时间: {}毫秒", joinPoint.getSignature(), duration);
|
}
|
|
return result;
|
}
|
}
|