diff --git a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java index 8e9163a555..a80441c48c 100644 --- a/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java +++ b/core/core-backend/src/main/java/io/dataease/dataset/manage/DatasetSQLManage.java @@ -95,15 +95,15 @@ public class DatasetSQLManage { if (ObjectUtils.isEmpty(union)) { return null; } + Set allDs = getAllDs(union); + boolean isCross = allDs.size() > 1; DatasetTableDTO currentDs = union.get(0).getCurrentDs(); // get datasource and schema,put map - String tableSchema = putObj2Map(dsMap, currentDs); + String tableSchema = putObj2Map(dsMap, currentDs, isCross); // get table DatasetTableInfoDTO infoDTO = JsonUtil.parseObject(currentDs.getInfo(), DatasetTableInfoDTO.class); - Set allDs = getAllDs(union); - boolean isCross = allDs.size() > 1; SQLObj tableName = getUnionTable(currentDs, infoDTO, tableSchema, 0, filterParameters(chartExtRequest, currentDs.getId()), chartExtRequest == null, isCross, dsMap); @@ -116,7 +116,7 @@ public class DatasetSQLManage { if (dsMap.containsKey(datasetTable.getDatasourceId())) { schema = dsMap.get(datasetTable.getDatasourceId()).getSchemaAlias(); } else { - schema = putObj2Map(dsMap, datasetTable); + schema = putObj2Map(dsMap, datasetTable, isCross); } SQLObj table = getUnionTable(datasetTable, tableInfo, schema, i, filterParameters(chartExtRequest, currentDs.getId()), chartExtRequest == null, isCross, dsMap); @@ -287,7 +287,7 @@ public class DatasetSQLManage { if (dsMap.containsKey(datasetTable.getDatasourceId())) { schema = dsMap.get(datasetTable.getDatasourceId()).getSchemaAlias(); } else { - schema = putObj2Map(dsMap, datasetTable); + schema = putObj2Map(dsMap, datasetTable, isCross); } SQLObj table = getUnionTable(datasetTable, tableInfo, schema, index, filterParameters(chartExtRequest, datasetTable.getId()), chartExtRequest == null, isCross, dsMap); @@ -444,7 +444,7 @@ public class DatasetSQLManage { return tableObj; } - private String putObj2Map(Map dsMap, DatasetTableDTO ds) throws Exception { + private String putObj2Map(Map dsMap, DatasetTableDTO ds, boolean isCross) throws Exception { // 通过datasource id校验数据源权限 BusiPerCheckDTO dto = new BusiPerCheckDTO(); dto.setId(ds.getDatasourceId()); @@ -464,7 +464,14 @@ public class DatasetSQLManage { if (StringUtils.equalsIgnoreCase("excel", coreDatasource.getType()) || StringUtils.equalsIgnoreCase("api", coreDatasource.getType())) { coreDatasource = engineManage.getDeEngine(); } - schemaAlias = String.format(SQLConstants.SCHEMA, coreDatasource.getId()); + + Map map = JsonUtil.parseObject(coreDatasource.getConfiguration(), Map.class); + if (!isCross && ObjectUtils.isNotEmpty(map.get("schema"))) { + schemaAlias = (String) map.get("schema"); + } else { + schemaAlias = String.format(SQLConstants.SCHEMA, coreDatasource.getId()); + } + if (!dsMap.containsKey(coreDatasource.getId())) { DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO(); BeanUtils.copyBean(datasourceSchemaDTO, coreDatasource); diff --git a/core/core-backend/src/main/java/io/dataease/engine/utils/Utils.java b/core/core-backend/src/main/java/io/dataease/engine/utils/Utils.java index c4e06cbff5..a53e462eb4 100644 --- a/core/core-backend/src/main/java/io/dataease/engine/utils/Utils.java +++ b/core/core-backend/src/main/java/io/dataease/engine/utils/Utils.java @@ -9,6 +9,7 @@ import io.dataease.extensions.datasource.dto.DatasourceSchemaDTO; import io.dataease.extensions.datasource.model.SQLObj; import io.dataease.extensions.datasource.vo.DatasourceConfiguration; import io.dataease.i18n.Translator; +import io.dataease.utils.JsonUtil; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; @@ -251,6 +252,10 @@ public class Utils { public static String replaceSchemaAlias(String sql, Map dsMap) { DatasourceSchemaDTO value = dsMap.entrySet().iterator().next().getValue(); + Map map = JsonUtil.parseObject(value.getConfiguration(), Map.class); + if (ObjectUtils.isNotEmpty(map.get("schema"))) { + return sql; + } return sql.replaceAll(SqlPlaceholderConstants.KEYWORD_PREFIX_REGEX + value.getSchemaAlias() + SqlPlaceholderConstants.KEYWORD_SUFFIX_REGEX + "\\.", ""); }