rulechain.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. NodeConfiguration
  44. }
  45. type NodeConfiguration struct {
  46. Url string `json:"url"`
  47. Method string `json:"method"`
  48. Headers []*Headers `json:"headers"`
  49. Retry int `json:"retry"`
  50. TimeOut int `json:"time_out"`
  51. RetryWait int `json:"retry_wait"`
  52. }
  53. type Headers struct {
  54. Key string `json:"key"`
  55. Value string `json:"value"`
  56. }
  57. type Branch struct {
  58. Cell string `json:"cell"`
  59. }
  60. // Validate ``
  61. func (a *RuleChain) Validate() error {
  62. if a.Name == "" {
  63. return errors.New("规则链名称为空")
  64. }
  65. return nil
  66. }