Skip to content

Commit bccbf47

Browse files
committed
feat: support complex having expression without brackets‌
1 parent 3a056c9 commit bccbf47

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,8 @@ protected String gainHavingItem(String quote, String table, String alias
17691769
+ "预编译模式下 @having:\"column?value;function(arg0,arg1,...)?value...\""
17701770
+ " 中 column?value 必须符合正则表达式 " + PATTERN_FUNCTION + " 且不包含连续减号 -- !不允许空格!");
17711771
}
1772-
return expression;
1772+
1773+
return parseSQLExpression(KEY_HAVING, expression, containRaw, false, null);
17731774
}
17741775

17751776
int end = expression.lastIndexOf(")");
@@ -2628,7 +2629,7 @@ else if (SQL_FUNCTION_MAP.containsKey(fun) == false) {
26282629
}
26292630

26302631
// 获取前半部分函数的参数解析 fun(arg0,agr1)
2631-
String agrsString1[] = parseArgsSplitWithComma(
2632+
String[] args = parseArgsSplitWithComma(
26322633
s1.substring(index1 + 1, s1.lastIndexOf(")")), false, containRaw, allowAlias
26332634
);
26342635

@@ -2652,9 +2653,9 @@ else if (SQL_FUNCTION_MAP.containsKey(fun) == false) {
26522653
}
26532654

26542655
// 获取后半部分的参数解析 (agr0 agr1 ...)
2655-
String[] argsString2 = parseArgsSplitWithComma(argString2, false, containRaw, allowAlias);
2656-
expression = fun + "(" + StringUtil.get(agrsString1) + (containOver ? ") OVER (" : ") AGAINST (")
2657-
+ StringUtil.get(argsString2) + ")" + suffix // 传参不传空格,拼接带空格
2656+
String[] args2 = parseArgsSplitWithComma(argString2, false, containRaw, allowAlias);
2657+
expression = fun + "(" + StringUtil.get(args) + (containOver ? ") OVER (" : ") AGAINST (")
2658+
+ StringUtil.get(args2) + ")" + suffix // 传参不传空格,拼接带空格
26582659
+ (StringUtil.isEmpty(alias, true) ? "" : gainAs() + quote + alias + quote);
26592660
}
26602661
}
@@ -5287,20 +5288,21 @@ private static <T, M extends Map<String, Object>, L extends List<Object>> String
52875288
String where = config.gainWhereString(true);
52885289

52895290
//根据方法不同,聚合语句不同。GROUP BY 和 HAVING 可以加在 HEAD 上, HAVING 可以加在 PUT, DELETE 上,GET 全加,POST 全都不加
5291+
RequestMethod method = config.getMethod();
52905292
String aggregation;
5291-
if (RequestMethod.isGetMethod(config.getMethod(), true)) {
5293+
if (RequestMethod.isGetMethod(method, true)) {
52925294
aggregation = config.gainGroupString(true) + config.gainHavingString(true)
52935295
+ config.gainSampleString(true) + config.gainLatestString(true)
52945296
+ config.gainPartitionString(true) + config.gainFillString(true)
52955297
+ config.gainOrderString(true);
52965298
}
5297-
else if (RequestMethod.isHeadMethod(config.getMethod(), true)) {
5298-
// TODO 加参数 isPagenation 判断是 GET 内分页 query:2 查总数,不用加这些条件
5299+
else if (RequestMethod.isHeadMethod(method, true)) {
5300+
// TODO 加参数 isPagination 判断是 GET 内分页 query:2 查总数,不用加这些条件
52995301
aggregation = config.gainGroupString(true) + config.gainHavingString(true)
53005302
+ config.gainSampleString(true) + config.gainLatestString(true)
53015303
+ config.gainPartitionString(true) + config.gainFillString(true);
53025304
}
5303-
else if (config.getMethod() == PUT || config.getMethod() == DELETE) {
5305+
else if (method == PUT || method == DELETE) {
53045306
aggregation = config.gainHavingString(true) ;
53055307
}
53065308
else {

0 commit comments

Comments
 (0)