fix: 【桌面版】创建excel数据源图式异常

This commit is contained in:
taojinlong
2025-01-06 10:30:45 +08:00
committed by dataeaseShu
parent a960603c56
commit 53db4ab447
3 changed files with 21 additions and 8 deletions

View File

@@ -669,7 +669,7 @@ public class SqlparserUtils {
}
private String handleSubstitutedSql(String sql) {
if (sql.contains(SysParamsSubstitutedParams)) {
if (sql.contains(SysParamsSubstitutedParams) && userEntity != null) {
sql = sql.replace(SysParamsSubstitutedParams + "sysParams.userId", userEntity.getAccount());
sql = sql.replace(SysParamsSubstitutedParams + "sysParams.userEmail", userEntity.getEmail());
sql = sql.replace(SysParamsSubstitutedParams + "sysParams.userName", userEntity.getName());
@@ -700,7 +700,7 @@ public class SqlparserUtils {
private String handleSubstitutedSqlForIn(String sql) {
if (sql.contains(SysParamsSubstitutedParams)) {
if (sql.contains(SysParamsSubstitutedParams) && userEntity != null) {
for (SysVariableValueItem variable : userEntity.getVariables()) {
List<String> values = new ArrayList<>();
if (!variable.isValid()) {

View File

@@ -130,8 +130,7 @@ public class DatasetDataManage {
} else {
// parser sql params and replace default value
String s = new String(Base64.getDecoder().decode(tableInfoDTO.getSql()));
UserFormVO userEntity = getRowPermissionsApi().getUserById(AuthUtils.getUser().getUserId());
String originSql = new SqlparserUtils().handleVariableDefaultValue(s, datasetTableDTO.getSqlVariableDetails(), false, false, null, false, datasourceRequest.getDsList(), pluginManage, userEntity);
String originSql = new SqlparserUtils().handleVariableDefaultValue(s, datasetTableDTO.getSqlVariableDetails(), false, false, null, false, datasourceRequest.getDsList(), pluginManage, getUserEntity());
originSql = provider.replaceComment(originSql);
// add sql table schema
@@ -397,6 +396,13 @@ public class DatasetDataManage {
return map;
}
private UserFormVO getUserEntity() {
if (getRowPermissionsApi() == null) {
return null;
}
return getRowPermissionsApi().getUserById(AuthUtils.getUser().getUserId());
}
public Map<String, Object> previewSql(PreviewSqlDTO dto) throws DEException {
CoreDatasource coreDatasource = dataSourceManage.getCoreDatasource(dto.getDatasourceId());
DatasourceSchemaDTO datasourceSchemaDTO = new DatasourceSchemaDTO();
@@ -422,8 +428,7 @@ public class DatasetDataManage {
// parser sql params and replace default value
String s = new String(Base64.getDecoder().decode(dto.getSql()));
UserFormVO userEntity = getRowPermissionsApi().getUserById(AuthUtils.getUser().getUserId());
String originSql = new SqlparserUtils().handleVariableDefaultValue(datasetSQLManage.subPrefixSuffixChar(s), dto.getSqlVariableDetails(), true, true, null, false, dsMap, pluginManage, userEntity);
String originSql = new SqlparserUtils().handleVariableDefaultValue(datasetSQLManage.subPrefixSuffixChar(s), dto.getSqlVariableDetails(), true, true, null, false, dsMap, pluginManage, getUserEntity());
originSql = provider.replaceComment(originSql);
// sql 作为临时表外层加上limit

View File

@@ -69,9 +69,11 @@ public class DatasetSQLManage {
private RowPermissionsApi rowPermissionsApi;
@Resource
private DataSourceManage dataSourceManage;
private RowPermissionsApi getRowPermissionsApi() {
return rowPermissionsApi;
}
private static Logger logger = LoggerFactory.getLogger(DatasetSQLManage.class);
private List<SqlVariableDetails> filterParameters(ChartExtRequest chartExtRequest, Long datasetTableId) {
@@ -461,6 +463,13 @@ public class DatasetSQLManage {
}
}
private UserFormVO getUserEntity() {
if (getRowPermissionsApi() == null) {
return null;
}
return getRowPermissionsApi().getUserById(AuthUtils.getUser().getUserId());
}
private SQLObj getUnionTable(DatasetTableDTO currentDs, DatasetTableInfoDTO infoDTO, String tableSchema, int index, List<SqlVariableDetails> parameters, boolean isFromDataSet, boolean isCross, Map<Long, DatasourceSchemaDTO> dsMap) {
SQLObj tableObj;
String tableAlias = String.format(SQLConstants.TABLE_ALIAS_PREFIX, index);
@@ -470,8 +479,7 @@ public class DatasetSQLManage {
Provider provider = ProviderFactory.getProvider(dsMap.entrySet().iterator().next().getValue().getType());
// parser sql params and replace default value
String s = new String(Base64.getDecoder().decode(infoDTO.getSql()));
UserFormVO userEntity = getRowPermissionsApi().getUserById(AuthUtils.getUser().getUserId());
String sql = new SqlparserUtils().handleVariableDefaultValue(s, currentDs.getSqlVariableDetails(), false, isFromDataSet, parameters, isCross, dsMap, pluginManage, userEntity);
String sql = new SqlparserUtils().handleVariableDefaultValue(s, currentDs.getSqlVariableDetails(), false, isFromDataSet, parameters, isCross, dsMap, pluginManage, getUserEntity());
sql = provider.replaceComment(sql);
// add table schema
if (isCross) {