fix: 修复sql数据集系统变量替换问题

This commit is contained in:
taojinlong
2025-03-08 22:27:10 +08:00
committed by taojinlong
parent e1f36721f1
commit 20d9e00c50
2 changed files with 29 additions and 2 deletions

View File

@@ -148,7 +148,19 @@ public class SqlparserUtils {
return sql;
}
private static boolean isParams(String paramId){
boolean isLong = false;
try {
Long.valueOf(paramId);
isLong = true;
}catch (Exception e){
isLong = false;
}
if(paramId.length() >= 18 && isLong){
return true;
}
return false;
}
private String removeVariables(final String sql, String dsType) throws Exception {
String tmpSql = sql.replaceAll("(?m)^\\s*$[\n\r]{0,}", "");
Pattern pattern = Pattern.compile(regex);
@@ -165,6 +177,10 @@ public class SqlparserUtils {
pattern = Pattern.compile(regex2);
matcher = pattern.matcher(tmpSql);
while (matcher.find()) {
String paramId = matcher.group().substring(1, matcher.group().length() - 1);
if(!isParams(paramId)){
continue;
}
hasVariables = true;
tmpSql = tmpSql.replace(matcher.group(), SubstitutedParams);
}
@@ -172,6 +188,10 @@ public class SqlparserUtils {
pattern = Pattern.compile(regex2);
matcher = pattern.matcher(tmpSql);
while (matcher.find()) {
String paramId = matcher.group().substring(1, matcher.group().length() - 1);
if(!isParams(paramId)){
continue;
}
hasVariables = true;
tmpSql = tmpSql.replace(matcher.group(), SysParamsSubstitutedParams + matcher.group().substring(1, matcher.group().length() - 1));
Map<String, String> sysParam = new HashMap<>();

View File

@@ -203,6 +203,8 @@ const insertFieldToCodeMirror = (value: string) => {
const setNameIdTrans = (from, to, originName, name2Auto?: string[]) => {
let name2Id = originName
const ids = [...builtInList.value, ...fieldFormList.value].map(item => item.id)
const names = [...builtInList.value, ...fieldFormList.value].map(item => item.name)
const nameIdMap = [...builtInList.value, ...fieldFormList.value].reduce((pre, next) => {
pre[next[from]] = next[to]
return pre
@@ -214,7 +216,12 @@ const setNameIdTrans = (from, to, originName, name2Auto?: string[]) => {
if (name2Auto) {
name2Auto.push(nameIdMap[ele])
}
name2Id = name2Id.replace(`[${ele}]`, `[${nameIdMap[ele]}]`)
if (from === 'id' && ids.includes(ele)) {
name2Id = name2Id.replace(`[${ele}]`, `[${nameIdMap[ele]}]`)
}
if (from === 'name' && names.includes(ele)) {
name2Id = name2Id.replace(`[${ele}]`, `[${nameIdMap[ele]}]`)
}
})
}
return name2Id