sopnode.go 10 KB

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