@having 支持复杂条件组合,且新增 @having& 简化 AND 连接的写法
This commit is contained in:
parent
a3d9c90a8d
commit
9776408d63
@ -147,6 +147,7 @@ public class JSONObject extends com.alibaba.fastjson.JSONObject {
|
||||
public static final String KEY_COMBINE = "@combine"; //条件组合,每个条件key前面可以放&,|,!逻辑关系 "id!{},&sex,!name&$"
|
||||
public static final String KEY_GROUP = "@group"; //分组方式
|
||||
public static final String KEY_HAVING = "@having"; //聚合函数条件,一般和@group一起用
|
||||
public static final String KEY_HAVING_AND = "@having&"; //聚合函数条件,一般和@group一起用
|
||||
public static final String KEY_ORDER = "@order"; //排序方式
|
||||
public static final String KEY_RAW = "@raw"; // 自定义原始 SQL 片段
|
||||
public static final String KEY_JSON = "@json"; //SQL Server 把字段转为 JSON 输出
|
||||
@ -167,6 +168,7 @@ public class JSONObject extends com.alibaba.fastjson.JSONObject {
|
||||
TABLE_KEY_LIST.add(KEY_COMBINE);
|
||||
TABLE_KEY_LIST.add(KEY_GROUP);
|
||||
TABLE_KEY_LIST.add(KEY_HAVING);
|
||||
TABLE_KEY_LIST.add(KEY_HAVING_AND);
|
||||
TABLE_KEY_LIST.add(KEY_ORDER);
|
||||
TABLE_KEY_LIST.add(KEY_RAW);
|
||||
TABLE_KEY_LIST.add(KEY_JSON);
|
||||
@ -350,7 +352,14 @@ public class JSONObject extends com.alibaba.fastjson.JSONObject {
|
||||
* @return
|
||||
*/
|
||||
public JSONObject setHaving(String keys) {
|
||||
return puts(KEY_HAVING, keys);
|
||||
return setHaving(keys, false);
|
||||
}
|
||||
/**set keys for having
|
||||
* @param keys "key0,key1,key2..."
|
||||
* @return
|
||||
*/
|
||||
public JSONObject setHaving(String keys, boolean isAnd) {
|
||||
return puts(isAnd ? KEY_HAVING_AND : KEY_HAVING, keys);
|
||||
}
|
||||
|
||||
/**set keys for order by
|
||||
|
@ -1063,13 +1063,13 @@ public abstract class AbstractParser<T> implements Parser<T>, ParserCreator<T>,
|
||||
boolean isExplain = cfg.isExplain();
|
||||
cfg.setExplain(false);
|
||||
|
||||
Subquery subq = new Subquery();
|
||||
subq.setFrom(cfg.getTable());
|
||||
subq.setConfig(cfg);
|
||||
Subquery subqy = new Subquery();
|
||||
subqy.setFrom(cfg.getTable());
|
||||
subqy.setConfig(cfg);
|
||||
|
||||
SQLConfig countSQLCfg = createSQLConfig();
|
||||
countSQLCfg.setColumn(Arrays.asList("count(*):count"));
|
||||
countSQLCfg.setFrom(subq);
|
||||
countSQLCfg.setFrom(subqy);
|
||||
|
||||
rp = executeSQL(countSQLCfg, false);
|
||||
|
||||
@ -1358,6 +1358,7 @@ public abstract class AbstractParser<T> implements Parser<T>, ParserCreator<T>,
|
||||
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_COMBINE);
|
||||
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_GROUP);
|
||||
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_HAVING);
|
||||
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_HAVING_AND);
|
||||
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_ORDER);
|
||||
JOIN_COPY_KEY_LIST.add(JSONRequest.KEY_RAW);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -159,8 +159,11 @@ public interface SQLConfig {
|
||||
String getGroup();
|
||||
SQLConfig setGroup(String group);
|
||||
|
||||
String getHaving();
|
||||
SQLConfig setHaving(String having);
|
||||
Map<String, Object> getHaving();
|
||||
SQLConfig setHaving(Map<String, Object> having);
|
||||
|
||||
String getHavingCombine();
|
||||
SQLConfig setHavingCombine(String havingCombine);
|
||||
|
||||
String getOrder();
|
||||
SQLConfig setOrder(String order);
|
||||
|
Loading…
Reference in New Issue
Block a user