Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复512 多表 gets bug、别名从代码解析改为数据库配置、支持sql@ update/delete #551

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 9 additions & 55 deletions APIJSONORM/src/main/java/apijson/orm/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2230,13 +2230,15 @@ protected JSONObject batchVerify(RequestMethod method, String tag, int version,
}

String _tag = buildTag(request, key, method, tag);
JSONObject requestItem = new JSONObject();
// key 处理别名
String _key = keyDelAlias(key);
requestItem.put(_key, obj);
JSONObject object = getRequestStructure(_method, _tag, version);
JSONObject ret = objectVerify(_method, _tag, version, name, requestItem, maxUpdateCount, creator, object);
jsonObject.put(key, ret.get(_key));
if(method == RequestMethod.CRUD && StringUtil.isEmpty(tag, true)) {
JSONObject requestItem = new JSONObject();
requestItem.put(key, obj);
JSONObject ret = objectVerify(_method, _tag, version, name, requestItem, maxUpdateCount, creator, object);
jsonObject.put(key, ret.get(key));
} else {
return objectVerify(_method, _tag, version, name, request, maxUpdateCount, creator, object);
}
} else {
jsonObject.put(key, obj);
}
Expand Down Expand Up @@ -2276,64 +2278,16 @@ protected void setRequestAttribute(String key, boolean isArray, String attrKey,
}
}

protected String keyDelAlias(String key) {
int keyIndex = key.indexOf(":");
if (keyIndex != -1) {
String _key = key.substring(0, keyIndex);
if (apijson.JSONObject.isTableArray(key)) {
_key += apijson.JSONObject.KEY_ARRAY;
}
return _key;
}
return key;
}

protected String buildTag(JSONObject request, String key, RequestMethod method, String tag) {
Object val = request.get(key);

if (method == RequestMethod.CRUD) {
Map<String, Object> attrMap = keyObjectAttributesMap.get(key);
Object _tag = attrMap == null ? null : attrMap.get(JSONRequest.KEY_TAG);

if (_tag != null) {
if (val instanceof JSONArray) {
return _tag.toString();
}

tag = _tag.toString();
} else {
// key 作为默认的 tag
if (StringUtil.isEmpty(tag)) {
if (val instanceof JSONArray) {
return keyDelAlias(key);
}

tag = key;
} else {
if (val instanceof JSONArray) {
return tag;
}
}
}
return _tag != null ? _tag.toString() : StringUtil.isEmpty(tag) ? key : tag;
} else {
if (StringUtil.isEmpty(tag, true)) {
throw new IllegalArgumentException("请在最外层传 tag !一般是 Table 名,例如 \"tag\": \"User\" ");
}
if (val instanceof JSONArray) {
return tag;
}
}

// 通用判断
// 对象, 需处理别名
if (val instanceof JSONObject && StringUtil.isNotEmpty(tag)) {
int keyIndex = tag.indexOf(":");
if (keyIndex != -1) {
return tag.substring(0, keyIndex);
}
return tag;
}

return tag;
}

Expand Down
2 changes: 1 addition & 1 deletion APIJSONORM/src/main/java/apijson/orm/AbstractVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ public static <T extends Object> JSONObject parse(@NotNull final RequestMethod m
}

// 不在target内的 key:{}
if (rk.startsWith("@") == false && objKeySet.contains(rk) == false) {
if (rk.startsWith("@") == false && rk.endsWith("@") == false && objKeySet.contains(rk) == false) {
if (rv instanceof JSONObject) {
throw new UnsupportedOperationException(method + " 请求,"
+ name + " 里面不允许传 " + rk + ":{} !");
Expand Down