message_records.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/custom_types"
  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.JSON("meta", custom_types.Meta{}).Optional().
  36. Annotations(entsql.WithComments(true)).
  37. Comment("元数据"),
  38. field.String("error_detail").Default("").
  39. Annotations(entsql.WithComments(true)).
  40. Comment("异常原因"),
  41. field.Time("send_time").Optional().
  42. Annotations(entsql.WithComments(true)).
  43. Comment("发送时间"),
  44. field.Int("source_type").Default(1).
  45. Annotations(entsql.WithComments(true)).
  46. Comment("源类型 1 点发 2 群发 3 SOP"),
  47. field.Uint64("source_id").Default(1).Optional().
  48. Annotations(entsql.WithComments(true)).
  49. Comment("源 ID"),
  50. field.Uint64("sub_source_id").Default(1).Optional().
  51. Annotations(entsql.WithComments(true)).
  52. Comment("次源 ID"),
  53. field.Uint64("organization_id").Optional().Default(1).
  54. Comment("机构 ID").
  55. Annotations(entsql.WithComments(true)),
  56. }
  57. }
  58. func (MessageRecords) Mixin() []ent.Mixin {
  59. return []ent.Mixin{
  60. mixins.IDMixin{},
  61. mixins.StatusMixin{},
  62. }
  63. }
  64. func (MessageRecords) Indexes() []ent.Index {
  65. return []ent.Index{
  66. index.Fields("source_type"),
  67. }
  68. }
  69. func (MessageRecords) Edges() []ent.Edge {
  70. return []ent.Edge{
  71. edge.From("sop_stage", SopStage.Type).
  72. Ref("stage_messages").
  73. Unique().
  74. Field("source_id"),
  75. edge.From("sop_node", SopNode.Type).
  76. Ref("node_messages").
  77. Unique().
  78. Field("sub_source_id"),
  79. edge.From("message_contact", Contact.Type).
  80. Ref("contact_messages").
  81. Unique().
  82. Field("contact_id"),
  83. }
  84. }
  85. func (MessageRecords) Annotations() []schema.Annotation {
  86. return []schema.Annotation{
  87. entsql.WithComments(true),
  88. entsql.Annotation{Table: "message_records"},
  89. }
  90. }