agent.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. // Edges holds the relations/edges for other nodes in the graph.
  35. // The values are being populated by the AgentQuery when eager-loading is set.
  36. Edges AgentEdges `json:"edges"`
  37. selectValues sql.SelectValues
  38. }
  39. // AgentEdges holds the relations/edges for other nodes in the graph.
  40. type AgentEdges struct {
  41. // WxAgent holds the value of the wx_agent edge.
  42. WxAgent []*Wx `json:"wx_agent,omitempty"`
  43. // loadedTypes holds the information for reporting if a
  44. // type was loaded (or requested) in eager-loading or not.
  45. loadedTypes [1]bool
  46. }
  47. // WxAgentOrErr returns the WxAgent value or an error if the edge
  48. // was not loaded in eager-loading.
  49. func (e AgentEdges) WxAgentOrErr() ([]*Wx, error) {
  50. if e.loadedTypes[0] {
  51. return e.WxAgent, nil
  52. }
  53. return nil, &NotLoadedError{edge: "wx_agent"}
  54. }
  55. // scanValues returns the types for scanning values from sql.Rows.
  56. func (*Agent) scanValues(columns []string) ([]any, error) {
  57. values := make([]any, len(columns))
  58. for i := range columns {
  59. switch columns[i] {
  60. case agent.FieldID, agent.FieldStatus, agent.FieldOrganizationID:
  61. values[i] = new(sql.NullInt64)
  62. case agent.FieldName, agent.FieldRole, agent.FieldBackground, agent.FieldExamples:
  63. values[i] = new(sql.NullString)
  64. case agent.FieldCreatedAt, agent.FieldUpdatedAt, agent.FieldDeletedAt:
  65. values[i] = new(sql.NullTime)
  66. default:
  67. values[i] = new(sql.UnknownType)
  68. }
  69. }
  70. return values, nil
  71. }
  72. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  73. // to the Agent fields.
  74. func (a *Agent) assignValues(columns []string, values []any) error {
  75. if m, n := len(values), len(columns); m < n {
  76. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  77. }
  78. for i := range columns {
  79. switch columns[i] {
  80. case agent.FieldID:
  81. value, ok := values[i].(*sql.NullInt64)
  82. if !ok {
  83. return fmt.Errorf("unexpected type %T for field id", value)
  84. }
  85. a.ID = uint64(value.Int64)
  86. case agent.FieldCreatedAt:
  87. if value, ok := values[i].(*sql.NullTime); !ok {
  88. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  89. } else if value.Valid {
  90. a.CreatedAt = value.Time
  91. }
  92. case agent.FieldUpdatedAt:
  93. if value, ok := values[i].(*sql.NullTime); !ok {
  94. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  95. } else if value.Valid {
  96. a.UpdatedAt = value.Time
  97. }
  98. case agent.FieldDeletedAt:
  99. if value, ok := values[i].(*sql.NullTime); !ok {
  100. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  101. } else if value.Valid {
  102. a.DeletedAt = value.Time
  103. }
  104. case agent.FieldName:
  105. if value, ok := values[i].(*sql.NullString); !ok {
  106. return fmt.Errorf("unexpected type %T for field name", values[i])
  107. } else if value.Valid {
  108. a.Name = value.String
  109. }
  110. case agent.FieldRole:
  111. if value, ok := values[i].(*sql.NullString); !ok {
  112. return fmt.Errorf("unexpected type %T for field role", values[i])
  113. } else if value.Valid {
  114. a.Role = value.String
  115. }
  116. case agent.FieldStatus:
  117. if value, ok := values[i].(*sql.NullInt64); !ok {
  118. return fmt.Errorf("unexpected type %T for field status", values[i])
  119. } else if value.Valid {
  120. a.Status = int(value.Int64)
  121. }
  122. case agent.FieldBackground:
  123. if value, ok := values[i].(*sql.NullString); !ok {
  124. return fmt.Errorf("unexpected type %T for field background", values[i])
  125. } else if value.Valid {
  126. a.Background = value.String
  127. }
  128. case agent.FieldExamples:
  129. if value, ok := values[i].(*sql.NullString); !ok {
  130. return fmt.Errorf("unexpected type %T for field examples", values[i])
  131. } else if value.Valid {
  132. a.Examples = value.String
  133. }
  134. case agent.FieldOrganizationID:
  135. if value, ok := values[i].(*sql.NullInt64); !ok {
  136. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  137. } else if value.Valid {
  138. a.OrganizationID = uint64(value.Int64)
  139. }
  140. default:
  141. a.selectValues.Set(columns[i], values[i])
  142. }
  143. }
  144. return nil
  145. }
  146. // Value returns the ent.Value that was dynamically selected and assigned to the Agent.
  147. // This includes values selected through modifiers, order, etc.
  148. func (a *Agent) Value(name string) (ent.Value, error) {
  149. return a.selectValues.Get(name)
  150. }
  151. // QueryWxAgent queries the "wx_agent" edge of the Agent entity.
  152. func (a *Agent) QueryWxAgent() *WxQuery {
  153. return NewAgentClient(a.config).QueryWxAgent(a)
  154. }
  155. // Update returns a builder for updating this Agent.
  156. // Note that you need to call Agent.Unwrap() before calling this method if this Agent
  157. // was returned from a transaction, and the transaction was committed or rolled back.
  158. func (a *Agent) Update() *AgentUpdateOne {
  159. return NewAgentClient(a.config).UpdateOne(a)
  160. }
  161. // Unwrap unwraps the Agent entity that was returned from a transaction after it was closed,
  162. // so that all future queries will be executed through the driver which created the transaction.
  163. func (a *Agent) Unwrap() *Agent {
  164. _tx, ok := a.config.driver.(*txDriver)
  165. if !ok {
  166. panic("ent: Agent is not a transactional entity")
  167. }
  168. a.config.driver = _tx.drv
  169. return a
  170. }
  171. // String implements the fmt.Stringer.
  172. func (a *Agent) String() string {
  173. var builder strings.Builder
  174. builder.WriteString("Agent(")
  175. builder.WriteString(fmt.Sprintf("id=%v, ", a.ID))
  176. builder.WriteString("created_at=")
  177. builder.WriteString(a.CreatedAt.Format(time.ANSIC))
  178. builder.WriteString(", ")
  179. builder.WriteString("updated_at=")
  180. builder.WriteString(a.UpdatedAt.Format(time.ANSIC))
  181. builder.WriteString(", ")
  182. builder.WriteString("deleted_at=")
  183. builder.WriteString(a.DeletedAt.Format(time.ANSIC))
  184. builder.WriteString(", ")
  185. builder.WriteString("name=")
  186. builder.WriteString(a.Name)
  187. builder.WriteString(", ")
  188. builder.WriteString("role=")
  189. builder.WriteString(a.Role)
  190. builder.WriteString(", ")
  191. builder.WriteString("status=")
  192. builder.WriteString(fmt.Sprintf("%v", a.Status))
  193. builder.WriteString(", ")
  194. builder.WriteString("background=")
  195. builder.WriteString(a.Background)
  196. builder.WriteString(", ")
  197. builder.WriteString("examples=")
  198. builder.WriteString(a.Examples)
  199. builder.WriteString(", ")
  200. builder.WriteString("organization_id=")
  201. builder.WriteString(fmt.Sprintf("%v", a.OrganizationID))
  202. builder.WriteByte(')')
  203. return builder.String()
  204. }
  205. // Agents is a parsable slice of Agent.
  206. type Agents []*Agent