wx.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package schema
  2. import (
  3. "wechat-api/ent/schema/localmixin"
  4. "entgo.io/ent"
  5. "entgo.io/ent/dialect/entsql"
  6. "entgo.io/ent/schema"
  7. "entgo.io/ent/schema/edge"
  8. "entgo.io/ent/schema/field"
  9. "entgo.io/ent/schema/index"
  10. "github.com/suyuan32/simple-admin-common/orm/ent/mixins"
  11. )
  12. type Wx struct {
  13. ent.Schema
  14. }
  15. func (Wx) Fields() []ent.Field {
  16. return []ent.Field{
  17. field.Uint64("server_id").Optional().Default(0).
  18. Annotations(entsql.WithComments(true)).
  19. Comment("服务器id"),
  20. field.String("port").Default("").
  21. Annotations(entsql.WithComments(true)).
  22. Comment("端口号"),
  23. field.String("process_id").Default("").
  24. Annotations(entsql.WithComments(true)).
  25. Comment("进程号"),
  26. field.String("callback").Default("").
  27. Annotations(entsql.WithComments(true)).
  28. Comment("回调地址"),
  29. field.String("wxid").Default("").
  30. Default("").
  31. Annotations(entsql.WithComments(true)).
  32. Comment("微信id"),
  33. field.String("account").Default("").
  34. Annotations(entsql.WithComments(true)).
  35. Comment("微信账号"),
  36. field.String("nickname").Default("").
  37. Annotations(entsql.WithComments(true)).
  38. Comment("微信昵称"),
  39. field.String("tel").Default("").
  40. Annotations(entsql.WithComments(true)).
  41. Comment("手机号"),
  42. field.String("head_big").Default("").
  43. Annotations(entsql.WithComments(true)).
  44. Comment("微信头像"),
  45. field.Uint64("organization_id").Optional().Default(1).
  46. Comment("机构 ID").
  47. Annotations(entsql.WithComments(true)),
  48. field.Uint64("agent_id").Default(0).
  49. Comment("模式ID").
  50. Annotations(entsql.WithComments(true)),
  51. }
  52. }
  53. func (Wx) Mixin() []ent.Mixin {
  54. return []ent.Mixin{
  55. mixins.IDMixin{},
  56. mixins.StatusMixin{},
  57. localmixin.SoftDeleteMixin{},
  58. }
  59. }
  60. func (Wx) Indexes() []ent.Index {
  61. return []ent.Index{
  62. index.Fields("server_id", "port").Unique(),
  63. index.Fields("wxid").Unique(),
  64. index.Fields("account"),
  65. index.Fields("nickname"),
  66. index.Fields("tel"),
  67. }
  68. }
  69. func (Wx) Edges() []ent.Edge {
  70. return []ent.Edge{
  71. edge.From("server", Server.Type).Ref("wxs").Unique().Field("server_id"),
  72. edge.From("agent", Agent.Type).
  73. Ref("wx_agent").
  74. Unique().
  75. Field("agent_id").
  76. Required(),
  77. }
  78. }
  79. func (Wx) Annotations() []schema.Annotation {
  80. return []schema.Annotation{
  81. entsql.WithComments(true),
  82. entsql.Annotation{Table: "wx"},
  83. }
  84. }