soptask.go 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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/soptask"
  9. "entgo.io/ent"
  10. "entgo.io/ent/dialect/sql"
  11. )
  12. // SopTask is the model entity for the SopTask schema.
  13. type SopTask 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. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  22. Status uint8 `json:"status,omitempty"`
  23. // Delete Time | 删除日期
  24. DeletedAt time.Time `json:"deleted_at,omitempty"`
  25. // SOP 任务名称
  26. Name string `json:"name,omitempty"`
  27. // 机器人微信 id 列表
  28. BotWxidList []string `json:"bot_wxid_list,omitempty"`
  29. // 标签类型:1好友,2群组,3企业微信联系人
  30. Type int `json:"type,omitempty"`
  31. // 任务计划开始时间
  32. PlanStartTime time.Time `json:"plan_start_time,omitempty"`
  33. // 任务计划结束时间
  34. PlanEndTime time.Time `json:"plan_end_time,omitempty"`
  35. // 创建者 id
  36. CreatorID string `json:"creator_id,omitempty"`
  37. // Edges holds the relations/edges for other nodes in the graph.
  38. // The values are being populated by the SopTaskQuery when eager-loading is set.
  39. Edges SopTaskEdges `json:"edges"`
  40. selectValues sql.SelectValues
  41. }
  42. // SopTaskEdges holds the relations/edges for other nodes in the graph.
  43. type SopTaskEdges struct {
  44. // TaskStages holds the value of the task_stages edge.
  45. TaskStages []*SopStage `json:"task_stages,omitempty"`
  46. // loadedTypes holds the information for reporting if a
  47. // type was loaded (or requested) in eager-loading or not.
  48. loadedTypes [1]bool
  49. }
  50. // TaskStagesOrErr returns the TaskStages value or an error if the edge
  51. // was not loaded in eager-loading.
  52. func (e SopTaskEdges) TaskStagesOrErr() ([]*SopStage, error) {
  53. if e.loadedTypes[0] {
  54. return e.TaskStages, nil
  55. }
  56. return nil, &NotLoadedError{edge: "task_stages"}
  57. }
  58. // scanValues returns the types for scanning values from sql.Rows.
  59. func (*SopTask) scanValues(columns []string) ([]any, error) {
  60. values := make([]any, len(columns))
  61. for i := range columns {
  62. switch columns[i] {
  63. case soptask.FieldBotWxidList:
  64. values[i] = new([]byte)
  65. case soptask.FieldID, soptask.FieldStatus, soptask.FieldType:
  66. values[i] = new(sql.NullInt64)
  67. case soptask.FieldName, soptask.FieldCreatorID:
  68. values[i] = new(sql.NullString)
  69. case soptask.FieldCreatedAt, soptask.FieldUpdatedAt, soptask.FieldDeletedAt, soptask.FieldPlanStartTime, soptask.FieldPlanEndTime:
  70. values[i] = new(sql.NullTime)
  71. default:
  72. values[i] = new(sql.UnknownType)
  73. }
  74. }
  75. return values, nil
  76. }
  77. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  78. // to the SopTask fields.
  79. func (st *SopTask) assignValues(columns []string, values []any) error {
  80. if m, n := len(values), len(columns); m < n {
  81. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  82. }
  83. for i := range columns {
  84. switch columns[i] {
  85. case soptask.FieldID:
  86. value, ok := values[i].(*sql.NullInt64)
  87. if !ok {
  88. return fmt.Errorf("unexpected type %T for field id", value)
  89. }
  90. st.ID = uint64(value.Int64)
  91. case soptask.FieldCreatedAt:
  92. if value, ok := values[i].(*sql.NullTime); !ok {
  93. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  94. } else if value.Valid {
  95. st.CreatedAt = value.Time
  96. }
  97. case soptask.FieldUpdatedAt:
  98. if value, ok := values[i].(*sql.NullTime); !ok {
  99. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  100. } else if value.Valid {
  101. st.UpdatedAt = value.Time
  102. }
  103. case soptask.FieldStatus:
  104. if value, ok := values[i].(*sql.NullInt64); !ok {
  105. return fmt.Errorf("unexpected type %T for field status", values[i])
  106. } else if value.Valid {
  107. st.Status = uint8(value.Int64)
  108. }
  109. case soptask.FieldDeletedAt:
  110. if value, ok := values[i].(*sql.NullTime); !ok {
  111. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  112. } else if value.Valid {
  113. st.DeletedAt = value.Time
  114. }
  115. case soptask.FieldName:
  116. if value, ok := values[i].(*sql.NullString); !ok {
  117. return fmt.Errorf("unexpected type %T for field name", values[i])
  118. } else if value.Valid {
  119. st.Name = value.String
  120. }
  121. case soptask.FieldBotWxidList:
  122. if value, ok := values[i].(*[]byte); !ok {
  123. return fmt.Errorf("unexpected type %T for field bot_wxid_list", values[i])
  124. } else if value != nil && len(*value) > 0 {
  125. if err := json.Unmarshal(*value, &st.BotWxidList); err != nil {
  126. return fmt.Errorf("unmarshal field bot_wxid_list: %w", err)
  127. }
  128. }
  129. case soptask.FieldType:
  130. if value, ok := values[i].(*sql.NullInt64); !ok {
  131. return fmt.Errorf("unexpected type %T for field type", values[i])
  132. } else if value.Valid {
  133. st.Type = int(value.Int64)
  134. }
  135. case soptask.FieldPlanStartTime:
  136. if value, ok := values[i].(*sql.NullTime); !ok {
  137. return fmt.Errorf("unexpected type %T for field plan_start_time", values[i])
  138. } else if value.Valid {
  139. st.PlanStartTime = value.Time
  140. }
  141. case soptask.FieldPlanEndTime:
  142. if value, ok := values[i].(*sql.NullTime); !ok {
  143. return fmt.Errorf("unexpected type %T for field plan_end_time", values[i])
  144. } else if value.Valid {
  145. st.PlanEndTime = value.Time
  146. }
  147. case soptask.FieldCreatorID:
  148. if value, ok := values[i].(*sql.NullString); !ok {
  149. return fmt.Errorf("unexpected type %T for field creator_id", values[i])
  150. } else if value.Valid {
  151. st.CreatorID = value.String
  152. }
  153. default:
  154. st.selectValues.Set(columns[i], values[i])
  155. }
  156. }
  157. return nil
  158. }
  159. // Value returns the ent.Value that was dynamically selected and assigned to the SopTask.
  160. // This includes values selected through modifiers, order, etc.
  161. func (st *SopTask) Value(name string) (ent.Value, error) {
  162. return st.selectValues.Get(name)
  163. }
  164. // QueryTaskStages queries the "task_stages" edge of the SopTask entity.
  165. func (st *SopTask) QueryTaskStages() *SopStageQuery {
  166. return NewSopTaskClient(st.config).QueryTaskStages(st)
  167. }
  168. // Update returns a builder for updating this SopTask.
  169. // Note that you need to call SopTask.Unwrap() before calling this method if this SopTask
  170. // was returned from a transaction, and the transaction was committed or rolled back.
  171. func (st *SopTask) Update() *SopTaskUpdateOne {
  172. return NewSopTaskClient(st.config).UpdateOne(st)
  173. }
  174. // Unwrap unwraps the SopTask entity that was returned from a transaction after it was closed,
  175. // so that all future queries will be executed through the driver which created the transaction.
  176. func (st *SopTask) Unwrap() *SopTask {
  177. _tx, ok := st.config.driver.(*txDriver)
  178. if !ok {
  179. panic("ent: SopTask is not a transactional entity")
  180. }
  181. st.config.driver = _tx.drv
  182. return st
  183. }
  184. // String implements the fmt.Stringer.
  185. func (st *SopTask) String() string {
  186. var builder strings.Builder
  187. builder.WriteString("SopTask(")
  188. builder.WriteString(fmt.Sprintf("id=%v, ", st.ID))
  189. builder.WriteString("created_at=")
  190. builder.WriteString(st.CreatedAt.Format(time.ANSIC))
  191. builder.WriteString(", ")
  192. builder.WriteString("updated_at=")
  193. builder.WriteString(st.UpdatedAt.Format(time.ANSIC))
  194. builder.WriteString(", ")
  195. builder.WriteString("status=")
  196. builder.WriteString(fmt.Sprintf("%v", st.Status))
  197. builder.WriteString(", ")
  198. builder.WriteString("deleted_at=")
  199. builder.WriteString(st.DeletedAt.Format(time.ANSIC))
  200. builder.WriteString(", ")
  201. builder.WriteString("name=")
  202. builder.WriteString(st.Name)
  203. builder.WriteString(", ")
  204. builder.WriteString("bot_wxid_list=")
  205. builder.WriteString(fmt.Sprintf("%v", st.BotWxidList))
  206. builder.WriteString(", ")
  207. builder.WriteString("type=")
  208. builder.WriteString(fmt.Sprintf("%v", st.Type))
  209. builder.WriteString(", ")
  210. builder.WriteString("plan_start_time=")
  211. builder.WriteString(st.PlanStartTime.Format(time.ANSIC))
  212. builder.WriteString(", ")
  213. builder.WriteString("plan_end_time=")
  214. builder.WriteString(st.PlanEndTime.Format(time.ANSIC))
  215. builder.WriteString(", ")
  216. builder.WriteString("creator_id=")
  217. builder.WriteString(st.CreatorID)
  218. builder.WriteByte(')')
  219. return builder.String()
  220. }
  221. // SopTasks is a parsable slice of SopTask.
  222. type SopTasks []*SopTask