message_records.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/schema/localmixin"
  11. )
  12. type MessageRecords struct {
  13. ent.Schema
  14. }
  15. func (MessageRecords) Fields() []ent.Field {
  16. return []ent.Field{
  17. field.String("bot_wxid").
  18. Annotations(entsql.WithComments(true)).
  19. Comment("机器人微信 id"),
  20. field.Uint64("contact_id").Optional().
  21. Annotations(entsql.WithComments(true)).
  22. Comment("联系人 id"),
  23. field.Int("contact_type").Default(1).
  24. Annotations(entsql.WithComments(true)).
  25. Comment("类型:1好友,2群组,3企业微信联系人"),
  26. field.String("contact_wxid").Default("").
  27. Annotations(entsql.WithComments(true)).
  28. Comment("接收方微信 id"),
  29. field.Int("content_type").Default(1).
  30. Annotations(entsql.WithComments(true)).
  31. Comment("内容类型 1 文本 2 文件"),
  32. field.String("content").Default("").
  33. Annotations(entsql.WithComments(true)).
  34. Comment("发送内容"),
  35. field.String("error_detail").Default("").
  36. Annotations(entsql.WithComments(true)).
  37. Comment("异常原因"),
  38. field.Time("send_time").Optional().
  39. Annotations(entsql.WithComments(true)).
  40. Comment("发送时间"),
  41. field.Int("source_type").Default(1).
  42. Annotations(entsql.WithComments(true)).
  43. Comment("源类型 1 点发 2 群发 3 SOP"),
  44. field.Uint64("source_id").Default(1).Optional().
  45. Annotations(entsql.WithComments(true)).
  46. Comment("源 ID"),
  47. field.Uint64("sub_source_id").Default(1).Optional().
  48. Annotations(entsql.WithComments(true)).
  49. Comment("次源 ID"),
  50. }
  51. }
  52. func (MessageRecords) Mixin() []ent.Mixin {
  53. return []ent.Mixin{
  54. mixins.IDMixin{},
  55. mixins.StatusMixin{},
  56. localmixin.SoftDeleteMixin{},
  57. }
  58. }
  59. func (MessageRecords) Indexes() []ent.Index {
  60. return []ent.Index{
  61. index.Fields("source_type"),
  62. }
  63. }
  64. func (MessageRecords) Edges() []ent.Edge {
  65. return []ent.Edge{
  66. edge.From("sop_stage", SopStage.Type).
  67. Ref("stage_messages").
  68. Unique().
  69. Field("source_id"),
  70. edge.From("sop_node", SopNode.Type).
  71. Ref("node_messages").
  72. Unique().
  73. Field("sub_source_id"),
  74. edge.From("message_contact", Contact.Type).
  75. Ref("contact_messages").
  76. Unique().
  77. Field("contact_id"),
  78. }
  79. }
  80. func (MessageRecords) Annotations() []schema.Annotation {
  81. return []schema.Annotation{entsql.Annotation{Table: "message_records"}}
  82. }