sopnode.go 11 KB

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