@@ -775,8 +775,8 @@ public String getUserIdKey() { |
775 | 775 | private Map<String, String> cast; |
776 | 776 | private Map<String, Object> content; //Request内容,key:value形式,column = content.keySet(),values = content.values() |
777 | 777 | private Map<String, Object> where; //筛选条件,key:value形式 |
778 | | - private Map<String, List<String>> combine; //条件组合,{ "&":[key], "|":[key], "!":[key] } |
779 | | - private String combineExpression; |
| 778 | + private String combine; //条件组合, a | (b & c & !(d | !e)) |
| 779 | + private Map<String, List<String>> combineMap; //条件组合,{ "&":[key], "|":[key], "!":[key] } |
780 | 780 |
|
781 | 781 | //array item <<<<<<<<<< |
782 | 782 | private int count; //Table数量 |
@@ -2238,31 +2238,31 @@ protected float getMaxCombineRatio() { |
2238 | 2238 |
|
2239 | 2239 |
|
2240 | 2240 | @Override |
2241 | | - public String getCombineExpression() { |
2242 | | - return combineExpression; |
| 2241 | + public String getCombine() { |
| 2242 | + return combine; |
2243 | 2243 | } |
2244 | 2244 | @Override |
2245 | | - public AbstractSQLConfig setCombineExpression(String combineExpression) { |
2246 | | - this.combineExpression = combineExpression; |
| 2245 | + public AbstractSQLConfig setCombine(String combine) { |
| 2246 | + this.combine = combine; |
2247 | 2247 | return this; |
2248 | 2248 | } |
2249 | 2249 |
|
2250 | 2250 | @NotNull |
2251 | 2251 | @Override |
2252 | | - public Map<String, List<String>> getCombine() { |
2253 | | - List<String> andList = combine == null ? null : combine.get("&"); |
| 2252 | + public Map<String, List<String>> getCombineMap() { |
| 2253 | + List<String> andList = combineMap == null ? null : combineMap.get("&"); |
2254 | 2254 | if (andList == null) { |
2255 | 2255 | andList = where == null ? new ArrayList<String>() : new ArrayList<String>(where.keySet()); |
2256 | | - if (combine == null) { |
2257 | | - combine = new HashMap<>(); |
| 2256 | + if (combineMap == null) { |
| 2257 | + combineMap = new HashMap<>(); |
2258 | 2258 | } |
2259 | | - combine.put("&", andList); |
| 2259 | + combineMap.put("&", andList); |
2260 | 2260 | } |
2261 | | - return combine; |
| 2261 | + return combineMap; |
2262 | 2262 | } |
2263 | 2263 | @Override |
2264 | | - public AbstractSQLConfig setCombine(Map<String, List<String>> combine) { |
2265 | | - this.combine = combine; |
| 2264 | + public AbstractSQLConfig setCombineMap(Map<String, List<String>> combineMap) { |
| 2265 | + this.combineMap = combineMap; |
2266 | 2266 | return this; |
2267 | 2267 | } |
2268 | 2268 |
|
@@ -2329,8 +2329,8 @@ public AbstractSQLConfig putWhere(String key, Object value, boolean prior) { |
2329 | 2329 | where.put(key, value); |
2330 | 2330 | } |
2331 | 2331 |
|
2332 | | - combine = getCombine(); |
2333 | | - List<String> andList = combine.get("&"); |
| 2332 | + Map<String, List<String>> combineMap = getCombineMap(); |
| 2333 | + List<String> andList = combineMap.get("&"); |
2334 | 2334 | if (value == null) { |
2335 | 2335 | if (andList != null) { |
2336 | 2336 | andList.remove(key); |
@@ -2392,7 +2392,7 @@ else if (key.equals(userIdInKey)) { |
2392 | 2392 | andList.add(key); //AbstractSQLExecutor.onPutColumn里getSQL,要保证缓存的SQL和查询的SQL里 where 的 key:value 顺序一致 |
2393 | 2393 | } |
2394 | 2394 | } |
2395 | | - combine.put("&", andList); |
| 2395 | + combineMap.put("&", andList); |
2396 | 2396 | } |
2397 | 2397 |
|
2398 | 2398 | return this; |
@@ -2405,11 +2405,11 @@ else if (key.equals(userIdInKey)) { |
2405 | 2405 | @JSONField(serialize = false) |
2406 | 2406 | @Override |
2407 | 2407 | public String getWhereString(boolean hasPrefix) throws Exception { |
2408 | | - String ce = getCombineExpression(); |
2409 | | - if (StringUtil.isEmpty(ce, true)) { |
2410 | | - return getWhereString(hasPrefix, getMethod(), getWhere(), getCombine(), getJoinList(), ! isTest()); |
| 2408 | + String combineExpr = getCombine(); |
| 2409 | + if (StringUtil.isEmpty(combineExpr, true)) { |
| 2410 | + return getWhereString(hasPrefix, getMethod(), getWhere(), getCombineMap(), getJoinList(), ! isTest()); |
2411 | 2411 | } |
2412 | | - return getWhereString(hasPrefix, getMethod(), getWhere(), ce, getJoinList(), ! isTest()); |
| 2412 | + return getWhereString(hasPrefix, getMethod(), getWhere(), combineExpr, getJoinList(), ! isTest()); |
2413 | 2413 | } |
2414 | 2414 | /**获取WHERE |
2415 | 2415 | * @param method |
@@ -2432,7 +2432,19 @@ public String getWhereString(boolean hasPrefix, RequestMethod method, Map<String |
2432 | 2432 | return result; |
2433 | 2433 | } |
2434 | 2434 |
|
2435 | | - |
| 2435 | + /**解析 @combine 条件 key 组合的与或非+括号的逻辑运算表达式为具体的完整条件组合 |
| 2436 | + * @param method |
| 2437 | + * @param quote |
| 2438 | + * @param table |
| 2439 | + * @param alias |
| 2440 | + * @param conditioinMap where 或 having 对应条件的 Map |
| 2441 | + * @param combine |
| 2442 | + * @param verifyName |
| 2443 | + * @param containRaw |
| 2444 | + * @param isHaving |
| 2445 | + * @return |
| 2446 | + * @throws Exception |
| 2447 | + */ |
2436 | 2448 | protected String parseCombineExpression(RequestMethod method, String quote, String table, String alias |
2437 | 2449 | , Map<String, Object> conditioinMap, String combine, boolean verifyName, boolean containRaw, boolean isHaving) throws Exception { |
2438 | 2450 |
|
@@ -2693,6 +2705,17 @@ else if (StringUtil.isNotEmpty(andCond, true)) { // andCond 必须放后面, |
2693 | 2705 | return result; |
2694 | 2706 | } |
2695 | 2707 |
|
| 2708 | + /**已废弃,最快 6.0 删除,请尽快把前端/客户端 @combine:"a,b" 这种旧方式改为 @combine:"a | b" 这种新方式 |
| 2709 | + * @param hasPrefix |
| 2710 | + * @param method |
| 2711 | + * @param where |
| 2712 | + * @param combine |
| 2713 | + * @param joinList |
| 2714 | + * @param verifyName |
| 2715 | + * @return |
| 2716 | + * @throws Exception |
| 2717 | + */ |
| 2718 | + @Deprecated |
2696 | 2719 | public String getWhereString(boolean hasPrefix, RequestMethod method, Map<String, Object> where, Map<String, List<String>> combine, List<Join> joinList, boolean verifyName) throws Exception { |
2697 | 2720 | Set<Entry<String, List<String>>> combineSet = combine == null ? null : combine.entrySet(); |
2698 | 2721 | if (combineSet == null || combineSet.isEmpty()) { |
@@ -4437,9 +4460,9 @@ else if (id instanceof Subquery) {} |
4437 | 4460 | List<String> whereList = null; |
4438 | 4461 |
|
4439 | 4462 | String[] ws = StringUtil.split(combine); |
4440 | | - String combineExpression = ws == null || ws.length != 1 ? null : ws[0]; |
| 4463 | + String combineExpr = ws == null || ws.length != 1 ? null : ws[0]; |
4441 | 4464 |
|
4442 | | - Map<String, List<String>> combineMap = StringUtil.isNotEmpty(combineExpression, true) ? null : new LinkedHashMap<>(); |
| 4465 | + Map<String, List<String>> combineMap = StringUtil.isNotEmpty(combineExpr, true) ? null : new LinkedHashMap<>(); |
4443 | 4466 | List<String> andList = combineMap == null ? null : new ArrayList<>(); |
4444 | 4467 | List<String> orList = combineMap == null ? null : new ArrayList<>(); |
4445 | 4468 | List<String> notList = combineMap == null ? null : new ArrayList<>(); |
@@ -4459,14 +4482,14 @@ else if (id instanceof Subquery) {} |
4459 | 4482 | } |
4460 | 4483 |
|
4461 | 4484 | if (combineMap == null) { |
4462 | | - if (StringUtil.isNotEmpty(combineExpression, true)) { |
| 4485 | + if (StringUtil.isNotEmpty(combineExpr, true)) { |
4463 | 4486 | List<String> banKeyList = Arrays.asList(idKey, idInKey, userIdKey, userIdInKey); |
4464 | 4487 |
|
4465 | 4488 | for (String key : banKeyList) { |
4466 | | - int index = combineExpression.indexOf(key); |
| 4489 | + int index = combineExpr.indexOf(key); |
4467 | 4490 | if (index >= 0) { |
4468 | | - char left = index <= 0 ? ' ' : combineExpression.charAt(index - 1); |
4469 | | - char right = index >= combineExpression.length() - key.length() ? ' ' : combineExpression.charAt(index + key.length()); |
| 4491 | + char left = index <= 0 ? ' ' : combineExpr.charAt(index - 1); |
| 4492 | + char right = index >= combineExpr.length() - key.length() ? ' ' : combineExpr.charAt(index + key.length()); |
4470 | 4493 | if ((left == ' ' || left == '(' || left == '&' || left == '|' || left == '!') && (right == ' ' || right == ')')) { |
4471 | 4494 | throw new UnsupportedOperationException(table + ":{} 里的 @combine:value 中的 value 里 " + key + " 不合法!" |
4472 | 4495 | + "不允许传 [" + idKey + ", " + idInKey + ", " + userIdKey + ", " + userIdInKey + "] 其中任何一个!"); |
@@ -4567,8 +4590,8 @@ else if (whereList != null && whereList.contains(key)) { |
4567 | 4590 | combineMap.put("|", orList); |
4568 | 4591 | combineMap.put("!", notList); |
4569 | 4592 | } |
4570 | | - config.setCombine(combineMap); |
4571 | | - config.setCombineExpression(combineExpression); |
| 4593 | + config.setCombineMap(combineMap); |
| 4594 | + config.setCombine(combineExpr); |
4572 | 4595 |
|
4573 | 4596 | config.setContent(tableContent); |
4574 | 4597 | } |
|