rulechain.go 2.5 KB

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