allocagent.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "wechat-api/ent/allocagent"
  9. "entgo.io/ent"
  10. "entgo.io/ent/dialect/sql"
  11. )
  12. // AllocAgent is the model entity for the AllocAgent schema.
  13. type AllocAgent struct {
  14. config `json:"-"`
  15. // ID of the ent.
  16. ID uint64 `json:"id,omitempty"`
  17. // Create Time | 创建日期
  18. CreatedAt time.Time `json:"created_at,omitempty"`
  19. // Update Time | 修改日期
  20. UpdatedAt time.Time `json:"updated_at,omitempty"`
  21. // Delete Time | 删除日期
  22. DeletedAt time.Time `json:"deleted_at,omitempty"`
  23. // user_id | 前台用户ID
  24. UserID string `json:"user_id,omitempty"`
  25. // organization_id | 租户ID
  26. OrganizationID uint64 `json:"organization_id,omitempty"`
  27. // agents | 分配的智能体IDs
  28. Agents []uint64 `json:"agents,omitempty"`
  29. // status | 状态 1-正常 2-禁用
  30. Status int `json:"status,omitempty"`
  31. selectValues sql.SelectValues
  32. }
  33. // scanValues returns the types for scanning values from sql.Rows.
  34. func (*AllocAgent) scanValues(columns []string) ([]any, error) {
  35. values := make([]any, len(columns))
  36. for i := range columns {
  37. switch columns[i] {
  38. case allocagent.FieldAgents:
  39. values[i] = new([]byte)
  40. case allocagent.FieldID, allocagent.FieldOrganizationID, allocagent.FieldStatus:
  41. values[i] = new(sql.NullInt64)
  42. case allocagent.FieldUserID:
  43. values[i] = new(sql.NullString)
  44. case allocagent.FieldCreatedAt, allocagent.FieldUpdatedAt, allocagent.FieldDeletedAt:
  45. values[i] = new(sql.NullTime)
  46. default:
  47. values[i] = new(sql.UnknownType)
  48. }
  49. }
  50. return values, nil
  51. }
  52. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  53. // to the AllocAgent fields.
  54. func (aa *AllocAgent) assignValues(columns []string, values []any) error {
  55. if m, n := len(values), len(columns); m < n {
  56. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  57. }
  58. for i := range columns {
  59. switch columns[i] {
  60. case allocagent.FieldID:
  61. value, ok := values[i].(*sql.NullInt64)
  62. if !ok {
  63. return fmt.Errorf("unexpected type %T for field id", value)
  64. }
  65. aa.ID = uint64(value.Int64)
  66. case allocagent.FieldCreatedAt:
  67. if value, ok := values[i].(*sql.NullTime); !ok {
  68. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  69. } else if value.Valid {
  70. aa.CreatedAt = value.Time
  71. }
  72. case allocagent.FieldUpdatedAt:
  73. if value, ok := values[i].(*sql.NullTime); !ok {
  74. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  75. } else if value.Valid {
  76. aa.UpdatedAt = value.Time
  77. }
  78. case allocagent.FieldDeletedAt:
  79. if value, ok := values[i].(*sql.NullTime); !ok {
  80. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  81. } else if value.Valid {
  82. aa.DeletedAt = value.Time
  83. }
  84. case allocagent.FieldUserID:
  85. if value, ok := values[i].(*sql.NullString); !ok {
  86. return fmt.Errorf("unexpected type %T for field user_id", values[i])
  87. } else if value.Valid {
  88. aa.UserID = value.String
  89. }
  90. case allocagent.FieldOrganizationID:
  91. if value, ok := values[i].(*sql.NullInt64); !ok {
  92. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  93. } else if value.Valid {
  94. aa.OrganizationID = uint64(value.Int64)
  95. }
  96. case allocagent.FieldAgents:
  97. if value, ok := values[i].(*[]byte); !ok {
  98. return fmt.Errorf("unexpected type %T for field agents", values[i])
  99. } else if value != nil && len(*value) > 0 {
  100. if err := json.Unmarshal(*value, &aa.Agents); err != nil {
  101. return fmt.Errorf("unmarshal field agents: %w", err)
  102. }
  103. }
  104. case allocagent.FieldStatus:
  105. if value, ok := values[i].(*sql.NullInt64); !ok {
  106. return fmt.Errorf("unexpected type %T for field status", values[i])
  107. } else if value.Valid {
  108. aa.Status = int(value.Int64)
  109. }
  110. default:
  111. aa.selectValues.Set(columns[i], values[i])
  112. }
  113. }
  114. return nil
  115. }
  116. // Value returns the ent.Value that was dynamically selected and assigned to the AllocAgent.
  117. // This includes values selected through modifiers, order, etc.
  118. func (aa *AllocAgent) Value(name string) (ent.Value, error) {
  119. return aa.selectValues.Get(name)
  120. }
  121. // Update returns a builder for updating this AllocAgent.
  122. // Note that you need to call AllocAgent.Unwrap() before calling this method if this AllocAgent
  123. // was returned from a transaction, and the transaction was committed or rolled back.
  124. func (aa *AllocAgent) Update() *AllocAgentUpdateOne {
  125. return NewAllocAgentClient(aa.config).UpdateOne(aa)
  126. }
  127. // Unwrap unwraps the AllocAgent entity that was returned from a transaction after it was closed,
  128. // so that all future queries will be executed through the driver which created the transaction.
  129. func (aa *AllocAgent) Unwrap() *AllocAgent {
  130. _tx, ok := aa.config.driver.(*txDriver)
  131. if !ok {
  132. panic("ent: AllocAgent is not a transactional entity")
  133. }
  134. aa.config.driver = _tx.drv
  135. return aa
  136. }
  137. // String implements the fmt.Stringer.
  138. func (aa *AllocAgent) String() string {
  139. var builder strings.Builder
  140. builder.WriteString("AllocAgent(")
  141. builder.WriteString(fmt.Sprintf("id=%v, ", aa.ID))
  142. builder.WriteString("created_at=")
  143. builder.WriteString(aa.CreatedAt.Format(time.ANSIC))
  144. builder.WriteString(", ")
  145. builder.WriteString("updated_at=")
  146. builder.WriteString(aa.UpdatedAt.Format(time.ANSIC))
  147. builder.WriteString(", ")
  148. builder.WriteString("deleted_at=")
  149. builder.WriteString(aa.DeletedAt.Format(time.ANSIC))
  150. builder.WriteString(", ")
  151. builder.WriteString("user_id=")
  152. builder.WriteString(aa.UserID)
  153. builder.WriteString(", ")
  154. builder.WriteString("organization_id=")
  155. builder.WriteString(fmt.Sprintf("%v", aa.OrganizationID))
  156. builder.WriteString(", ")
  157. builder.WriteString("agents=")
  158. builder.WriteString(fmt.Sprintf("%v", aa.Agents))
  159. builder.WriteString(", ")
  160. builder.WriteString("status=")
  161. builder.WriteString(fmt.Sprintf("%v", aa.Status))
  162. builder.WriteByte(')')
  163. return builder.String()
  164. }
  165. // AllocAgents is a parsable slice of AllocAgent.
  166. type AllocAgents []*AllocAgent