messagerecords.go 13 KB

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