agent.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // Agent is the model entity for the Agent schema.
  12. type Agent struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID uint64 `json:"id,omitempty"`
  16. // Create Time | 创建日期
  17. CreatedAt time.Time `json:"created_at,omitempty"`
  18. // Update Time | 修改日期
  19. UpdatedAt time.Time `json:"updated_at,omitempty"`
  20. // Delete Time | 删除日期
  21. DeletedAt time.Time `json:"deleted_at,omitempty"`
  22. // name | 角色名称
  23. Name string `json:"name,omitempty"`
  24. // role | 角色设定
  25. Role string `json:"role,omitempty"`
  26. // status | 状态 1-正常 2-禁用
  27. Status int `json:"status,omitempty"`
  28. // background | 背景介绍
  29. Background string `json:"background,omitempty"`
  30. // examples | 对话案例
  31. Examples string `json:"examples,omitempty"`
  32. // organization_id | 租户ID
  33. OrganizationID uint64 `json:"organization_id,omitempty"`
  34. // dataset_id | 知识库ID
  35. DatasetID string `json:"dataset_id,omitempty"`
  36. // collection_id | 集合ID
  37. CollectionID string `json:"collection_id,omitempty"`
  38. // model | 模型
  39. Model string `json:"model,omitempty"`
  40. // api_base | api_base
  41. APIBase string `json:"api_base,omitempty"`
  42. // api_key | api_key
  43. APIKey string `json:"api_key,omitempty"`
  44. // type | 类型 1. 内置 2. 接入
  45. Type int `json:"type,omitempty"`
  46. // Edges holds the relations/edges for other nodes in the graph.
  47. // The values are being populated by the AgentQuery when eager-loading is set.
  48. Edges AgentEdges `json:"edges"`
  49. selectValues sql.SelectValues
  50. }
  51. // AgentEdges holds the relations/edges for other nodes in the graph.
  52. type AgentEdges struct {
  53. // WxAgent holds the value of the wx_agent edge.
  54. WxAgent []*Wx `json:"wx_agent,omitempty"`
  55. // TokenAgent holds the value of the token_agent edge.
  56. TokenAgent []*Token `json:"token_agent,omitempty"`
  57. // WaAgent holds the value of the wa_agent edge.
  58. WaAgent []*Whatsapp `json:"wa_agent,omitempty"`
  59. // XjsAgent holds the value of the xjs_agent edge.
  60. XjsAgent []*XunjiService `json:"xjs_agent,omitempty"`
  61. // KeyAgent holds the value of the key_agent edge.
  62. KeyAgent []*ApiKey `json:"key_agent,omitempty"`
  63. // loadedTypes holds the information for reporting if a
  64. // type was loaded (or requested) in eager-loading or not.
  65. loadedTypes [5]bool
  66. }
  67. // WxAgentOrErr returns the WxAgent value or an error if the edge
  68. // was not loaded in eager-loading.
  69. func (e AgentEdges) WxAgentOrErr() ([]*Wx, error) {
  70. if e.loadedTypes[0] {
  71. return e.WxAgent, nil
  72. }
  73. return nil, &NotLoadedError{edge: "wx_agent"}
  74. }
  75. // TokenAgentOrErr returns the TokenAgent value or an error if the edge
  76. // was not loaded in eager-loading.
  77. func (e AgentEdges) TokenAgentOrErr() ([]*Token, error) {
  78. if e.loadedTypes[1] {
  79. return e.TokenAgent, nil
  80. }
  81. return nil, &NotLoadedError{edge: "token_agent"}
  82. }
  83. // WaAgentOrErr returns the WaAgent value or an error if the edge
  84. // was not loaded in eager-loading.
  85. func (e AgentEdges) WaAgentOrErr() ([]*Whatsapp, error) {
  86. if e.loadedTypes[2] {
  87. return e.WaAgent, nil
  88. }
  89. return nil, &NotLoadedError{edge: "wa_agent"}
  90. }
  91. // XjsAgentOrErr returns the XjsAgent value or an error if the edge
  92. // was not loaded in eager-loading.
  93. func (e AgentEdges) XjsAgentOrErr() ([]*XunjiService, error) {
  94. if e.loadedTypes[3] {
  95. return e.XjsAgent, nil
  96. }
  97. return nil, &NotLoadedError{edge: "xjs_agent"}
  98. }
  99. // KeyAgentOrErr returns the KeyAgent value or an error if the edge
  100. // was not loaded in eager-loading.
  101. func (e AgentEdges) KeyAgentOrErr() ([]*ApiKey, error) {
  102. if e.loadedTypes[4] {
  103. return e.KeyAgent, nil
  104. }
  105. return nil, &NotLoadedError{edge: "key_agent"}
  106. }
  107. // scanValues returns the types for scanning values from sql.Rows.
  108. func (*Agent) scanValues(columns []string) ([]any, error) {
  109. values := make([]any, len(columns))
  110. for i := range columns {
  111. switch columns[i] {
  112. case agent.FieldID, agent.FieldStatus, agent.FieldOrganizationID, agent.FieldType:
  113. values[i] = new(sql.NullInt64)
  114. case agent.FieldName, agent.FieldRole, agent.FieldBackground, agent.FieldExamples, agent.FieldDatasetID, agent.FieldCollectionID, agent.FieldModel, agent.FieldAPIBase, agent.FieldAPIKey:
  115. values[i] = new(sql.NullString)
  116. case agent.FieldCreatedAt, agent.FieldUpdatedAt, agent.FieldDeletedAt:
  117. values[i] = new(sql.NullTime)
  118. default:
  119. values[i] = new(sql.UnknownType)
  120. }
  121. }
  122. return values, nil
  123. }
  124. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  125. // to the Agent fields.
  126. func (a *Agent) assignValues(columns []string, values []any) error {
  127. if m, n := len(values), len(columns); m < n {
  128. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  129. }
  130. for i := range columns {
  131. switch columns[i] {
  132. case agent.FieldID:
  133. value, ok := values[i].(*sql.NullInt64)
  134. if !ok {
  135. return fmt.Errorf("unexpected type %T for field id", value)
  136. }
  137. a.ID = uint64(value.Int64)
  138. case agent.FieldCreatedAt:
  139. if value, ok := values[i].(*sql.NullTime); !ok {
  140. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  141. } else if value.Valid {
  142. a.CreatedAt = value.Time
  143. }
  144. case agent.FieldUpdatedAt:
  145. if value, ok := values[i].(*sql.NullTime); !ok {
  146. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  147. } else if value.Valid {
  148. a.UpdatedAt = value.Time
  149. }
  150. case agent.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. a.DeletedAt = value.Time
  155. }
  156. case agent.FieldName:
  157. if value, ok := values[i].(*sql.NullString); !ok {
  158. return fmt.Errorf("unexpected type %T for field name", values[i])
  159. } else if value.Valid {
  160. a.Name = value.String
  161. }
  162. case agent.FieldRole:
  163. if value, ok := values[i].(*sql.NullString); !ok {
  164. return fmt.Errorf("unexpected type %T for field role", values[i])
  165. } else if value.Valid {
  166. a.Role = value.String
  167. }
  168. case agent.FieldStatus:
  169. if value, ok := values[i].(*sql.NullInt64); !ok {
  170. return fmt.Errorf("unexpected type %T for field status", values[i])
  171. } else if value.Valid {
  172. a.Status = int(value.Int64)
  173. }
  174. case agent.FieldBackground:
  175. if value, ok := values[i].(*sql.NullString); !ok {
  176. return fmt.Errorf("unexpected type %T for field background", values[i])
  177. } else if value.Valid {
  178. a.Background = value.String
  179. }
  180. case agent.FieldExamples:
  181. if value, ok := values[i].(*sql.NullString); !ok {
  182. return fmt.Errorf("unexpected type %T for field examples", values[i])
  183. } else if value.Valid {
  184. a.Examples = value.String
  185. }
  186. case agent.FieldOrganizationID:
  187. if value, ok := values[i].(*sql.NullInt64); !ok {
  188. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  189. } else if value.Valid {
  190. a.OrganizationID = uint64(value.Int64)
  191. }
  192. case agent.FieldDatasetID:
  193. if value, ok := values[i].(*sql.NullString); !ok {
  194. return fmt.Errorf("unexpected type %T for field dataset_id", values[i])
  195. } else if value.Valid {
  196. a.DatasetID = value.String
  197. }
  198. case agent.FieldCollectionID:
  199. if value, ok := values[i].(*sql.NullString); !ok {
  200. return fmt.Errorf("unexpected type %T for field collection_id", values[i])
  201. } else if value.Valid {
  202. a.CollectionID = value.String
  203. }
  204. case agent.FieldModel:
  205. if value, ok := values[i].(*sql.NullString); !ok {
  206. return fmt.Errorf("unexpected type %T for field model", values[i])
  207. } else if value.Valid {
  208. a.Model = value.String
  209. }
  210. case agent.FieldAPIBase:
  211. if value, ok := values[i].(*sql.NullString); !ok {
  212. return fmt.Errorf("unexpected type %T for field api_base", values[i])
  213. } else if value.Valid {
  214. a.APIBase = value.String
  215. }
  216. case agent.FieldAPIKey:
  217. if value, ok := values[i].(*sql.NullString); !ok {
  218. return fmt.Errorf("unexpected type %T for field api_key", values[i])
  219. } else if value.Valid {
  220. a.APIKey = value.String
  221. }
  222. case agent.FieldType:
  223. if value, ok := values[i].(*sql.NullInt64); !ok {
  224. return fmt.Errorf("unexpected type %T for field type", values[i])
  225. } else if value.Valid {
  226. a.Type = int(value.Int64)
  227. }
  228. default:
  229. a.selectValues.Set(columns[i], values[i])
  230. }
  231. }
  232. return nil
  233. }
  234. // Value returns the ent.Value that was dynamically selected and assigned to the Agent.
  235. // This includes values selected through modifiers, order, etc.
  236. func (a *Agent) Value(name string) (ent.Value, error) {
  237. return a.selectValues.Get(name)
  238. }
  239. // QueryWxAgent queries the "wx_agent" edge of the Agent entity.
  240. func (a *Agent) QueryWxAgent() *WxQuery {
  241. return NewAgentClient(a.config).QueryWxAgent(a)
  242. }
  243. // QueryTokenAgent queries the "token_agent" edge of the Agent entity.
  244. func (a *Agent) QueryTokenAgent() *TokenQuery {
  245. return NewAgentClient(a.config).QueryTokenAgent(a)
  246. }
  247. // QueryWaAgent queries the "wa_agent" edge of the Agent entity.
  248. func (a *Agent) QueryWaAgent() *WhatsappQuery {
  249. return NewAgentClient(a.config).QueryWaAgent(a)
  250. }
  251. // QueryXjsAgent queries the "xjs_agent" edge of the Agent entity.
  252. func (a *Agent) QueryXjsAgent() *XunjiServiceQuery {
  253. return NewAgentClient(a.config).QueryXjsAgent(a)
  254. }
  255. // QueryKeyAgent queries the "key_agent" edge of the Agent entity.
  256. func (a *Agent) QueryKeyAgent() *ApiKeyQuery {
  257. return NewAgentClient(a.config).QueryKeyAgent(a)
  258. }
  259. // Update returns a builder for updating this Agent.
  260. // Note that you need to call Agent.Unwrap() before calling this method if this Agent
  261. // was returned from a transaction, and the transaction was committed or rolled back.
  262. func (a *Agent) Update() *AgentUpdateOne {
  263. return NewAgentClient(a.config).UpdateOne(a)
  264. }
  265. // Unwrap unwraps the Agent entity that was returned from a transaction after it was closed,
  266. // so that all future queries will be executed through the driver which created the transaction.
  267. func (a *Agent) Unwrap() *Agent {
  268. _tx, ok := a.config.driver.(*txDriver)
  269. if !ok {
  270. panic("ent: Agent is not a transactional entity")
  271. }
  272. a.config.driver = _tx.drv
  273. return a
  274. }
  275. // String implements the fmt.Stringer.
  276. func (a *Agent) String() string {
  277. var builder strings.Builder
  278. builder.WriteString("Agent(")
  279. builder.WriteString(fmt.Sprintf("id=%v, ", a.ID))
  280. builder.WriteString("created_at=")
  281. builder.WriteString(a.CreatedAt.Format(time.ANSIC))
  282. builder.WriteString(", ")
  283. builder.WriteString("updated_at=")
  284. builder.WriteString(a.UpdatedAt.Format(time.ANSIC))
  285. builder.WriteString(", ")
  286. builder.WriteString("deleted_at=")
  287. builder.WriteString(a.DeletedAt.Format(time.ANSIC))
  288. builder.WriteString(", ")
  289. builder.WriteString("name=")
  290. builder.WriteString(a.Name)
  291. builder.WriteString(", ")
  292. builder.WriteString("role=")
  293. builder.WriteString(a.Role)
  294. builder.WriteString(", ")
  295. builder.WriteString("status=")
  296. builder.WriteString(fmt.Sprintf("%v", a.Status))
  297. builder.WriteString(", ")
  298. builder.WriteString("background=")
  299. builder.WriteString(a.Background)
  300. builder.WriteString(", ")
  301. builder.WriteString("examples=")
  302. builder.WriteString(a.Examples)
  303. builder.WriteString(", ")
  304. builder.WriteString("organization_id=")
  305. builder.WriteString(fmt.Sprintf("%v", a.OrganizationID))
  306. builder.WriteString(", ")
  307. builder.WriteString("dataset_id=")
  308. builder.WriteString(a.DatasetID)
  309. builder.WriteString(", ")
  310. builder.WriteString("collection_id=")
  311. builder.WriteString(a.CollectionID)
  312. builder.WriteString(", ")
  313. builder.WriteString("model=")
  314. builder.WriteString(a.Model)
  315. builder.WriteString(", ")
  316. builder.WriteString("api_base=")
  317. builder.WriteString(a.APIBase)
  318. builder.WriteString(", ")
  319. builder.WriteString("api_key=")
  320. builder.WriteString(a.APIKey)
  321. builder.WriteString(", ")
  322. builder.WriteString("type=")
  323. builder.WriteString(fmt.Sprintf("%v", a.Type))
  324. builder.WriteByte(')')
  325. return builder.String()
  326. }
  327. // Agents is a parsable slice of Agent.
  328. type Agents []*Agent