sop_node.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 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.Uint64("no_reply_condition").Default(0).
  34. Annotations(entsql.WithComments(true)).
  35. Comment("超时触发时间(分钟)"),
  36. field.JSON("action_message", []custom_types.Action{}).Optional().
  37. Annotations(entsql.WithComments(true)).
  38. Comment("命中后发送的消息内容"),
  39. field.JSON("action_label", []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. }
  46. }
  47. func (SopNode) Mixin() []ent.Mixin {
  48. return []ent.Mixin{
  49. mixins.IDMixin{},
  50. mixins.StatusMixin{},
  51. localmixin.SoftDeleteMixin{},
  52. }
  53. }
  54. func (SopNode) Indexes() []ent.Index {
  55. return []ent.Index{
  56. index.Fields("name"),
  57. }
  58. }
  59. func (SopNode) Edges() []ent.Edge {
  60. return []ent.Edge{
  61. edge.From("sop_stage", SopStage.Type).
  62. Ref("stage_nodes").
  63. Unique().
  64. Field("stage_id").
  65. Required(),
  66. edge.To("node_messages", MessageRecords.Type),
  67. }
  68. }
  69. func (SopNode) Annotations() []schema.Annotation {
  70. return []schema.Annotation{
  71. entsql.WithComments(true),
  72. entsql.Annotation{Table: "sop_node"},
  73. }
  74. }