USER-20240325AU\Administrator 1 год назад
Родитель
Сommit
99a5b65876

+ 2 - 2
zd-modules/zd-security/src/main/java/com/zd/security/config/SqlCostAspect.java

@@ -6,7 +6,7 @@ import org.springframework.stereotype.Component;
 
 @Aspect
 @Component
-@Slf4j(topic = "sql aop - ")
+@Slf4j(topic = "sql aop -- ")
 public class SqlCostAspect {
     @Pointcut("execution(* com.zd.security.mapper.*.*(..))")
     public void mapperPointcut() {}
@@ -16,7 +16,7 @@ public class SqlCostAspect {
         long startTime = System.currentTimeMillis();
         Object result = joinPoint.proceed();
         long endTime = System.currentTimeMillis();
-        long costTime = (endTime - startTime) / 1000;
+        long costTime = endTime - startTime;
 
         String methodName = joinPoint.getSignature().toShortString();
         System.out.println("SQL 执行耗时:" + costTime + " s, Method: " + methodName);

+ 4 - 2
zd-modules/zd-security/src/main/java/com/zd/security/config/SqlCostInterceptor.java

@@ -1,5 +1,6 @@
 package com.zd.security.config;
 
+import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.mapping.MappedStatement;
 import org.apache.ibatis.plugin.*;
 
@@ -9,17 +10,18 @@ import org.apache.ibatis.executor.Executor;
         @Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class}),
         @Signature(type = Executor.class, method = "query", args = {MappedStatement.class, Object.class})
 })
+@Slf4j(topic = "sql-interceptor---")
 public class SqlCostInterceptor implements Interceptor {
     @Override
     public Object intercept(Invocation invocation) throws Throwable {
         long startTime = System.currentTimeMillis();
         Object result = invocation.proceed();
         long endTime = System.currentTimeMillis();
-        long costTime = endTime - startTime;
+        long costTime = (endTime - startTime) / 1000;
 
         MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
         String sqlId = mappedStatement.getId();
-        System.out.println("SQL 执行耗时:" + costTime + "ms, SQL ID: " + sqlId);
+        log.info("The sql execution took {} seconds, SQL ID: {}" ,costTime, sqlId);
         return result;
     }