agent.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. // Edges holds the relations/edges for other nodes in the graph.
  39. // The values are being populated by the AgentQuery when eager-loading is set.
  40. Edges AgentEdges `json:"edges"`
  41. selectValues sql.SelectValues
  42. }
  43. // AgentEdges holds the relations/edges for other nodes in the graph.
  44. type AgentEdges struct {
  45. // WxAgent holds the value of the wx_agent edge.
  46. WxAgent []*Wx `json:"wx_agent,omitempty"`
  47. // TokenAgent holds the value of the token_agent edge.
  48. TokenAgent []*Token `json:"token_agent,omitempty"`
  49. // WaAgent holds the value of the wa_agent edge.
  50. WaAgent []*Whatsapp `json:"wa_agent,omitempty"`
  51. // XjsAgent holds the value of the xjs_agent edge.
  52. XjsAgent []*XunjiService `json:"xjs_agent,omitempty"`
  53. // KeyAgent holds the value of the key_agent edge.
  54. KeyAgent []*ApiKey `json:"key_agent,omitempty"`
  55. // loadedTypes holds the information for reporting if a
  56. // type was loaded (or requested) in eager-loading or not.
  57. loadedTypes [5]bool
  58. }
  59. // WxAgentOrErr returns the WxAgent value or an error if the edge
  60. // was not loaded in eager-loading.
  61. func (e AgentEdges) WxAgentOrErr() ([]*Wx, error) {
  62. if e.loadedTypes[0] {
  63. return e.WxAgent, nil
  64. }
  65. return nil, &NotLoadedError{edge: "wx_agent"}
  66. }
  67. // TokenAgentOrErr returns the TokenAgent value or an error if the edge
  68. // was not loaded in eager-loading.
  69. func (e AgentEdges) TokenAgentOrErr() ([]*Token, error) {
  70. if e.loadedTypes[1] {
  71. return e.TokenAgent, nil
  72. }
  73. return nil, &NotLoadedError{edge: "token_agent"}
  74. }
  75. // WaAgentOrErr returns the WaAgent value or an error if the edge
  76. // was not loaded in eager-loading.
  77. func (e AgentEdges) WaAgentOrErr() ([]*Whatsapp, error) {
  78. if e.loadedTypes[2] {
  79. return e.WaAgent, nil
  80. }
  81. return nil, &NotLoadedError{edge: "wa_agent"}
  82. }
  83. // XjsAgentOrErr returns the XjsAgent value or an error if the edge
  84. // was not loaded in eager-loading.
  85. func (e AgentEdges) XjsAgentOrErr() ([]*XunjiService, error) {
  86. if e.loadedTypes[3] {
  87. return e.XjsAgent, nil
  88. }
  89. return nil, &NotLoadedError{edge: "xjs_agent"}
  90. }
  91. // KeyAgentOrErr returns the KeyAgent value or an error if the edge
  92. // was not loaded in eager-loading.
  93. func (e AgentEdges) KeyAgentOrErr() ([]*ApiKey, error) {
  94. if e.loadedTypes[4] {
  95. return e.KeyAgent, nil
  96. }
  97. return nil, &NotLoadedError{edge: "key_agent"}
  98. }
  99. // scanValues returns the types for scanning values from sql.Rows.
  100. func (*Agent) scanValues(columns []string) ([]any, error) {
  101. values := make([]any, len(columns))
  102. for i := range columns {
  103. switch columns[i] {
  104. case agent.FieldID, agent.FieldStatus, agent.FieldOrganizationID:
  105. values[i] = new(sql.NullInt64)
  106. case agent.FieldName, agent.FieldRole, agent.FieldBackground, agent.FieldExamples, agent.FieldDatasetID, agent.FieldCollectionID:
  107. values[i] = new(sql.NullString)
  108. case agent.FieldCreatedAt, agent.FieldUpdatedAt, agent.FieldDeletedAt:
  109. values[i] = new(sql.NullTime)
  110. default:
  111. values[i] = new(sql.UnknownType)
  112. }
  113. }
  114. return values, nil
  115. }
  116. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  117. // to the Agent fields.
  118. func (a *Agent) assignValues(columns []string, values []any) error {
  119. if m, n := len(values), len(columns); m < n {
  120. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  121. }
  122. for i := range columns {
  123. switch columns[i] {
  124. case agent.FieldID:
  125. value, ok := values[i].(*sql.NullInt64)
  126. if !ok {
  127. return fmt.Errorf("unexpected type %T for field id", value)
  128. }
  129. a.ID = uint64(value.Int64)
  130. case agent.FieldCreatedAt:
  131. if value, ok := values[i].(*sql.NullTime); !ok {
  132. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  133. } else if value.Valid {
  134. a.CreatedAt = value.Time
  135. }
  136. case agent.FieldUpdatedAt:
  137. if value, ok := values[i].(*sql.NullTime); !ok {
  138. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  139. } else if value.Valid {
  140. a.UpdatedAt = value.Time
  141. }
  142. case agent.FieldDeletedAt:
  143. if value, ok := values[i].(*sql.NullTime); !ok {
  144. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  145. } else if value.Valid {
  146. a.DeletedAt = value.Time
  147. }
  148. case agent.FieldName:
  149. if value, ok := values[i].(*sql.NullString); !ok {
  150. return fmt.Errorf("unexpected type %T for field name", values[i])
  151. } else if value.Valid {
  152. a.Name = value.String
  153. }
  154. case agent.FieldRole:
  155. if value, ok := values[i].(*sql.NullString); !ok {
  156. return fmt.Errorf("unexpected type %T for field role", values[i])
  157. } else if value.Valid {
  158. a.Role = value.String
  159. }
  160. case agent.FieldStatus:
  161. if value, ok := values[i].(*sql.NullInt64); !ok {
  162. return fmt.Errorf("unexpected type %T for field status", values[i])
  163. } else if value.Valid {
  164. a.Status = int(value.Int64)
  165. }
  166. case agent.FieldBackground:
  167. if value, ok := values[i].(*sql.NullString); !ok {
  168. return fmt.Errorf("unexpected type %T for field background", values[i])
  169. } else if value.Valid {
  170. a.Background = value.String
  171. }
  172. case agent.FieldExamples:
  173. if value, ok := values[i].(*sql.NullString); !ok {
  174. return fmt.Errorf("unexpected type %T for field examples", values[i])
  175. } else if value.Valid {
  176. a.Examples = value.String
  177. }
  178. case agent.FieldOrganizationID:
  179. if value, ok := values[i].(*sql.NullInt64); !ok {
  180. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  181. } else if value.Valid {
  182. a.OrganizationID = uint64(value.Int64)
  183. }
  184. case agent.FieldDatasetID:
  185. if value, ok := values[i].(*sql.NullString); !ok {
  186. return fmt.Errorf("unexpected type %T for field dataset_id", values[i])
  187. } else if value.Valid {
  188. a.DatasetID = value.String
  189. }
  190. case agent.FieldCollectionID:
  191. if value, ok := values[i].(*sql.NullString); !ok {
  192. return fmt.Errorf("unexpected type %T for field collection_id", values[i])
  193. } else if value.Valid {
  194. a.CollectionID = value.String
  195. }
  196. default:
  197. a.selectValues.Set(columns[i], values[i])
  198. }
  199. }
  200. return nil
  201. }
  202. // Value returns the ent.Value that was dynamically selected and assigned to the Agent.
  203. // This includes values selected through modifiers, order, etc.
  204. func (a *Agent) Value(name string) (ent.Value, error) {
  205. return a.selectValues.Get(name)
  206. }
  207. // QueryWxAgent queries the "wx_agent" edge of the Agent entity.
  208. func (a *Agent) QueryWxAgent() *WxQuery {
  209. return NewAgentClient(a.config).QueryWxAgent(a)
  210. }
  211. // QueryTokenAgent queries the "token_agent" edge of the Agent entity.
  212. func (a *Agent) QueryTokenAgent() *TokenQuery {
  213. return NewAgentClient(a.config).QueryTokenAgent(a)
  214. }
  215. // QueryWaAgent queries the "wa_agent" edge of the Agent entity.
  216. func (a *Agent) QueryWaAgent() *WhatsappQuery {
  217. return NewAgentClient(a.config).QueryWaAgent(a)
  218. }
  219. // QueryXjsAgent queries the "xjs_agent" edge of the Agent entity.
  220. func (a *Agent) QueryXjsAgent() *XunjiServiceQuery {
  221. return NewAgentClient(a.config).QueryXjsAgent(a)
  222. }
  223. // QueryKeyAgent queries the "key_agent" edge of the Agent entity.
  224. func (a *Agent) QueryKeyAgent() *ApiKeyQuery {
  225. return NewAgentClient(a.config).QueryKeyAgent(a)
  226. }
  227. // Update returns a builder for updating this Agent.
  228. // Note that you need to call Agent.Unwrap() before calling this method if this Agent
  229. // was returned from a transaction, and the transaction was committed or rolled back.
  230. func (a *Agent) Update() *AgentUpdateOne {
  231. return NewAgentClient(a.config).UpdateOne(a)
  232. }
  233. // Unwrap unwraps the Agent entity that was returned from a transaction after it was closed,
  234. // so that all future queries will be executed through the driver which created the transaction.
  235. func (a *Agent) Unwrap() *Agent {
  236. _tx, ok := a.config.driver.(*txDriver)
  237. if !ok {
  238. panic("ent: Agent is not a transactional entity")
  239. }
  240. a.config.driver = _tx.drv
  241. return a
  242. }
  243. // String implements the fmt.Stringer.
  244. func (a *Agent) String() string {
  245. var builder strings.Builder
  246. builder.WriteString("Agent(")
  247. builder.WriteString(fmt.Sprintf("id=%v, ", a.ID))
  248. builder.WriteString("created_at=")
  249. builder.WriteString(a.CreatedAt.Format(time.ANSIC))
  250. builder.WriteString(", ")
  251. builder.WriteString("updated_at=")
  252. builder.WriteString(a.UpdatedAt.Format(time.ANSIC))
  253. builder.WriteString(", ")
  254. builder.WriteString("deleted_at=")
  255. builder.WriteString(a.DeletedAt.Format(time.ANSIC))
  256. builder.WriteString(", ")
  257. builder.WriteString("name=")
  258. builder.WriteString(a.Name)
  259. builder.WriteString(", ")
  260. builder.WriteString("role=")
  261. builder.WriteString(a.Role)
  262. builder.WriteString(", ")
  263. builder.WriteString("status=")
  264. builder.WriteString(fmt.Sprintf("%v", a.Status))
  265. builder.WriteString(", ")
  266. builder.WriteString("background=")
  267. builder.WriteString(a.Background)
  268. builder.WriteString(", ")
  269. builder.WriteString("examples=")
  270. builder.WriteString(a.Examples)
  271. builder.WriteString(", ")
  272. builder.WriteString("organization_id=")
  273. builder.WriteString(fmt.Sprintf("%v", a.OrganizationID))
  274. builder.WriteString(", ")
  275. builder.WriteString("dataset_id=")
  276. builder.WriteString(a.DatasetID)
  277. builder.WriteString(", ")
  278. builder.WriteString("collection_id=")
  279. builder.WriteString(a.CollectionID)
  280. builder.WriteByte(')')
  281. return builder.String()
  282. }
  283. // Agents is a parsable slice of Agent.
  284. type Agents []*Agent