package com.ruoyi.framework.aspect;

import com.ruoyi.common.annotation.LogicIgnore;
import com.ruoyi.framework.mybatis.holder.LogicHolder;
import com.ruoyi.framework.mybatis.holder.TenantHolder;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

/**
 * 租户拦截器
 */
@Aspect
public class LogicAspect {

    @Around("@annotation(logicIgnore)")
    public Object around(ProceedingJoinPoint point, LogicIgnore logicIgnore) throws Throwable {
        try {
            String[] alias = logicIgnore.alias();
            String[] tableName = logicIgnore.tableName();
            LogicHolder logicHolder = new LogicHolder();
            logicHolder.setAliases(alias);
            logicHolder.setTableNames(tableName);
            // 开启忽略
            LogicHolder.setLogicHolder(logicHolder);
            // 执行方法
            return point.proceed();
        } finally {
            // 关闭忽略
            LogicHolder.clear();
        }
    }

}
