Skip to content

Commit 3b153f8

Browse files
authored
扩展PUT combine,同一个key在筛选/数据体中可同时存在,两者非互斥逻辑
不限制combine内的key只能作为条件,可使用table:{"a":"1","@combine":"a:a=3331"}的方式对a=3331的数据修改为a=1。同时兼容旧的combine格式 2种方式 1.(原有的方式)根据条件combine拼接数据体生成筛选条件,修数据:update Table set b='2' where a='2' {"Table":{"a":"2","b":"2","@combine":"a"}} 2.(新增)根据条件combine+数据生成筛选条件,修数据:update Table set a='2',b='2' where a='111' {"Table":{"a":"2","b":"2","@combine":"a:a=111"}}
1 parent ac18667 commit 3b153f8

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java

+30-7
Original file line numberDiff line numberDiff line change
@@ -3012,9 +3012,20 @@ protected String parseCombineExpression(RequestMethod method, String quote, Stri
30123012
}
30133013

30143014
String column = key;
3015-
int keyIndex = column.indexOf(":");
3016-
column = keyIndex > 0 ? column.substring(0, keyIndex) : column;
3017-
Object value = conditionMap.get(column);
3015+
int keyIndex = column.indexOf(":");
3016+
Object value = null;
3017+
//combine增加数据筛选,兼容combine与data中存在同字段,可用combine筛选后再通过data覆盖字段数据
3018+
if (keyIndex > -1) {
3019+
String valueKey = key.substring(keyIndex);
3020+
if (valueKey != null && valueKey.indexOf("=") > -1) {
3021+
int valueKeyIndex = valueKey.indexOf("=");
3022+
value = valueKey.substring(valueKeyIndex + 1);
3023+
}
3024+
}
3025+
column = keyIndex > 0 ? column.substring(0, keyIndex) : column;
3026+
if (value == null) {
3027+
value = conditionMap.get(column);
3028+
}
30183029
String wi = "";
30193030
if (value == null && conditionMap.containsKey(column) == false) { // 兼容@null
30203031
isNot = false; // 以占位表达式为准
@@ -5471,16 +5482,28 @@ else if (w.startsWith("!")) {
54715482
}
54725483

54735484
// 兼容 PUT @combine
5474-
// 解决AccessVerifier新增userId没有作为条件,而是作为内容,导致PUT,DELETE出错
5475-
if ((isWhere || (StringUtil.isName(key.replaceFirst("[+-]$", "")) == false))
5476-
|| (isWhere == false && StringUtil.isNotEmpty(combineExpr, true) && isKeyInCombineExpr(combineExpr, key))) {
5485+
// 解决AccessVerifier新增userId没有作为条件,而是作为内容,导致PUT,DELETE出错
5486+
//if ((isWhere || (StringUtil.isName(key.replaceFirst("[+-]$", "")) == false)) || (isWhere == false && StringUtil.isNotEmpty(combineExpr, true) && isKeyInCombineExpr(combineExpr, key))) {
5487+
//tableWhere.put(key, value);
5488+
//if (whereList.contains(key) == false) {
5489+
//andList.add(key);
5490+
//}
5491+
//} else if (whereList.contains(key)) {
5492+
// tableWhere.put(key, value);
5493+
//} else {
5494+
// tableContent.put(key, value); // 一样 instanceof JSONArray ? JSON.toJSONString(value) : value);
5495+
//}
5496+
//不限制combine内的key只能作为条件,可使用table:{"a":"1","@combine":"a:a=3331"}的方式对a=3331的数据修改为a=1。同时兼容旧的combine格式
5497+
if ((isWhere || (StringUtil.isName(key.replaceFirst("[+-]$", "")) == false)) || (isWhere == false && StringUtil.isNotEmpty(combineExpr, true)) && isKeyInCombineExpr(combineExpr, key)) {
54775498
tableWhere.put(key, value);
54785499
if (whereList.contains(key) == false) {
54795500
andList.add(key);
54805501
}
54815502
} else if (whereList.contains(key)) {
54825503
tableWhere.put(key, value);
5483-
} else {
5504+
}
5505+
//当combine只有单个key没有数据时,将数据内容转成条件。当combine有key=value时,对数据内容进行修改
5506+
if (!key.equals(combineExpr)) {
54845507
tableContent.put(key, value); // 一样 instanceof JSONArray ? JSON.toJSONString(value) : value);
54855508
}
54865509
}

0 commit comments

Comments
 (0)