Skip to content

Commit

Permalink
Merge pull request #119 from zhoulingfengofcd/zhoulingfengofcd-patch-1
Browse files Browse the repository at this point in the history
Update AbstractObjectParser.java
  • Loading branch information
TommyLemon committed Feb 27, 2020
2 parents 1317a47 + 692c9fc commit 1d2d25f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 6 deletions.
36 changes: 32 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
.DS_Store
.idea
.gradle
yarn.lock
*.project

HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**
!**/src/test/**

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

yarn.lock
*.classpath
*.project
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/

### VS Code ###
.vscode/
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static zuo.biao.apijson.JSONObject.KEY_COMBINE;
import static zuo.biao.apijson.JSONObject.KEY_DROP;
import static zuo.biao.apijson.JSONObject.KEY_TRY;
import static zuo.biao.apijson.RequestMethod.POST;
import static zuo.biao.apijson.RequestMethod.PUT;
import static zuo.biao.apijson.server.SQLConfig.TYPE_ITEM;

Expand Down Expand Up @@ -240,8 +241,33 @@ public AbstractObjectParser parse() throws Exception {
response.put(key, onChildParse(index, key, (JSONObject)value));
index ++;
}
}
else if (method == PUT && value instanceof JSONArray
} else if (value instanceof JSONArray && method == POST &&
key.startsWith("@") == false && key.endsWith("@") == false) {//JSONArray,批量新增,往下一级提取
JSONArray valueArray = (JSONArray)value;

for (int i = 0; i < valueArray.size(); i++) {
if (childMap != null) {//添加到childMap,最后再解析
childMap.put(key, valueArray.getJSONObject(i));
}
else {//直接解析并替换原来的,[]:{} 内必须直接解析,否则会因为丢掉count等属性,并且total@:"/[]/total"必须在[]:{} 后!
JSONObject result = (JSONObject)onChildParse(index, key, valueArray.getJSONObject(i));
//合并结果
JSONObject before = (JSONObject)response.get(key);
if(result.get("code").equals(200)){
if(before!=null){
before.put("count",before.getInteger("count")+result.getInteger("count"));
response.put(key, before);
}else{
response.put(key, result);
}
} else {
//只要有一条失败,则抛出异常,全部失败
throw new RuntimeException(key + "," + valueArray.getJSONObject(i) +",新增失败!");
}
}
}
index ++;
} else if (method == PUT && value instanceof JSONArray
&& (whereList == null || whereList.contains(key) == false)) {//PUT JSONArray
onPUTArrayParse(key, (JSONArray) value);
}
Expand Down

0 comments on commit 1d2d25f

Please sign in to comment.