| | |
| | | import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import net.sf.jsqlparser.expression.Expression; |
| | |
| | | import org.springframework.beans.factory.SmartInitializingSingleton; |
| | | import org.springframework.context.ApplicationContext; |
| | | |
| | | /* loaded from: blade-starter-tenant-9.3.0.0-SNAPSHOT.jar:org/springblade/core/tenant/BladeTenantHandler.class */ |
| | | public class BladeTenantHandler implements TenantLineHandler, SmartInitializingSingleton { |
| | | private static final Logger log = LoggerFactory.getLogger(BladeTenantHandler.class); |
| | | private final List<String> tenantTableList = new ArrayList(); |
| | | private final List<String> tenantTableList = new ArrayList<>(); |
| | | private final List<String> excludeTableList = Arrays.asList("blade_user", "blade_dept", "blade_role", "blade_tenant", "act_de_model"); |
| | | private final BladeTenantProperties tenantProperties; |
| | | |
| | |
| | | } |
| | | |
| | | public boolean ignoreTable(String tableName) { |
| | | if (BladeTenantHolder.isIgnore().booleanValue()) { |
| | | return true; |
| | | } |
| | | return (!this.tenantTableList.contains(tableName) || !StringUtil.isNotBlank(AuthUtil.getTenantId())); |
| | | /* |
| | | return (!BladeTenantHolder.isIgnore().booleanValue() && this.tenantTableList.contains(tableName) && StringUtil.isNotBlank(AuthUtil.getTenantId())) ? false : true; |
| | | */ |
| | | } |
| | | |
| | | public void afterSingletonsInstantiated() { |
| | | ApplicationContext context = SpringUtil.getContext(); |
| | | if (this.tenantProperties.getAnnotationExclude().booleanValue() && context != null) { |
| | | Map<String, Object> tables = context.getBeansWithAnnotation(TableExclude.class); |
| | | List<String> excludeTables = this.tenantProperties.getExcludeTables(); |
| | | for (Object o : tables.values()) { |
| | | TableExclude annotation = (TableExclude) o.getClass().getAnnotation(TableExclude.class); |
| | | String value = annotation.value(); |
| | | excludeTables.add(value); |
| | | } |
| | | } |
| | | List<TableInfo> tableInfos = TableInfoHelper.getTableInfos(); |
| | | for (TableInfo tableInfo : tableInfos) { |
| | | String tableName = tableInfo.getTableName(); |
| | | if (!this.tenantProperties.getExcludeTables().contains(tableName) && !this.excludeTableList.contains(tableName.toLowerCase()) && !this.excludeTableList.contains(tableName.toUpperCase())) { |
| | | List<TableFieldInfo> fieldList = tableInfo.getFieldList(); |
| | | Iterator<TableFieldInfo> it = fieldList.iterator(); |
| | | while (true) { |
| | | if (it.hasNext()) { |
| | | TableFieldInfo fieldInfo = it.next(); |
| | | String column = fieldInfo.getColumn(); |
| | | if (this.tenantProperties.getColumn().equals(column)) { |
| | | this.tenantTableList.add(tableName); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (this.tenantProperties.getAnnotationExclude().booleanValue() && context != null) { |
| | | Map<String, Object> tables = context.getBeansWithAnnotation(TableExclude.class); |
| | | List<String> excludeTables = this.tenantProperties.getExcludeTables(); |
| | | for (Object o : tables.values()) { |
| | | TableExclude annotation = o.getClass().<TableExclude>getAnnotation(TableExclude.class); |
| | | String value = annotation.value(); |
| | | excludeTables.add(value); |
| | | } |
| | | } |
| | | List<TableInfo> tableInfos = TableInfoHelper.getTableInfos(); |
| | | for (TableInfo tableInfo : tableInfos) { |
| | | String tableName = tableInfo.getTableName(); |
| | | if (this.tenantProperties.getExcludeTables().contains(tableName) |
| | | || this.excludeTableList.contains(tableName.toLowerCase()) |
| | | || this.excludeTableList.contains(tableName.toUpperCase())) |
| | | continue; |
| | | List<TableFieldInfo> fieldList = tableInfo.getFieldList(); |
| | | for (TableFieldInfo fieldInfo : fieldList) { |
| | | String column = fieldInfo.getColumn(); |
| | | if (this.tenantProperties.getColumn().equals(column)) |
| | | this.tenantTableList.add(tableName); |
| | | } |
| | | } |
| | | } |
| | | } |