wx.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. agent_base_wx_agent *string
  65. selectValues sql.SelectValues
  66. }
  67. // WxEdges holds the relations/edges for other nodes in the graph.
  68. type WxEdges struct {
  69. // Server holds the value of the server edge.
  70. Server *Server `json:"server,omitempty"`
  71. // Agent holds the value of the agent edge.
  72. Agent *Agent `json:"agent,omitempty"`
  73. // loadedTypes holds the information for reporting if a
  74. // type was loaded (or requested) in eager-loading or not.
  75. loadedTypes [2]bool
  76. }
  77. // ServerOrErr returns the Server value or an error if the edge
  78. // was not loaded in eager-loading, or loaded but was not found.
  79. func (e WxEdges) ServerOrErr() (*Server, error) {
  80. if e.Server != nil {
  81. return e.Server, nil
  82. } else if e.loadedTypes[0] {
  83. return nil, &NotFoundError{label: server.Label}
  84. }
  85. return nil, &NotLoadedError{edge: "server"}
  86. }
  87. // AgentOrErr returns the Agent value or an error if the edge
  88. // was not loaded in eager-loading, or loaded but was not found.
  89. func (e WxEdges) AgentOrErr() (*Agent, error) {
  90. if e.Agent != nil {
  91. return e.Agent, nil
  92. } else if e.loadedTypes[1] {
  93. return nil, &NotFoundError{label: agent.Label}
  94. }
  95. return nil, &NotLoadedError{edge: "agent"}
  96. }
  97. // scanValues returns the types for scanning values from sql.Rows.
  98. func (*Wx) scanValues(columns []string) ([]any, error) {
  99. values := make([]any, len(columns))
  100. for i := range columns {
  101. switch columns[i] {
  102. case wx.FieldAllowList, wx.FieldGroupAllowList, wx.FieldBlockList, wx.FieldGroupBlockList:
  103. values[i] = new([]byte)
  104. case wx.FieldID, wx.FieldStatus, wx.FieldServerID, wx.FieldOrganizationID, wx.FieldAgentID:
  105. values[i] = new(sql.NullInt64)
  106. case wx.FieldPort, wx.FieldProcessID, wx.FieldCallback, wx.FieldWxid, wx.FieldAccount, wx.FieldNickname, wx.FieldTel, wx.FieldHeadBig, wx.FieldAPIBase, wx.FieldAPIKey:
  107. values[i] = new(sql.NullString)
  108. case wx.FieldCreatedAt, wx.FieldUpdatedAt, wx.FieldDeletedAt:
  109. values[i] = new(sql.NullTime)
  110. case wx.ForeignKeys[0]: // agent_base_wx_agent
  111. values[i] = new(sql.NullString)
  112. default:
  113. values[i] = new(sql.UnknownType)
  114. }
  115. }
  116. return values, nil
  117. }
  118. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  119. // to the Wx fields.
  120. func (w *Wx) assignValues(columns []string, values []any) error {
  121. if m, n := len(values), len(columns); m < n {
  122. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  123. }
  124. for i := range columns {
  125. switch columns[i] {
  126. case wx.FieldID:
  127. value, ok := values[i].(*sql.NullInt64)
  128. if !ok {
  129. return fmt.Errorf("unexpected type %T for field id", value)
  130. }
  131. w.ID = uint64(value.Int64)
  132. case wx.FieldCreatedAt:
  133. if value, ok := values[i].(*sql.NullTime); !ok {
  134. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  135. } else if value.Valid {
  136. w.CreatedAt = value.Time
  137. }
  138. case wx.FieldUpdatedAt:
  139. if value, ok := values[i].(*sql.NullTime); !ok {
  140. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  141. } else if value.Valid {
  142. w.UpdatedAt = value.Time
  143. }
  144. case wx.FieldStatus:
  145. if value, ok := values[i].(*sql.NullInt64); !ok {
  146. return fmt.Errorf("unexpected type %T for field status", values[i])
  147. } else if value.Valid {
  148. w.Status = uint8(value.Int64)
  149. }
  150. case wx.FieldDeletedAt:
  151. if value, ok := values[i].(*sql.NullTime); !ok {
  152. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  153. } else if value.Valid {
  154. w.DeletedAt = value.Time
  155. }
  156. case wx.FieldServerID:
  157. if value, ok := values[i].(*sql.NullInt64); !ok {
  158. return fmt.Errorf("unexpected type %T for field server_id", values[i])
  159. } else if value.Valid {
  160. w.ServerID = uint64(value.Int64)
  161. }
  162. case wx.FieldPort:
  163. if value, ok := values[i].(*sql.NullString); !ok {
  164. return fmt.Errorf("unexpected type %T for field port", values[i])
  165. } else if value.Valid {
  166. w.Port = value.String
  167. }
  168. case wx.FieldProcessID:
  169. if value, ok := values[i].(*sql.NullString); !ok {
  170. return fmt.Errorf("unexpected type %T for field process_id", values[i])
  171. } else if value.Valid {
  172. w.ProcessID = value.String
  173. }
  174. case wx.FieldCallback:
  175. if value, ok := values[i].(*sql.NullString); !ok {
  176. return fmt.Errorf("unexpected type %T for field callback", values[i])
  177. } else if value.Valid {
  178. w.Callback = value.String
  179. }
  180. case wx.FieldWxid:
  181. if value, ok := values[i].(*sql.NullString); !ok {
  182. return fmt.Errorf("unexpected type %T for field wxid", values[i])
  183. } else if value.Valid {
  184. w.Wxid = value.String
  185. }
  186. case wx.FieldAccount:
  187. if value, ok := values[i].(*sql.NullString); !ok {
  188. return fmt.Errorf("unexpected type %T for field account", values[i])
  189. } else if value.Valid {
  190. w.Account = value.String
  191. }
  192. case wx.FieldNickname:
  193. if value, ok := values[i].(*sql.NullString); !ok {
  194. return fmt.Errorf("unexpected type %T for field nickname", values[i])
  195. } else if value.Valid {
  196. w.Nickname = value.String
  197. }
  198. case wx.FieldTel:
  199. if value, ok := values[i].(*sql.NullString); !ok {
  200. return fmt.Errorf("unexpected type %T for field tel", values[i])
  201. } else if value.Valid {
  202. w.Tel = value.String
  203. }
  204. case wx.FieldHeadBig:
  205. if value, ok := values[i].(*sql.NullString); !ok {
  206. return fmt.Errorf("unexpected type %T for field head_big", values[i])
  207. } else if value.Valid {
  208. w.HeadBig = value.String
  209. }
  210. case wx.FieldOrganizationID:
  211. if value, ok := values[i].(*sql.NullInt64); !ok {
  212. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  213. } else if value.Valid {
  214. w.OrganizationID = uint64(value.Int64)
  215. }
  216. case wx.FieldAgentID:
  217. if value, ok := values[i].(*sql.NullInt64); !ok {
  218. return fmt.Errorf("unexpected type %T for field agent_id", values[i])
  219. } else if value.Valid {
  220. w.AgentID = uint64(value.Int64)
  221. }
  222. case wx.FieldAPIBase:
  223. if value, ok := values[i].(*sql.NullString); !ok {
  224. return fmt.Errorf("unexpected type %T for field api_base", values[i])
  225. } else if value.Valid {
  226. w.APIBase = value.String
  227. }
  228. case wx.FieldAPIKey:
  229. if value, ok := values[i].(*sql.NullString); !ok {
  230. return fmt.Errorf("unexpected type %T for field api_key", values[i])
  231. } else if value.Valid {
  232. w.APIKey = value.String
  233. }
  234. case wx.FieldAllowList:
  235. if value, ok := values[i].(*[]byte); !ok {
  236. return fmt.Errorf("unexpected type %T for field allow_list", values[i])
  237. } else if value != nil && len(*value) > 0 {
  238. if err := json.Unmarshal(*value, &w.AllowList); err != nil {
  239. return fmt.Errorf("unmarshal field allow_list: %w", err)
  240. }
  241. }
  242. case wx.FieldGroupAllowList:
  243. if value, ok := values[i].(*[]byte); !ok {
  244. return fmt.Errorf("unexpected type %T for field group_allow_list", values[i])
  245. } else if value != nil && len(*value) > 0 {
  246. if err := json.Unmarshal(*value, &w.GroupAllowList); err != nil {
  247. return fmt.Errorf("unmarshal field group_allow_list: %w", err)
  248. }
  249. }
  250. case wx.FieldBlockList:
  251. if value, ok := values[i].(*[]byte); !ok {
  252. return fmt.Errorf("unexpected type %T for field block_list", values[i])
  253. } else if value != nil && len(*value) > 0 {
  254. if err := json.Unmarshal(*value, &w.BlockList); err != nil {
  255. return fmt.Errorf("unmarshal field block_list: %w", err)
  256. }
  257. }
  258. case wx.FieldGroupBlockList:
  259. if value, ok := values[i].(*[]byte); !ok {
  260. return fmt.Errorf("unexpected type %T for field group_block_list", values[i])
  261. } else if value != nil && len(*value) > 0 {
  262. if err := json.Unmarshal(*value, &w.GroupBlockList); err != nil {
  263. return fmt.Errorf("unmarshal field group_block_list: %w", err)
  264. }
  265. }
  266. case wx.ForeignKeys[0]:
  267. if value, ok := values[i].(*sql.NullString); !ok {
  268. return fmt.Errorf("unexpected type %T for field agent_base_wx_agent", values[i])
  269. } else if value.Valid {
  270. w.agent_base_wx_agent = new(string)
  271. *w.agent_base_wx_agent = value.String
  272. }
  273. default:
  274. w.selectValues.Set(columns[i], values[i])
  275. }
  276. }
  277. return nil
  278. }
  279. // Value returns the ent.Value that was dynamically selected and assigned to the Wx.
  280. // This includes values selected through modifiers, order, etc.
  281. func (w *Wx) Value(name string) (ent.Value, error) {
  282. return w.selectValues.Get(name)
  283. }
  284. // QueryServer queries the "server" edge of the Wx entity.
  285. func (w *Wx) QueryServer() *ServerQuery {
  286. return NewWxClient(w.config).QueryServer(w)
  287. }
  288. // QueryAgent queries the "agent" edge of the Wx entity.
  289. func (w *Wx) QueryAgent() *AgentQuery {
  290. return NewWxClient(w.config).QueryAgent(w)
  291. }
  292. // Update returns a builder for updating this Wx.
  293. // Note that you need to call Wx.Unwrap() before calling this method if this Wx
  294. // was returned from a transaction, and the transaction was committed or rolled back.
  295. func (w *Wx) Update() *WxUpdateOne {
  296. return NewWxClient(w.config).UpdateOne(w)
  297. }
  298. // Unwrap unwraps the Wx entity that was returned from a transaction after it was closed,
  299. // so that all future queries will be executed through the driver which created the transaction.
  300. func (w *Wx) Unwrap() *Wx {
  301. _tx, ok := w.config.driver.(*txDriver)
  302. if !ok {
  303. panic("ent: Wx is not a transactional entity")
  304. }
  305. w.config.driver = _tx.drv
  306. return w
  307. }
  308. // String implements the fmt.Stringer.
  309. func (w *Wx) String() string {
  310. var builder strings.Builder
  311. builder.WriteString("Wx(")
  312. builder.WriteString(fmt.Sprintf("id=%v, ", w.ID))
  313. builder.WriteString("created_at=")
  314. builder.WriteString(w.CreatedAt.Format(time.ANSIC))
  315. builder.WriteString(", ")
  316. builder.WriteString("updated_at=")
  317. builder.WriteString(w.UpdatedAt.Format(time.ANSIC))
  318. builder.WriteString(", ")
  319. builder.WriteString("status=")
  320. builder.WriteString(fmt.Sprintf("%v", w.Status))
  321. builder.WriteString(", ")
  322. builder.WriteString("deleted_at=")
  323. builder.WriteString(w.DeletedAt.Format(time.ANSIC))
  324. builder.WriteString(", ")
  325. builder.WriteString("server_id=")
  326. builder.WriteString(fmt.Sprintf("%v", w.ServerID))
  327. builder.WriteString(", ")
  328. builder.WriteString("port=")
  329. builder.WriteString(w.Port)
  330. builder.WriteString(", ")
  331. builder.WriteString("process_id=")
  332. builder.WriteString(w.ProcessID)
  333. builder.WriteString(", ")
  334. builder.WriteString("callback=")
  335. builder.WriteString(w.Callback)
  336. builder.WriteString(", ")
  337. builder.WriteString("wxid=")
  338. builder.WriteString(w.Wxid)
  339. builder.WriteString(", ")
  340. builder.WriteString("account=")
  341. builder.WriteString(w.Account)
  342. builder.WriteString(", ")
  343. builder.WriteString("nickname=")
  344. builder.WriteString(w.Nickname)
  345. builder.WriteString(", ")
  346. builder.WriteString("tel=")
  347. builder.WriteString(w.Tel)
  348. builder.WriteString(", ")
  349. builder.WriteString("head_big=")
  350. builder.WriteString(w.HeadBig)
  351. builder.WriteString(", ")
  352. builder.WriteString("organization_id=")
  353. builder.WriteString(fmt.Sprintf("%v", w.OrganizationID))
  354. builder.WriteString(", ")
  355. builder.WriteString("agent_id=")
  356. builder.WriteString(fmt.Sprintf("%v", w.AgentID))
  357. builder.WriteString(", ")
  358. builder.WriteString("api_base=")
  359. builder.WriteString(w.APIBase)
  360. builder.WriteString(", ")
  361. builder.WriteString("api_key=")
  362. builder.WriteString(w.APIKey)
  363. builder.WriteString(", ")
  364. builder.WriteString("allow_list=")
  365. builder.WriteString(fmt.Sprintf("%v", w.AllowList))
  366. builder.WriteString(", ")
  367. builder.WriteString("group_allow_list=")
  368. builder.WriteString(fmt.Sprintf("%v", w.GroupAllowList))
  369. builder.WriteString(", ")
  370. builder.WriteString("block_list=")
  371. builder.WriteString(fmt.Sprintf("%v", w.BlockList))
  372. builder.WriteString(", ")
  373. builder.WriteString("group_block_list=")
  374. builder.WriteString(fmt.Sprintf("%v", w.GroupBlockList))
  375. builder.WriteByte(')')
  376. return builder.String()
  377. }
  378. // Wxes is a parsable slice of Wx.
  379. type Wxes []*Wx