sopnode.go 9.0 KB

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