sop_node.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }
  43. }
  44. func (SopNode) Mixin() []ent.Mixin {
  45. return []ent.Mixin{
  46. mixins.IDMixin{},
  47. mixins.StatusMixin{},
  48. localmixin.SoftDeleteMixin{},
  49. }
  50. }
  51. func (SopNode) Indexes() []ent.Index {
  52. return []ent.Index{
  53. index.Fields("name"),
  54. }
  55. }
  56. func (SopNode) Edges() []ent.Edge {
  57. return []ent.Edge{
  58. edge.From("sop_stage", SopStage.Type).
  59. Ref("stage_nodes").
  60. Unique().
  61. Field("stage_id").
  62. Required(),
  63. edge.To("node_messages", MessageRecords.Type),
  64. }
  65. }
  66. func (SopNode) Annotations() []schema.Annotation {
  67. return []schema.Annotation{
  68. entsql.WithComments(true),
  69. entsql.Annotation{Table: "sop_node"},
  70. }
  71. }