|
|
@@ -12,16 +12,8 @@
|
|
|
*/
|
|
|
package vip.xiaonuo.ten.core.config;
|
|
|
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
|
|
|
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
-import net.sf.jsqlparser.expression.Expression;
|
|
|
-import net.sf.jsqlparser.expression.StringValue;
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
@@ -34,12 +26,10 @@ import springfox.documentation.service.Contact;
|
|
|
import springfox.documentation.spi.DocumentationType;
|
|
|
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
import vip.xiaonuo.common.pojo.CommonResult;
|
|
|
-import vip.xiaonuo.ten.core.context.TenContextHolder;
|
|
|
import vip.xiaonuo.ten.core.filter.TenResolveFilter;
|
|
|
import vip.xiaonuo.ten.core.prop.TenProperties;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 动态租户解析过滤器配置
|
|
|
@@ -75,46 +65,46 @@ public class TenConfigurer implements WebMvcConfigurer {
|
|
|
* @author xuyuxiang
|
|
|
* @date 2022/3/11 10:59
|
|
|
**/
|
|
|
- @Bean
|
|
|
- public MybatisPlusInterceptor mybatisPlusInterceptorPrimary() {
|
|
|
- MybatisPlusInterceptor mybatisPlusInterceptorPrimary = new MybatisPlusInterceptor();
|
|
|
- // 添加行级动态租户插件
|
|
|
- mybatisPlusInterceptorPrimary.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
|
|
|
- @Override
|
|
|
- public Expression getTenantId() {
|
|
|
- // 获取当前租户的ID
|
|
|
- String currentTenantId = TenContextHolder.get();
|
|
|
- return ObjectUtil.isEmpty(currentTenantId)?new StringValue(tenProperties.getDefaultTenId()):new StringValue(currentTenantId);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean ignoreTable(String tableName) {
|
|
|
- // 未开启多租户则返回true,表示所有表都不需要拼多租户条件
|
|
|
- if(!tenProperties.getEnabled()) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- // 根据配置的忽略表名决定是否拼接
|
|
|
- String ignoreTableNames = tenProperties.getIgnoreTableNames();
|
|
|
- if(ObjectUtil.isNotEmpty(ignoreTableNames)) {
|
|
|
- List<String> ignoreTableNameList = StrUtil.split(ignoreTableNames.toLowerCase(), StrUtil.COMMA);
|
|
|
- return ignoreTableNameList.contains(tableName.toLowerCase());
|
|
|
- } else {
|
|
|
- // 未配置则返回false表示所有表都需要拼多租户条件
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getTenantIdColumn() {
|
|
|
- // 租户字段名称
|
|
|
- return tenProperties.getTenIdColumnName();
|
|
|
- }
|
|
|
- }));
|
|
|
- // 添加分页插件
|
|
|
- mybatisPlusInterceptorPrimary.addInnerInterceptor(new PaginationInnerInterceptor());
|
|
|
- return mybatisPlusInterceptorPrimary;
|
|
|
- }
|
|
|
+// @Bean
|
|
|
+// public MybatisPlusInterceptor mybatisPlusInterceptorPrimary() {
|
|
|
+// // MybatisPlusInterceptor mybatisPlusInterceptorPrimary = new MybatisPlusInterceptor();
|
|
|
+// // 添加行级动态租户插件
|
|
|
+//// mybatisPlusInterceptorPrimary.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
|
|
|
+//// @Override
|
|
|
+//// public Expression getTenantId() {
|
|
|
+//// // 获取当前租户的ID
|
|
|
+//// String currentTenantId = TenContextHolder.get();
|
|
|
+//// return ObjectUtil.isEmpty(currentTenantId)?new StringValue(tenProperties.getDefaultTenId()):new StringValue(currentTenantId);
|
|
|
+//// }
|
|
|
+//
|
|
|
+//// @Override
|
|
|
+//// public boolean ignoreTable(String tableName) {
|
|
|
+//// // 未开启多租户则返回true,表示所有表都不需要拼多租户条件
|
|
|
+//// if(!tenProperties.getEnabled()) {
|
|
|
+//// return true;
|
|
|
+//// } else {
|
|
|
+//// // 根据配置的忽略表名决定是否拼接
|
|
|
+//// String ignoreTableNames = tenProperties.getIgnoreTableNames();
|
|
|
+//// if(ObjectUtil.isNotEmpty(ignoreTableNames)) {
|
|
|
+//// List<String> ignoreTableNameList = StrUtil.split(ignoreTableNames.toLowerCase(), StrUtil.COMMA);
|
|
|
+//// return ignoreTableNameList.contains(tableName.toLowerCase());
|
|
|
+//// } else {
|
|
|
+//// // 未配置则返回false表示所有表都需要拼多租户条件
|
|
|
+//// return false;
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+//// }
|
|
|
+//
|
|
|
+//// @Override
|
|
|
+//// public String getTenantIdColumn() {
|
|
|
+//// // 租户字段名称
|
|
|
+//// return tenProperties.getTenIdColumnName();
|
|
|
+//// }
|
|
|
+// // }));
|
|
|
+// // 添加分页插件
|
|
|
+// // mybatisPlusInterceptorPrimary.addInnerInterceptor(new PaginationInnerInterceptor());
|
|
|
+// return mybatisPlusInterceptorPrimary;
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* API文档分组配置
|