sop_stage.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package schema
  2. import (
  3. "entgo.io/ent"
  4. "entgo.io/ent/dialect/entsql"
  5. "entgo.io/ent/schema"
  6. "entgo.io/ent/schema/edge"
  7. "entgo.io/ent/schema/field"
  8. "entgo.io/ent/schema/index"
  9. "github.com/suyuan32/simple-admin-common/orm/ent/mixins"
  10. "github.com/suyuan32/simple-admin-job/ent/custom_types"
  11. )
  12. type SopStage struct {
  13. ent.Schema
  14. }
  15. func (SopStage) Fields() []ent.Field {
  16. return []ent.Field{
  17. field.Uint64("task_id").
  18. Annotations(entsql.WithComments(true)).
  19. Comment("SOP 任务 ID"),
  20. field.String("name").Default("").
  21. Annotations(entsql.WithComments(true)).
  22. Comment("阶段名称"),
  23. field.Int("condition_type").Default(1).
  24. Annotations(entsql.WithComments(true)).
  25. Comment("客群筛选条件类型 1 按标签筛选 2 按客户基本信息筛选"),
  26. field.Int("condition_operator").Default(1).
  27. Annotations(entsql.WithComments(true)).
  28. Comment("筛选条件关系 1 满足所有条件(and) 2 满足任意条件(or)"),
  29. field.JSON("condition_list", []custom_types.Condition{}).
  30. Annotations(entsql.WithComments(true)).
  31. Comment("筛选条件列表"),
  32. field.JSON("action_message", []custom_types.Action{}).Optional().
  33. Annotations(entsql.WithComments(true)).
  34. Comment("命中后发送的消息内容"),
  35. field.JSON("action_label", []uint64{}).Optional().
  36. Annotations(entsql.WithComments(true)).
  37. Comment("命中后需要打的标签"),
  38. field.Int("index_sort").Default(1).Optional().
  39. Annotations(entsql.WithComments(true)).
  40. Comment("阶段顺序"),
  41. field.Time("deleted_at").
  42. Optional().
  43. Comment("Delete Time | 删除日期").
  44. Annotations(entsql.WithComments(true)),
  45. }
  46. }
  47. func (SopStage) Mixin() []ent.Mixin {
  48. return []ent.Mixin{
  49. mixins.IDMixin{},
  50. mixins.StatusMixin{},
  51. }
  52. }
  53. func (SopStage) Indexes() []ent.Index {
  54. return []ent.Index{
  55. index.Fields("name"),
  56. }
  57. }
  58. func (SopStage) Edges() []ent.Edge {
  59. return []ent.Edge{
  60. edge.From("sop_task", SopTask.Type).
  61. Ref("task_stages").
  62. Unique().
  63. Field("task_id").
  64. Required(),
  65. edge.To("stage_nodes", SopNode.Type),
  66. edge.To("stage_messages", MessageRecords.Type),
  67. }
  68. }
  69. func (SopStage) Annotations() []schema.Annotation {
  70. return []schema.Annotation{entsql.Annotation{Table: "sop_stage"}}
  71. }