message_records.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. field.Uint64("organization_id").Optional().Default(1).
  55. Comment("机构 ID").
  56. Annotations(entsql.WithComments(true)),
  57. }
  58. }
  59. func (MessageRecords) Mixin() []ent.Mixin {
  60. return []ent.Mixin{
  61. mixins.IDMixin{},
  62. mixins.StatusMixin{},
  63. localmixin.SoftDeleteMixin{},
  64. }
  65. }
  66. func (MessageRecords) Indexes() []ent.Index {
  67. return []ent.Index{
  68. index.Fields("source_type"),
  69. }
  70. }
  71. func (MessageRecords) Edges() []ent.Edge {
  72. return []ent.Edge{
  73. edge.From("sop_stage", SopStage.Type).
  74. Ref("stage_messages").
  75. Unique().
  76. Field("source_id"),
  77. edge.From("sop_node", SopNode.Type).
  78. Ref("node_messages").
  79. Unique().
  80. Field("sub_source_id"),
  81. edge.From("message_contact", Contact.Type).
  82. Ref("contact_messages").
  83. Unique().
  84. Field("contact_id"),
  85. }
  86. }
  87. func (MessageRecords) Annotations() []schema.Annotation {
  88. return []schema.Annotation{
  89. entsql.WithComments(true),
  90. entsql.Annotation{Table: "message_records"},
  91. }
  92. }