

package com.jeelowcode.framework.tenant.aspect;


import com.jeelowcode.tool.framework.tenant.core.context.TenantContextHolder;
import com.jeelowcode.framework.tenant.utils.JeeLowCodeTenantUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;


@Aspect
public class JeeLowCodeTenantAspect {

    public JeeLowCodeTenantAspect() {
    }


    // 定义一个切点，用于匹配带有Administrator注解的类
    @Pointcut("@within(com.jeelowcode.framework.tenant.annotation.JeeLowCodeTenantIgnore)")
    private void pointcutClass() {}

    // 定义一个切点，用于匹配带有Administrator注解的方法
    @Pointcut("@annotation(com.jeelowcode.framework.tenant.annotation.JeeLowCodeTenantIgnore)")
    private void pointcutMethod() {}

    @Around("pointcutClass() || pointcutMethod()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object obj;
        boolean oldjeelowcodeIgnore = JeeLowCodeTenantUtils.isIgnore();
        boolean oldIgnore = TenantContextHolder.isIgnore();
        try {
            JeeLowCodeTenantUtils.setIgnore(Boolean.TRUE);
            TenantContextHolder.setIgnore(true);//芋道
            obj = point.proceed();
        } finally {
            JeeLowCodeTenantUtils.setIgnore(oldjeelowcodeIgnore);
            TenantContextHolder.setIgnore(oldIgnore);
        }

        return obj;
    }

}
