agent.go 9.5 KB

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