5050import com .alibaba .fastjson .JSONArray ;
5151import com .alibaba .fastjson .JSONObject ;
5252import com .alibaba .fastjson .annotation .JSONField ;
53+ import com .sun .xml .internal .ws .util .StringUtils ;
5354
5455import zuo .biao .apijson .Log ;
5556import zuo .biao .apijson .RequestMethod ;
@@ -191,7 +192,7 @@ public SQLConfig setDatabase(String database) {
191192 this .database = database ;
192193 return this ;
193194 }
194-
195+
195196 @ Override
196197 public String getSchema () {
197198 String sqlTable = getSQLTable ();
@@ -611,7 +612,7 @@ public String getColumnString() throws Exception {
611612 }
612613
613614 }
614-
615+
615616 c = StringUtil .getString (keys );
616617
617618 return (c .contains (":" ) == false ? c : c .replaceAll (":" , " AS " )) + (StringUtil .isEmpty (joinColumn , true ) ? "" : ", " + joinColumn );//不能在这里改,后续还要用到:
@@ -959,6 +960,12 @@ else if ("!".equals(ce.getKey())) {
959960
960961 if (joinList != null ) {
961962
963+ String newWs = "" ;
964+ String ws = "" + whereString ;
965+
966+ List <Object > newPvl = new ArrayList <>();
967+ List <Object > pvl = new ArrayList <>(preparedValueList );
968+
962969 SQLConfig jc ;
963970 String js ;
964971 //各种 JOIN 没办法统一用 & | !连接,只能按优先级,和 @combine 一样?
@@ -968,8 +975,8 @@ else if ("!".equals(ce.getKey())) {
968975 case "|" : //不支持 <>, [] ,避免太多符号
969976 case "&" :
970977 case "!" :
971- logic = Logic . getType ( j . getJoinType ());
972-
978+ case "^" :
979+ case "*" :
973980 jc = j .getJoinConfig ();
974981 boolean isMain = jc .isMain ();
975982 jc .setMain (false ).setPrepared (isPrepared ()).setPreparedValueList (new ArrayList <Object >());
@@ -980,21 +987,44 @@ else if ("!".equals(ce.getKey())) {
980987 continue ;
981988 }
982989
983- whereString = " ( "
984- + getCondition (
985- Logic .isNot (logic ),
986- whereString
987- + ( StringUtil .isEmpty (whereString , true ) ? "" : (Logic .isAnd (logic ) ? AND : OR ) )
988- + " ( " + js + " ) "
989- )
990- + " ) " ;
990+ if (StringUtil .isEmpty (newWs , true ) == false ) {
991+ newWs += AND ;
992+ }
993+
994+ if ("^" .equals (j .getJoinType ())) { // (A & ! B) | (B & ! A)
995+ newWs += " ( ( " + ws + ( StringUtil .isEmpty (ws , true ) ? "" : AND + NOT ) + " ( " + js + " ) ) "
996+ + OR
997+ + " ( " + js + AND + NOT + " ( " + ws + " ) ) ) " ;
998+
999+ newPvl .addAll (pvl );
1000+ newPvl .addAll (jc .getPreparedValueList ());
1001+ newPvl .addAll (jc .getPreparedValueList ());
1002+ newPvl .addAll (pvl );
1003+ }
1004+ else {
1005+ logic = Logic .getType (j .getJoinType ());
1006+
1007+ newWs += " ( "
1008+ + getCondition (
1009+ Logic .isNot (logic ),
1010+ ws
1011+ + ( StringUtil .isEmpty (ws , true ) ? "" : (Logic .isAnd (logic ) ? AND : OR ) )
1012+ + " ( " + js + " ) "
1013+ )
1014+ + " ) " ;
1015+
1016+ newPvl .addAll (pvl );
1017+ newPvl .addAll (jc .getPreparedValueList ());
1018+ }
9911019
992- preparedValueList .addAll (jc .getPreparedValueList ());
9931020 break ;
9941021 //可能 LEFT JOIN 和 INNER JOIN 同时存在 default:
9951022 // throw new UnsupportedOperationException("");
9961023 }
9971024 }
1025+
1026+ whereString = newWs ;
1027+ preparedValueList = newPvl ;
9981028 }
9991029
10001030 String s = whereString .isEmpty () ? "" : (hasPrefix ? " WHERE " : "" ) + whereString ;
@@ -1581,8 +1611,10 @@ public String getJoinString() throws Exception {
15811611 case "|" : //不支持 <>, [] ,避免太多符号
15821612 case "&" :
15831613 case "!" :
1584- sql = " INNER JOIN " + jc .getTablePath () + " ON " + jc .getTable () + "." + j .getKey () + " = "
1585- + j .getTargetName () + "." + j .getTargetKey ();
1614+ case "^" :
1615+ case "*" :
1616+ sql = ("*" .equals (j .getJoinType ()) ? " CROSS JOIN " : " INNER JOIN " ) + jc .getTablePath ()
1617+ + " ON " + jc .getTable () + "." + j .getKey () + " = " + j .getTargetName () + "." + j .getTargetKey ();
15861618 break ;
15871619 case "<" :
15881620 case ">" :
@@ -1595,7 +1627,7 @@ public String getJoinString() throws Exception {
15951627 preparedValueList .addAll (jc .getPreparedValueList ());
15961628 break ;
15971629 default :
1598- throw new UnsupportedOperationException ("服务器内部错误:不支持JOIN类型 " + type + " !" );
1630+ throw new UnsupportedOperationException ("服务器内部错误:不支持JOIN类型 " + j . getJoinType () + " !" );
15991631 }
16001632
16011633 joinOns += " \n " + sql ;
@@ -1882,11 +1914,11 @@ LEFT JOIN ( SELECT count(*) AS count FROM sys.Comment ) AS Comment ON Comment.m
18821914 if (RequestMethod .isHeadMethod (method , true )) {
18831915 joinConfig .setMethod (GET ); //子查询不能为 SELECT count(*) ,而应该是 SELECT momentId
18841916 joinConfig .setColumn (j .getKey ()); //优化性能,不取非必要的字段
1885-
1917+
18861918 cacheConfig .setMethod (GET ); //子查询不能为 SELECT count(*) ,而应该是 SELECT momentId
18871919 cacheConfig .setColumn (j .getKey ()); //优化性能,不取非必要的字段
18881920 }
1889-
1921+
18901922 j .setJoinConfig (joinConfig );
18911923 j .setCacheConfig (cacheConfig );
18921924 }
0 commit comments