yangys
2024-05-06 e19227de97d21c10fd22536f85c8153e63072d0c
smart-starter-tenant/src/main/java/com/qianwen/core/tenant/BladeTenantHandler.java
@@ -6,7 +6,6 @@
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;
@@ -21,10 +20,9 @@
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;
@@ -41,37 +39,39 @@
    }
    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);
         }
      }
    }
}