package com.yd.csf.service.config;

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;

@Aspect
@Component
@Slf4j
public class MethodTimeAspect {
    @Around("execution(* com.yd.csf.service..*.*(..))")
    public Object measure(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        Object result = pjp.proceed();
        long cost = System.currentTimeMillis() - start;
        log.info("【性能】{}.{} 耗时 {} ms",
                pjp.getTarget().getClass().getSimpleName(),
                pjp.getSignature().getName(),
                cost);
        return result;
    }
}