sopstage.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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/custom_types"
  9. "wechat-api/ent/sopstage"
  10. "wechat-api/ent/soptask"
  11. "entgo.io/ent"
  12. "entgo.io/ent/dialect/sql"
  13. )
  14. // SopStage is the model entity for the SopStage schema.
  15. type SopStage struct {
  16. config `json:"-"`
  17. // ID of the ent.
  18. ID uint64 `json:"id,omitempty"`
  19. // Create Time | 创建日期
  20. CreatedAt time.Time `json:"created_at,omitempty"`
  21. // Update Time | 修改日期
  22. UpdatedAt time.Time `json:"updated_at,omitempty"`
  23. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  24. Status uint8 `json:"status,omitempty"`
  25. // Delete Time | 删除日期
  26. DeletedAt time.Time `json:"deleted_at,omitempty"`
  27. // SOP 任务 ID
  28. TaskID uint64 `json:"task_id,omitempty"`
  29. // 阶段名称
  30. Name string `json:"name,omitempty"`
  31. // 客群筛选条件类型 1 按标签筛选 2 按客户基本信息筛选
  32. ConditionType int `json:"condition_type,omitempty"`
  33. // 筛选条件关系 1 满足所有条件(and) 2 满足任意条件(or)
  34. ConditionOperator int `json:"condition_operator,omitempty"`
  35. // 筛选条件列表
  36. ConditionList []custom_types.Condition `json:"condition_list,omitempty"`
  37. // 命中后发送的消息内容
  38. ActionMessage []custom_types.Action `json:"action_message,omitempty"`
  39. // 命中后需要打的标签
  40. ActionLabel []uint64 `json:"action_label,omitempty"`
  41. // 阶段顺序
  42. IndexSort int `json:"index_sort,omitempty"`
  43. // Edges holds the relations/edges for other nodes in the graph.
  44. // The values are being populated by the SopStageQuery when eager-loading is set.
  45. Edges SopStageEdges `json:"edges"`
  46. selectValues sql.SelectValues
  47. }
  48. // SopStageEdges holds the relations/edges for other nodes in the graph.
  49. type SopStageEdges struct {
  50. // SopTask holds the value of the sop_task edge.
  51. SopTask *SopTask `json:"sop_task,omitempty"`
  52. // StageNodes holds the value of the stage_nodes edge.
  53. StageNodes []*SopNode `json:"stage_nodes,omitempty"`
  54. // StageMessages holds the value of the stage_messages edge.
  55. StageMessages []*MessageRecords `json:"stage_messages,omitempty"`
  56. // loadedTypes holds the information for reporting if a
  57. // type was loaded (or requested) in eager-loading or not.
  58. loadedTypes [3]bool
  59. }
  60. // SopTaskOrErr returns the SopTask value or an error if the edge
  61. // was not loaded in eager-loading, or loaded but was not found.
  62. func (e SopStageEdges) SopTaskOrErr() (*SopTask, error) {
  63. if e.SopTask != nil {
  64. return e.SopTask, nil
  65. } else if e.loadedTypes[0] {
  66. return nil, &NotFoundError{label: soptask.Label}
  67. }
  68. return nil, &NotLoadedError{edge: "sop_task"}
  69. }
  70. // StageNodesOrErr returns the StageNodes value or an error if the edge
  71. // was not loaded in eager-loading.
  72. func (e SopStageEdges) StageNodesOrErr() ([]*SopNode, error) {
  73. if e.loadedTypes[1] {
  74. return e.StageNodes, nil
  75. }
  76. return nil, &NotLoadedError{edge: "stage_nodes"}
  77. }
  78. // StageMessagesOrErr returns the StageMessages value or an error if the edge
  79. // was not loaded in eager-loading.
  80. func (e SopStageEdges) StageMessagesOrErr() ([]*MessageRecords, error) {
  81. if e.loadedTypes[2] {
  82. return e.StageMessages, nil
  83. }
  84. return nil, &NotLoadedError{edge: "stage_messages"}
  85. }
  86. // scanValues returns the types for scanning values from sql.Rows.
  87. func (*SopStage) scanValues(columns []string) ([]any, error) {
  88. values := make([]any, len(columns))
  89. for i := range columns {
  90. switch columns[i] {
  91. case sopstage.FieldConditionList, sopstage.FieldActionMessage, sopstage.FieldActionLabel:
  92. values[i] = new([]byte)
  93. case sopstage.FieldID, sopstage.FieldStatus, sopstage.FieldTaskID, sopstage.FieldConditionType, sopstage.FieldConditionOperator, sopstage.FieldIndexSort:
  94. values[i] = new(sql.NullInt64)
  95. case sopstage.FieldName:
  96. values[i] = new(sql.NullString)
  97. case sopstage.FieldCreatedAt, sopstage.FieldUpdatedAt, sopstage.FieldDeletedAt:
  98. values[i] = new(sql.NullTime)
  99. default:
  100. values[i] = new(sql.UnknownType)
  101. }
  102. }
  103. return values, nil
  104. }
  105. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  106. // to the SopStage fields.
  107. func (ss *SopStage) assignValues(columns []string, values []any) error {
  108. if m, n := len(values), len(columns); m < n {
  109. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  110. }
  111. for i := range columns {
  112. switch columns[i] {
  113. case sopstage.FieldID:
  114. value, ok := values[i].(*sql.NullInt64)
  115. if !ok {
  116. return fmt.Errorf("unexpected type %T for field id", value)
  117. }
  118. ss.ID = uint64(value.Int64)
  119. case sopstage.FieldCreatedAt:
  120. if value, ok := values[i].(*sql.NullTime); !ok {
  121. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  122. } else if value.Valid {
  123. ss.CreatedAt = value.Time
  124. }
  125. case sopstage.FieldUpdatedAt:
  126. if value, ok := values[i].(*sql.NullTime); !ok {
  127. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  128. } else if value.Valid {
  129. ss.UpdatedAt = value.Time
  130. }
  131. case sopstage.FieldStatus:
  132. if value, ok := values[i].(*sql.NullInt64); !ok {
  133. return fmt.Errorf("unexpected type %T for field status", values[i])
  134. } else if value.Valid {
  135. ss.Status = uint8(value.Int64)
  136. }
  137. case sopstage.FieldDeletedAt:
  138. if value, ok := values[i].(*sql.NullTime); !ok {
  139. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  140. } else if value.Valid {
  141. ss.DeletedAt = value.Time
  142. }
  143. case sopstage.FieldTaskID:
  144. if value, ok := values[i].(*sql.NullInt64); !ok {
  145. return fmt.Errorf("unexpected type %T for field task_id", values[i])
  146. } else if value.Valid {
  147. ss.TaskID = uint64(value.Int64)
  148. }
  149. case sopstage.FieldName:
  150. if value, ok := values[i].(*sql.NullString); !ok {
  151. return fmt.Errorf("unexpected type %T for field name", values[i])
  152. } else if value.Valid {
  153. ss.Name = value.String
  154. }
  155. case sopstage.FieldConditionType:
  156. if value, ok := values[i].(*sql.NullInt64); !ok {
  157. return fmt.Errorf("unexpected type %T for field condition_type", values[i])
  158. } else if value.Valid {
  159. ss.ConditionType = int(value.Int64)
  160. }
  161. case sopstage.FieldConditionOperator:
  162. if value, ok := values[i].(*sql.NullInt64); !ok {
  163. return fmt.Errorf("unexpected type %T for field condition_operator", values[i])
  164. } else if value.Valid {
  165. ss.ConditionOperator = int(value.Int64)
  166. }
  167. case sopstage.FieldConditionList:
  168. if value, ok := values[i].(*[]byte); !ok {
  169. return fmt.Errorf("unexpected type %T for field condition_list", values[i])
  170. } else if value != nil && len(*value) > 0 {
  171. if err := json.Unmarshal(*value, &ss.ConditionList); err != nil {
  172. return fmt.Errorf("unmarshal field condition_list: %w", err)
  173. }
  174. }
  175. case sopstage.FieldActionMessage:
  176. if value, ok := values[i].(*[]byte); !ok {
  177. return fmt.Errorf("unexpected type %T for field action_message", values[i])
  178. } else if value != nil && len(*value) > 0 {
  179. if err := json.Unmarshal(*value, &ss.ActionMessage); err != nil {
  180. return fmt.Errorf("unmarshal field action_message: %w", err)
  181. }
  182. }
  183. case sopstage.FieldActionLabel:
  184. if value, ok := values[i].(*[]byte); !ok {
  185. return fmt.Errorf("unexpected type %T for field action_label", values[i])
  186. } else if value != nil && len(*value) > 0 {
  187. if err := json.Unmarshal(*value, &ss.ActionLabel); err != nil {
  188. return fmt.Errorf("unmarshal field action_label: %w", err)
  189. }
  190. }
  191. case sopstage.FieldIndexSort:
  192. if value, ok := values[i].(*sql.NullInt64); !ok {
  193. return fmt.Errorf("unexpected type %T for field index_sort", values[i])
  194. } else if value.Valid {
  195. ss.IndexSort = int(value.Int64)
  196. }
  197. default:
  198. ss.selectValues.Set(columns[i], values[i])
  199. }
  200. }
  201. return nil
  202. }
  203. // Value returns the ent.Value that was dynamically selected and assigned to the SopStage.
  204. // This includes values selected through modifiers, order, etc.
  205. func (ss *SopStage) Value(name string) (ent.Value, error) {
  206. return ss.selectValues.Get(name)
  207. }
  208. // QuerySopTask queries the "sop_task" edge of the SopStage entity.
  209. func (ss *SopStage) QuerySopTask() *SopTaskQuery {
  210. return NewSopStageClient(ss.config).QuerySopTask(ss)
  211. }
  212. // QueryStageNodes queries the "stage_nodes" edge of the SopStage entity.
  213. func (ss *SopStage) QueryStageNodes() *SopNodeQuery {
  214. return NewSopStageClient(ss.config).QueryStageNodes(ss)
  215. }
  216. // QueryStageMessages queries the "stage_messages" edge of the SopStage entity.
  217. func (ss *SopStage) QueryStageMessages() *MessageRecordsQuery {
  218. return NewSopStageClient(ss.config).QueryStageMessages(ss)
  219. }
  220. // Update returns a builder for updating this SopStage.
  221. // Note that you need to call SopStage.Unwrap() before calling this method if this SopStage
  222. // was returned from a transaction, and the transaction was committed or rolled back.
  223. func (ss *SopStage) Update() *SopStageUpdateOne {
  224. return NewSopStageClient(ss.config).UpdateOne(ss)
  225. }
  226. // Unwrap unwraps the SopStage entity that was returned from a transaction after it was closed,
  227. // so that all future queries will be executed through the driver which created the transaction.
  228. func (ss *SopStage) Unwrap() *SopStage {
  229. _tx, ok := ss.config.driver.(*txDriver)
  230. if !ok {
  231. panic("ent: SopStage is not a transactional entity")
  232. }
  233. ss.config.driver = _tx.drv
  234. return ss
  235. }
  236. // String implements the fmt.Stringer.
  237. func (ss *SopStage) String() string {
  238. var builder strings.Builder
  239. builder.WriteString("SopStage(")
  240. builder.WriteString(fmt.Sprintf("id=%v, ", ss.ID))
  241. builder.WriteString("created_at=")
  242. builder.WriteString(ss.CreatedAt.Format(time.ANSIC))
  243. builder.WriteString(", ")
  244. builder.WriteString("updated_at=")
  245. builder.WriteString(ss.UpdatedAt.Format(time.ANSIC))
  246. builder.WriteString(", ")
  247. builder.WriteString("status=")
  248. builder.WriteString(fmt.Sprintf("%v", ss.Status))
  249. builder.WriteString(", ")
  250. builder.WriteString("deleted_at=")
  251. builder.WriteString(ss.DeletedAt.Format(time.ANSIC))
  252. builder.WriteString(", ")
  253. builder.WriteString("task_id=")
  254. builder.WriteString(fmt.Sprintf("%v", ss.TaskID))
  255. builder.WriteString(", ")
  256. builder.WriteString("name=")
  257. builder.WriteString(ss.Name)
  258. builder.WriteString(", ")
  259. builder.WriteString("condition_type=")
  260. builder.WriteString(fmt.Sprintf("%v", ss.ConditionType))
  261. builder.WriteString(", ")
  262. builder.WriteString("condition_operator=")
  263. builder.WriteString(fmt.Sprintf("%v", ss.ConditionOperator))
  264. builder.WriteString(", ")
  265. builder.WriteString("condition_list=")
  266. builder.WriteString(fmt.Sprintf("%v", ss.ConditionList))
  267. builder.WriteString(", ")
  268. builder.WriteString("action_message=")
  269. builder.WriteString(fmt.Sprintf("%v", ss.ActionMessage))
  270. builder.WriteString(", ")
  271. builder.WriteString("action_label=")
  272. builder.WriteString(fmt.Sprintf("%v", ss.ActionLabel))
  273. builder.WriteString(", ")
  274. builder.WriteString("index_sort=")
  275. builder.WriteString(fmt.Sprintf("%v", ss.IndexSort))
  276. builder.WriteByte(')')
  277. return builder.String()
  278. }
  279. // SopStages is a parsable slice of SopStage.
  280. type SopStages []*SopStage