rulechain.go 2.7 KB

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