agent.go 11 KB

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