GeezerVison is showing github.com — apijson json服务编排 · Issue #482 · APIJSON/APIJSON
DescriptionDescription
@TommyLemon
功能描述:
一个服务编排的伪码流程设计
将伪码转换为 apijson json、前置、后置函数、javascript、redis、elasticSearch等
并且能够mork每一步,执行中间流程,还能查询每个阶段执行的sql语句,及结果.
json格式:
{
"@transaction": true,
"id@-()": "getCurrentUserId()", // 前置函数
"@post": [
"xxx"
],
"xxx": {
"@method": "xxx",
"@version": "", // 版本,控制校验
"@datasource": "" // 数据源相关配置
// 分表规则等,后面再说
}
"@explain": true
}
1、独立定义一个url method, 通过解析不同method执行不同流程
和已有method区分开,避免歧义
2、最外层新增传参 "transaction": true 来指定开启事务
3、控制每条语句的数据源
4、完善 “@Explain"
如果没有执行计划,则返回sql语句. 能够在 reponse返回值中, 看到json中执行的每条sql,方便排错
5、@Version支持
定义不同场景的 新增、修改、删除等执行规则. 请通过version版本区分
6、前置函数
- 要能拿到其他数据源
- 能拿到json执行过程中的数据
- 拿到当前数据源(和外部json一个事物执行)
- 从数据库/或其他数据源 查询获取对照关系
组装数据, 调用对应数据源的api方法执行即可
- 前置函数,能调用其他函数
把一些计算, 执行,计算 等 放到一个函数进行整合
还没细化
7、支持mork
通过伪码,分解为不同 阶段 的json语句执行
测试点:
1、测试 一个json多条语句,后置函数啥时候执行
2、操作其他数据源, 事物是json执行完才会提交, 需要保证一致性
3、redis、elasticSearch、javascript、lua等功能测试 ActivitycloudAndMonkey commented on Nov 26, 2022 ContributorAuthor More actions @TommyLemon
1、独立定义一个url method, 通过解析不同method执行不同流程
和已有method区分开,避免歧义
对,这样更好,enum RequestMethod.java 新增 CRUD 这个枚举值,对应 URL 为 /crud,对于前端没传参 transaction: true 时自动放入 transaction: true。
场景:
method= crud
1、传递 "@transaction": true
2、不传
这里实现方案要考虑几个点:
1、在校验模块, 遍历json每个对象、数组的 method, 就知道是否需要开启事物
但是 为了后面 函数调用支持事物, 这个方式有局限性
2、对应 URL 为 /crud,对于前端没传参 transaction: true 时自动放入 transaction: true
3、将不同method功能区分开
现在json执行是通用解析,需不需要控制, 只能调用crud 方法,才能支持增删改查等操作. 其他method, 除了函数、子查询,就只能和 url method保持一致的操作 TommyLemon commented on Nov 26, 2022
1、在校验模块, 遍历json每个对象、数组的 method, 就知道是否需要开启事物
扫描所有字段来识别是否有 transaction 代价太大了。
没有 transaction: true,那就不做全局事务处理,局部有 增删改 就局部处理事务。
如果业务需求必须整体有事务,那就通过 Request 表配置规则来强制 PUT transaction: true。
非 CRUD 方法,都只能和 URL method 完全一致,避免意料之外的安全风险。
如果传了 method 相关键值对("@delete":"Comment" 等),直接抛异常 "不支持在 GET 中 DELETE !"
话说现有使用方式 "@delete":["Comment"] 麻烦了点,前端传参应该尽可能简化,除非有兼容等严重问题或实现代价太大,APIJSON 所有 key 不支持逗号 , 分号 ; 斜杠 / 反斜杠 \,所以 "@delete":"Comment[],Moment" 并不会有兼容问题。
可以用 StringUtil.split 分割逗号,内部处理了整体空值、局部空值等。 cloudAndMonkey commented on Nov 26, 2022 ContributorAuthor More actions
@TommyLemon
1、扫描所有字段来识别是否有 transaction 代价太大了。
要考虑数组的情况, 不可行. 我当时就是不想全部解析, 只通过key及@变量
2、事物这块
那就通过 Request 表配置规则来强制 PUT transaction: true。
不需要, 每条执行语句都知道它的method
我先测一下
3、 "@delete":["Comment"]
我来改一下, 当时采用数组, 是想到后台直接jsonArray转换方便
4、非 CRUD 方法,都只能和 URL method 完全一致,避免意料之外的安全风险。
如果传了 method 相关键值对("@delete":"Comment" 等),直接抛异常 "不支持在 GET 中 DELETE !"
TommyLemon commented on Nov 26, 2022 cloudAndMonkey commented on Nov 27, 2022 ContributorAuthor More actions
1、在校验模块, 遍历json每个对象、数组的 method, 就知道是否需要开启事物
扫描所有字段来识别是否有 transaction 代价太大了。 没有 transaction: true,那就不做全局事务处理,局部有 增删改 就局部处理事务。 如果业务需求必须整体有事务,那就通过 Request 表配置规则来强制 PUT transaction: true。
非 CRUD 方法,都只能和 URL method 完全一致,避免意料之外的安全风险。 如果传了 method 相关键值对("@delete":"Comment" 等),直接抛异常 "不支持在 GET 中 DELETE !"
话说现有使用方式 "@delete":["Comment"] 麻烦了点,前端传参应该尽可能简化,除非有兼容等严重问题或实现代价太大,APIJSON 所有 key 不支持逗号 , 分号 ; 斜杠 / 反斜杠 \,所以 "@delete":"Comment[],Moment" 并不会有兼容问题。 可以用 StringUtil.split 分割逗号,内部处理了整体空值、局部空值等。
@TommyLemon
1、全局事物这块
没有 transaction: true,那就不做全局事务处理,局部有 增删改 就局部处理事务。
不好意思, 这里我没有理解你的意思.
说说我的理解哈
json配置 datasource, 是知道哪些操作共享一个 datasource.
同一个数据源, 多个 PUT、DELETE、POST 使用同一个Connection.
也就是说, 只要一个 connection, 存在 PUT、DELETE、POST,就开启全局事物?
不好意思, 还是你更优的解决方案,我没有get到?


