From cf08de3e6ee8a8e4a73b6ae800173fd5e828555b Mon Sep 17 00:00:00 2001 From: RB Date: Wed, 18 Dec 2024 14:52:59 +0800 Subject: [PATCH] fix: equation --- .../core/service/query/AdvFilterParser.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/rebuild/core/service/query/AdvFilterParser.java b/src/main/java/com/rebuild/core/service/query/AdvFilterParser.java index ecf1b9134..50b4735c8 100644 --- a/src/main/java/com/rebuild/core/service/query/AdvFilterParser.java +++ b/src/main/java/com/rebuild/core/service/query/AdvFilterParser.java @@ -188,20 +188,23 @@ public String toSqlWhere() { return "( " + StringUtils.join(indexItemSqls.values(), " and ") + " )"; } else { // 高级表达式 eg: (1 AND 2) or (3 AND 4) - String[] tokens = equation.toLowerCase().split(" "); + String[] tokens = equation.toLowerCase() + .replace("and", " and ") + .replace("or", " or ") + .replace("(", " ( ") + .replace(")", " ) ") + .replace(" ", " ").split(" "); List itemSqls = new ArrayList<>(); for (String token : tokens) { - if (StringUtils.isBlank(token)) { - continue; - } + if (StringUtils.isBlank(token)) continue; - boolean hasRP = false; // the `)` + boolean appendRP = false; // the `)` if (token.length() > 1) { if (token.startsWith("(")) { itemSqls.add("("); token = token.substring(1); } else if (token.endsWith(")")) { - hasRP = true; + appendRP = true; token = token.substring(0, token.length() - 1); } } @@ -215,10 +218,9 @@ public String toSqlWhere() { log.warn("Invalid equation token : {}", token); } - if (hasRP) { - itemSqls.add(")"); - } + if (appendRP) itemSqls.add(")"); } + return "( " + StringUtils.join(itemSqls, " ") + " )"; } }