rule_chain_service.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package ruleEngine
  2. type RuleChainService interface {
  3. // 根据id查询规则链数据
  4. FindRuleChainById(tenantId, ruleChainId string) (*RuleChain, error)
  5. // 根据id查询规则节点数据
  6. FindRuleNodeById(tenantId, ruleNodeId string) (*RuleNode, error)
  7. // 查询规则链的节点列表
  8. GetRuleChainNodes(tenantId, ruleChainId string) ([]*RuleNode, error)
  9. // 查询租户的全部规则链
  10. FindRuleChains(tenantId string) ([]*RuleChain, error)
  11. // 查询节点的连接关系列表
  12. GetRuleNodeRelations(tenantId, nodeId string) ([]*Relation, error)
  13. }
  14. type TestRuleChainService struct {
  15. }
  16. func (t *TestRuleChainService) GetRuleNodeRelations(tenantId, nodeId string) ([]*Relation, error) {
  17. if nodeId == "node1" {
  18. return []*Relation{
  19. {
  20. From: "node1",
  21. To: "node2",
  22. Type: "True",
  23. RelationTypeGroup: COMMON,
  24. },
  25. }, nil
  26. }
  27. if nodeId == "node2" {
  28. return []*Relation {
  29. {
  30. From: "node2",
  31. To: "node3",
  32. Type: "True",
  33. RelationTypeGroup: COMMON,
  34. },
  35. }, nil
  36. }
  37. return nil, nil
  38. }
  39. func (t *TestRuleChainService) FindRuleChainById(tenantId, ruleChainId string) (*RuleChain, error) {
  40. return &RuleChain{
  41. TenantId: "tenant_1",
  42. Name: "test rule chain 1",
  43. FirstNodeId: "node1",
  44. IsDebug: false,
  45. IsRoot: true,
  46. Config: "",
  47. ChainId: "chain id 1",
  48. }, nil
  49. }
  50. func (t *TestRuleChainService) FindRuleNodeById(tenantId, ruleNodeId string) (*RuleNode, error) {
  51. switch ruleNodeId {
  52. case "node1":
  53. return &RuleNode{
  54. RuleChainId: "chain id 1",
  55. Type: "MsgTypeFilterNode",
  56. Name: "filternode1",
  57. IsDebug: false,
  58. Config: "",
  59. RuleNodeId: "node1",
  60. }, nil
  61. case "node2":
  62. return &RuleNode{
  63. RuleChainId: "chain id 2",
  64. Type: "MsgTypeFilterNode",
  65. Name: "filternode2",
  66. IsDebug: false,
  67. Config: "",
  68. RuleNodeId: "node2",
  69. }, nil
  70. case "node3":
  71. return &RuleNode{
  72. RuleChainId: "chain id 2",
  73. Type: "RestApiRequestNode",
  74. Name: "rest api",
  75. IsDebug: false,
  76. Config: "",
  77. RuleNodeId: "node3",
  78. }, nil
  79. }
  80. return nil, nil
  81. }
  82. func (t *TestRuleChainService) GetRuleChainNodes(tenantId, ruleChainId string) ([]*RuleNode, error) {
  83. return []*RuleNode{
  84. {
  85. RuleChainId: "chain id 1",
  86. Type: "MsgTypeFilterNode",
  87. Name: "filternode",
  88. IsDebug: false,
  89. Config: "",
  90. RuleNodeId: "node1",
  91. },
  92. {
  93. RuleChainId: "chain id 2",
  94. Type: "MsgTypeFilterNode",
  95. Name: "filternode",
  96. IsDebug: false,
  97. Config: "",
  98. RuleNodeId: "node2",
  99. },
  100. {
  101. RuleChainId: "chain id 2",
  102. Type: "RestApiRequestNode",
  103. Name: "rest api",
  104. IsDebug: false,
  105. Config: "",
  106. RuleNodeId: "node3",
  107. },
  108. }, nil
  109. }
  110. func (t *TestRuleChainService) FindRuleChains(tenantId string) ([]*RuleChain, error) {
  111. return []*RuleChain{
  112. {
  113. TenantId: "tenant_1",
  114. Name: "test rule chain 1",
  115. FirstNodeId: "node1",
  116. IsDebug: false,
  117. IsRoot: true,
  118. Config: "",
  119. ChainId: "chain id 1",
  120. },
  121. }, nil
  122. }