sop_node.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.String("no_reply_unit").Default("").
  37. Annotations(entsql.WithComments(true)).
  38. Comment("超时触发时间单位"),
  39. field.JSON("action_message", []custom_types.Action{}).Optional().
  40. Annotations(entsql.WithComments(true)).
  41. Comment("命中后发送的消息内容"),
  42. field.JSON("action_label_add", []uint64{}).Optional().
  43. Annotations(entsql.WithComments(true)).
  44. Comment("命中后需要打的标签"),
  45. field.JSON("action_label_del", []uint64{}).Optional().
  46. Annotations(entsql.WithComments(true)).
  47. Comment("命中后需要移除的标签"),
  48. field.JSON("action_forward", &custom_types.ActionForward{}).Optional().
  49. Annotations(entsql.WithComments(true)).
  50. Comment("命中后转发的消息"),
  51. }
  52. }
  53. func (SopNode) Mixin() []ent.Mixin {
  54. return []ent.Mixin{
  55. mixins.IDMixin{},
  56. mixins.StatusMixin{},
  57. localmixin.SoftDeleteMixin{},
  58. }
  59. }
  60. func (SopNode) Indexes() []ent.Index {
  61. return []ent.Index{
  62. index.Fields("name"),
  63. }
  64. }
  65. func (SopNode) Edges() []ent.Edge {
  66. return []ent.Edge{
  67. edge.From("sop_stage", SopStage.Type).
  68. Ref("stage_nodes").
  69. Unique().
  70. Field("stage_id").
  71. Required(),
  72. edge.To("node_messages", MessageRecords.Type),
  73. }
  74. }
  75. func (SopNode) Annotations() []schema.Annotation {
  76. return []schema.Annotation{
  77. entsql.WithComments(true),
  78. entsql.Annotation{Table: "sop_node"},
  79. }
  80. }