mirror of
https://github.com/dataease/dataease.git
synced 2026-05-14 04:12:11 +08:00
perf: 对接 SQLBot 使用关联数据集无法开启问数
This commit is contained in:
committed by
fit2cloud-chenyw
parent
cf400dc0d5
commit
bd82b1da94
@@ -55,7 +55,7 @@ public interface DataSetAssistantMapper {
|
||||
|
||||
from `core_dataset_group` cdg
|
||||
left join `core_dataset_table` cdt on cdg.id = cdt.dataset_group_id
|
||||
left join `core_dataset_table_field` cdtf on cdtf.dataset_group_id = cdg.id
|
||||
left join `core_dataset_table_field` cdtf on cdtf.dataset_group_id = cdg.id and (cdtf.dataset_table_id is NULL or cdtf.dataset_table_id = cdt.id)
|
||||
inner join `core_datasource` cd on cdt.datasource_id = cd.id
|
||||
where cdg.is_cross != 1 and (cd.STATUS IS NULL OR cd.STATUS != 'Error')
|
||||
${ew.customSqlSegment}
|
||||
@@ -119,7 +119,7 @@ public interface DataSetAssistantMapper {
|
||||
INNER JOIN `core_datasource` cd ON cdt.datasource_id = cd.id and (cd.STATUS IS NULL OR cd.STATUS != 'Error')
|
||||
INNER JOIN `core_dataset_group` cdg ON cdg.id = cdt.dataset_group_id
|
||||
AND cdg.is_cross != 1
|
||||
INNER JOIN `core_dataset_table_field` cdtf ON cdtf.dataset_group_id = cdg.id
|
||||
INNER JOIN `core_dataset_table_field` cdtf ON cdtf.dataset_group_id = cdg.id and (cdtf.dataset_table_id is NULL or cdtf.dataset_table_id = cdt.id)
|
||||
where not exists( select 1 from user_ds_permissions ds_p where cd.id = ds_p.resource_id )
|
||||
and not exists( select 1 from user_dg_permissions dg_p where cdg.id = dg_p.resource_id )
|
||||
${ew.customSqlSegment}
|
||||
@@ -212,7 +212,7 @@ public interface DataSetAssistantMapper {
|
||||
AND (cd.STATUS IS NULL OR cd.STATUS != 'Error')
|
||||
INNER JOIN `core_dataset_group` cdg ON cdg.id = cdt.dataset_group_id
|
||||
AND cdg.is_cross != 1
|
||||
INNER JOIN `core_dataset_table_field` cdtf ON cdtf.dataset_group_id = cdg.id
|
||||
INNER JOIN `core_dataset_table_field` cdtf ON cdtf.dataset_group_id = cdg.id and (cdtf.dataset_table_id is NULL or cdtf.dataset_table_id = cdt.id)
|
||||
INNER JOIN user_ds_permissions ds_p ON cd.id = ds_p.resource_id
|
||||
INNER JOIN user_dg_permissions dg_p ON cdg.id = dg_p.resource_id
|
||||
${ew.customSqlSegment}
|
||||
|
||||
@@ -34,6 +34,7 @@ import io.dataease.extensions.datasource.dto.DatasourceSchemaDTO;
|
||||
import io.dataease.extensions.datasource.dto.FieldGroupDTO;
|
||||
import io.dataease.extensions.datasource.factory.ProviderFactory;
|
||||
import io.dataease.extensions.datasource.model.SQLMeta;
|
||||
import io.dataease.extensions.datasource.model.SQLObj;
|
||||
import io.dataease.extensions.datasource.provider.Provider;
|
||||
import io.dataease.extensions.datasource.vo.Configuration;
|
||||
import io.dataease.extensions.datasource.vo.DatasourceConfiguration;
|
||||
@@ -105,8 +106,10 @@ public class DatasetSQLBotManage {
|
||||
}
|
||||
return AesUtils.aesEncrypt(text, aesKey, iv);
|
||||
}
|
||||
|
||||
TypeReference<List<Long>> listTypeReference = new TypeReference<List<Long>>() {
|
||||
};
|
||||
|
||||
private Map<Long, List<DataSetColumnPermissionsDTO>> getColPermission(Long uid, List<Long> roleIds) {
|
||||
ColumnPermissionsApi columnPermissionsApi = CommonBeanFactory.getBean(ColumnPermissionsApi.class);
|
||||
Objects.requireNonNull(columnPermissionsApi);
|
||||
@@ -123,10 +126,10 @@ public class DatasetSQLBotManage {
|
||||
dataSetColumnPermissionsDTO.setAuthTargetType("role");
|
||||
List<DataSetColumnPermissionsDTO> roleDataSetColumnPermissionsDTOS = columnPermissionsApi.list(dataSetColumnPermissionsDTO);
|
||||
if (CollectionUtils.isNotEmpty(roleDataSetColumnPermissionsDTOS)) {
|
||||
for (DataSetColumnPermissionsDTO dto :roleDataSetColumnPermissionsDTOS) {
|
||||
for (DataSetColumnPermissionsDTO dto : roleDataSetColumnPermissionsDTOS) {
|
||||
List<Long> userIdList = JsonUtil.parseList(dto.getWhiteListUser(), listTypeReference);
|
||||
if (CollectionUtils.isEmpty(userIdList) || !userIdList.contains(uid)) {
|
||||
// roleColumnPermissionsDTOS.add(columnPermissionsDTO);
|
||||
// roleColumnPermissionsDTOS.add(columnPermissionsDTO);
|
||||
dataSetColumnPermissionsDTOS.add(dto);
|
||||
}
|
||||
}
|
||||
@@ -218,6 +221,16 @@ public class DatasetSQLBotManage {
|
||||
tableFlagMap.put(tableId, table);
|
||||
vo.getTables().add(table);
|
||||
}
|
||||
Object cdt_id_obj = null;
|
||||
Long cdt_id = null;
|
||||
|
||||
if (ObjectUtils.isNotEmpty(cdt_id_obj = row.get("cdt_id")) && !table.getTableIds().contains(cdt_id = Long.parseLong(cdt_id_obj.toString()))) {
|
||||
table.getTableIds().add(cdt_id);
|
||||
if (table.getTableIds().size() > 1) {
|
||||
table.setNeedTransform(true);
|
||||
}
|
||||
}
|
||||
|
||||
// build field
|
||||
String fieldId = row.get("cdtf_id").toString();
|
||||
SQLBotAssistantField field = fieldFlagMap.get(fieldId);
|
||||
@@ -397,6 +410,13 @@ public class DatasetSQLBotManage {
|
||||
String querySQL;
|
||||
querySQL = SQLProvider.createQuerySQL(sqlMeta, false, needOrder, false);
|
||||
querySQL = provider.rebuildSQL(querySQL, sqlMeta, false, dsMap, true);
|
||||
for (int i = 0; i < sqlMeta.getXFields().size(); i++) {
|
||||
SQLObj fieldObj = sqlMeta.getXFields().get(i);
|
||||
DatasetTableFieldDTO fieldDTO = fields.get(i);
|
||||
if (fieldObj.getFieldAlias().endsWith("_" + String.valueOf(i) + '`')) {
|
||||
table.getFields().get(i).setName(fieldObj.getFieldAlias().substring(1, fieldObj.getFieldAlias().length() - 1));
|
||||
}
|
||||
}
|
||||
table.setSql(querySQL);
|
||||
}
|
||||
|
||||
@@ -546,6 +566,9 @@ public class DatasetSQLBotManage {
|
||||
Map<String, Object> tableRowData = buildRowData(row, 1);
|
||||
tableRowData.put("datasource_id", Long.parseLong(row.get("cd_id").toString()));
|
||||
table.setRowData(tableRowData);
|
||||
Set<Long> tableIds = new HashSet<>();
|
||||
tableIds.add(Long.parseLong(row.get("cdt_id").toString()));
|
||||
table.setTableIds(tableIds);
|
||||
return table;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ public class Field2SQLObj {
|
||||
}
|
||||
|
||||
if (ObjectUtils.isNotEmpty(fields)) {
|
||||
Set<String> aliasSet = new HashSet<>();
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
DatasetTableFieldDTO x = fields.get(i);
|
||||
String originField;
|
||||
@@ -86,6 +87,10 @@ public class Field2SQLObj {
|
||||
if (ObjectUtils.isNotEmpty(x.getExtField()) && !x.getExtField().equals(ExtFieldConstant.EXT_NORMAL) && StringUtils.isNotBlank(x.getName())) {
|
||||
fieldAlias = x.getName();
|
||||
}
|
||||
if (aliasSet.contains(fieldAlias)) {
|
||||
fieldAlias += ('_' + String.valueOf(i));
|
||||
}
|
||||
aliasSet.add(fieldAlias);
|
||||
fieldAlias = String.format(FIELD_DOT_FIX, fieldAlias);
|
||||
}
|
||||
// 处理横轴字段
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class SQLBotAssistanTable implements Serializable {
|
||||
@@ -24,5 +25,6 @@ public class SQLBotAssistanTable implements Serializable {
|
||||
private boolean needPermission;
|
||||
@JsonIgnore
|
||||
private Map<String, Object> rowData;
|
||||
|
||||
@JsonIgnore
|
||||
private Set<Long> tableIds;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user