package com.tofly.feesapi.common;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
@Slf4j
public class LogRecordAspect {
    @Pointcut("execution(* com.tofly.feesapi..controller..*.*(..))")
    public void controllerMethods() {}

    @Before("controllerMethods()")
    public void beforeControllerMethod(JoinPoint joinPoint) {
        ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = attrs.getRequest();
        String requestURI = request.getRequestURI(); // 获取请求的URI部分

       // String requestURI="";
        log.info(String.format("=================Request ControllerName【%s】请求开始================== ",requestURI+"/"+joinPoint.getSignature().getName()));

    }

    @After("controllerMethods()")
    public void afterControllerMethod(JoinPoint joinPoint) {
       log.info(String.format("=================【%s】请求结束==================",joinPoint.getSignature().getName()));
    }

}
