package cn.aqroid.business.common.tenant;

/**
 * 租户上下文
 * 使用ThreadLocal存储当前请求的租户ID
 *
 * @author aqroid
 */
public class TenantContext {

    private static final ThreadLocal<Long> TENANT_ID_HOLDER = new ThreadLocal<>();

    /**
     * 设置当前租户ID
     */
    public static void setTenantId(Long tenantId) {
        TENANT_ID_HOLDER.set(tenantId);
    }

    /**
     * 获取当前租户ID
     */
    public static Long getTenantId() {
        return TENANT_ID_HOLDER.get();
    }

    /**
     * 清除租户ID
     */
    public static void clear() {
        TENANT_ID_HOLDER.remove();
    }

    /**
     * 判断是否有租户ID
     */
    public static boolean hasTenantId() {
        return TENANT_ID_HOLDER.get() != null;
    }
}
