Skip to content

Commit

Permalink
fix: equation
Browse files Browse the repository at this point in the history
  • Loading branch information
getrebuild committed Dec 18, 2024
1 parent 7ebab09 commit cf08de3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/java/com/rebuild/core/service/query/AdvFilterParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
}
}
Expand All @@ -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, " ") + " )";
}
}
Expand Down

0 comments on commit cf08de3

Please sign in to comment.