rulechain.go 3.2 KB

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