commit 提交事物:
是在多个 操作( PUT、DELETE、POST ) 执行完, 才调用:
 TommyLemon commented on Nov 27, 2022 如果不是全局事务,那就只有当执行 增/删/改 时开启,执行完马上 commit,碰到下一个 增/删/改 再开启和 commit。
如果是全局事务,则一开始就开启,执行完整个请求再 commit。 cloudAndMonkey commented on Nov 28, 2022 ContributorAuthor More actions @TommyLemon
这几点我已经搞好了
1、url method crud支持
解析顺序
- 对象内 "@method"
- "@post","@put","@delete"
- 对于没有显式声明操作方法的,直接用 URL(/get, /post 等) 对应的默认操作方法
第三点不适用了,url method =crud,必须显示定义操作方法
throw new IllegalArgumentException("url crud方法,必须定义 " + key + " 对应的method, 例如: @post: "xxx,xxx[]" 或者 对象内 @method="POST" !");

2、非 CRUD 方法,都只能和 URL method 完全一致,避免意料之外的安全风险。
如果传了 method 相关键值对("@delete":"Comment" 等),直接抛异常 "不支持在 GET 中 DELETE !"
http://xxx/put
{
"@post": "User:aa",
"User:aa":{
"username":"test-3",
"password": "233223",
"state": 1
},
"tag": "User",
"@explain": true
}

3、非crud
支持函数、sql@ 子查询调用.
4、修改 "@get": 数组 改为 字符串
{
"@post": "User:aa,User_address[]",
"User:aa":{
"username":"test1",
"password": "123456",
"state": 1
},
"User_address[]": [
{
"user_id@": "User:aa/id",
"addr": "ddd",
"count": 1
},
{
"user_id@": "User:aa/id",
"addr": "ddd1",
"count": 2
}
],
"@delete": "User:delUser,User_address:delUserAddress",
"User:delUser":{
"id{}": ["b6d7c307-cb82-4780-8361-2509973d88de", "c63d7bd8-cbb8-41f8-9ee0-713f0d30474b","cadeca84-2901-4850-aa36-6672d9d34299"]
},
"User_address:delUserAddress": {
"id{}": ["887edfe9-0206-415d-96de-325d97e248cb", "24eb9e05-d3ef-4661-8d22-c063643f61cd"]
},
"@explain": true
}

