soptask.go 8.5 KB

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