| | |
| | | @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 { |
| | |
| | | |
| | | @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); |