wx.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. field.Uint64("ctype").Default(1).Optional().
  70. Annotations(entsql.WithComments(true)).
  71. Comment("账号类型:1-个微 2-企微"),
  72. }
  73. }
  74. func (Wx) Mixin() []ent.Mixin {
  75. return []ent.Mixin{
  76. mixins.IDMixin{},
  77. mixins.StatusMixin{},
  78. localmixin.SoftDeleteMixin{},
  79. }
  80. }
  81. func (Wx) Indexes() []ent.Index {
  82. return []ent.Index{
  83. index.Fields("server_id", "port", "ctype").Unique(),
  84. index.Fields("wxid").Unique(),
  85. index.Fields("account"),
  86. index.Fields("nickname"),
  87. index.Fields("tel"),
  88. }
  89. }
  90. func (Wx) Edges() []ent.Edge {
  91. return []ent.Edge{
  92. edge.From("server", Server.Type).Ref("wxs").Unique().Field("server_id"),
  93. edge.From("agent", Agent.Type).
  94. Ref("wx_agent").
  95. Unique().
  96. Field("agent_id").
  97. Required(),
  98. }
  99. }
  100. func (Wx) Annotations() []schema.Annotation {
  101. return []schema.Annotation{
  102. entsql.WithComments(true),
  103. entsql.Annotation{Table: "wx"},
  104. }
  105. }