package com.hdkj.lt.core.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @Description 打印执行时间
 * @Author wcx
 * @Date 2023/6/8 9:56
 * @Version 1.0
 */
@Aspect
@Component
@Slf4j
public class ExecutionTimeLogger {

    // Aop打印执行时间
    @Around("@annotation(com.hdkj.lt.base.annotations.LogExecutionTime)")
    public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        Long startTime = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        Long endTime = System.currentTimeMillis();
        log.info("{} 执行时间：{} ms", joinPoint.getSignature(), endTime - startTime);
        return result;
    }

}
