wx.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. }
  58. }
  59. func (Wx) Mixin() []ent.Mixin {
  60. return []ent.Mixin{
  61. mixins.IDMixin{},
  62. mixins.StatusMixin{},
  63. localmixin.SoftDeleteMixin{},
  64. }
  65. }
  66. func (Wx) Indexes() []ent.Index {
  67. return []ent.Index{
  68. index.Fields("server_id", "port").Unique(),
  69. index.Fields("wxid").Unique(),
  70. index.Fields("account"),
  71. index.Fields("nickname"),
  72. index.Fields("tel"),
  73. }
  74. }
  75. func (Wx) Edges() []ent.Edge {
  76. return []ent.Edge{
  77. edge.From("server", Server.Type).Ref("wxs").Unique().Field("server_id"),
  78. edge.From("agent", Agent.Type).
  79. Ref("wx_agent").
  80. Unique().
  81. Field("agent_id").
  82. Required(),
  83. }
  84. }
  85. func (Wx) Annotations() []schema.Annotation {
  86. return []schema.Annotation{
  87. entsql.WithComments(true),
  88. entsql.Annotation{Table: "wx"},
  89. }
  90. }