wx.go 13 KB

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