sopnode.go 12 KB

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