123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package ruleEngine
- type RuleChainService interface {
- // 根据id查询规则链数据
- FindRuleChainById(tenantId, ruleChainId string) (*RuleChain, error)
- // 根据id查询规则节点数据
- FindRuleNodeById(tenantId, ruleNodeId string) (*RuleNode, error)
- // 查询规则链的节点列表
- GetRuleChainNodes(tenantId, ruleChainId string) ([]*RuleNode, error)
- // 查询租户的全部规则链
- FindRuleChains(tenantId string) ([]*RuleChain, error)
- // 查询节点的连接关系列表
- GetRuleNodeRelations(tenantId, nodeId string) ([]*Relation, error)
- }
- type TestRuleChainService struct {
- }
- func (t *TestRuleChainService) GetRuleNodeRelations(tenantId, nodeId string) ([]*Relation, error) {
- if nodeId == "node1" {
- return []*Relation{
- {
- From: "node1",
- To: "node2",
- Type: "True",
- RelationTypeGroup: COMMON,
- },
- }, nil
- }
- if nodeId == "node2" {
- return []*Relation {
- {
- From: "node2",
- To: "node3",
- Type: "True",
- RelationTypeGroup: COMMON,
- },
- }, nil
- }
- return nil, nil
- }
- func (t *TestRuleChainService) FindRuleChainById(tenantId, ruleChainId string) (*RuleChain, error) {
- return &RuleChain{
- TenantId: "4jnh0r0hrl0c5a8mmecuoew200o32b8g",
- Name: "test rule chain 1",
- FirstNodeId: "node1",
- IsDebug: false,
- IsRoot: true,
- Config: "",
- ChainId: "chain id 1",
- }, nil
- }
- func (t *TestRuleChainService) FindRuleNodeById(tenantId, ruleNodeId string) (*RuleNode, error) {
- switch ruleNodeId {
- case "node1":
- return &RuleNode{
- RuleChainId: "chain id 1",
- Type: "MsgTypeFilterNode",
- Name: "filternode1",
- IsDebug: false,
- Config: "",
- RuleNodeId: "node1",
- }, nil
- case "node2":
- return &RuleNode{
- RuleChainId: "chain id 2",
- Type: "MsgTypeFilterNode",
- Name: "filternode2",
- IsDebug: false,
- Config: "",
- RuleNodeId: "node2",
- }, nil
- case "node3":
- return &RuleNode{
- RuleChainId: "chain id 2",
- Type: "RestApiRequestNode",
- Name: "rest api",
- IsDebug: false,
- Config: "",
- RuleNodeId: "node3",
- }, nil
- }
- return nil, nil
- }
- func (t *TestRuleChainService) GetRuleChainNodes(tenantId, ruleChainId string) ([]*RuleNode, error) {
- return []*RuleNode{
- {
- RuleChainId: "chain id 1",
- Type: "MsgTypeFilterNode",
- Name: "filternode",
- IsDebug: false,
- Config: "",
- RuleNodeId: "node1",
- },
- {
- RuleChainId: "chain id 2",
- Type: "MsgTypeFilterNode",
- Name: "filternode",
- IsDebug: false,
- Config: "",
- RuleNodeId: "node2",
- },
- {
- RuleChainId: "chain id 2",
- Type: "RestApiRequestNode",
- Name: "rest api",
- IsDebug: false,
- Config: "{\"url\":\"http://localhost/api/test\",\"headers\":{},\"retry\":3,\"method\":\"post\",\"time_out\":5,\"retry_wait\":1}",
- RuleNodeId: "node3",
- },
- }, nil
- }
- func (t *TestRuleChainService) FindRuleChains(tenantId string) ([]*RuleChain, error) {
- return []*RuleChain{
- {
- TenantId: "4jnh0r0hrl0c5a8mmecuoew200o32b8g",
- Name: "test rule chain 1",
- FirstNodeId: "node1",
- IsDebug: false,
- IsRoot: true,
- Config: "",
- ChainId: "chain id 1",
- },
- }, nil
- }
|