| | |
| | | import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory; |
| | | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor; |
| | | import com.vincent.rsf.server.system.entity.User; |
| | | import net.sf.jsqlparser.expression.Expression; |
| | | import net.sf.jsqlparser.expression.LongValue; |
| | | import net.sf.jsqlparser.expression.NullValue; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.security.core.Authentication; |
| | |
| | | import org.springframework.transaction.annotation.EnableTransactionManagement; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * MybatisPlus配置 |
| | |
| | | @EnableTransactionManagement |
| | | public class MybatisPlusConfig { |
| | | |
| | | /** 小写表名;与 {@link #tenantIgnoreTable(String)} 解析结果比对 */ |
| | | private static final Set<String> TENANT_IGNORE_TABLES_LC = new HashSet<>(Arrays.asList( |
| | | "sys_tenant", |
| | | "sys_host", |
| | | "sys_user_role", |
| | | "sys_role_menu", |
| | | "sys_menu", |
| | | "sys_http_audit_log", |
| | | "sys_http_audit_rule", |
| | | "sys_http_audit_config", |
| | | "man_loc_type_rela", |
| | | "man_qly_inspect_result", |
| | | "view_stock_manage", |
| | | "view_stock_statistic", |
| | | "man_transfer_order", |
| | | "man_wave_order_rela", |
| | | "cus_item_sync_view", |
| | | "cus_barcode_sync_view")); |
| | | |
| | | /** 解析后表名与忽略列表一致则跳过租户条件(含 schema、反引号、大小写) */ |
| | | static boolean tenantIgnoreTable(String tableName) { |
| | | if (tableName == null || tableName.isEmpty()) { |
| | | return false; |
| | | } |
| | | String t = tableName.trim().replace("`", ""); |
| | | int dot = t.lastIndexOf('.'); |
| | | if (dot >= 0) { |
| | | t = t.substring(dot + 1).trim(); |
| | | } |
| | | return TENANT_IGNORE_TABLES_LC.contains(t.toLowerCase()); |
| | | } |
| | | |
| | | @Bean |
| | | public MybatisPlusInterceptor mybatisPlusInterceptor() { |
| | | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
| | | |
| | | // 添加乐观锁插件 |
| | | interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); |
| | | |
| | | // 多租户插件配置 |
| | | TenantLineHandler tenantLineHandler = new TenantLineHandler() { |
| | |
| | | |
| | | @Override |
| | | public boolean ignoreTable(String tableName) { |
| | | return Arrays.asList( |
| | | "sys_tenant", |
| | | "sys_host", |
| | | "sys_user_role", |
| | | "sys_role_menu", |
| | | "sys_menu" |
| | | ).contains(tableName); |
| | | return tenantIgnoreTable(tableName); |
| | | } |
| | | }; |
| | | TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor(tenantLineHandler); |
| | |
| | | } |
| | | }; |
| | | } |
| | | |
| | | } |