messagerecords.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/contact"
  8. "wechat-api/ent/messagerecords"
  9. "wechat-api/ent/sopnode"
  10. "wechat-api/ent/sopstage"
  11. "entgo.io/ent"
  12. "entgo.io/ent/dialect/sql"
  13. )
  14. // MessageRecords is the model entity for the MessageRecords schema.
  15. type MessageRecords 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. BotWxid string `json:"bot_wxid,omitempty"`
  29. // 联系人 id
  30. ContactID uint64 `json:"contact_id,omitempty"`
  31. // 类型:1好友,2群组,3企业微信联系人
  32. ContactType int `json:"contact_type,omitempty"`
  33. // 接收方微信 id
  34. ContactWxid string `json:"contact_wxid,omitempty"`
  35. // 内容类型 1 文本 2 文件
  36. ContentType int `json:"content_type,omitempty"`
  37. // 发送内容
  38. Content string `json:"content,omitempty"`
  39. // 异常原因
  40. ErrorDetail string `json:"error_detail,omitempty"`
  41. // 发送时间
  42. SendTime time.Time `json:"send_time,omitempty"`
  43. // 源类型 1 点发 2 群发 3 SOP
  44. SourceType int `json:"source_type,omitempty"`
  45. // 源 ID
  46. SourceID uint64 `json:"source_id,omitempty"`
  47. // 次源 ID
  48. SubSourceID uint64 `json:"sub_source_id,omitempty"`
  49. // Edges holds the relations/edges for other nodes in the graph.
  50. // The values are being populated by the MessageRecordsQuery when eager-loading is set.
  51. Edges MessageRecordsEdges `json:"edges"`
  52. selectValues sql.SelectValues
  53. }
  54. // MessageRecordsEdges holds the relations/edges for other nodes in the graph.
  55. type MessageRecordsEdges struct {
  56. // SopStage holds the value of the sop_stage edge.
  57. SopStage *SopStage `json:"sop_stage,omitempty"`
  58. // SopNode holds the value of the sop_node edge.
  59. SopNode *SopNode `json:"sop_node,omitempty"`
  60. // MessageContact holds the value of the message_contact edge.
  61. MessageContact *Contact `json:"message_contact,omitempty"`
  62. // loadedTypes holds the information for reporting if a
  63. // type was loaded (or requested) in eager-loading or not.
  64. loadedTypes [3]bool
  65. }
  66. // SopStageOrErr returns the SopStage value or an error if the edge
  67. // was not loaded in eager-loading, or loaded but was not found.
  68. func (e MessageRecordsEdges) SopStageOrErr() (*SopStage, error) {
  69. if e.SopStage != nil {
  70. return e.SopStage, nil
  71. } else if e.loadedTypes[0] {
  72. return nil, &NotFoundError{label: sopstage.Label}
  73. }
  74. return nil, &NotLoadedError{edge: "sop_stage"}
  75. }
  76. // SopNodeOrErr returns the SopNode value or an error if the edge
  77. // was not loaded in eager-loading, or loaded but was not found.
  78. func (e MessageRecordsEdges) SopNodeOrErr() (*SopNode, error) {
  79. if e.SopNode != nil {
  80. return e.SopNode, nil
  81. } else if e.loadedTypes[1] {
  82. return nil, &NotFoundError{label: sopnode.Label}
  83. }
  84. return nil, &NotLoadedError{edge: "sop_node"}
  85. }
  86. // MessageContactOrErr returns the MessageContact value or an error if the edge
  87. // was not loaded in eager-loading, or loaded but was not found.
  88. func (e MessageRecordsEdges) MessageContactOrErr() (*Contact, error) {
  89. if e.MessageContact != nil {
  90. return e.MessageContact, nil
  91. } else if e.loadedTypes[2] {
  92. return nil, &NotFoundError{label: contact.Label}
  93. }
  94. return nil, &NotLoadedError{edge: "message_contact"}
  95. }
  96. // scanValues returns the types for scanning values from sql.Rows.
  97. func (*MessageRecords) scanValues(columns []string) ([]any, error) {
  98. values := make([]any, len(columns))
  99. for i := range columns {
  100. switch columns[i] {
  101. case messagerecords.FieldID, messagerecords.FieldStatus, messagerecords.FieldContactID, messagerecords.FieldContactType, messagerecords.FieldContentType, messagerecords.FieldSourceType, messagerecords.FieldSourceID, messagerecords.FieldSubSourceID:
  102. values[i] = new(sql.NullInt64)
  103. case messagerecords.FieldBotWxid, messagerecords.FieldContactWxid, messagerecords.FieldContent, messagerecords.FieldErrorDetail:
  104. values[i] = new(sql.NullString)
  105. case messagerecords.FieldCreatedAt, messagerecords.FieldUpdatedAt, messagerecords.FieldDeletedAt, messagerecords.FieldSendTime:
  106. values[i] = new(sql.NullTime)
  107. default:
  108. values[i] = new(sql.UnknownType)
  109. }
  110. }
  111. return values, nil
  112. }
  113. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  114. // to the MessageRecords fields.
  115. func (mr *MessageRecords) assignValues(columns []string, values []any) error {
  116. if m, n := len(values), len(columns); m < n {
  117. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  118. }
  119. for i := range columns {
  120. switch columns[i] {
  121. case messagerecords.FieldID:
  122. value, ok := values[i].(*sql.NullInt64)
  123. if !ok {
  124. return fmt.Errorf("unexpected type %T for field id", value)
  125. }
  126. mr.ID = uint64(value.Int64)
  127. case messagerecords.FieldCreatedAt:
  128. if value, ok := values[i].(*sql.NullTime); !ok {
  129. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  130. } else if value.Valid {
  131. mr.CreatedAt = value.Time
  132. }
  133. case messagerecords.FieldUpdatedAt:
  134. if value, ok := values[i].(*sql.NullTime); !ok {
  135. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  136. } else if value.Valid {
  137. mr.UpdatedAt = value.Time
  138. }
  139. case messagerecords.FieldStatus:
  140. if value, ok := values[i].(*sql.NullInt64); !ok {
  141. return fmt.Errorf("unexpected type %T for field status", values[i])
  142. } else if value.Valid {
  143. mr.Status = uint8(value.Int64)
  144. }
  145. case messagerecords.FieldDeletedAt:
  146. if value, ok := values[i].(*sql.NullTime); !ok {
  147. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  148. } else if value.Valid {
  149. mr.DeletedAt = value.Time
  150. }
  151. case messagerecords.FieldBotWxid:
  152. if value, ok := values[i].(*sql.NullString); !ok {
  153. return fmt.Errorf("unexpected type %T for field bot_wxid", values[i])
  154. } else if value.Valid {
  155. mr.BotWxid = value.String
  156. }
  157. case messagerecords.FieldContactID:
  158. if value, ok := values[i].(*sql.NullInt64); !ok {
  159. return fmt.Errorf("unexpected type %T for field contact_id", values[i])
  160. } else if value.Valid {
  161. mr.ContactID = uint64(value.Int64)
  162. }
  163. case messagerecords.FieldContactType:
  164. if value, ok := values[i].(*sql.NullInt64); !ok {
  165. return fmt.Errorf("unexpected type %T for field contact_type", values[i])
  166. } else if value.Valid {
  167. mr.ContactType = int(value.Int64)
  168. }
  169. case messagerecords.FieldContactWxid:
  170. if value, ok := values[i].(*sql.NullString); !ok {
  171. return fmt.Errorf("unexpected type %T for field contact_wxid", values[i])
  172. } else if value.Valid {
  173. mr.ContactWxid = value.String
  174. }
  175. case messagerecords.FieldContentType:
  176. if value, ok := values[i].(*sql.NullInt64); !ok {
  177. return fmt.Errorf("unexpected type %T for field content_type", values[i])
  178. } else if value.Valid {
  179. mr.ContentType = int(value.Int64)
  180. }
  181. case messagerecords.FieldContent:
  182. if value, ok := values[i].(*sql.NullString); !ok {
  183. return fmt.Errorf("unexpected type %T for field content", values[i])
  184. } else if value.Valid {
  185. mr.Content = value.String
  186. }
  187. case messagerecords.FieldErrorDetail:
  188. if value, ok := values[i].(*sql.NullString); !ok {
  189. return fmt.Errorf("unexpected type %T for field error_detail", values[i])
  190. } else if value.Valid {
  191. mr.ErrorDetail = value.String
  192. }
  193. case messagerecords.FieldSendTime:
  194. if value, ok := values[i].(*sql.NullTime); !ok {
  195. return fmt.Errorf("unexpected type %T for field send_time", values[i])
  196. } else if value.Valid {
  197. mr.SendTime = value.Time
  198. }
  199. case messagerecords.FieldSourceType:
  200. if value, ok := values[i].(*sql.NullInt64); !ok {
  201. return fmt.Errorf("unexpected type %T for field source_type", values[i])
  202. } else if value.Valid {
  203. mr.SourceType = int(value.Int64)
  204. }
  205. case messagerecords.FieldSourceID:
  206. if value, ok := values[i].(*sql.NullInt64); !ok {
  207. return fmt.Errorf("unexpected type %T for field source_id", values[i])
  208. } else if value.Valid {
  209. mr.SourceID = uint64(value.Int64)
  210. }
  211. case messagerecords.FieldSubSourceID:
  212. if value, ok := values[i].(*sql.NullInt64); !ok {
  213. return fmt.Errorf("unexpected type %T for field sub_source_id", values[i])
  214. } else if value.Valid {
  215. mr.SubSourceID = uint64(value.Int64)
  216. }
  217. default:
  218. mr.selectValues.Set(columns[i], values[i])
  219. }
  220. }
  221. return nil
  222. }
  223. // Value returns the ent.Value that was dynamically selected and assigned to the MessageRecords.
  224. // This includes values selected through modifiers, order, etc.
  225. func (mr *MessageRecords) Value(name string) (ent.Value, error) {
  226. return mr.selectValues.Get(name)
  227. }
  228. // QuerySopStage queries the "sop_stage" edge of the MessageRecords entity.
  229. func (mr *MessageRecords) QuerySopStage() *SopStageQuery {
  230. return NewMessageRecordsClient(mr.config).QuerySopStage(mr)
  231. }
  232. // QuerySopNode queries the "sop_node" edge of the MessageRecords entity.
  233. func (mr *MessageRecords) QuerySopNode() *SopNodeQuery {
  234. return NewMessageRecordsClient(mr.config).QuerySopNode(mr)
  235. }
  236. // QueryMessageContact queries the "message_contact" edge of the MessageRecords entity.
  237. func (mr *MessageRecords) QueryMessageContact() *ContactQuery {
  238. return NewMessageRecordsClient(mr.config).QueryMessageContact(mr)
  239. }
  240. // Update returns a builder for updating this MessageRecords.
  241. // Note that you need to call MessageRecords.Unwrap() before calling this method if this MessageRecords
  242. // was returned from a transaction, and the transaction was committed or rolled back.
  243. func (mr *MessageRecords) Update() *MessageRecordsUpdateOne {
  244. return NewMessageRecordsClient(mr.config).UpdateOne(mr)
  245. }
  246. // Unwrap unwraps the MessageRecords entity that was returned from a transaction after it was closed,
  247. // so that all future queries will be executed through the driver which created the transaction.
  248. func (mr *MessageRecords) Unwrap() *MessageRecords {
  249. _tx, ok := mr.config.driver.(*txDriver)
  250. if !ok {
  251. panic("ent: MessageRecords is not a transactional entity")
  252. }
  253. mr.config.driver = _tx.drv
  254. return mr
  255. }
  256. // String implements the fmt.Stringer.
  257. func (mr *MessageRecords) String() string {
  258. var builder strings.Builder
  259. builder.WriteString("MessageRecords(")
  260. builder.WriteString(fmt.Sprintf("id=%v, ", mr.ID))
  261. builder.WriteString("created_at=")
  262. builder.WriteString(mr.CreatedAt.Format(time.ANSIC))
  263. builder.WriteString(", ")
  264. builder.WriteString("updated_at=")
  265. builder.WriteString(mr.UpdatedAt.Format(time.ANSIC))
  266. builder.WriteString(", ")
  267. builder.WriteString("status=")
  268. builder.WriteString(fmt.Sprintf("%v", mr.Status))
  269. builder.WriteString(", ")
  270. builder.WriteString("deleted_at=")
  271. builder.WriteString(mr.DeletedAt.Format(time.ANSIC))
  272. builder.WriteString(", ")
  273. builder.WriteString("bot_wxid=")
  274. builder.WriteString(mr.BotWxid)
  275. builder.WriteString(", ")
  276. builder.WriteString("contact_id=")
  277. builder.WriteString(fmt.Sprintf("%v", mr.ContactID))
  278. builder.WriteString(", ")
  279. builder.WriteString("contact_type=")
  280. builder.WriteString(fmt.Sprintf("%v", mr.ContactType))
  281. builder.WriteString(", ")
  282. builder.WriteString("contact_wxid=")
  283. builder.WriteString(mr.ContactWxid)
  284. builder.WriteString(", ")
  285. builder.WriteString("content_type=")
  286. builder.WriteString(fmt.Sprintf("%v", mr.ContentType))
  287. builder.WriteString(", ")
  288. builder.WriteString("content=")
  289. builder.WriteString(mr.Content)
  290. builder.WriteString(", ")
  291. builder.WriteString("error_detail=")
  292. builder.WriteString(mr.ErrorDetail)
  293. builder.WriteString(", ")
  294. builder.WriteString("send_time=")
  295. builder.WriteString(mr.SendTime.Format(time.ANSIC))
  296. builder.WriteString(", ")
  297. builder.WriteString("source_type=")
  298. builder.WriteString(fmt.Sprintf("%v", mr.SourceType))
  299. builder.WriteString(", ")
  300. builder.WriteString("source_id=")
  301. builder.WriteString(fmt.Sprintf("%v", mr.SourceID))
  302. builder.WriteString(", ")
  303. builder.WriteString("sub_source_id=")
  304. builder.WriteString(fmt.Sprintf("%v", mr.SubSourceID))
  305. builder.WriteByte(')')
  306. return builder.String()
  307. }
  308. // MessageRecordsSlice is a parsable slice of MessageRecords.
  309. type MessageRecordsSlice []*MessageRecords