From 3e18d4bfbf2c657b08b21512c2d884cc9d59df7b Mon Sep 17 00:00:00 2001 From: dengzedong <dengzedong@email> Date: 星期一, 14 十月 2024 16:29:49 +0800 Subject: [PATCH] 模型运行 --- iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/db/dynamic/TenantDsProcessor.java | 33 +++++++++++++++++++++++++++------ 1 files changed, 27 insertions(+), 6 deletions(-) diff --git a/iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/db/dynamic/TenantDsProcessor.java b/iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/db/dynamic/TenantDsProcessor.java index 1aada2a..24b2eff 100644 --- a/iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/db/dynamic/TenantDsProcessor.java +++ b/iailab-framework/iailab-common-biz-tenant/src/main/java/com/iailab/framework/tenant/core/db/dynamic/TenantDsProcessor.java @@ -4,8 +4,11 @@ import com.baomidou.dynamic.datasource.creator.DataSourceProperty; import com.baomidou.dynamic.datasource.creator.DefaultDataSourceCreator; import com.baomidou.dynamic.datasource.processor.DsProcessor; +import com.iailab.framework.tenant.core.context.DataContextHolder; import com.iailab.framework.tenant.core.context.TenantContextHolder; import com.iailab.framework.tenant.core.service.TenantFrameworkService; +import com.iailab.module.infra.api.db.DataSourceConfigServiceApi; +import com.iailab.module.infra.api.db.dto.DataSourceConfigRespDTO; import lombok.RequiredArgsConstructor; import org.aopalliance.intercept.MethodInvocation; import org.springframework.context.annotation.Lazy; @@ -46,18 +49,36 @@ @Lazy private DefaultDataSourceCreator dataSourceCreator; + @Resource + @Lazy + private DataSourceConfigServiceApi dataSourceConfigServiceApi; + @Override public boolean matches(String key) { - return Objects.equals(key, TenantDS.KEY); + return Objects.equals(key, TenantDS.KEY) || Objects.equals(key, DataDS.KEY); } @Override public String doDetermineDatasource(MethodInvocation invocation, String key) { - // 获得数据源配置 - Long tenantId = TenantContextHolder.getRequiredTenantId(); - DataSourceProperty dataSourceProperty = tenantFrameworkService.getDataSourceProperty(tenantId); - // 创建 or 创建数据源,并返回数据源名字 - return createDatasourceIfAbsent(dataSourceProperty); + if (DataDS.KEY.equals(key)){ + // 获得数据源配置 + Long dataSourceId = DataContextHolder.getRequiredDataSourceId(); + DataSourceConfigRespDTO dataSourceConfigRespDTO = dataSourceConfigServiceApi.getDataSourceConfig(dataSourceId); + DataSourceProperty dataSourceProperty = new DataSourceProperty(); + dataSourceProperty.setPoolName(dataSourceConfigRespDTO.getName()); + dataSourceProperty.setUrl(dataSourceConfigRespDTO.getUrl()); + dataSourceProperty.setUsername(dataSourceConfigRespDTO.getUsername()); + dataSourceProperty.setPassword(dataSourceConfigRespDTO.getPassword()); + // 创建 or 创建数据源,并返回数据源名字 + return createDatasourceIfAbsent(dataSourceProperty); + }else if(TenantDS.KEY.equals(key)){ + // 获得数据源配置 + Long tenantId = TenantContextHolder.getRequiredTenantId(); + DataSourceProperty dataSourceProperty = tenantFrameworkService.getDataSourceProperty(tenantId); + // 创建 or 创建数据源,并返回数据源名字 + return createDatasourceIfAbsent(dataSourceProperty); + } + return key; } private String createDatasourceIfAbsent(DataSourceProperty dataSourceProperty) { -- Gitblit v1.9.3