messagerecords.go 13 KB

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