rulechain.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package models
  2. import (
  3. "errors"
  4. "github.com/gogf/gf/encoding/gjson"
  5. "github.com/jinzhu/gorm"
  6. )
  7. // RuleChain 规则链
  8. type RuleChain struct {
  9. gorm.Model
  10. RecordId string `gorm:"column:record_id;size:32;index"`
  11. AdditionalInfo string `gorm:"column:additional_info"` //节点属性信息
  12. Configuration string `gorm:"column:configuration"` //配置信息
  13. Name string `gorm:"column:name"` //名称
  14. FirstRuleNodeID string `gorm:"column:first_rule_node_id"` //第一个节点的ID
  15. Root bool `gorm:"column:root"` //是否为root chain
  16. DebugModel bool `gorm:"column:debug_model"` //调试模式
  17. Intro string `gorm:"column:intro"` //描述
  18. VendorID string `gorm:"column:vendor_id"` //厂商ID
  19. }
  20. // RuleChainParams 更新规则链参数
  21. type RuleChainParams struct {
  22. VendorId string `json:"VendorID"` // 厂商id
  23. RecordId string `json:"RecordId"` // 记录id
  24. Cell []*gjson.Json `json:"cell"`
  25. Cells []*Cell
  26. }
  27. // ChangeRootParams 更新规则链参数
  28. type ChangeRootParams struct {
  29. VendorId string `json:"vendor_id"` // 厂商id
  30. RecordId string `json:"record_id"` // 记录id
  31. Root bool `json:"root"`
  32. }
  33. type CreatChainReq struct {
  34. RecordId string `json:"record_id"`
  35. Name string `json:"name"`
  36. Cell Cells `json:"cells"`
  37. }
  38. type Cells []*Cell
  39. type Cell struct {
  40. Id string `json:"id"` // id
  41. Shape string `json:"shape"`
  42. Data CellData `json:"data"` // 数据
  43. Source Branch `json:"source"` // 上级节点
  44. Target Branch `json:"target"` // 下级节点
  45. }
  46. type CellData struct {
  47. Name string `json:"name"` // 名称
  48. Id string `json:"id"` // id
  49. Type string `json:"type"` // 节点类型
  50. Desc string `json:"desc"` // 备注
  51. ZIndex string `json:"ZIndex"` // 序号
  52. FuncBody string `json:"func_body"` // 代码
  53. Label string `json:"label"`
  54. Source string `json:"source"` // 源节点id
  55. Target string `json:"target"` // 目标节点id
  56. MesType []string `json:"mes_type"` // 消息类型
  57. Headers []*Headers `json:"headers"`
  58. Url string `json:"url"`
  59. Method string `json:"method"`
  60. Retry int `json:"retry"`
  61. TimeOut int `json:"time_out"`
  62. RetryWait int `json:"retry_wait"`
  63. }
  64. type NodeConfiguration struct {
  65. Url string `json:"url"`
  66. Method string `json:"method"`
  67. Headers map[string]interface{} `json:"headers"`
  68. Retry int `json:"retry"`
  69. TimeOut int `json:"time_out"`
  70. RetryWait int `json:"retry_wait"`
  71. }
  72. type Headers struct {
  73. Key string `json:"key"`
  74. Value string `json:"value"`
  75. }
  76. type Branch struct {
  77. Cell string `json:"cell"`
  78. }
  79. // Validate ``
  80. func (a *RuleChain) Validate() error {
  81. if a.Name == "" {
  82. return errors.New("规则链名称为空")
  83. }
  84. return nil
  85. }
  86. // Validate ``
  87. func (a *RuleChainParams) Validate() error {
  88. return nil
  89. }
  90. // Validate ``
  91. func (a *ChangeRootParams) Validate() error {
  92. if a.RecordId == "" {
  93. return errors.New("记录id不能为空")
  94. }
  95. return nil
  96. }