feat(数据集): 参数值只在编辑 sql 时生效
This commit is contained in:
parent
8d13c10d97
commit
969b3d2fcf
@ -106,7 +106,7 @@ public class ViewPluginBaseServiceImpl implements ViewPluginBaseService {
|
||||
tableName = dataTableInfoDTO.getTable();
|
||||
break;
|
||||
case SQL:
|
||||
tableName = dataSetTableService.handleVariableDefaultValue(dataTableInfoDTO.getSql(), pluginViewSet.getSqlVariableDetails());
|
||||
tableName = dataSetTableService.handleVariableDefaultValue(dataTableInfoDTO.getSql(), null);
|
||||
tableName = "(" + tableName + ")";
|
||||
break;
|
||||
case CUSTOM:
|
||||
|
||||
@ -656,7 +656,8 @@ public class DataSetTableService {
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(ds);
|
||||
|
||||
String sql = handleVariableDefaultValue(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getSql(), datasetTable.getSqlVariableDetails());
|
||||
String sql = handleVariableDefaultValue(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getSql(), null);
|
||||
|
||||
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
||||
datasourceRequest.setQuery(
|
||||
qp.createQuerySQLWithPage(sql, fields, page, pageSize, realSize, false, customFilter));
|
||||
@ -962,22 +963,25 @@ public class DataSetTableService {
|
||||
if (StringUtils.isEmpty(sql)) {
|
||||
DataEaseException.throwException(Translator.get("i18n_sql_not_empty"));
|
||||
}
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(sql);
|
||||
while (matcher.find()) {
|
||||
SqlVariableDetails defaultsSqlVariableDetail = null;
|
||||
List<SqlVariableDetails> defaultsSqlVariableDetails = new Gson().fromJson(sqlVariableDetails, new TypeToken<List<SqlVariableDetails>>() {
|
||||
}.getType());
|
||||
for (SqlVariableDetails sqlVariableDetail : defaultsSqlVariableDetails) {
|
||||
if (matcher.group().substring(2, matcher.group().length() - 1).equalsIgnoreCase(sqlVariableDetail.getVariableName())) {
|
||||
defaultsSqlVariableDetail = sqlVariableDetail;
|
||||
break;
|
||||
if(sqlVariableDetails != null){
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(sql);
|
||||
while (matcher.find()) {
|
||||
SqlVariableDetails defaultsSqlVariableDetail = null;
|
||||
List<SqlVariableDetails> defaultsSqlVariableDetails = new Gson().fromJson(sqlVariableDetails, new TypeToken<List<SqlVariableDetails>>() {
|
||||
}.getType());
|
||||
for (SqlVariableDetails sqlVariableDetail : defaultsSqlVariableDetails) {
|
||||
if (matcher.group().substring(2, matcher.group().length() - 1).equalsIgnoreCase(sqlVariableDetail.getVariableName())) {
|
||||
defaultsSqlVariableDetail = sqlVariableDetail;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (defaultsSqlVariableDetail != null && StringUtils.isNotEmpty(defaultsSqlVariableDetail.getDefaultValue())) {
|
||||
sql = sql.replace(matcher.group(), defaultsSqlVariableDetail.getDefaultValue());
|
||||
}
|
||||
}
|
||||
if (defaultsSqlVariableDetail != null && StringUtils.isNotEmpty(defaultsSqlVariableDetail.getDefaultValue())) {
|
||||
sql = sql.replace(matcher.group(), defaultsSqlVariableDetail.getDefaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
sql = removeVariables(sql);
|
||||
} catch (Exception e) {
|
||||
@ -1683,7 +1687,7 @@ public class DataSetTableService {
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDatasource(ds);
|
||||
QueryProvider qp = ProviderFactory.getQueryProvider(ds.getType());
|
||||
String sql = handleVariableDefaultValue(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getSql(), datasetTable.getSqlVariableDetails());
|
||||
String sql = handleVariableDefaultValue(new Gson().fromJson(datasetTable.getInfo(), DataTableInfoDTO.class).getSql(), null);
|
||||
String sqlAsTable = qp.createSQLPreview(sql, null);
|
||||
datasourceRequest.setQuery(sqlAsTable);
|
||||
fields = datasourceProvider.fetchResultField(datasourceRequest);
|
||||
|
||||
@ -132,6 +132,7 @@ export default {
|
||||
},
|
||||
commons: {
|
||||
default_value: 'Default Value',
|
||||
params_value: 'Param Value',
|
||||
publish: 'publish',
|
||||
unpublished: 'unpublished',
|
||||
default_pwd: 'Default Pwd',
|
||||
@ -1123,6 +1124,7 @@ export default {
|
||||
max_more_than_mix: 'Max must more than Min'
|
||||
},
|
||||
dataset: {
|
||||
params_work: 'Effective only when editing SQL',
|
||||
sql_variable_limit_1: '1、SQL variables can only be used in where conditions',
|
||||
sql_variable_limit_2: '2、Example:select * from table_name where column_name=‘${parm_name}',
|
||||
select_year: 'Select Year',
|
||||
|
||||
@ -132,6 +132,7 @@ export default {
|
||||
},
|
||||
commons: {
|
||||
default_value: '默認值',
|
||||
params_value: '参数值',
|
||||
publish: '發布',
|
||||
unpublished: '取消發布',
|
||||
default_pwd: '初始密碼',
|
||||
@ -1123,6 +1124,7 @@ export default {
|
||||
max_more_than_mix: '最大值必須大於最小值'
|
||||
},
|
||||
dataset: {
|
||||
params_work: '僅在編輯 sql 時生效',
|
||||
sql_variable_limit_1: '1、SQL變數只能在WHERE條件中使用',
|
||||
sql_variable_limit_2: '2、示例:select * from table_name where column_name=‘${parm_name}',
|
||||
select_year: '選擇年',
|
||||
|
||||
@ -132,6 +132,7 @@ export default {
|
||||
},
|
||||
commons: {
|
||||
default_value: '默认值',
|
||||
params_value: '参数值',
|
||||
publish: '发布',
|
||||
unpublished: '取消发布',
|
||||
default_pwd: '初始密码',
|
||||
@ -1125,6 +1126,7 @@ export default {
|
||||
max_more_than_mix: '最大值必须大于最小值'
|
||||
},
|
||||
dataset: {
|
||||
params_work: '仅在编辑sql时生效',
|
||||
select_year: '选择年',
|
||||
sql_variable_limit_1: '1、SQL 变量只能在 WHERE 条件中使用',
|
||||
sql_variable_limit_2: '2、示例:select * from table_name where column_name=‘${parm_name}',
|
||||
|
||||
@ -128,7 +128,7 @@
|
||||
</el-cascader>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="defaultValue" :label="$t('commons.default_value')">
|
||||
<el-table-column prop="defaultValue" :label="$t('commons.params_value')" :render-header="renderPrice">
|
||||
<template slot-scope="scope">
|
||||
<el-input size="mini" v-if="scope.row.type[0] === 'TEXT'" type="text" v-model="scope.row.defaultValue" />
|
||||
<el-input size="mini" v-if="scope.row.type[0] === 'LONG' || scope.row.type[0] === 'DOUBLE'" type="number" v-model="scope.row.defaultValue" />
|
||||
@ -495,7 +495,22 @@ export default {
|
||||
},
|
||||
variableTypeChange(row){
|
||||
row.defaultValue = ''
|
||||
}
|
||||
},
|
||||
renderPrice(h, { column, $index }) {
|
||||
return [
|
||||
column.label,
|
||||
h(
|
||||
'el-tooltip',
|
||||
{
|
||||
props: {
|
||||
content: this.$t('dataset.params_work'),
|
||||
placement: 'top'
|
||||
}
|
||||
},
|
||||
[h('span', { class: { 'el-icon-info': true }})]
|
||||
)
|
||||
]
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user