messagerecords.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. // Code generated by ent, DO NOT EDIT.
  2. package ent
  3. import (
  4. "fmt"
  5. "strings"
  6. "time"
  7. "wechat-api/ent/messagerecords"
  8. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // MessageRecords is the model entity for the MessageRecords schema.
  12. type MessageRecords struct {
  13. config `json:"-"`
  14. // ID of the ent.
  15. ID uint64 `json:"id,omitempty"`
  16. // Create Time | 创建日期
  17. CreatedAt time.Time `json:"created_at,omitempty"`
  18. // Update Time | 修改日期
  19. UpdatedAt time.Time `json:"updated_at,omitempty"`
  20. // Status 1: normal 2: ban | 状态 1 正常 2 禁用
  21. Status uint8 `json:"status,omitempty"`
  22. // Delete Time | 删除日期
  23. DeletedAt time.Time `json:"deleted_at,omitempty"`
  24. // 机器人微信 id
  25. BotWxid string `json:"bot_wxid,omitempty"`
  26. // 联系人 id
  27. ContactID int `json:"contact_id,omitempty"`
  28. // 类型:1好友,2群组,3企业微信联系人
  29. ContactType int `json:"contact_type,omitempty"`
  30. // 接收方微信 id
  31. ContactWxid string `json:"contact_wxid,omitempty"`
  32. // 内容类型 1 文本 2 文件
  33. ContentType int `json:"content_type,omitempty"`
  34. // 发送内容
  35. Content string `json:"content,omitempty"`
  36. // 异常原因
  37. ErrorDetail string `json:"error_detail,omitempty"`
  38. // 发送时间
  39. SendTime time.Time `json:"send_time,omitempty"`
  40. // 源类型 1 点发 2 群发 3 SOP
  41. SourceType int `json:"source_type,omitempty"`
  42. // 源 ID
  43. SourceID int `json:"source_id,omitempty"`
  44. // 次源 ID
  45. SubSourceID int `json:"sub_source_id,omitempty"`
  46. selectValues sql.SelectValues
  47. }
  48. // scanValues returns the types for scanning values from sql.Rows.
  49. func (*MessageRecords) scanValues(columns []string) ([]any, error) {
  50. values := make([]any, len(columns))
  51. for i := range columns {
  52. switch columns[i] {
  53. case messagerecords.FieldID, messagerecords.FieldStatus, messagerecords.FieldContactID, messagerecords.FieldContactType, messagerecords.FieldContentType, messagerecords.FieldSourceType, messagerecords.FieldSourceID, messagerecords.FieldSubSourceID:
  54. values[i] = new(sql.NullInt64)
  55. case messagerecords.FieldBotWxid, messagerecords.FieldContactWxid, messagerecords.FieldContent, messagerecords.FieldErrorDetail:
  56. values[i] = new(sql.NullString)
  57. case messagerecords.FieldCreatedAt, messagerecords.FieldUpdatedAt, messagerecords.FieldDeletedAt, messagerecords.FieldSendTime:
  58. values[i] = new(sql.NullTime)
  59. default:
  60. values[i] = new(sql.UnknownType)
  61. }
  62. }
  63. return values, nil
  64. }
  65. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  66. // to the MessageRecords fields.
  67. func (mr *MessageRecords) assignValues(columns []string, values []any) error {
  68. if m, n := len(values), len(columns); m < n {
  69. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  70. }
  71. for i := range columns {
  72. switch columns[i] {
  73. case messagerecords.FieldID:
  74. value, ok := values[i].(*sql.NullInt64)
  75. if !ok {
  76. return fmt.Errorf("unexpected type %T for field id", value)
  77. }
  78. mr.ID = uint64(value.Int64)
  79. case messagerecords.FieldCreatedAt:
  80. if value, ok := values[i].(*sql.NullTime); !ok {
  81. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  82. } else if value.Valid {
  83. mr.CreatedAt = value.Time
  84. }
  85. case messagerecords.FieldUpdatedAt:
  86. if value, ok := values[i].(*sql.NullTime); !ok {
  87. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  88. } else if value.Valid {
  89. mr.UpdatedAt = value.Time
  90. }
  91. case messagerecords.FieldStatus:
  92. if value, ok := values[i].(*sql.NullInt64); !ok {
  93. return fmt.Errorf("unexpected type %T for field status", values[i])
  94. } else if value.Valid {
  95. mr.Status = uint8(value.Int64)
  96. }
  97. case messagerecords.FieldDeletedAt:
  98. if value, ok := values[i].(*sql.NullTime); !ok {
  99. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  100. } else if value.Valid {
  101. mr.DeletedAt = value.Time
  102. }
  103. case messagerecords.FieldBotWxid:
  104. if value, ok := values[i].(*sql.NullString); !ok {
  105. return fmt.Errorf("unexpected type %T for field bot_wxid", values[i])
  106. } else if value.Valid {
  107. mr.BotWxid = value.String
  108. }
  109. case messagerecords.FieldContactID:
  110. if value, ok := values[i].(*sql.NullInt64); !ok {
  111. return fmt.Errorf("unexpected type %T for field contact_id", values[i])
  112. } else if value.Valid {
  113. mr.ContactID = int(value.Int64)
  114. }
  115. case messagerecords.FieldContactType:
  116. if value, ok := values[i].(*sql.NullInt64); !ok {
  117. return fmt.Errorf("unexpected type %T for field contact_type", values[i])
  118. } else if value.Valid {
  119. mr.ContactType = int(value.Int64)
  120. }
  121. case messagerecords.FieldContactWxid:
  122. if value, ok := values[i].(*sql.NullString); !ok {
  123. return fmt.Errorf("unexpected type %T for field contact_wxid", values[i])
  124. } else if value.Valid {
  125. mr.ContactWxid = value.String
  126. }
  127. case messagerecords.FieldContentType:
  128. if value, ok := values[i].(*sql.NullInt64); !ok {
  129. return fmt.Errorf("unexpected type %T for field content_type", values[i])
  130. } else if value.Valid {
  131. mr.ContentType = int(value.Int64)
  132. }
  133. case messagerecords.FieldContent:
  134. if value, ok := values[i].(*sql.NullString); !ok {
  135. return fmt.Errorf("unexpected type %T for field content", values[i])
  136. } else if value.Valid {
  137. mr.Content = value.String
  138. }
  139. case messagerecords.FieldErrorDetail:
  140. if value, ok := values[i].(*sql.NullString); !ok {
  141. return fmt.Errorf("unexpected type %T for field error_detail", values[i])
  142. } else if value.Valid {
  143. mr.ErrorDetail = value.String
  144. }
  145. case messagerecords.FieldSendTime:
  146. if value, ok := values[i].(*sql.NullTime); !ok {
  147. return fmt.Errorf("unexpected type %T for field send_time", values[i])
  148. } else if value.Valid {
  149. mr.SendTime = value.Time
  150. }
  151. case messagerecords.FieldSourceType:
  152. if value, ok := values[i].(*sql.NullInt64); !ok {
  153. return fmt.Errorf("unexpected type %T for field source_type", values[i])
  154. } else if value.Valid {
  155. mr.SourceType = int(value.Int64)
  156. }
  157. case messagerecords.FieldSourceID:
  158. if value, ok := values[i].(*sql.NullInt64); !ok {
  159. return fmt.Errorf("unexpected type %T for field source_id", values[i])
  160. } else if value.Valid {
  161. mr.SourceID = int(value.Int64)
  162. }
  163. case messagerecords.FieldSubSourceID:
  164. if value, ok := values[i].(*sql.NullInt64); !ok {
  165. return fmt.Errorf("unexpected type %T for field sub_source_id", values[i])
  166. } else if value.Valid {
  167. mr.SubSourceID = int(value.Int64)
  168. }
  169. default:
  170. mr.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 MessageRecords.
  176. // This includes values selected through modifiers, order, etc.
  177. func (mr *MessageRecords) Value(name string) (ent.Value, error) {
  178. return mr.selectValues.Get(name)
  179. }
  180. // Update returns a builder for updating this MessageRecords.
  181. // Note that you need to call MessageRecords.Unwrap() before calling this method if this MessageRecords
  182. // was returned from a transaction, and the transaction was committed or rolled back.
  183. func (mr *MessageRecords) Update() *MessageRecordsUpdateOne {
  184. return NewMessageRecordsClient(mr.config).UpdateOne(mr)
  185. }
  186. // Unwrap unwraps the MessageRecords entity that was returned from a transaction after it was closed,
  187. // so that all future queries will be executed through the driver which created the transaction.
  188. func (mr *MessageRecords) Unwrap() *MessageRecords {
  189. _tx, ok := mr.config.driver.(*txDriver)
  190. if !ok {
  191. panic("ent: MessageRecords is not a transactional entity")
  192. }
  193. mr.config.driver = _tx.drv
  194. return mr
  195. }
  196. // String implements the fmt.Stringer.
  197. func (mr *MessageRecords) String() string {
  198. var builder strings.Builder
  199. builder.WriteString("MessageRecords(")
  200. builder.WriteString(fmt.Sprintf("id=%v, ", mr.ID))
  201. builder.WriteString("created_at=")
  202. builder.WriteString(mr.CreatedAt.Format(time.ANSIC))
  203. builder.WriteString(", ")
  204. builder.WriteString("updated_at=")
  205. builder.WriteString(mr.UpdatedAt.Format(time.ANSIC))
  206. builder.WriteString(", ")
  207. builder.WriteString("status=")
  208. builder.WriteString(fmt.Sprintf("%v", mr.Status))
  209. builder.WriteString(", ")
  210. builder.WriteString("deleted_at=")
  211. builder.WriteString(mr.DeletedAt.Format(time.ANSIC))
  212. builder.WriteString(", ")
  213. builder.WriteString("bot_wxid=")
  214. builder.WriteString(mr.BotWxid)
  215. builder.WriteString(", ")
  216. builder.WriteString("contact_id=")
  217. builder.WriteString(fmt.Sprintf("%v", mr.ContactID))
  218. builder.WriteString(", ")
  219. builder.WriteString("contact_type=")
  220. builder.WriteString(fmt.Sprintf("%v", mr.ContactType))
  221. builder.WriteString(", ")
  222. builder.WriteString("contact_wxid=")
  223. builder.WriteString(mr.ContactWxid)
  224. builder.WriteString(", ")
  225. builder.WriteString("content_type=")
  226. builder.WriteString(fmt.Sprintf("%v", mr.ContentType))
  227. builder.WriteString(", ")
  228. builder.WriteString("content=")
  229. builder.WriteString(mr.Content)
  230. builder.WriteString(", ")
  231. builder.WriteString("error_detail=")
  232. builder.WriteString(mr.ErrorDetail)
  233. builder.WriteString(", ")
  234. builder.WriteString("send_time=")
  235. builder.WriteString(mr.SendTime.Format(time.ANSIC))
  236. builder.WriteString(", ")
  237. builder.WriteString("source_type=")
  238. builder.WriteString(fmt.Sprintf("%v", mr.SourceType))
  239. builder.WriteString(", ")
  240. builder.WriteString("source_id=")
  241. builder.WriteString(fmt.Sprintf("%v", mr.SourceID))
  242. builder.WriteString(", ")
  243. builder.WriteString("sub_source_id=")
  244. builder.WriteString(fmt.Sprintf("%v", mr.SubSourceID))
  245. builder.WriteByte(')')
  246. return builder.String()
  247. }
  248. // MessageRecordsSlice is a parsable slice of MessageRecords.
  249. type MessageRecordsSlice []*MessageRecords