rulechain.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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:"vendor_id"` // 厂商id
  22. RecordId string `json:"record_id"` // 记录id
  23. Cell interface{} `json:"cell"`
  24. Cells []*Cell
  25. }
  26. type CreatChainReq struct {
  27. RecordId string `json:"record_id"`
  28. Name string `json:"name"`
  29. Cell Cells `json:"cells"`
  30. }
  31. type Cells []*Cell
  32. type Cell struct {
  33. Id string `json:"id"` // id
  34. Shape string `json:"shape"`
  35. Data CellData `json:"data"` // 数据
  36. Source Branch `json:"source"` // 上级节点
  37. Target Branch `json:"target"` // 下级节点
  38. }
  39. type CellData struct {
  40. Name string `json:"name"` // 名称
  41. Id string `json:"id"` // id
  42. Type string `json:"type"` // 节点类型
  43. Desc string `json:"desc"` // 备注
  44. ZIndex string `json:"ZIndex"` // 序号
  45. FuncBody string `json:"func_body"` // 代码
  46. Label string `json:"label"`
  47. Source string `json:"source"` // 源节点id
  48. Target string `json:"target"` // 目标节点id
  49. MesType []string `json:"mes_type"` // 消息类型
  50. Headers []*Headers `json:"headers"`
  51. Url string `json:"url"`
  52. Method string `json:"method"`
  53. Retry int `json:"retry"`
  54. TimeOut int `json:"time_out"`
  55. RetryWait int `json:"retry_wait"`
  56. }
  57. type NodeConfiguration struct {
  58. Url string `json:"url"`
  59. Method string `json:"method"`
  60. Headers map[string]interface{} `json:"headers"`
  61. Retry int `json:"retry"`
  62. TimeOut int `json:"time_out"`
  63. RetryWait int `json:"retry_wait"`
  64. }
  65. type Headers struct {
  66. Key string `json:"key"`
  67. Value string `json:"value"`
  68. }
  69. type Branch struct {
  70. Cell string `json:"cell"`
  71. }
  72. // Validate ``
  73. func (a *RuleChain) Validate() error {
  74. if a.Name == "" {
  75. return errors.New("规则链名称为空")
  76. }
  77. return nil
  78. }
  79. // Validate ``
  80. func (a *RuleChainParams) Validate() error {
  81. return nil
  82. }