fix: 修复关联数据集缺失schema

This commit is contained in:
junjun 2022-04-28 18:28:50 +08:00
parent 24ae00582f
commit 6336c1bdfe

View File

@ -1,5 +1,7 @@
package io.dataease.service.dataset; package io.dataease.service.dataset;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson; import com.google.gson.Gson;
import io.dataease.auth.annotation.DeCleaner; import io.dataease.auth.annotation.DeCleaner;
import io.dataease.auth.api.dto.CurrentUserDto; import io.dataease.auth.api.dto.CurrentUserDto;
@ -960,6 +962,8 @@ public class DataSetTableService {
res.put("data", jsonArray); res.put("data", jsonArray);
return res; return res;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
return res; return res;
} }
} }
@ -1321,6 +1325,17 @@ public class DataSetTableService {
DatasourceTypes datasourceTypes = DatasourceTypes.valueOf(ds.getType()); DatasourceTypes datasourceTypes = DatasourceTypes.valueOf(ds.getType());
String keyword = datasourceTypes.getKeywordPrefix() + "%s" + datasourceTypes.getKeywordSuffix(); String keyword = datasourceTypes.getKeywordPrefix() + "%s" + datasourceTypes.getKeywordSuffix();
String configuration = ds.getConfiguration();
JSONObject jsonObject = JSON.parseObject(configuration);
String schema = jsonObject.getString("schema");
String joinPrefix = "";
if (StringUtils.isNotEmpty(schema) && (StringUtils.equalsIgnoreCase(ds.getType(), DatasourceTypes.db2.getType()) ||
StringUtils.equalsIgnoreCase(ds.getType(), DatasourceTypes.sqlServer.getType()) ||
StringUtils.equalsIgnoreCase(ds.getType(), DatasourceTypes.oracle.getType()) ||
StringUtils.equalsIgnoreCase(ds.getType(), DatasourceTypes.pg.getType()))) {
joinPrefix = String.format(keyword, schema) + ".";
}
List<UnionDTO> union = dataTableInfoDTO.getUnion(); List<UnionDTO> union = dataTableInfoDTO.getUnion();
// 所有选中的字段即select后的查询字段 // 所有选中的字段即select后的查询字段
Map<String, String[]> checkedInfo = new LinkedHashMap<>(); Map<String, String[]> checkedInfo = new LinkedHashMap<>();
@ -1386,7 +1401,7 @@ public class DataSetTableService {
String currentTableName = new Gson().fromJson(currentTable.getInfo(), DataTableInfoDTO.class) String currentTableName = new Gson().fromJson(currentTable.getInfo(), DataTableInfoDTO.class)
.getTable(); .getTable();
join.append(" ").append(joinType).append(" ").append(String.format(keyword, currentTableName)) join.append(" ").append(joinType).append(" ").append(joinPrefix).append(String.format(keyword, currentTableName))
.append(" ON "); .append(" ON ");
for (int i = 0; i < unionParamDTO.getUnionFields().size(); i++) { for (int i = 0; i < unionParamDTO.getUnionFields().size(); i++) {
UnionItemDTO unionItemDTO = unionParamDTO.getUnionFields().get(i); UnionItemDTO unionItemDTO = unionParamDTO.getUnionFields().get(i);
@ -1409,13 +1424,13 @@ public class DataSetTableService {
if (StringUtils.isEmpty(f)) { if (StringUtils.isEmpty(f)) {
DEException.throwException(Translator.get("i18n_union_ds_no_checked")); DEException.throwException(Translator.get("i18n_union_ds_no_checked"));
} }
sql = MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName)) + join.toString(); sql = MessageFormat.format("SELECT {0} FROM {1}", f, joinPrefix + String.format(keyword, tableName)) + join.toString();
} else { } else {
String f = StringUtils.join(checkedInfo.get(tableName), ","); String f = StringUtils.join(checkedInfo.get(tableName), ",");
if (StringUtils.isEmpty(f)) { if (StringUtils.isEmpty(f)) {
throw new RuntimeException(Translator.get("i18n_union_ds_no_checked")); throw new RuntimeException(Translator.get("i18n_union_ds_no_checked"));
} }
sql = MessageFormat.format("SELECT {0} FROM {1}", f, String.format(keyword, tableName)); sql = MessageFormat.format("SELECT {0} FROM {1}", f, joinPrefix + String.format(keyword, tableName));
} }
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
map.put("sql", sql); map.put("sql", sql);