wx.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. field.String("api_base").Optional().Default("").
  52. Annotations(entsql.WithComments(true)).
  53. Comment("大模型服务地址"),
  54. field.String("api_key").Optional().Default("").
  55. Annotations(entsql.WithComments(true)).
  56. Comment("大模型服务密钥"),
  57. field.JSON("allow_list", []string{}).
  58. Annotations(entsql.WithComments(true)).
  59. Comment("白名单"),
  60. field.JSON("group_allow_list", []string{}).
  61. Annotations(entsql.WithComments(true)).
  62. Comment("群白名单"),
  63. field.JSON("block_list", []string{}).
  64. Annotations(entsql.WithComments(true)).
  65. Comment("黑名单"),
  66. field.JSON("group_block_list", []string{}).
  67. Annotations(entsql.WithComments(true)).
  68. Comment("群黑名单"),
  69. }
  70. }
  71. func (Wx) Mixin() []ent.Mixin {
  72. return []ent.Mixin{
  73. mixins.IDMixin{},
  74. mixins.StatusMixin{},
  75. localmixin.SoftDeleteMixin{},
  76. }
  77. }
  78. func (Wx) Indexes() []ent.Index {
  79. return []ent.Index{
  80. index.Fields("server_id", "port").Unique(),
  81. index.Fields("wxid").Unique(),
  82. index.Fields("account"),
  83. index.Fields("nickname"),
  84. index.Fields("tel"),
  85. }
  86. }
  87. func (Wx) Edges() []ent.Edge {
  88. return []ent.Edge{
  89. edge.From("server", Server.Type).Ref("wxs").Unique().Field("server_id"),
  90. edge.From("agent", Agent.Type).
  91. Ref("wx_agent").
  92. Unique().
  93. Field("agent_id").
  94. Required(),
  95. }
  96. }
  97. func (Wx) Annotations() []schema.Annotation {
  98. return []schema.Annotation{
  99. entsql.WithComments(true),
  100. entsql.Annotation{Table: "wx"},
  101. }
  102. }