Skip to content

Commit 3405b13

Browse files
committed
Server:新增 @ combine:"key0,&key1,|key2,!key3,..." 支持与或非条件组合;删除 @ condition;解决put/balance接口在未登录时返回错误不是未登录;
1 parent b541d5c commit 3405b13

5 files changed

Lines changed: 195 additions & 67 deletions

File tree

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/JSONObject.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ public JSONObject setUserIdIn(List<Object> list) {
122122

123123
//@key关键字都放这个类 <<<<<<<<<<<<<<<<<<<<<<
124124
public static final String KEY_ROLE = "@role"; //角色,拥有对某些数据的某些操作的权限
125-
public static final String KEY_CONDITION = "@condition"; //条件 TODO 用 @where& @where| @where! 替代?
126125
public static final String KEY_TRY = "@try"; //尝试,忽略异常
127126
public static final String KEY_DROP = "@drop"; //丢弃,不返回
128127
public static final String KEY_CORRECT = "@correct"; //字段校正
129128

130129
public static final String KEY_SCHEMA = "@schema"; //数据库,Table在非默认schema内时需要声明
131130
public static final String KEY_ABOUT = "@about"; //关于,返回数据库表的信息,包括表说明和字段说明
132131
public static final String KEY_COLUMN = "@column"; //查询的Table字段或SQL函数
132+
public static final String KEY_COMBINE = "@combine"; //条件组合,每个条件key前面可以放&,|,!逻辑关系 "id!{},&sex,!name&$"
133133
public static final String KEY_GROUP = "@group"; //分组方式
134134
public static final String KEY_HAVING = "@having"; //聚合函数条件,一般和@group一起用
135135
public static final String KEY_ORDER = "@order"; //排序方式
@@ -138,10 +138,10 @@ public JSONObject setUserIdIn(List<Object> list) {
138138
static {
139139
TABLE_KEY_LIST = new ArrayList<String>();
140140
TABLE_KEY_LIST.add(KEY_ROLE);
141-
TABLE_KEY_LIST.add(KEY_CONDITION);
142141
TABLE_KEY_LIST.add(KEY_SCHEMA);
143142
TABLE_KEY_LIST.add(KEY_ABOUT);
144143
TABLE_KEY_LIST.add(KEY_COLUMN);
144+
TABLE_KEY_LIST.add(KEY_COMBINE);
145145
TABLE_KEY_LIST.add(KEY_GROUP);
146146
TABLE_KEY_LIST.add(KEY_HAVING);
147147
TABLE_KEY_LIST.add(KEY_ORDER);
@@ -215,6 +215,21 @@ public JSONObject setColumn(String keys) {
215215
return puts(KEY_COLUMN, keys);
216216
}
217217

218+
/**set combination of keys for conditions
219+
* @param keys key0, key1, key2 ...
220+
* @return {@link #setColumn(String)}
221+
*/
222+
public JSONObject setCombine(String... keys) {
223+
return setCombine(StringUtil.getString(keys, true));
224+
}
225+
/**set combination of keys for conditions
226+
* @param keys "key0,key1,key2..."
227+
* @return
228+
*/
229+
public JSONObject setCombine(String keys) {
230+
return puts(KEY_COMBINE, keys);
231+
}
232+
218233
/**set keys for group by
219234
* @param keys key0, key1, key2 ...
220235
* @return {@link #setGroup(String)}

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractObjectParser.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
package zuo.biao.apijson.server;
1616

17-
import static zuo.biao.apijson.JSONObject.KEY_CONDITION;
17+
import static zuo.biao.apijson.JSONObject.KEY_COMBINE;
1818
import static zuo.biao.apijson.JSONObject.KEY_CORRECT;
1919
import static zuo.biao.apijson.JSONObject.KEY_DROP;
2020
import static zuo.biao.apijson.JSONObject.KEY_TRY;
@@ -225,13 +225,22 @@ public AbstractObjectParser parse() throws Exception {
225225

226226

227227
//条件<<<<<<<<<<<<<<<<<<<
228-
List<String> conditionList = null;
228+
List<String> whereList = null;
229229
if (method == PUT) { //这里只有PUTArray需要处理 || method == DELETE) {
230-
String[] conditions = StringUtil.split(request.getString(KEY_CONDITION));
230+
String[] combine = StringUtil.split(request.getString(KEY_COMBINE));
231+
if (combine != null) {
232+
String w;
233+
for (int i = 0; i < combine.length; i++) { //去除 &,|,! 前缀
234+
w = combine[i];
235+
if (w != null && (w.startsWith("&") || w.startsWith("|") || w.startsWith("!"))) {
236+
combine[i] = w.substring(1);
237+
}
238+
}
239+
}
231240
//Arrays.asList()返回值不支持add方法!
232-
conditionList = new ArrayList<String>(Arrays.asList(conditions != null ? conditions : new String[]{}));
233-
conditionList.add(zuo.biao.apijson.JSONRequest.KEY_ID);
234-
conditionList.add(zuo.biao.apijson.JSONRequest.KEY_ID_IN);
241+
whereList = new ArrayList<String>(Arrays.asList(combine != null ? combine : new String[]{}));
242+
whereList.add(zuo.biao.apijson.JSONRequest.KEY_ID);
243+
whereList.add(zuo.biao.apijson.JSONRequest.KEY_ID_IN);
235244
}
236245
//条件>>>>>>>>>>>>>>>>>>>
237246

@@ -259,7 +268,7 @@ public AbstractObjectParser parse() throws Exception {
259268
}
260269
}
261270
else if (method == PUT && value instanceof JSONArray
262-
&& (conditionList == null || conditionList.contains(key) == false)) {//PUT JSONArray
271+
&& (whereList == null || whereList.contains(key) == false)) {//PUT JSONArray
263272
onPUTArrayParse(key, (JSONArray) value);
264273
}
265274
else {//JSONArray或其它Object,直接填充
@@ -369,13 +378,13 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
369378

370379
JSON child;
371380
boolean isEmpty;
372-
381+
373382
if (zuo.biao.apijson.JSONObject.isArrayKey(key)) {//APIJSON Array
374383
if (isMain) {
375384
throw new IllegalArgumentException(parentPath + "/" + key + ":{} 不合法!"
376385
+ "数组 []:{} 中第一个 key:{} 必须是主表 TableKey:{} !不能为 arrayKey[]:{} !");
377386
}
378-
387+
379388
child = parser.onArrayParse(value, path, key);
380389
isEmpty = child == null || ((JSONArray) child).isEmpty();
381390
}
@@ -384,9 +393,9 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
384393
throw new IllegalArgumentException(parentPath + "/" + key + ":{} 不合法!"
385394
+ "数组 []:{} 中每个 key:{} 都必须是表 TableKey:{} 或 数组 arrayKey[]:{} !");
386395
}
387-
396+
388397
child = parser.onObjectParse(value, path, key, isMain ? arrayConfig.setType(SQLConfig.TYPE_ITEM_CHILD_0) : null);
389-
398+
390399
isEmpty = child == null || ((JSONObject) child).isEmpty();
391400
if (isFirst && isEmpty) {
392401
invalidate();
@@ -578,7 +587,7 @@ public JSONObject response() throws Exception {
578587
public Object onFunctionParse(JSONObject json, String function) throws Exception {
579588
return null;
580589
}
581-
590+
582591
@Override
583592
public Object onReferenceParse(@NotNull String path) {
584593
return parser.getValueByPath(path);

0 commit comments

Comments
 (0)