#
zjj
2025-03-29 70cfd99dc22d873878ccf734bfa162d8528f8b87
#
1个文件已修改
68 ■■■■ 已修改文件
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/common/config/MybatisPlusConfig.java 68 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/common/config/MybatisPlusConfig.java
@@ -1,5 +1,6 @@
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;
@@ -27,9 +28,7 @@
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        TenantLineHandler tenantLineHandler = new TenantLineHandler() {
        interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
            @Override
            public Expression getTenantId() {
                return getLoginUserTenantId();
@@ -40,6 +39,7 @@
                return "host_id";
            }
            // 这是 default 方法,默认返回 false 表示所有表都需要拼多租户条件
            @Override
            public boolean ignoreTable(String tableName) {
                if (getTenantId() == null) {
@@ -48,21 +48,65 @@
                    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
     *