package thyyxxk.webserver.utils;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


/**
 * <p>
 * 描述：
 * </p>
 *
 * @author xc
 * @date 2022-01-07 16:07
 */
@Slf4j
@Component
@Aspect
public class StringTrimUtil {
    //    lombok
    @Pointcut("@annotation(thyyxxk.webserver.utils.StringTrim)")
    public void stringTrim() {
    }

    //在事件通知类型中申明returning即可获取返回值
    @Before("stringTrim()")
    public void doBefore(JoinPoint joinPoint) {
        log.info("  切面类  ---！");
        log.info("数据:{}", joinPoint.getArgs());
    }

    @Around("stringTrim()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("  切面类  --- ！ around");
        return joinPoint.proceed();
    }

    @After("stringTrim()")
    public void checkAfter(JoinPoint joinPoint) {
        log.info("数据:{}", joinPoint.getArgs());
        log.info("数据:{}", joinPoint.getTarget());
        log.info("  切面类  --- ！ checkAfter");
    }

    @AfterReturning("stringTrim()")
    public void afterReturning(JoinPoint joinPoint) {
        log.info("切面类 --- ! afterReturning ");
    }

    @AfterThrowing("stringTrim()")
    public void afterThrowing(JoinPoint joinPoint) {
        log.info("切面类 --- ! 错误信息 ");
    }

}