cloudAndMonkey commented on Nov 28, 2022 ContributorAuthor More actions @TommyLemon
还有一个功能需要支持, put, 能够按照 name="xxx" 来修改.例如 update xxx set xxx ="" wehre name = "xxx"
目前非id put修改,只能通过ref引用做为条件进行修改,例如:
// 非id修改
{
"sql@": {
"@method": "GET",
"with": true,
"from": "User",
"User": {
"@column": "username",
"username": "非id-update-test-0"
}
},
"User": {
"@state": 1,
"password": "123456",
"username{}@": "sql"
},
"explan": true
}
WITH `sql` AS (SELECT `username` FROM `housekeeping`.`User` WHERE ( (`username` = '非id-update-test-0') ) )
UPDATE `housekeeping`.`User` SET `password` = '123456_1669605075502' WHERE ( (`username` IN ( SELECT * FROM `sql`) ) )
你看这么改行不?
对象内的临时变量 @xxx 作为条件, 例如 :
"User": {
"@state": 1,
"password": "123456"
}
update user set password = "123456" where state = 1; TommyLemon commented on Nov 28, 2022
@TommyLemon 这几点我已经搞好了 1、url method crud支持
解析顺序
- 对象内 "@method"
- "@post","@put","@delete"
- 对于没有显式声明操作方法的,直接用 URL(/get, /post 等) 对应的默认操作方法
第三点不适用了,url method =crud,必须显示定义操作方法
throw new IllegalArgumentException("url crud方法,必须定义 " + key + " 对应的method, 例如: @post: "xxx,xxx[]" 或者 对象内 @method="POST" !");

2、非 CRUD 方法,都只能和 URL method 完全一致,避免意料之外的安全风险。 如果传了 method 相关键值对("@delete":"Comment" 等),直接抛异常 "不支持在 GET 中 DELETE !" http://xxx/put { "@post": "User:aa", "User:aa":{ "username":"test-3", "password": "233223", "state": 1 }, "tag": "User", "@Explain": true } 3、非crud 支持函数、sql@ 子查询调用. 4、修改 "@get": 数组 改为 字符串 { "@post": "User:aa,User_address[]", "User:aa":{ "username":"test1", "password": "123456", "state": 1 }, "User_address[]": [ { "user_id@": "User:aa/id", "addr": "ddd", "count": 1 }, { "user_id@": "User:aa/id", "addr": "ddd1", "count": 2 } ], "@delete": "User:delUser,User_address:delUserAddress", "User:delUser":{ "id{}": ["b6d7c307-cb82-4780-8361-2509973d88de", "c63d7bd8-cbb8-41f8-9ee0-713f0d30474b","cadeca84-2901-4850-aa36-6672d9d34299"] }, "User_address:delUserAddress": { "id{}": ["887edfe9-0206-415d-96de-325d97e248cb", "24eb9e05-d3ef-4661-8d22-c063643f61cd"] }, "@Explain": true } 
CRUD 方法,没有声明就用 GET。
@method 看起来已经没有必要了,可以考虑去掉。 TommyLemon commented on Nov 28, 2022 cloudAndMonkey commented on Nov 28, 2022 ContributorAuthor More actions
WITH `sql` AS (SELECT `username` FROM `housekeeping`.`User` WHERE ( (`username` = '非id-update-test-0') ) )
@State 会被认为是自定义关键词,与现有语法冲突,不合适。 目前可以用 "@combine":"state" 指定 "state": 1 是条件。 https://github.com/Tencent/APIJSON/blob/master/Document.md#3.2 
#277 #425
嗯嗯,不好意思, 应该先查文档
测了一下,没问题, 转换为了regexp_like 正则匹配
{
"User": {
"state~": "1",
"password": "123456",
"username~": "test4",
"@combine": "state~ & username~"
},
"explan": true
}
UPDATE `housekeeping`.`User` SET `password` = '123456_1669608632896' WHERE ( regexp_like(`state`, '1', 'c') ) AND ( regexp_like(`username`, 'test4', 'c') ) cloudAndMonkey commented on Nov 28, 2022 ContributorAuthor More actions
CRUD 方法,没有声明就用 GET。 @method 看起来已经没有必要了,可以考虑去掉。
@TommyLemon
CRUD 方法,没有声明就用 GET。
会出现吞并 json执行语句, 返回200的情况. 不方便排错.
框架是"正确"执行, 但是 对于用户来说, 就是一种"错觉"
这也是我很想避免的情况
比如: http://xxx/crud
{
"User:aa":{
"username":"test1",
"password": "123456",
"state": 1
},
"User_address[]": [
{
"user_id@": "User:aa/id",
"addr": "ddd",
"count": 1
},
{
"user_id@": "User:aa/id",
"addr": "ddd1",
"count": 2
}
],
"@put": "User_address:modifUA",
"User_address:modifUA":
{
"id": "5e2d528c-106a-4f14-90b2-f27b5943e3e1",
"user_id@": "User:aa/id",
"addr": "addr-01",
"count": 1
},
"@explain": true
}

