From 20d9e00c5017111559123ad5de9be87b1f657a78 Mon Sep 17 00:00:00 2001 From: taojinlong Date: Sat, 8 Mar 2025 22:27:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dsql=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E9=9B=86=E7=B3=BB=E7=BB=9F=E5=8F=98=E9=87=8F=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/utils/SqlparserUtils.java | 22 ++++++++++++++++++- .../visualized/data/dataset/form/AddSql.vue | 9 +++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/core/core-backend/src/main/java/io/dataease/commons/utils/SqlparserUtils.java b/core/core-backend/src/main/java/io/dataease/commons/utils/SqlparserUtils.java index 95811eb715..ed54708c2a 100644 --- a/core/core-backend/src/main/java/io/dataease/commons/utils/SqlparserUtils.java +++ b/core/core-backend/src/main/java/io/dataease/commons/utils/SqlparserUtils.java @@ -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 sysParam = new HashMap<>(); diff --git a/core/core-frontend/src/views/visualized/data/dataset/form/AddSql.vue b/core/core-frontend/src/views/visualized/data/dataset/form/AddSql.vue index 7cc863305b..edd956a279 100644 --- a/core/core-frontend/src/views/visualized/data/dataset/form/AddSql.vue +++ b/core/core-frontend/src/views/visualized/data/dataset/form/AddSql.vue @@ -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