wx.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/agent"
  8. "wechat-api/ent/server"
  9. "wechat-api/ent/wx"
  10. "entgo.io/ent"
  11. "entgo.io/ent/dialect/sql"
  12. )
  13. // Wx is the model entity for the Wx schema.
  14. type Wx struct {
  15. config `json:"-"`
  16. // ID of the ent.
  17. ID uint64 `json:"id,omitempty"`
  18. // Create Time | 创建日期
  19. CreatedAt time.Time `json:"created_at,omitempty"`
  20. // Update Time | 修改日期
  21. UpdatedAt time.Time `json:"updated_at,omitempty"`
  22. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  23. Status uint8 `json:"status,omitempty"`
  24. // Delete Time | 删除日期
  25. DeletedAt time.Time `json:"deleted_at,omitempty"`
  26. // 服务器id
  27. ServerID uint64 `json:"server_id,omitempty"`
  28. // 端口号
  29. Port string `json:"port,omitempty"`
  30. // 进程号
  31. ProcessID string `json:"process_id,omitempty"`
  32. // 回调地址
  33. Callback string `json:"callback,omitempty"`
  34. // 微信id
  35. Wxid string `json:"wxid,omitempty"`
  36. // 微信账号
  37. Account string `json:"account,omitempty"`
  38. // 微信昵称
  39. Nickname string `json:"nickname,omitempty"`
  40. // 手机号
  41. Tel string `json:"tel,omitempty"`
  42. // 微信头像
  43. HeadBig string `json:"head_big,omitempty"`
  44. // 机构 ID
  45. OrganizationID uint64 `json:"organization_id,omitempty"`
  46. // 模式ID
  47. AgentID uint64 `json:"agent_id,omitempty"`
  48. // 大模型服务地址
  49. APIBase string `json:"api_base,omitempty"`
  50. // 大模型服务密钥
  51. APIKey string `json:"api_key,omitempty"`
  52. // Edges holds the relations/edges for other nodes in the graph.
  53. // The values are being populated by the WxQuery when eager-loading is set.
  54. Edges WxEdges `json:"edges"`
  55. selectValues sql.SelectValues
  56. }
  57. // WxEdges holds the relations/edges for other nodes in the graph.
  58. type WxEdges struct {
  59. // Server holds the value of the server edge.
  60. Server *Server `json:"server,omitempty"`
  61. // Agent holds the value of the agent edge.
  62. Agent *Agent `json:"agent,omitempty"`
  63. // loadedTypes holds the information for reporting if a
  64. // type was loaded (or requested) in eager-loading or not.
  65. loadedTypes [2]bool
  66. }
  67. // ServerOrErr returns the Server value or an error if the edge
  68. // was not loaded in eager-loading, or loaded but was not found.
  69. func (e WxEdges) ServerOrErr() (*Server, error) {
  70. if e.Server != nil {
  71. return e.Server, nil
  72. } else if e.loadedTypes[0] {
  73. return nil, &NotFoundError{label: server.Label}
  74. }
  75. return nil, &NotLoadedError{edge: "server"}
  76. }
  77. // AgentOrErr returns the Agent value or an error if the edge
  78. // was not loaded in eager-loading, or loaded but was not found.
  79. func (e WxEdges) AgentOrErr() (*Agent, error) {
  80. if e.Agent != nil {
  81. return e.Agent, nil
  82. } else if e.loadedTypes[1] {
  83. return nil, &NotFoundError{label: agent.Label}
  84. }
  85. return nil, &NotLoadedError{edge: "agent"}
  86. }
  87. // scanValues returns the types for scanning values from sql.Rows.
  88. func (*Wx) scanValues(columns []string) ([]any, error) {
  89. values := make([]any, len(columns))
  90. for i := range columns {
  91. switch columns[i] {
  92. case wx.FieldID, wx.FieldStatus, wx.FieldServerID, wx.FieldOrganizationID, wx.FieldAgentID:
  93. values[i] = new(sql.NullInt64)
  94. case wx.FieldPort, wx.FieldProcessID, wx.FieldCallback, wx.FieldWxid, wx.FieldAccount, wx.FieldNickname, wx.FieldTel, wx.FieldHeadBig, wx.FieldAPIBase, wx.FieldAPIKey:
  95. values[i] = new(sql.NullString)
  96. case wx.FieldCreatedAt, wx.FieldUpdatedAt, wx.FieldDeletedAt:
  97. values[i] = new(sql.NullTime)
  98. default:
  99. values[i] = new(sql.UnknownType)
  100. }
  101. }
  102. return values, nil
  103. }
  104. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  105. // to the Wx fields.
  106. func (w *Wx) assignValues(columns []string, values []any) error {
  107. if m, n := len(values), len(columns); m < n {
  108. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  109. }
  110. for i := range columns {
  111. switch columns[i] {
  112. case wx.FieldID:
  113. value, ok := values[i].(*sql.NullInt64)
  114. if !ok {
  115. return fmt.Errorf("unexpected type %T for field id", value)
  116. }
  117. w.ID = uint64(value.Int64)
  118. case wx.FieldCreatedAt:
  119. if value, ok := values[i].(*sql.NullTime); !ok {
  120. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  121. } else if value.Valid {
  122. w.CreatedAt = value.Time
  123. }
  124. case wx.FieldUpdatedAt:
  125. if value, ok := values[i].(*sql.NullTime); !ok {
  126. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  127. } else if value.Valid {
  128. w.UpdatedAt = value.Time
  129. }
  130. case wx.FieldStatus:
  131. if value, ok := values[i].(*sql.NullInt64); !ok {
  132. return fmt.Errorf("unexpected type %T for field status", values[i])
  133. } else if value.Valid {
  134. w.Status = uint8(value.Int64)
  135. }
  136. case wx.FieldDeletedAt:
  137. if value, ok := values[i].(*sql.NullTime); !ok {
  138. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  139. } else if value.Valid {
  140. w.DeletedAt = value.Time
  141. }
  142. case wx.FieldServerID:
  143. if value, ok := values[i].(*sql.NullInt64); !ok {
  144. return fmt.Errorf("unexpected type %T for field server_id", values[i])
  145. } else if value.Valid {
  146. w.ServerID = uint64(value.Int64)
  147. }
  148. case wx.FieldPort:
  149. if value, ok := values[i].(*sql.NullString); !ok {
  150. return fmt.Errorf("unexpected type %T for field port", values[i])
  151. } else if value.Valid {
  152. w.Port = value.String
  153. }
  154. case wx.FieldProcessID:
  155. if value, ok := values[i].(*sql.NullString); !ok {
  156. return fmt.Errorf("unexpected type %T for field process_id", values[i])
  157. } else if value.Valid {
  158. w.ProcessID = value.String
  159. }
  160. case wx.FieldCallback:
  161. if value, ok := values[i].(*sql.NullString); !ok {
  162. return fmt.Errorf("unexpected type %T for field callback", values[i])
  163. } else if value.Valid {
  164. w.Callback = value.String
  165. }
  166. case wx.FieldWxid:
  167. if value, ok := values[i].(*sql.NullString); !ok {
  168. return fmt.Errorf("unexpected type %T for field wxid", values[i])
  169. } else if value.Valid {
  170. w.Wxid = value.String
  171. }
  172. case wx.FieldAccount:
  173. if value, ok := values[i].(*sql.NullString); !ok {
  174. return fmt.Errorf("unexpected type %T for field account", values[i])
  175. } else if value.Valid {
  176. w.Account = value.String
  177. }
  178. case wx.FieldNickname:
  179. if value, ok := values[i].(*sql.NullString); !ok {
  180. return fmt.Errorf("unexpected type %T for field nickname", values[i])
  181. } else if value.Valid {
  182. w.Nickname = value.String
  183. }
  184. case wx.FieldTel:
  185. if value, ok := values[i].(*sql.NullString); !ok {
  186. return fmt.Errorf("unexpected type %T for field tel", values[i])
  187. } else if value.Valid {
  188. w.Tel = value.String
  189. }
  190. case wx.FieldHeadBig:
  191. if value, ok := values[i].(*sql.NullString); !ok {
  192. return fmt.Errorf("unexpected type %T for field head_big", values[i])
  193. } else if value.Valid {
  194. w.HeadBig = value.String
  195. }
  196. case wx.FieldOrganizationID:
  197. if value, ok := values[i].(*sql.NullInt64); !ok {
  198. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  199. } else if value.Valid {
  200. w.OrganizationID = uint64(value.Int64)
  201. }
  202. case wx.FieldAgentID:
  203. if value, ok := values[i].(*sql.NullInt64); !ok {
  204. return fmt.Errorf("unexpected type %T for field agent_id", values[i])
  205. } else if value.Valid {
  206. w.AgentID = uint64(value.Int64)
  207. }
  208. case wx.FieldAPIBase:
  209. if value, ok := values[i].(*sql.NullString); !ok {
  210. return fmt.Errorf("unexpected type %T for field api_base", values[i])
  211. } else if value.Valid {
  212. w.APIBase = value.String
  213. }
  214. case wx.FieldAPIKey:
  215. if value, ok := values[i].(*sql.NullString); !ok {
  216. return fmt.Errorf("unexpected type %T for field api_key", values[i])
  217. } else if value.Valid {
  218. w.APIKey = value.String
  219. }
  220. default:
  221. w.selectValues.Set(columns[i], values[i])
  222. }
  223. }
  224. return nil
  225. }
  226. // Value returns the ent.Value that was dynamically selected and assigned to the Wx.
  227. // This includes values selected through modifiers, order, etc.
  228. func (w *Wx) Value(name string) (ent.Value, error) {
  229. return w.selectValues.Get(name)
  230. }
  231. // QueryServer queries the "server" edge of the Wx entity.
  232. func (w *Wx) QueryServer() *ServerQuery {
  233. return NewWxClient(w.config).QueryServer(w)
  234. }
  235. // QueryAgent queries the "agent" edge of the Wx entity.
  236. func (w *Wx) QueryAgent() *AgentQuery {
  237. return NewWxClient(w.config).QueryAgent(w)
  238. }
  239. // Update returns a builder for updating this Wx.
  240. // Note that you need to call Wx.Unwrap() before calling this method if this Wx
  241. // was returned from a transaction, and the transaction was committed or rolled back.
  242. func (w *Wx) Update() *WxUpdateOne {
  243. return NewWxClient(w.config).UpdateOne(w)
  244. }
  245. // Unwrap unwraps the Wx entity that was returned from a transaction after it was closed,
  246. // so that all future queries will be executed through the driver which created the transaction.
  247. func (w *Wx) Unwrap() *Wx {
  248. _tx, ok := w.config.driver.(*txDriver)
  249. if !ok {
  250. panic("ent: Wx is not a transactional entity")
  251. }
  252. w.config.driver = _tx.drv
  253. return w
  254. }
  255. // String implements the fmt.Stringer.
  256. func (w *Wx) String() string {
  257. var builder strings.Builder
  258. builder.WriteString("Wx(")
  259. builder.WriteString(fmt.Sprintf("id=%v, ", w.ID))
  260. builder.WriteString("created_at=")
  261. builder.WriteString(w.CreatedAt.Format(time.ANSIC))
  262. builder.WriteString(", ")
  263. builder.WriteString("updated_at=")
  264. builder.WriteString(w.UpdatedAt.Format(time.ANSIC))
  265. builder.WriteString(", ")
  266. builder.WriteString("status=")
  267. builder.WriteString(fmt.Sprintf("%v", w.Status))
  268. builder.WriteString(", ")
  269. builder.WriteString("deleted_at=")
  270. builder.WriteString(w.DeletedAt.Format(time.ANSIC))
  271. builder.WriteString(", ")
  272. builder.WriteString("server_id=")
  273. builder.WriteString(fmt.Sprintf("%v", w.ServerID))
  274. builder.WriteString(", ")
  275. builder.WriteString("port=")
  276. builder.WriteString(w.Port)
  277. builder.WriteString(", ")
  278. builder.WriteString("process_id=")
  279. builder.WriteString(w.ProcessID)
  280. builder.WriteString(", ")
  281. builder.WriteString("callback=")
  282. builder.WriteString(w.Callback)
  283. builder.WriteString(", ")
  284. builder.WriteString("wxid=")
  285. builder.WriteString(w.Wxid)
  286. builder.WriteString(", ")
  287. builder.WriteString("account=")
  288. builder.WriteString(w.Account)
  289. builder.WriteString(", ")
  290. builder.WriteString("nickname=")
  291. builder.WriteString(w.Nickname)
  292. builder.WriteString(", ")
  293. builder.WriteString("tel=")
  294. builder.WriteString(w.Tel)
  295. builder.WriteString(", ")
  296. builder.WriteString("head_big=")
  297. builder.WriteString(w.HeadBig)
  298. builder.WriteString(", ")
  299. builder.WriteString("organization_id=")
  300. builder.WriteString(fmt.Sprintf("%v", w.OrganizationID))
  301. builder.WriteString(", ")
  302. builder.WriteString("agent_id=")
  303. builder.WriteString(fmt.Sprintf("%v", w.AgentID))
  304. builder.WriteString(", ")
  305. builder.WriteString("api_base=")
  306. builder.WriteString(w.APIBase)
  307. builder.WriteString(", ")
  308. builder.WriteString("api_key=")
  309. builder.WriteString(w.APIKey)
  310. builder.WriteByte(')')
  311. return builder.String()
  312. }
  313. // Wxes is a parsable slice of Wx.
  314. type Wxes []*Wx