2021年12月17日
决策引擎是一种计算机程序,用于计算一个系统的决策。
目标 提供规则集、决策表、交叉决策表(决策矩阵)、决策树、评分卡、复杂评分卡、规则流等八种类型的业务规则设计工具 并发执行规则 数据库设计 规则 表名称: rules 字段名称 字段类型 描述 id string primary key created int 创建时间 updated int 更新时间 merchant string 商户 code string 规则编码 type string(enum) 规则类型 information json(dict) 规则信息 name string 规则名称 description string 规则描述 type enum列表 raw - 原始脚本 ruleset - 规则集 normal_score_card - 普通评分卡 complex_score_card - 复杂评分卡 decision_tree - 决策树 decision_table - 决策表 decision_matrix - 决策矩阵 information json字段介绍 type == raw 时的information 1 2 3 { "script": "string, 脚本字符串" } type == ruleset 时的information 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 { "rules": [ { "name": "string, 子规则名称", "description": "string, 子规则描述", "rule_group": { // 树形结构 // type: string(enum), 规则条件类型, enum: expression, logic_expression "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [ { "type": "expression", "operator": "string(enum), 表达式操作符, eq, neq, gt, gte, lt, lte, in, nin", "left_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" }, "right_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" } }, { "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [] } ] } } ] }
type == decision_table 时的information 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 { "table_conditions": [ { // 树形结构 // type: string(enum), 规则条件类型, enum: expression, logic_expression "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [ { "type": "expression", "operator": "string(enum), 表达式操作符, eq, neq, gt, gte, lt, lte, in, nin", "left_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" }, "right_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" } }, { "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [] } ] } ], "table_actions": [ // type: string(enum), 动作类型, assignment, function { "type": "assignment", "field": "string, 字段路径", "value": "string, 写入值" }, { "type": "function", "function_name": "string, 函数名", "arguments": [ { "type": "string(enum), 参数类型, variable, constant", "value": "string, 参数值" } ] } ] }
type == decision_matrix 时的information 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 { // 赋值动作 "action": { "field": "string, 字段路径" }, // 表信息 "matrix": [ [ { "crosswise_conditions": [ { "type": "expression", "operator": "string(enum), 表达式操作符, eq, neq, gt, gte, lt, lte, in, nin", "left_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" }, "right_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" } }, { "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [] } ], "lengthwise_conditions": [ { "type": "expression", "operator": "string(enum), 表达式操作符, eq, neq, gt, gte, lt, lte, in, nin", "left_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" }, "right_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" } }, { "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [] } ], "value": "string, 值" } ] ] }
type == normal_score_card 时的information 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 { "is_weight": "boolean, 权重", "action": { // 求和方式 "type": "function", "function_name": "string, 函数名称" }, "score_card_table": { "string, 字段路径": { "weight": "int, 权重", "conditions_and_score": [ { "conditions": [ { "type": "expression", "operator": "string(enum), 表达式操作符, eq, neq, gt, gte, lt, lte, in, nin", "left_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" }, "right_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" } }, { "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [] } ], "score": "int, 分数" } ] } } }
type == complex_score_card 时的information 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 { "action": { // 求和方式 "type": "function", "function_name": "string, 函数名称" }, "score_card_table": [ [ { "string, 字段路径": { "weight": "int, 权重", "conditions_and_score": [ { "conditions": [ { "type": "expression", "operator": "string(enum), 表达式操作符, eq, neq, gt, gte, lt, lte, in, nin", "left_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" }, "right_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" } }, { "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [] } ], "score": "int, 分数" } ] } } ] ] }
type == decision_tree 时的information 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 { "field": "string, 字段路径", "nodes": [ { "conditions": [ // 需要执行的条件 { "type": "expression", "operator": "string(enum), 表达式操作符, eq, neq, gt, gte, lt, lte, in, nin", "left_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" }, "right_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" } }, { "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [] } ], "alise": { // type: string(enum), enum: leaf_node(叶子节点), non_leaf_node(非叶子节点) "type": "string(enum), enum: leaf_node", "action": [ // type: string(enum), 动作类型, assignment, function { "type": "assignment", "field": "string, 字段路径", "value": "string, 写入值" }, { "type": "function", "function_name": "string, 函数名", "arguments": [ { "type": "string(enum), 参数类型, variable, constant", "value": "string, 参数值" } ] } ] } }, { "conditions": [ // 需要执行的条件 { "type": "expression", "operator": "string(enum), 表达式操作符, eq, neq, gt, gte, lt, lte, in, nin", "left_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" }, "right_value": { "type": "string(enum), 左值类型, variable, constant, function", "value": "string, 左值值" } }, { "type": "logic_expression", "op": "string(enum), 规则操作符, or, and", "conditions": [] } ], "alise": { // type: string(enum), enum: leaf_node(叶子节点), non_leaf_node(非叶子节点) "type": "string(enum), enum: non_leaf_node", "field": "string, 字段路径", "nodes": [] } } ] }
决策流 表名称: decision_flow 字段名称 字段类型 描述 id string primary key created int 创建时间 updated int 更新时间 merchant string 商户 code string 决策流编码 name string 决策流名称 description string 决策流描述 决策流-规则节点 表名称: decision_flow_node 字段名称 字段类型 描述 id string primary key created int 创建时间 updated int 更新时间 merchant string 商户 decision_flow_code string 决策流编码 rule_code string 规则编码 next_node list[string] 下一步规则节点编码列表 name string 规则节点名称 description string 规则节点描述 数据库图
接口文档 规则 创建 Request Method: POST URL: /v1/rule Headers: Content-Type: application/json Body 1 2 3 4 5 6 7 8 9 10 11 12 { "data_list": [ { "merchant": "string, 商户号", "code": "string, 规则编码", "type": "string(enum), 规则类型", "information": "json(dict), 规则信息, 根据type进行变化", "name": "string, 规则名称", "description": "string, 规则描述" } ] } Response 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 { "data": [ { "data": { "id": "string, 主键", "created": "int, 创建时间", "updated": "int, 更新时间" // 其余全量数据 }, "msg": "success", "code": 0 } ], "msg": "success", "code": 0 } 描述 无……
阅读全文