TommyLemon commented on Nov 28, 2022 cloudAndMonkey commented on Nov 28, 2022 ContributorAuthor More actions json 不用传递 @method, 代码我已经调整
我也做了head 子查询sql@的兼容,避免子查询别转化为 count执行
错误语句:
WITH `sql` AS (SELECT count(*) FROM `housekeeping`.`Sys_user_role` WHERE ( (`user_id` = '4732209c-5785-4827-b532-5092f154fd94') ) ) \nSELECT * FROM `housekeeping`.`Sys_role` WHERE ( (`id` IN ( SELECT * FROM `sql`) ) ) LIMIT 1
正确语句:
WITH `sql` AS (SELECT `role_id` FROM `housekeeping`.`Sys_user_role` WHERE ( (`user_id` = '4732209c-5785-4827-b532-5092f154fd94') ) ) \nSELECT * FROM `housekeeping`.`Sys_role` WHERE ( (`id` IN ( SELECT * FROM `sql`) ) ) LIMIT 1 TommyLemon commented on Nov 28, 2022
CRUD 方法,没有声明就用 GET。 @method 看起来已经没有必要了,可以考虑去掉。
@TommyLemon CRUD 方法,没有声明就用 GET。 会出现吞并 json执行语句, 返回200的情况. 不方便排错. 框架是"正确"执行, 但是 对于用户来说, 就是一种"错觉" 这也是我很想避免的情况 比如: http://xxx/crud
{
"User:aa":{
"username":"test1",
"password": "123456",
"state": 1
},
"User_address[]": [
{
"user_id@": "User:aa/id",
"addr": "ddd",
"count": 1
},
{
"user_id@": "User:aa/id",
"addr": "ddd1",
"count": 2
}
],
"@put": "User_address:modifUA",
"User_address:modifUA":
{
"id": "5e2d528c-106a-4f14-90b2-f27b5943e3e1",
"user_id@": "User:aa/id",
"addr": "addr-01",
"count": 1
},
"@explain": true
}

未显示声明 method,默认用 GET,至于参数被吞掉,没有实际执行,这是 bug,改掉就好了 TommyLemon commented on Jan 5, 2023 TommyLemon commented on Jan 5, 2023 cloudAndMonkey commented on Jan 5, 2023 ContributorAuthor More actions
@TommyLemon
哈哈,很早以前我加过,差点蒙圈😁
redis好像还有一个问题
更新数据库Access、Request表字段,重启没法自动更新redis。需要调用增量初始化接口 cloudAndMonkey commented on Jan 5, 2023 ContributorAuthor More actions
@cloudAndMonkey "@combine": "a" 强制指定 "a": "" 为条件, 带功能符号的就直接作为条件,可以不用 @combine #277
@TommyLemon
嗯嗯, 你以前跟我说过 ,带功能符号的就直接作为条件,可以不用 @combine
{ "User_address": { "user_id": "3123f016-a4cc-455c-aac5-264c1230dcb", "count+": 1, "@combine": "user_id" }, "tag": "User_address", "@Explain": true }
"msg": "User_address:{ @combine:'user_id' } 中字符 'user_id' 对应的条件键值对 user_id:value 不存在!"
这个和apijson解析顺序有关, 如果要实现"h@combine": "a" 强制指定 "a": "" 为条件,需要调整解析顺序,还要考虑是否有其他影响?
应该是解析到 @combine 时是从 Map<String, Object> where 中取值,但 PUT user_id 是放在 Map<String, Object> content 中, 应该要提前处理 @combine,或者 where 中取不到再从 content 中取。
有两个 getWhereString 方法都需要多传一个参数 content,然后有个再传给 parseCombineExpression https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2677-L2679 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2688-L2714 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2798 
应该只有 "@combine":"a | (b & c)" 这种逻辑表达式才会出现以上 bug,只需要改 parseCombineExpression 相关的。
因为 "@combine":"a,b,&c,!d" 这种简单组合方式已经提前处理过了:
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L4951-L4956 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5013-L5050 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5072-L5085 
解析表达式比较复杂,所以这里就没有提前处理了,还是简单的加个 content 参数再加上 if (value == null) { value = content.get(key) } 来解决 bug 更简单方便
@TommyLemon
兼容 PUT @combine
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5073

