sopnode.go 9.6 KB

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