sop_node.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. "wechat-api/ent/custom_types"
  11. "wechat-api/ent/schema/localmixin"
  12. )
  13. type SopNode struct {
  14. ent.Schema
  15. }
  16. func (SopNode) Fields() []ent.Field {
  17. return []ent.Field{
  18. field.Uint64("stage_id").
  19. Annotations(entsql.WithComments(true)).
  20. Comment("阶段 ID"),
  21. field.Uint64("parent_id").
  22. Annotations(entsql.WithComments(true)).
  23. Comment("父节点 ID"),
  24. field.String("name").Default("").
  25. Annotations(entsql.WithComments(true)).
  26. Comment("节点名称"),
  27. field.Int("condition_type").Default(1).
  28. Annotations(entsql.WithComments(true)).
  29. Comment("触发条件类型 1 客户回复后触发 2 超时后触发"),
  30. field.JSON("condition_list", []string{}).Optional().
  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", []uint64{}).Optional().
  37. Annotations(entsql.WithComments(true)).
  38. Comment("命中后需要打的标签"),
  39. }
  40. }
  41. func (SopNode) Mixin() []ent.Mixin {
  42. return []ent.Mixin{
  43. mixins.IDMixin{},
  44. mixins.StatusMixin{},
  45. localmixin.SoftDeleteMixin{},
  46. }
  47. }
  48. func (SopNode) Indexes() []ent.Index {
  49. return []ent.Index{
  50. index.Fields("name"),
  51. }
  52. }
  53. func (SopNode) Edges() []ent.Edge {
  54. return []ent.Edge{
  55. edge.From("sop_stage", SopStage.Type).
  56. Ref("stage_nodes").
  57. Unique().
  58. Field("stage_id").
  59. Required(),
  60. edge.To("node_messages", MessageRecords.Type),
  61. }
  62. }
  63. func (SopNode) Annotations() []schema.Annotation {
  64. return []schema.Annotation{entsql.Annotation{Table: "sop_node"}}
  65. }