这里需要将key 和 combineExpr 表达式进行比较,或者 将combineExpr表达式进行解析获取字段名,然后进行比较?
{
"User_address": {
"user_id!": "3123f016-a4cc-455c-aac5-264c1230dcb",
"count": "10",
"count+": 1,
"@combine": "user_id! | count"
},
"tag": "User_address",
"@Explain": true
}
UPDATE housekeeping.User_address SET count = count + 1, addr = 'null_1672908535358' WHERE (deleted != '1') AND ( ( user_id != '3123f016-a4cc-455c-aac5-264c1230dcb' ) OR ( count = '10' ) ) TommyLemon commented on Jan 5, 2023
@TommyLemon 哈哈,很早以前我加过,差点蒙圈😁 redis好像还有一个问题 更新数据库Access、Request表字段,重启没法自动更新redis。需要调用增量初始化接口
可以在启动后、init 前 REDIS_TEMPLATE.discard(); 清空缓存,但更好的方式是不缓存 APIJSON 配置表,毕竟数据量非常有限,而且很少更新(尤其是相当于业务表,更新频率低很多)。
APIJSON/APIJSON-Demo@3c1a542 TommyLemon commented on Jan 5, 2023
@cloudAndMonkey "@combine": "a" 强制指定 "a": "" 为条件, 带功能符号的就直接作为条件,可以不用 @combine #277
@TommyLemon
嗯嗯, 你以前跟我说过 ,带功能符号的就直接作为条件,可以不用 @combine
{ "User_address": { "user_id": "3123f016-a4cc-455c-aac5-264c1230dcb", "count+": 1, "@combine": "user_id" }, "tag": "User_address", "@Explain": true }
"msg": "User_address:{ @combine:'user_id' } 中字符 'user_id' 对应的条件键值对 user_id:value 不存在!"
这个和apijson解析顺序有关, 如果要实现"h@combine": "a" 强制指定 "a": "" 为条件,需要调整解析顺序,还要考虑是否有其他影响?
应该是解析到 @combine 时是从 Map<String, Object> where 中取值,但 PUT user_id 是放在 Map<String, Object> content 中, 应该要提前处理 @combine,或者 where 中取不到再从 content 中取。
有两个 getWhereString 方法都需要多传一个参数 content,然后有个再传给 parseCombineExpression https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2677-L2679 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2688-L2714 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2798 
应该只有 "@combine":"a | (b & c)" 这种逻辑表达式才会出现以上 bug,只需要改 parseCombineExpression 相关的。
因为 "@combine":"a,b,&c,!d" 这种简单组合方式已经提前处理过了:
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L4951-L4956 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5013-L5050 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5072-L5085 
解析表达式比较复杂,所以这里就没有提前处理了,还是简单的加个 content 参数再加上 if (value == null) { value = content.get(key) } 来解决 bug 更简单方便
@TommyLemon 兼容 PUT @combine https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5073 
这里需要将key 和 combineExpr 表达式进行比较,或者 将combineExpr表达式进行解析获取字段名,然后进行比较? { "User_address": { "user_id!": "3123f016-a4cc-455c-aac5-264c1230dcb", "count": "10", "count+": 1, "@combine": "user_id! | count" }, "tag": "User_address", "@Explain": true } UPDATE housekeeping.User_address SET count = count + 1, addr = 'null_1672908535358' WHERE (deleted != '1') AND ( ( user_id != '3123f016-a4cc-455c-aac5-264c1230dcb' ) OR ( count = '10' ) )
直接 combineExpr.contains(key) 会有误判,例如 "admin_user_id | name".contains("user_id"),

可以按这个逻辑来判断,key 左侧、右侧可能的字符不能和它拼接成一个有效的键名
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L4992-L5002
 cloudAndMonkey commented on Jan 5, 2023 ContributorAuthor More actions
