soptask.go 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. // 机构 ID
  38. OrganizationID uint64 `json:"organization_id,omitempty"`
  39. // Token
  40. Token []string `json:"token,omitempty"`
  41. // Edges holds the relations/edges for other nodes in the graph.
  42. // The values are being populated by the SopTaskQuery when eager-loading is set.
  43. Edges SopTaskEdges `json:"edges"`
  44. selectValues sql.SelectValues
  45. }
  46. // SopTaskEdges holds the relations/edges for other nodes in the graph.
  47. type SopTaskEdges struct {
  48. // TaskStages holds the value of the task_stages edge.
  49. TaskStages []*SopStage `json:"task_stages,omitempty"`
  50. // loadedTypes holds the information for reporting if a
  51. // type was loaded (or requested) in eager-loading or not.
  52. loadedTypes [1]bool
  53. }
  54. // TaskStagesOrErr returns the TaskStages value or an error if the edge
  55. // was not loaded in eager-loading.
  56. func (e SopTaskEdges) TaskStagesOrErr() ([]*SopStage, error) {
  57. if e.loadedTypes[0] {
  58. return e.TaskStages, nil
  59. }
  60. return nil, &NotLoadedError{edge: "task_stages"}
  61. }
  62. // scanValues returns the types for scanning values from sql.Rows.
  63. func (*SopTask) scanValues(columns []string) ([]any, error) {
  64. values := make([]any, len(columns))
  65. for i := range columns {
  66. switch columns[i] {
  67. case soptask.FieldBotWxidList, soptask.FieldToken:
  68. values[i] = new([]byte)
  69. case soptask.FieldID, soptask.FieldStatus, soptask.FieldType, soptask.FieldOrganizationID:
  70. values[i] = new(sql.NullInt64)
  71. case soptask.FieldName, soptask.FieldCreatorID:
  72. values[i] = new(sql.NullString)
  73. case soptask.FieldCreatedAt, soptask.FieldUpdatedAt, soptask.FieldDeletedAt, soptask.FieldPlanStartTime, soptask.FieldPlanEndTime:
  74. values[i] = new(sql.NullTime)
  75. default:
  76. values[i] = new(sql.UnknownType)
  77. }
  78. }
  79. return values, nil
  80. }
  81. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  82. // to the SopTask fields.
  83. func (st *SopTask) assignValues(columns []string, values []any) error {
  84. if m, n := len(values), len(columns); m < n {
  85. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  86. }
  87. for i := range columns {
  88. switch columns[i] {
  89. case soptask.FieldID:
  90. value, ok := values[i].(*sql.NullInt64)
  91. if !ok {
  92. return fmt.Errorf("unexpected type %T for field id", value)
  93. }
  94. st.ID = uint64(value.Int64)
  95. case soptask.FieldCreatedAt:
  96. if value, ok := values[i].(*sql.NullTime); !ok {
  97. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  98. } else if value.Valid {
  99. st.CreatedAt = value.Time
  100. }
  101. case soptask.FieldUpdatedAt:
  102. if value, ok := values[i].(*sql.NullTime); !ok {
  103. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  104. } else if value.Valid {
  105. st.UpdatedAt = value.Time
  106. }
  107. case soptask.FieldStatus:
  108. if value, ok := values[i].(*sql.NullInt64); !ok {
  109. return fmt.Errorf("unexpected type %T for field status", values[i])
  110. } else if value.Valid {
  111. st.Status = uint8(value.Int64)
  112. }
  113. case soptask.FieldDeletedAt:
  114. if value, ok := values[i].(*sql.NullTime); !ok {
  115. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  116. } else if value.Valid {
  117. st.DeletedAt = value.Time
  118. }
  119. case soptask.FieldName:
  120. if value, ok := values[i].(*sql.NullString); !ok {
  121. return fmt.Errorf("unexpected type %T for field name", values[i])
  122. } else if value.Valid {
  123. st.Name = value.String
  124. }
  125. case soptask.FieldBotWxidList:
  126. if value, ok := values[i].(*[]byte); !ok {
  127. return fmt.Errorf("unexpected type %T for field bot_wxid_list", values[i])
  128. } else if value != nil && len(*value) > 0 {
  129. if err := json.Unmarshal(*value, &st.BotWxidList); err != nil {
  130. return fmt.Errorf("unmarshal field bot_wxid_list: %w", err)
  131. }
  132. }
  133. case soptask.FieldType:
  134. if value, ok := values[i].(*sql.NullInt64); !ok {
  135. return fmt.Errorf("unexpected type %T for field type", values[i])
  136. } else if value.Valid {
  137. st.Type = int(value.Int64)
  138. }
  139. case soptask.FieldPlanStartTime:
  140. if value, ok := values[i].(*sql.NullTime); !ok {
  141. return fmt.Errorf("unexpected type %T for field plan_start_time", values[i])
  142. } else if value.Valid {
  143. st.PlanStartTime = value.Time
  144. }
  145. case soptask.FieldPlanEndTime:
  146. if value, ok := values[i].(*sql.NullTime); !ok {
  147. return fmt.Errorf("unexpected type %T for field plan_end_time", values[i])
  148. } else if value.Valid {
  149. st.PlanEndTime = value.Time
  150. }
  151. case soptask.FieldCreatorID:
  152. if value, ok := values[i].(*sql.NullString); !ok {
  153. return fmt.Errorf("unexpected type %T for field creator_id", values[i])
  154. } else if value.Valid {
  155. st.CreatorID = value.String
  156. }
  157. case soptask.FieldOrganizationID:
  158. if value, ok := values[i].(*sql.NullInt64); !ok {
  159. return fmt.Errorf("unexpected type %T for field organization_id", values[i])
  160. } else if value.Valid {
  161. st.OrganizationID = uint64(value.Int64)
  162. }
  163. case soptask.FieldToken:
  164. if value, ok := values[i].(*[]byte); !ok {
  165. return fmt.Errorf("unexpected type %T for field token", values[i])
  166. } else if value != nil && len(*value) > 0 {
  167. if err := json.Unmarshal(*value, &st.Token); err != nil {
  168. return fmt.Errorf("unmarshal field token: %w", err)
  169. }
  170. }
  171. default:
  172. st.selectValues.Set(columns[i], values[i])
  173. }
  174. }
  175. return nil
  176. }
  177. // Value returns the ent.Value that was dynamically selected and assigned to the SopTask.
  178. // This includes values selected through modifiers, order, etc.
  179. func (st *SopTask) Value(name string) (ent.Value, error) {
  180. return st.selectValues.Get(name)
  181. }
  182. // QueryTaskStages queries the "task_stages" edge of the SopTask entity.
  183. func (st *SopTask) QueryTaskStages() *SopStageQuery {
  184. return NewSopTaskClient(st.config).QueryTaskStages(st)
  185. }
  186. // Update returns a builder for updating this SopTask.
  187. // Note that you need to call SopTask.Unwrap() before calling this method if this SopTask
  188. // was returned from a transaction, and the transaction was committed or rolled back.
  189. func (st *SopTask) Update() *SopTaskUpdateOne {
  190. return NewSopTaskClient(st.config).UpdateOne(st)
  191. }
  192. // Unwrap unwraps the SopTask entity that was returned from a transaction after it was closed,
  193. // so that all future queries will be executed through the driver which created the transaction.
  194. func (st *SopTask) Unwrap() *SopTask {
  195. _tx, ok := st.config.driver.(*txDriver)
  196. if !ok {
  197. panic("ent: SopTask is not a transactional entity")
  198. }
  199. st.config.driver = _tx.drv
  200. return st
  201. }
  202. // String implements the fmt.Stringer.
  203. func (st *SopTask) String() string {
  204. var builder strings.Builder
  205. builder.WriteString("SopTask(")
  206. builder.WriteString(fmt.Sprintf("id=%v, ", st.ID))
  207. builder.WriteString("created_at=")
  208. builder.WriteString(st.CreatedAt.Format(time.ANSIC))
  209. builder.WriteString(", ")
  210. builder.WriteString("updated_at=")
  211. builder.WriteString(st.UpdatedAt.Format(time.ANSIC))
  212. builder.WriteString(", ")
  213. builder.WriteString("status=")
  214. builder.WriteString(fmt.Sprintf("%v", st.Status))
  215. builder.WriteString(", ")
  216. builder.WriteString("deleted_at=")
  217. builder.WriteString(st.DeletedAt.Format(time.ANSIC))
  218. builder.WriteString(", ")
  219. builder.WriteString("name=")
  220. builder.WriteString(st.Name)
  221. builder.WriteString(", ")
  222. builder.WriteString("bot_wxid_list=")
  223. builder.WriteString(fmt.Sprintf("%v", st.BotWxidList))
  224. builder.WriteString(", ")
  225. builder.WriteString("type=")
  226. builder.WriteString(fmt.Sprintf("%v", st.Type))
  227. builder.WriteString(", ")
  228. builder.WriteString("plan_start_time=")
  229. builder.WriteString(st.PlanStartTime.Format(time.ANSIC))
  230. builder.WriteString(", ")
  231. builder.WriteString("plan_end_time=")
  232. builder.WriteString(st.PlanEndTime.Format(time.ANSIC))
  233. builder.WriteString(", ")
  234. builder.WriteString("creator_id=")
  235. builder.WriteString(st.CreatorID)
  236. builder.WriteString(", ")
  237. builder.WriteString("organization_id=")
  238. builder.WriteString(fmt.Sprintf("%v", st.OrganizationID))
  239. builder.WriteString(", ")
  240. builder.WriteString("token=")
  241. builder.WriteString(fmt.Sprintf("%v", st.Token))
  242. builder.WriteByte(')')
  243. return builder.String()
  244. }
  245. // SopTasks is a parsable slice of SopTask.
  246. type SopTasks []*SopTask