diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java index fd9631c2e..17aebb59a 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java @@ -775,8 +775,8 @@ public String getUserIdKey() { private Map cast; private Map content; //Request内容,key:value形式,column = content.keySet(),values = content.values() private Map where; //筛选条件,key:value形式 - private Map> combine; //条件组合,{ "&":[key], "|":[key], "!":[key] } - private String combineExpression; + private String combine; //条件组合, a | (b & c & !(d | !e)) + private Map> combineMap; //条件组合,{ "&":[key], "|":[key], "!":[key] } //array item <<<<<<<<<< private int count; //Table数量 @@ -2238,31 +2238,31 @@ protected float getMaxCombineRatio() { @Override - public String getCombineExpression() { - return combineExpression; + public String getCombine() { + return combine; } @Override - public AbstractSQLConfig setCombineExpression(String combineExpression) { - this.combineExpression = combineExpression; + public AbstractSQLConfig setCombine(String combine) { + this.combine = combine; return this; } @NotNull @Override - public Map> getCombine() { - List andList = combine == null ? null : combine.get("&"); + public Map> getCombineMap() { + List andList = combineMap == null ? null : combineMap.get("&"); if (andList == null) { andList = where == null ? new ArrayList() : new ArrayList(where.keySet()); - if (combine == null) { - combine = new HashMap<>(); + if (combineMap == null) { + combineMap = new HashMap<>(); } - combine.put("&", andList); + combineMap.put("&", andList); } - return combine; + return combineMap; } @Override - public AbstractSQLConfig setCombine(Map> combine) { - this.combine = combine; + public AbstractSQLConfig setCombineMap(Map> combineMap) { + this.combineMap = combineMap; return this; } @@ -2329,8 +2329,8 @@ public AbstractSQLConfig putWhere(String key, Object value, boolean prior) { where.put(key, value); } - combine = getCombine(); - List andList = combine.get("&"); + Map> combineMap = getCombineMap(); + List andList = combineMap.get("&"); if (value == null) { if (andList != null) { andList.remove(key); @@ -2392,7 +2392,7 @@ else if (key.equals(userIdInKey)) { andList.add(key); //AbstractSQLExecutor.onPutColumn里getSQL,要保证缓存的SQL和查询的SQL里 where 的 key:value 顺序一致 } } - combine.put("&", andList); + combineMap.put("&", andList); } return this; @@ -2405,11 +2405,11 @@ else if (key.equals(userIdInKey)) { @JSONField(serialize = false) @Override public String getWhereString(boolean hasPrefix) throws Exception { - String ce = getCombineExpression(); - if (StringUtil.isEmpty(ce, true)) { - return getWhereString(hasPrefix, getMethod(), getWhere(), getCombine(), getJoinList(), ! isTest()); + String combineExpr = getCombine(); + if (StringUtil.isEmpty(combineExpr, true)) { + return getWhereString(hasPrefix, getMethod(), getWhere(), getCombineMap(), getJoinList(), ! isTest()); } - return getWhereString(hasPrefix, getMethod(), getWhere(), ce, getJoinList(), ! isTest()); + return getWhereString(hasPrefix, getMethod(), getWhere(), combineExpr, getJoinList(), ! isTest()); } /**获取WHERE * @param method @@ -2432,7 +2432,19 @@ public String getWhereString(boolean hasPrefix, RequestMethod method, Map conditioinMap, String combine, boolean verifyName, boolean containRaw, boolean isHaving) throws Exception { @@ -2693,6 +2705,17 @@ else if (StringUtil.isNotEmpty(andCond, true)) { // andCond 必须放后面, return result; } + /**已废弃,最快 6.0 删除,请尽快把前端/客户端 @combine:"a,b" 这种旧方式改为 @combine:"a | b" 这种新方式 + * @param hasPrefix + * @param method + * @param where + * @param combine + * @param joinList + * @param verifyName + * @return + * @throws Exception + */ + @Deprecated public String getWhereString(boolean hasPrefix, RequestMethod method, Map where, Map> combine, List joinList, boolean verifyName) throws Exception { Set>> combineSet = combine == null ? null : combine.entrySet(); if (combineSet == null || combineSet.isEmpty()) { @@ -4437,9 +4460,9 @@ else if (id instanceof Subquery) {} List whereList = null; String[] ws = StringUtil.split(combine); - String combineExpression = ws == null || ws.length != 1 ? null : ws[0]; + String combineExpr = ws == null || ws.length != 1 ? null : ws[0]; - Map> combineMap = StringUtil.isNotEmpty(combineExpression, true) ? null : new LinkedHashMap<>(); + Map> combineMap = StringUtil.isNotEmpty(combineExpr, true) ? null : new LinkedHashMap<>(); List andList = combineMap == null ? null : new ArrayList<>(); List orList = combineMap == null ? null : new ArrayList<>(); List notList = combineMap == null ? null : new ArrayList<>(); @@ -4459,14 +4482,14 @@ else if (id instanceof Subquery) {} } if (combineMap == null) { - if (StringUtil.isNotEmpty(combineExpression, true)) { + if (StringUtil.isNotEmpty(combineExpr, true)) { List banKeyList = Arrays.asList(idKey, idInKey, userIdKey, userIdInKey); for (String key : banKeyList) { - int index = combineExpression.indexOf(key); + int index = combineExpr.indexOf(key); if (index >= 0) { - char left = index <= 0 ? ' ' : combineExpression.charAt(index - 1); - char right = index >= combineExpression.length() - key.length() ? ' ' : combineExpression.charAt(index + key.length()); + char left = index <= 0 ? ' ' : combineExpr.charAt(index - 1); + char right = index >= combineExpr.length() - key.length() ? ' ' : combineExpr.charAt(index + key.length()); if ((left == ' ' || left == '(' || left == '&' || left == '|' || left == '!') && (right == ' ' || right == ')')) { throw new UnsupportedOperationException(table + ":{} 里的 @combine:value 中的 value 里 " + key + " 不合法!" + "不允许传 [" + idKey + ", " + idInKey + ", " + userIdKey + ", " + userIdInKey + "] 其中任何一个!"); @@ -4567,8 +4590,8 @@ else if (whereList != null && whereList.contains(key)) { combineMap.put("|", orList); combineMap.put("!", notList); } - config.setCombine(combineMap); - config.setCombineExpression(combineExpression); + config.setCombineMap(combineMap); + config.setCombine(combineExpr); config.setContent(tableContent); } diff --git a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java index bd5c0cf00..c99f1e5eb 100755 --- a/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java +++ b/APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java @@ -335,7 +335,7 @@ public JSONObject execute(@NotNull SQLConfig config, boolean unknowType) throws capacity = config.getCount() <= 0 ? Parser.MAX_QUERY_COUNT : config.getCount(); if (capacity > 100) { // 有条件,条件越多过滤数据越多 - Map> combine = config.getCombine(); + Map> combine = config.getCombineMap(); List andList = combine == null ? null : combine.get("&"); int andCondCount = andList == null ? (config.getWhere() == null ? 0 : config.getWhere().size()) : andList.size(); diff --git a/APIJSONORM/src/main/java/apijson/orm/SQLConfig.java b/APIJSONORM/src/main/java/apijson/orm/SQLConfig.java index 22acf1461..43561fdd8 100755 --- a/APIJSONORM/src/main/java/apijson/orm/SQLConfig.java +++ b/APIJSONORM/src/main/java/apijson/orm/SQLConfig.java @@ -156,18 +156,6 @@ public interface SQLConfig { List getRaw(); SQLConfig setRaw(List raw); - String getGroup(); - SQLConfig setGroup(String group); - - Map getHaving(); - SQLConfig setHaving(Map having); - - String getHavingCombine(); - SQLConfig setHavingCombine(String havingCombine); - - String getOrder(); - SQLConfig setOrder(String order); - Subquery getFrom(); SQLConfig setFrom(Subquery from); @@ -180,11 +168,11 @@ public interface SQLConfig { Map getContent(); SQLConfig setContent(Map content); - Map> getCombine(); - SQLConfig setCombine(Map> combine); + Map> getCombineMap(); + SQLConfig setCombineMap(Map> combineMap); - String getCombineExpression(); - SQLConfig setCombineExpression(String combineExpression); + String getCombine(); + SQLConfig setCombine(String combine); Map getCast(); SQLConfig setCast(Map cast); @@ -195,6 +183,18 @@ public interface SQLConfig { Map getWhere(); SQLConfig setWhere(Map where); + String getGroup(); + SQLConfig setGroup(String group); + + Map getHaving(); + SQLConfig setHaving(Map having); + + String getHavingCombine(); + SQLConfig setHavingCombine(String havingCombine); + + String getOrder(); + SQLConfig setOrder(String order); + /** * exactMatch = false * @param key