@cloudAndMonkey "@combine": "a" 强制指定 "a": "" 为条件, 带功能符号的就直接作为条件,可以不用 @combine #277
@TommyLemon
嗯嗯, 你以前跟我说过 ,带功能符号的就直接作为条件,可以不用 @combine
{ "User_address": { "user_id": "3123f016-a4cc-455c-aac5-264c1230dcb", "count+": 1, "@combine": "user_id" }, "tag": "User_address", "@Explain": true }
"msg": "User_address:{ @combine:'user_id' } 中字符 'user_id' 对应的条件键值对 user_id:value 不存在!"
这个和apijson解析顺序有关, 如果要实现"h@combine": "a" 强制指定 "a": "" 为条件,需要调整解析顺序,还要考虑是否有其他影响?
应该是解析到 @combine 时是从 Map<String, Object> where 中取值,但 PUT user_id 是放在 Map<String, Object> content 中, 应该要提前处理 @combine,或者 where 中取不到再从 content 中取。
有两个 getWhereString 方法都需要多传一个参数 content,然后有个再传给 parseCombineExpression https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2677-L2679 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2688-L2714 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L2798 
应该只有 "@combine":"a | (b & c)" 这种逻辑表达式才会出现以上 bug,只需要改 parseCombineExpression 相关的。
因为 "@combine":"a,b,&c,!d" 这种简单组合方式已经提前处理过了:
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L4951-L4956 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5013-L5050 
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5072-L5085 
解析表达式比较复杂,所以这里就没有提前处理了,还是简单的加个 content 参数再加上 if (value == null) { value = content.get(key) } 来解决 bug 更简单方便
@TommyLemon 兼容 PUT @combine https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L5073 
这里需要将key 和 combineExpr 表达式进行比较,或者 将combineExpr表达式进行解析获取字段名,然后进行比较? { "User_address": { "user_id!": "3123f016-a4cc-455c-aac5-264c1230dcb", "count": "10", "count+": 1, "@combine": "user_id! | count" }, "tag": "User_address", "@Explain": true } UPDATE housekeeping.User_address SET count = count + 1, addr = 'null_1672908535358' WHERE (deleted != '1') AND ( ( user_id != '3123f016-a4cc-455c-aac5-264c1230dcb' ) OR ( count = '10' ) )
直接 combineExpr.contains(key) 会有误判,例如 "admin_user_id | name".contains("user_id"), 
可以按这个逻辑来判断,key 左侧、右侧可能的字符不能和它拼接成一个有效的键名 https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L4992-L5002 
收到,我改一下 cloudAndMonkey commented on Jan 5, 2023 ContributorAuthor More actions @TommyLemon
private static boolean keyInCombineExpr(String combineExpr, String key) {
// while 解决 key = "count" ,combineExpr = "ab & (user_id! | count! | count )" 的场景
while (combineExpr.isEmpty() == false) {
int index = combineExpr.indexOf(key);
if (index < 0) {
return false;
}
char left = index <= 0 ? ' ' : combineExpr.charAt(index - 1);
char right = index >= combineExpr.length() - key.length() ? ' ' : combineExpr.charAt(index + key.length());
if ((left == ' ' || left == '(' || left == '&' || left == '|' || left == '!') && (right == ' ' || right == ')')) {
return true;
}
int newIndex = index + key.length() + 1;
if (combineExpr.length() <= newIndex) {
break;
}
combineExpr = combineExpr.substring(newIndex);
}
return false;
}
我把这个地方改一下,调用一个方法哈
https://github.com/Tencent/APIJSON/blob/master/APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java#L4992-L5002 cloudAndMonkey commented on Jan 5, 2023 ContributorAuthor More actions 搞完了, 累死了
明天来提交代码
redis(api太多了)、redisql (调整了,还没复测),测完我提交 Reacted by TommyLemon Reacted by TommyLemon Reacted by TommyLemon cloudAndMonkey commented on Jan 6, 2023 ContributorAuthor More actions
赞,这样的话可以把 RequestMethod method, String tag, int version, @NotNull JSONObject request, HttpSession session 等参数作为全局参数传进去供脚本使用
@TommyLemon
脚本支持传递全局对象参数, 也可以自定义java类,供脚本调用, 这块你改一下哈
TommyLemon commented on Jan 6, 2023 cloudAndMonkey commented on Jan 6, 2023 ContributorAuthor More actions
可以的
@TommyLemon
纠结了一下,哈哈
等我忙完,我来加吧,最近整理了资料,我搞也要不了多久
把自定义类传参也加上去,抽象一个方法,业务侧通过脚本名去控制
TommyLemon commented on Jan 6, 2023
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|