sop_stage.go 2.4 KB

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