tuqin
2026-10-29 0a3129cb06fcea6677245097715dcc6fa3de65e5
src/main/java/com/ruoyi/common/handler/CustomTenantLineHandler.java
@@ -16,10 +16,20 @@
@Component
public class CustomTenantLineHandler implements TenantLineHandler {
    /**
     * 临时跳过租户过滤的开关。
     *
     * 场景:匿名接口(设备回传)、全局配置表(如清洗规则)这类没有登录上下文的数据,
     * 不应该被自动加上 tenant_id 条件。用法:
     *   CustomTenantLineHandler.TEMP_IGNORE.set(Boolean.TRUE);
     *   try { ... } finally { CustomTenantLineHandler.TEMP_IGNORE.remove(); }
     */
    public static final ThreadLocal<Boolean> TEMP_IGNORE = new ThreadLocal<>();
    @Override
    public Expression getTenantId() {
        try {
            Integer tenantId = SecurityUtils.getLoginUser().getTenantId();
            Long tenantId = SecurityUtils.getLoginUser().getTenantId();
            return new LongValue(tenantId);
        } catch (Exception e) {
            return null;
@@ -28,6 +38,10 @@
    @Override
    public boolean ignoreTable(String tableName) {
        // 临时跳过(匿名接口 / 全局配置表)
        if (Boolean.TRUE.equals(TEMP_IGNORE.get())) {
            return true;
        }
        // 指定不需要添加过滤条件的表
        Set<String> ignoreTables = IgnoreTableConfig.IGNORE_TABLES;
        return ignoreTables.contains(tableName);