| | |
| | | package com.zy.asrs.wcs.common.config; |
| | | |
| | | import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer; |
| | | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; |
| | | import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; |
| | | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; |
| | |
| | | @Bean |
| | | public MybatisPlusInterceptor mybatisPlusInterceptor() { |
| | | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
| | | |
| | | TenantLineHandler tenantLineHandler = new TenantLineHandler() { |
| | | |
| | | interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() { |
| | | @Override |
| | | public Expression getTenantId() { |
| | | return getLoginUserTenantId(); |
| | |
| | | return "host_id"; |
| | | } |
| | | |
| | | // 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件 |
| | | @Override |
| | | public boolean ignoreTable(String tableName) { |
| | | if (getTenantId() == null) { |
| | |
| | | return Arrays.asList( |
| | | "sys_host", |
| | | "sys_user_role", |
| | | "sys_role_menu" |
| | | "sys_role_menu", |
| | | "wcs_bas_shuttle_err", |
| | | "wcs_bas_lift_err" |
| | | ).contains(tableName); |
| | | } |
| | | } |
| | | |
| | | }; |
| | | TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor(tenantLineHandler); |
| | | interceptor.addInnerInterceptor(tenantLineInnerInterceptor); |
| | | |
| | | PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
| | | interceptor.addInnerInterceptor(paginationInnerInterceptor); |
| | | |
| | | })); |
| | | // 如果用了分页插件注意先 add TenantLineInnerInterceptor 再 add PaginationInnerInterceptor |
| | | // 用了分页插件必须设置 MybatisConfiguration#useDeprecatedExecutor = false |
| | | interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); |
| | | return interceptor; |
| | | } |
| | | |
| | | @Bean |
| | | public ConfigurationCustomizer configurationCustomizer() { |
| | | return configuration -> configuration.setUseDeprecatedExecutor(false); |
| | | } |
| | | |
| | | // @Bean |
| | | // public MybatisPlusInterceptor mybatisPlusInterceptor() { |
| | | // MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); |
| | | // |
| | | // TenantLineHandler tenantLineHandler = new TenantLineHandler() { |
| | | // |
| | | // @Override |
| | | // public Expression getTenantId() { |
| | | // return getLoginUserTenantId(); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public String getTenantIdColumn() { |
| | | // return "host_id"; |
| | | // } |
| | | // |
| | | // @Override |
| | | // public boolean ignoreTable(String tableName) { |
| | | // if (getTenantId() == null) { |
| | | // return true; |
| | | // }else { |
| | | // return Arrays.asList( |
| | | // "sys_host", |
| | | // "sys_user_role", |
| | | // "sys_role_menu", |
| | | // "wcs_bas_shuttle_err", |
| | | // "wcs_bas_lift_err" |
| | | // ).contains(tableName); |
| | | // } |
| | | // } |
| | | // |
| | | // }; |
| | | // TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor(tenantLineHandler); |
| | | // interceptor.addInnerInterceptor(tenantLineInnerInterceptor); |
| | | // |
| | | // PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); |
| | | // interceptor.addInnerInterceptor(paginationInnerInterceptor); |
| | | // |
| | | // return interceptor; |
| | | // } |
| | | |
| | | /** |
| | | * 获取当前登录用户的租户id |
| | | * |