@@ -2376,6 +2376,7 @@ public String getWhereString(boolean hasPrefix, RequestMethod method, Map<String
23762376 char lastLogic = 0 ;
23772377 char last = 0 ;
23782378 boolean first = true ;
2379+ boolean isNot = false ;
23792380
23802381 String key = "" ;
23812382 Map <String , Integer > usedKeyCountMap = new HashMap <>(whereSize );
@@ -2394,7 +2395,7 @@ public String getWhereString(boolean hasPrefix, RequestMethod method, Map<String
23942395 if (isEmpty == false ) {
23952396 if (first == false && lastLogic <= 0 ) {
23962397 throw new IllegalArgumentException (table + ":{ @combine: '" + combine + "' } 中字符 '" + s .substring (i - key .length () - (isOver ? 1 : 0 ))
2397- + "' 不合法!左边缺少 & | 其中一个逻辑连接符!" );
2398+ + "' 不合法!左边缺少 & | ! 其中一个逻辑连接符!" );
23982399 }
23992400
24002401 allCount ++;
@@ -2408,27 +2409,28 @@ public String getWhereString(boolean hasPrefix, RequestMethod method, Map<String
24082409 + " 已超过 最大倍数,必须在条件键值对数量 0-" + maxCombineRatio + " 倍内!" );
24092410 }
24102411
2411- Object value = where .get (key );
2412+ String column = key ;
2413+
2414+ Object value = where .get (column );
24122415 if (value == null ) {
2413- throw new IllegalArgumentException (table + ":{ @combine: '" + combine + "' } 中字符 '" + key + "' 对应的条件键值对 " + key + ":value 不存在!" );
2416+ throw new IllegalArgumentException (table + ":{ @combine: '" + combine + "' } 中字符 '" + key + "' 对应的条件键值对 " + column + ":value 不存在!" );
24142417 }
24152418
2416- String wi = getWhereItem (key , value , method , verifyName );
2419+ String wi = getWhereItem (column , value , method , verifyName );
24172420 if (StringUtil .isEmpty (wi , true )) { // 转成 1=1 ?
2418- throw new IllegalArgumentException (table + ":{ @combine: '" + combine + "' } 中字符 '" + key + "' 对应的 " + key + ":value 不是有效条件键值对!" );
2421+ throw new IllegalArgumentException (table + ":{ @combine: '" + combine + "' } 中字符 '" + key + "' 对应的 " + column + ":value 不是有效条件键值对!" );
24192422 }
24202423
2421- Integer count = usedKeyCountMap .get (key );
2424+ Integer count = usedKeyCountMap .get (column );
24222425 count = count == null ? 1 : count + 1 ;
24232426 if (count > maxCombineKeyCount && maxCombineKeyCount > 0 ) {
2424- throw new IllegalArgumentException (table + ":{ @combine: '" + combine + "' } 中字符 '" + s + "' 不合法!其中 '" + key
2427+ throw new IllegalArgumentException (table + ":{ @combine: '" + combine + "' } 中字符 '" + s + "' 不合法!其中 '" + column
24252428 + "' 重复引用,次数 " + count + " 已超过最大值,必须在 0-" + maxCombineKeyCount + " 内!" );
24262429 }
2430+ usedKeyCountMap .put (column , count );
24272431
2428- usedKeyCountMap .put (key , count );
2429-
2430-
2431- whereString += "( " + wi + " )" ;
2432+ whereString += "( " + getCondition (isNot , wi ) + " )" ;
2433+ isNot = false ;
24322434 first = false ;
24332435 }
24342436
@@ -2473,8 +2475,22 @@ else if (c == '|') {
24732475 key += c ;
24742476 }
24752477 }
2478+ else if (c == '!' ) {
2479+ last = i < 1 ? 0 : s .charAt (i - 1 ); // & | 后面跳过了空格
2480+ if (i < n - 1 && s .charAt (i + 1 ) == '(' ) {
2481+ whereString += SQL .NOT ;
2482+ lastLogic = c ;
2483+ }
2484+ else if (last <= 0 || last == ' ' || last == '(' ) {
2485+ isNot = true ;
2486+ // lastLogic = c;
2487+ }
2488+ else {
2489+ key += c ;
2490+ }
2491+ }
24762492 else if (c == '(' ) {
2477- if (key .isEmpty () == false || (i > 0 && lastLogic <= 0 )) {
2493+ if (key .isEmpty () == false || (i > 0 && lastLogic <= 0 && last != '(' )) {
24782494 throw new IllegalArgumentException (table + ":{ @combine: '" + combine + "' } 中字符 '" + s .substring (i ) + "' 不合法!左边缺少 & | 逻辑连接符!" );
24792495 }
24802496
@@ -3555,7 +3571,7 @@ public String getSubqueryString(Subquery subquery) throws Exception {
35553571 * @param condition
35563572 * @return
35573573 */
3558- private static String getCondition (boolean not , String condition ) {
3574+ public static String getCondition (boolean not , String condition ) {
35593575 return not ? NOT + "(" + condition + ")" : condition ;
35603576 }
35613577
0 commit comments