sopstage.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. ActionLabelAdd []uint64 `json:"action_label_add,omitempty"`
  41. // 命中后需要移除的标签
  42. ActionLabelDel []uint64 `json:"action_label_del,omitempty"`
  43. // 命中后转发的消息
  44. ActionForward *custom_types.ActionForward `json:"action_forward,omitempty"`
  45. // 阶段顺序
  46. IndexSort int `json:"index_sort,omitempty"`
  47. // Edges holds the relations/edges for other nodes in the graph.
  48. // The values are being populated by the SopStageQuery when eager-loading is set.
  49. Edges SopStageEdges `json:"edges"`
  50. selectValues sql.SelectValues
  51. }
  52. // SopStageEdges holds the relations/edges for other nodes in the graph.
  53. type SopStageEdges struct {
  54. // SopTask holds the value of the sop_task edge.
  55. SopTask *SopTask `json:"sop_task,omitempty"`
  56. // StageNodes holds the value of the stage_nodes edge.
  57. StageNodes []*SopNode `json:"stage_nodes,omitempty"`
  58. // StageMessages holds the value of the stage_messages edge.
  59. StageMessages []*MessageRecords `json:"stage_messages,omitempty"`
  60. // loadedTypes holds the information for reporting if a
  61. // type was loaded (or requested) in eager-loading or not.
  62. loadedTypes [3]bool
  63. }
  64. // SopTaskOrErr returns the SopTask value or an error if the edge
  65. // was not loaded in eager-loading, or loaded but was not found.
  66. func (e SopStageEdges) SopTaskOrErr() (*SopTask, error) {
  67. if e.SopTask != nil {
  68. return e.SopTask, nil
  69. } else if e.loadedTypes[0] {
  70. return nil, &NotFoundError{label: soptask.Label}
  71. }
  72. return nil, &NotLoadedError{edge: "sop_task"}
  73. }
  74. // StageNodesOrErr returns the StageNodes value or an error if the edge
  75. // was not loaded in eager-loading.
  76. func (e SopStageEdges) StageNodesOrErr() ([]*SopNode, error) {
  77. if e.loadedTypes[1] {
  78. return e.StageNodes, nil
  79. }
  80. return nil, &NotLoadedError{edge: "stage_nodes"}
  81. }
  82. // StageMessagesOrErr returns the StageMessages value or an error if the edge
  83. // was not loaded in eager-loading.
  84. func (e SopStageEdges) StageMessagesOrErr() ([]*MessageRecords, error) {
  85. if e.loadedTypes[2] {
  86. return e.StageMessages, nil
  87. }
  88. return nil, &NotLoadedError{edge: "stage_messages"}
  89. }
  90. // scanValues returns the types for scanning values from sql.Rows.
  91. func (*SopStage) scanValues(columns []string) ([]any, error) {
  92. values := make([]any, len(columns))
  93. for i := range columns {
  94. switch columns[i] {
  95. case sopstage.FieldConditionList, sopstage.FieldActionMessage, sopstage.FieldActionLabelAdd, sopstage.FieldActionLabelDel, sopstage.FieldActionForward:
  96. values[i] = new([]byte)
  97. case sopstage.FieldID, sopstage.FieldStatus, sopstage.FieldTaskID, sopstage.FieldConditionType, sopstage.FieldConditionOperator, sopstage.FieldIndexSort:
  98. values[i] = new(sql.NullInt64)
  99. case sopstage.FieldName:
  100. values[i] = new(sql.NullString)
  101. case sopstage.FieldCreatedAt, sopstage.FieldUpdatedAt, sopstage.FieldDeletedAt:
  102. values[i] = new(sql.NullTime)
  103. default:
  104. values[i] = new(sql.UnknownType)
  105. }
  106. }
  107. return values, nil
  108. }
  109. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  110. // to the SopStage fields.
  111. func (ss *SopStage) assignValues(columns []string, values []any) error {
  112. if m, n := len(values), len(columns); m < n {
  113. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  114. }
  115. for i := range columns {
  116. switch columns[i] {
  117. case sopstage.FieldID:
  118. value, ok := values[i].(*sql.NullInt64)
  119. if !ok {
  120. return fmt.Errorf("unexpected type %T for field id", value)
  121. }
  122. ss.ID = uint64(value.Int64)
  123. case sopstage.FieldCreatedAt:
  124. if value, ok := values[i].(*sql.NullTime); !ok {
  125. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  126. } else if value.Valid {
  127. ss.CreatedAt = value.Time
  128. }
  129. case sopstage.FieldUpdatedAt:
  130. if value, ok := values[i].(*sql.NullTime); !ok {
  131. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  132. } else if value.Valid {
  133. ss.UpdatedAt = value.Time
  134. }
  135. case sopstage.FieldStatus:
  136. if value, ok := values[i].(*sql.NullInt64); !ok {
  137. return fmt.Errorf("unexpected type %T for field status", values[i])
  138. } else if value.Valid {
  139. ss.Status = uint8(value.Int64)
  140. }
  141. case sopstage.FieldDeletedAt:
  142. if value, ok := values[i].(*sql.NullTime); !ok {
  143. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  144. } else if value.Valid {
  145. ss.DeletedAt = value.Time
  146. }
  147. case sopstage.FieldTaskID:
  148. if value, ok := values[i].(*sql.NullInt64); !ok {
  149. return fmt.Errorf("unexpected type %T for field task_id", values[i])
  150. } else if value.Valid {
  151. ss.TaskID = uint64(value.Int64)
  152. }
  153. case sopstage.FieldName:
  154. if value, ok := values[i].(*sql.NullString); !ok {
  155. return fmt.Errorf("unexpected type %T for field name", values[i])
  156. } else if value.Valid {
  157. ss.Name = value.String
  158. }
  159. case sopstage.FieldConditionType:
  160. if value, ok := values[i].(*sql.NullInt64); !ok {
  161. return fmt.Errorf("unexpected type %T for field condition_type", values[i])
  162. } else if value.Valid {
  163. ss.ConditionType = int(value.Int64)
  164. }
  165. case sopstage.FieldConditionOperator:
  166. if value, ok := values[i].(*sql.NullInt64); !ok {
  167. return fmt.Errorf("unexpected type %T for field condition_operator", values[i])
  168. } else if value.Valid {
  169. ss.ConditionOperator = int(value.Int64)
  170. }
  171. case sopstage.FieldConditionList:
  172. if value, ok := values[i].(*[]byte); !ok {
  173. return fmt.Errorf("unexpected type %T for field condition_list", values[i])
  174. } else if value != nil && len(*value) > 0 {
  175. if err := json.Unmarshal(*value, &ss.ConditionList); err != nil {
  176. return fmt.Errorf("unmarshal field condition_list: %w", err)
  177. }
  178. }
  179. case sopstage.FieldActionMessage:
  180. if value, ok := values[i].(*[]byte); !ok {
  181. return fmt.Errorf("unexpected type %T for field action_message", values[i])
  182. } else if value != nil && len(*value) > 0 {
  183. if err := json.Unmarshal(*value, &ss.ActionMessage); err != nil {
  184. return fmt.Errorf("unmarshal field action_message: %w", err)
  185. }
  186. }
  187. case sopstage.FieldActionLabelAdd:
  188. if value, ok := values[i].(*[]byte); !ok {
  189. return fmt.Errorf("unexpected type %T for field action_label_add", values[i])
  190. } else if value != nil && len(*value) > 0 {
  191. if err := json.Unmarshal(*value, &ss.ActionLabelAdd); err != nil {
  192. return fmt.Errorf("unmarshal field action_label_add: %w", err)
  193. }
  194. }
  195. case sopstage.FieldActionLabelDel:
  196. if value, ok := values[i].(*[]byte); !ok {
  197. return fmt.Errorf("unexpected type %T for field action_label_del", values[i])
  198. } else if value != nil && len(*value) > 0 {
  199. if err := json.Unmarshal(*value, &ss.ActionLabelDel); err != nil {
  200. return fmt.Errorf("unmarshal field action_label_del: %w", err)
  201. }
  202. }
  203. case sopstage.FieldActionForward:
  204. if value, ok := values[i].(*[]byte); !ok {
  205. return fmt.Errorf("unexpected type %T for field action_forward", values[i])
  206. } else if value != nil && len(*value) > 0 {
  207. if err := json.Unmarshal(*value, &ss.ActionForward); err != nil {
  208. return fmt.Errorf("unmarshal field action_forward: %w", err)
  209. }
  210. }
  211. case sopstage.FieldIndexSort:
  212. if value, ok := values[i].(*sql.NullInt64); !ok {
  213. return fmt.Errorf("unexpected type %T for field index_sort", values[i])
  214. } else if value.Valid {
  215. ss.IndexSort = int(value.Int64)
  216. }
  217. default:
  218. ss.selectValues.Set(columns[i], values[i])
  219. }
  220. }
  221. return nil
  222. }
  223. // Value returns the ent.Value that was dynamically selected and assigned to the SopStage.
  224. // This includes values selected through modifiers, order, etc.
  225. func (ss *SopStage) Value(name string) (ent.Value, error) {
  226. return ss.selectValues.Get(name)
  227. }
  228. // QuerySopTask queries the "sop_task" edge of the SopStage entity.
  229. func (ss *SopStage) QuerySopTask() *SopTaskQuery {
  230. return NewSopStageClient(ss.config).QuerySopTask(ss)
  231. }
  232. // QueryStageNodes queries the "stage_nodes" edge of the SopStage entity.
  233. func (ss *SopStage) QueryStageNodes() *SopNodeQuery {
  234. return NewSopStageClient(ss.config).QueryStageNodes(ss)
  235. }
  236. // QueryStageMessages queries the "stage_messages" edge of the SopStage entity.
  237. func (ss *SopStage) QueryStageMessages() *MessageRecordsQuery {
  238. return NewSopStageClient(ss.config).QueryStageMessages(ss)
  239. }
  240. // Update returns a builder for updating this SopStage.
  241. // Note that you need to call SopStage.Unwrap() before calling this method if this SopStage
  242. // was returned from a transaction, and the transaction was committed or rolled back.
  243. func (ss *SopStage) Update() *SopStageUpdateOne {
  244. return NewSopStageClient(ss.config).UpdateOne(ss)
  245. }
  246. // Unwrap unwraps the SopStage entity that was returned from a transaction after it was closed,
  247. // so that all future queries will be executed through the driver which created the transaction.
  248. func (ss *SopStage) Unwrap() *SopStage {
  249. _tx, ok := ss.config.driver.(*txDriver)
  250. if !ok {
  251. panic("ent: SopStage is not a transactional entity")
  252. }
  253. ss.config.driver = _tx.drv
  254. return ss
  255. }
  256. // String implements the fmt.Stringer.
  257. func (ss *SopStage) String() string {
  258. var builder strings.Builder
  259. builder.WriteString("SopStage(")
  260. builder.WriteString(fmt.Sprintf("id=%v, ", ss.ID))
  261. builder.WriteString("created_at=")
  262. builder.WriteString(ss.CreatedAt.Format(time.ANSIC))
  263. builder.WriteString(", ")
  264. builder.WriteString("updated_at=")
  265. builder.WriteString(ss.UpdatedAt.Format(time.ANSIC))
  266. builder.WriteString(", ")
  267. builder.WriteString("status=")
  268. builder.WriteString(fmt.Sprintf("%v", ss.Status))
  269. builder.WriteString(", ")
  270. builder.WriteString("deleted_at=")
  271. builder.WriteString(ss.DeletedAt.Format(time.ANSIC))
  272. builder.WriteString(", ")
  273. builder.WriteString("task_id=")
  274. builder.WriteString(fmt.Sprintf("%v", ss.TaskID))
  275. builder.WriteString(", ")
  276. builder.WriteString("name=")
  277. builder.WriteString(ss.Name)
  278. builder.WriteString(", ")
  279. builder.WriteString("condition_type=")
  280. builder.WriteString(fmt.Sprintf("%v", ss.ConditionType))
  281. builder.WriteString(", ")
  282. builder.WriteString("condition_operator=")
  283. builder.WriteString(fmt.Sprintf("%v", ss.ConditionOperator))
  284. builder.WriteString(", ")
  285. builder.WriteString("condition_list=")
  286. builder.WriteString(fmt.Sprintf("%v", ss.ConditionList))
  287. builder.WriteString(", ")
  288. builder.WriteString("action_message=")
  289. builder.WriteString(fmt.Sprintf("%v", ss.ActionMessage))
  290. builder.WriteString(", ")
  291. builder.WriteString("action_label_add=")
  292. builder.WriteString(fmt.Sprintf("%v", ss.ActionLabelAdd))
  293. builder.WriteString(", ")
  294. builder.WriteString("action_label_del=")
  295. builder.WriteString(fmt.Sprintf("%v", ss.ActionLabelDel))
  296. builder.WriteString(", ")
  297. builder.WriteString("action_forward=")
  298. builder.WriteString(fmt.Sprintf("%v", ss.ActionForward))
  299. builder.WriteString(", ")
  300. builder.WriteString("index_sort=")
  301. builder.WriteString(fmt.Sprintf("%v", ss.IndexSort))
  302. builder.WriteByte(')')
  303. return builder.String()
  304. }
  305. // SopStages is a parsable slice of SopStage.
  306. type SopStages []*SopStage