package com.crm.rely.backend.util;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;

/**
 * @Author houn
 * @Date 2024/12/24 17:26
 * @PackageName:com.crm.rely.backend.util
 * @ClassName: PointcutExpressionResolver
 * @Description: 匹配动态切点表达式解析器
 */
public class PointcutExpressionResolver {

    private final AspectJExpressionPointcut pointcut;

    public PointcutExpressionResolver(String expression) {
        pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression(expression);
    }

    /**
     * 判断 JoinPoint 是否匹配切点表达式
     *
     * @param joinPoint 当前 JoinPoint
     * @return true 如果匹配切点表达式；false 否则
     */
    public boolean matches(JoinPoint joinPoint) {
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        return pointcut.matches(methodSignature.getMethod(), joinPoint.getTarget().getClass());
    }
}