message_records.go 2.6 KB

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