fix: API 数据源参数校验

This commit is contained in:
taojinlong 2024-07-01 19:26:06 +08:00
parent 2c3a93dd2c
commit b3f9f01339
3 changed files with 44 additions and 9 deletions

View File

@ -453,13 +453,15 @@ public class CalciteProvider extends Provider {
if (StringUtils.isEmpty(configuration.getSchema())) { if (StringUtils.isEmpty(configuration.getSchema())) {
DEException.throwException(Translator.get("i18n_schema_is_empty")); DEException.throwException(Translator.get("i18n_schema_is_empty"));
} }
sql = String.format("SELECT \n" + sql = String.format("SELECT \n" +
" c.name ,t.name ,ep.value \n" + " c.name ,t.name ,ep.value \n" +
"FROM \n" + "FROM \n" +
" sys.columns AS c\n" + " sys.columns AS c\n" +
"LEFT JOIN sys.extended_properties AS ep ON c.object_id = ep.major_id AND c.column_id = ep.minor_id\n" + "LEFT JOIN sys.extended_properties AS ep ON c.object_id = ep.major_id AND c.column_id = ep.minor_id\n" +
"LEFT JOIN sys.types AS t ON c.user_type_id = t.user_type_id\n" + "LEFT JOIN sys.types AS t ON c.user_type_id = t.user_type_id\n" +
"WHERE c.object_id = OBJECT_ID('%s') ", datasourceRequest.getTable()); "LEFT JOIN sys.objects AS o ON c.object_id = o.object_id\n" +
"WHERE o.name = '%s'", datasourceRequest.getTable());
break; break;
case pg: case pg:
configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class); configuration = JsonUtil.parseObject(datasourceRequest.getDatasource().getConfiguration(), Pg.class);

View File

@ -220,6 +220,21 @@ const saveItem = () => {
ElMessage.error(t('datasource.api_field_not_empty')) ElMessage.error(t('datasource.api_field_not_empty'))
return return
} }
if (apiItem.type === 'params') {
for (let i = 0; i < apiItem.fields.length; i++) {
for (let j = 0; j < paramsList.length; j++) {
for (let k = 0; k < paramsList[j].fields.length; k++) {
if (
apiItem.fields[i].name === paramsList[j].fields[k].name &&
apiItem.serialNumber !== paramsList[j].serialNumber
) {
ElMessage.error('已经存在同名参数:' + apiItem.fields[i].name)
return
}
}
}
}
}
for (let i = 0; i < apiItem.fields.length - 1; i++) { for (let i = 0; i < apiItem.fields.length - 1; i++) {
for (let j = i + 1; j < apiItem.fields.length; j++) { for (let j = i + 1; j < apiItem.fields.length; j++) {
if (apiItem.fields[i].name === apiItem.fields[j].name) { if (apiItem.fields[i].name === apiItem.fields[j].name) {
@ -241,6 +256,17 @@ const next = () => {
ElMessage.error(t('datasource.please_input_dataPath')) ElMessage.error(t('datasource.please_input_dataPath'))
return return
} }
if (apiItem.type === 'params') {
for (let i = 0; i < paramsList.length; i++) {
if (
paramsList[i].name === apiItem.name &&
apiItem.serialNumber !== paramsList[i].serialNumber
) {
ElMessage.error('已经存在同名的参数表')
return
}
}
} else {
for (let i = 0; i < apiItemList.length; i++) { for (let i = 0; i < apiItemList.length; i++) {
if ( if (
apiItemList[i].name === apiItem.name && apiItemList[i].name === apiItem.name &&
@ -250,6 +276,8 @@ const next = () => {
return return
} }
} }
}
cancelMap['/datasource/checkApiDatasource']?.() cancelMap['/datasource/checkApiDatasource']?.()
const params = Base64.encode(JSON.stringify(paramsList)) const params = Base64.encode(JSON.stringify(paramsList))

View File

@ -379,6 +379,9 @@ const returnItem = apiItem => {
if (form.value.paramsConfiguration[i].serialNumber === apiItem.serialNumber) { if (form.value.paramsConfiguration[i].serialNumber === apiItem.serialNumber) {
find = true find = true
form.value.paramsConfiguration[i] = apiItem form.value.paramsConfiguration[i] = apiItem
if (apiItem.serialNumber === activeParamsID.value) {
setActiveName(apiItem)
}
} }
} }
if (!find) { if (!find) {
@ -498,6 +501,7 @@ const apiRule = {
const dialogEditParams = ref(false) const dialogEditParams = ref(false)
const dialogRenameApi = ref(false) const dialogRenameApi = ref(false)
const activeParamsName = ref('') const activeParamsName = ref('')
const activeParamsID = ref(0)
const paramsObj = ref({ const paramsObj = ref({
name: '', name: '',
id: 1, id: 1,
@ -542,6 +546,7 @@ const apiObjRules = {
const setActiveName = val => { const setActiveName = val => {
gridData.value = val.fields gridData.value = val.fields
activeParamsName.value = val.name activeParamsName.value = val.name
activeParamsName.value = val.serialNumber
} }
const paramsObjRef = ref() const paramsObjRef = ref()