重构: base 包资源核心类型迁移到 req/resx,新增 res_watcher/res_api_param

base/resource.go、resource_hooks.go、resource_test.go、query_field.go 删除,ResField 等具体实现搬到 req/resx(见 res_field.go 里的类型别名)。res_listener.go 替换成 res_watcher.go,对应资源变更监听概念改名。新增 res_api_param.go 及配套测试(ResApi 参数建模,给 MCP tool 的 JSON Schema 生成用)。
This commit is contained in:
2026-07-22 09:13:05 +08:00
parent 53169264da
commit 9446571363
20 changed files with 2882 additions and 1427 deletions
+758
View File
@@ -0,0 +1,758 @@
[
{
"id": 271,
"pid": 0,
"code": "fields",
"name": "查询字段",
"category": "param",
"type": "array",
"desc": "查询字段,不传则返回所有字段",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 282,
"pid": 0,
"code": "groupBy",
"name": "分组规则",
"category": "param",
"type": "array",
"desc": "GROUP BY 字段列表,配合 fields 中的聚合字段使用",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 287,
"pid": 0,
"code": "orderBy",
"name": "排序规则",
"category": "param",
"type": "array",
"desc": "排序规则列表,多项按顺序依次应用",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 299,
"pid": 0,
"code": "relations",
"name": "资源关联",
"category": "param",
"type": "array",
"desc": "关联配置列表,支持 JOINinner / left / right)将关联字段合并到主查询,或子查询(hasOne / hasMany)将关联数据聚合为独立 JSON 字段",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 258,
"pid": 0,
"code": "conditions",
"name": "树形查询条件",
"category": "param",
"type": "json",
"desc": "WHERE 条件树。\rexprs 每项生成一段比较:[{columnSqlFunc}(]{columnResource}.{column}[)] {operator} {value},同层多项以 type(and/or) 连接;\rchildren 为同结构子节点,递归嵌套实现复杂过滤。",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 297,
"pid": 0,
"code": "limit",
"name": "每页条数",
"category": "param",
"type": "integer",
"desc": "返回的最大记录数",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": "30"
},
{
"id": 298,
"pid": 0,
"code": "offset",
"name": "偏移量",
"category": "param",
"type": "integer",
"desc": "跳过的记录数",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": "0"
},
{
"id": 259,
"pid": 258,
"code": "type",
"name": "逻辑连接符",
"category": "param",
"type": "string",
"desc": "当前节点的逻辑运算符,将 exprs 各项与 children 各组以 AND 或 OR 连接",
"isRequired": true,
"constraints": {
"enum": [
"and",
"or"
]
},
"rank": 0,
"ref_id": 0,
"df_val": "and"
},
{
"id": 261,
"pid": 258,
"code": "children",
"name": "子条件",
"category": "param",
"type": "array",
"desc": "子条件节点,递归结构",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 260,
"pid": 258,
"code": "exprs",
"name": "条件表达式列表",
"category": "param",
"type": "array",
"desc": "当前层的叶子比较列表,每项生成一个 column {operator} value 片段,同层多项以 type 连接",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 262,
"pid": 260,
"code": "items",
"name": "_items",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 312,
"pid": 261,
"code": "items",
"name": "_items",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 258,
"df_val": ""
},
{
"id": 263,
"pid": 262,
"code": "column",
"name": "字段编码",
"category": "param",
"type": "string",
"desc": "",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 264,
"pid": 262,
"code": "columnResource",
"name": "所属资源",
"category": "param",
"type": "string",
"desc": "字段所属资源标识,取值为顶层 resource 或 relations[].code",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 268,
"pid": 262,
"code": "columnSqlFunc",
"name": "列SQL函数",
"category": "param",
"type": "string",
"desc": "对列应用 SQL 函数后再参与比较,拼接为 {func}({columnResource}.{column}) {operator} {value}。\r\n支持 SQL-92 / SQL:1999 / SQL:2003 标准函数及数据库方言函数,如 DATE、UPPER、ROUND。\r\n需要第二参数的函数(如 ROUND、CAST)配合 columnSqlFuncParam 使用。",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 269,
"pid": 262,
"code": "columnSqlFuncParam",
"name": "列SQL函数参数",
"category": "param",
"type": "string",
"desc": "columnSqlFunc 的附加参数,按函数类型用途不同:\r\r通用函数(有 param 时):{func}({columnResource}.{column}, {columnSqlFuncParam}) {operator} {value}\r 示例:ROUND(col, 2) → columnSqlFuncParam=\"2\"\r SUBSTRING(col, 1, 10) → columnSqlFuncParam=\"1, 10\"\r\rJSON 函数(param 为 JSON 路径表达式):\r json_member_ofvalue 是否是列 JSON 数组的成员):\r 无 paramJSON_CONTAINS({value}, JSON_ARRAY({column}))\r 有 paramJSON_CONTAINS({columnSqlFuncParam}, JSON_ARRAY({column}))\r json_contains(列 JSON 是否包含 value):\r 无 paramJSON_CONTAINS({column}, JSON_ARRAY({value}))\r 有 paramJSON_CONTAINS({columnSqlFuncParam}, JSON_ARRAY({value}))",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 265,
"pid": 262,
"code": "operator",
"name": "运算符",
"category": "param",
"type": "string",
"desc": "标准 SQL 比较运算符:\r\n= / != / \u003e / \u003e= / \u003c / \u003c=\r\nLIKE:模糊匹配(%keyword%\r\nIN:包含,value 逗号分隔多值\r\nIS NULL / IS NOT NULL:空值判断,无需 value\r\nREGEXP:正则匹配",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": "="
},
{
"id": 266,
"pid": 262,
"code": "value",
"name": "比较值",
"category": "param",
"type": "string",
"desc": "比较目标,内容由 valueType 决定。operator 为 IS NULL/IS NOT NULL 时可省略",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 267,
"pid": 262,
"code": "valueType",
"name": "比较值类型",
"category": "param",
"type": "string",
"desc": "先选类型再填 value\r\nstringvalue 填字面量如 '2024-01-01'\r\nfuncvalue 填内置函数名 UserID|UserUuid|UserRolesUuid|UserPlatform|UserSaaS\r\nparamvalue 填请求参数路径如 body.status\r\nsqlvalue 填原始SQL如 CURRENT_DATE",
"isRequired": false,
"constraints": {
"enum": [
"string",
"func"
]
},
"rank": 0,
"ref_id": 0,
"df_val": "string"
},
{
"id": 270,
"pid": 262,
"code": "ignoreEmptyParam",
"name": "忽略空参数",
"category": "param",
"type": "bool",
"desc": "当 valueType=param 且请求参数值为空(空字符串或 null)时,跳过该条件不生成 SQL。用于实现可选过滤项",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": "false"
},
{
"id": 272,
"pid": 271,
"code": "oneOf",
"name": "字段编码",
"category": "param",
"type": "string",
"desc": "字段引用,格式:{columnResource}.{column} 或 {column}",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 279,
"pid": 271,
"code": "oneOf",
"name": "表达式字段",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 275,
"pid": 271,
"code": "oneOf",
"name": "资源字段",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 278,
"pid": 275,
"code": "alias",
"name": "别名",
"category": "param",
"type": "string",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 276,
"pid": 275,
"code": "column",
"name": "字段编码",
"category": "param",
"type": "string",
"desc": "",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 277,
"pid": 275,
"code": "columnResource",
"name": "所属资源",
"category": "param",
"type": "string",
"desc": "字段所属资源标识,取值为顶层 resource 或 relations[].code",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 281,
"pid": 279,
"code": "alias",
"name": "别名",
"category": "param",
"type": "string",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 280,
"pid": 279,
"code": "expr",
"name": "SQL 表达式",
"category": "param",
"type": "string",
"desc": "SQL 表达式:如 COUNT(*) / SUM(amount)\r{column}:字段编码,默认归属顶层 resource\r{columnResource}.{column}:显式指定资源的字段引用",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 283,
"pid": 282,
"code": "oneOf",
"name": "分组表达式",
"category": "param",
"type": "string",
"desc": "SQL 表达式:如 COUNT(*) / SUM(amount)\r{column}:字段编码,默认归属顶层 resource\r{columnResource}.{column}:显式指定资源的字段引用",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 284,
"pid": 282,
"code": "oneOf",
"name": "资源字段",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 285,
"pid": 284,
"code": "column",
"name": "字段编码",
"category": "param",
"type": "string",
"desc": "",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 286,
"pid": 284,
"code": "columnResource",
"name": "所属资源",
"category": "param",
"type": "string",
"desc": "字段所属资源标识,取值为顶层 resource 或 relations[].code",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 288,
"pid": 287,
"code": "oneOf",
"name": "SQL 表达式 (ASC)",
"category": "param",
"type": "string",
"desc": "SQL 表达式:如 COUNT(*) / SUM(amount)\r{column}:字段编码,默认归属顶层 resource\r{columnResource}.{column}:显式指定资源的字段引用\r默认升序(asc)",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 289,
"pid": 287,
"code": "oneOf",
"name": "SQL 表达式排序",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 292,
"pid": 287,
"code": "oneOf",
"name": "资源字段排序",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 291,
"pid": 289,
"code": "direction",
"name": "排序方向",
"category": "param",
"type": "string",
"desc": "",
"isRequired": false,
"constraints": {
"enum": [
"asc",
"desc"
]
},
"rank": 0,
"ref_id": 0,
"df_val": "asc"
},
{
"id": 290,
"pid": 289,
"code": "expr",
"name": "SQL 表达式",
"category": "param",
"type": "string",
"desc": "SQL 表达式:如 COUNT(*) / SUM(amount)\r{column}:字段编码,默认归属顶层 resource\r{columnResource}.{column}:显式指定资源的字段引用",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 293,
"pid": 292,
"code": "column",
"name": "字段编码",
"category": "param",
"type": "string",
"desc": "",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 295,
"pid": 292,
"code": "columnResource",
"name": "所属资源",
"category": "param",
"type": "string",
"desc": "",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 296,
"pid": 292,
"code": "direction",
"name": "排序方向",
"category": "param",
"type": "string",
"desc": "",
"isRequired": false,
"constraints": {
"enum": [
"asc",
"desc"
]
},
"rank": 0,
"ref_id": 0,
"df_val": "asc"
},
{
"id": 300,
"pid": 299,
"code": "items",
"name": "",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 305,
"pid": 300,
"code": "actuallyField",
"name": "实际资源字段",
"category": "param",
"type": "string",
"desc": "目标资源(code)参与 ON 条件的字段",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 304,
"pid": 300,
"code": "actuallyResource",
"name": "实际资源",
"category": "param",
"type": "string",
"desc": "被关联的目标资源编码(相当于 SQL 表名)。JOIN 拼接为:{type} JOIN {actuallyResource} AS {code} ON {code}.{actuallyField} = {relationResource}.{relationField}",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 303,
"pid": 300,
"code": "code",
"name": "关联标识",
"category": "param",
"type": "string",
"desc": "关联唯一标识,同时作为别名:JOIN 时为表别名(AS code),子查询时为结果 JSON 字段的键名",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 302,
"pid": 300,
"code": "name",
"name": "关联名称",
"category": "param",
"type": "string",
"desc": "关联的显示名称",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 307,
"pid": 300,
"code": "relationField",
"name": "被关联资源字段",
"category": "param",
"type": "string",
"desc": "ON 条件对端资源的字段",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 306,
"pid": 300,
"code": "relationResource",
"name": "被关联资源",
"category": "param",
"type": "string",
"desc": "ON 条件对端的资源编码(通常为主资源或父关联资源)",
"isRequired": true,
"constraints": {},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 301,
"pid": 300,
"code": "type",
"name": "关联类型",
"category": "param",
"type": "string",
"desc": "关联模式:\r\ninner / left / rightSQL JOIN,将关联资源字段合并到主查询行\r\nhasOne:子查询,关联结果聚合为单个对象(result[code] = {}\r\nhasMany:子查询,关联结果聚合为对象数组(result[code] = [...]",
"isRequired": true,
"constraints": {
"enum": [
"inner",
"left",
"right",
"hasOne",
"hasMany"
]
},
"rank": 0,
"ref_id": 0,
"df_val": ""
},
{
"id": 309,
"pid": 300,
"code": "groupBy",
"name": "关联分组,仅 hasOne/hasMany 有效",
"category": "param",
"type": "array",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 282,
"df_val": ""
},
{
"id": 310,
"pid": 300,
"code": "orderBy",
"name": "关联排序,仅 hasOne/hasMany 有效",
"category": "param",
"type": "array",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 287,
"df_val": ""
},
{
"id": 308,
"pid": 300,
"code": "conditions",
"name": "关联的过滤条件",
"category": "param",
"type": "json",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 258,
"df_val": ""
},
{
"id": 311,
"pid": 300,
"code": "limit",
"name": "关联条数限制,仅 hasOne/hasMany 有效",
"category": "param",
"type": "integer",
"desc": "",
"isRequired": false,
"constraints": {},
"rank": 0,
"ref_id": 297,
"df_val": ""
}
]