contact.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. "entgo.io/ent"
  9. "entgo.io/ent/dialect/sql"
  10. )
  11. // Contact is the model entity for the Contact schema.
  12. type Contact 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. WxWxid string `json:"wx_wxid,omitempty"`
  26. // 联系人类型:1好友,2群组,3公众号,4企业微信联系人
  27. Type int `json:"type,omitempty"`
  28. // 微信id 公众号微信ID
  29. Wxid string `json:"wxid,omitempty"`
  30. // 微信账号
  31. Account string `json:"account,omitempty"`
  32. // 微信昵称 群备注名称
  33. Nickname string `json:"nickname,omitempty"`
  34. // 备注名
  35. Markname string `json:"markname,omitempty"`
  36. // 头像
  37. Headimg string `json:"headimg,omitempty"`
  38. // 性别 0未知 1男 2女
  39. Sex int `json:"sex,omitempty"`
  40. // 星标 65/67=星标 1/3=未星标
  41. Starrole string `json:"starrole,omitempty"`
  42. // 不让他看我的朋友圈 0可以看 1不让看
  43. Dontseeit int `json:"dontseeit,omitempty"`
  44. // 不看他的朋友圈 0可以看 1不看 1=开启了不看他 128/129=仅聊天
  45. Dontseeme int `json:"dontseeme,omitempty"`
  46. // 所属标签id清单,多开会用逗号隔开
  47. Lag string `json:"lag,omitempty"`
  48. // 群组id
  49. Gid string `json:"gid,omitempty"`
  50. // 群组名称
  51. Gname string `json:"gname,omitempty"`
  52. // v3数据
  53. V3 string `json:"v3,omitempty"`
  54. // Edges holds the relations/edges for other nodes in the graph.
  55. // The values are being populated by the ContactQuery when eager-loading is set.
  56. Edges ContactEdges `json:"edges"`
  57. selectValues sql.SelectValues
  58. }
  59. // ContactEdges holds the relations/edges for other nodes in the graph.
  60. type ContactEdges struct {
  61. // ContactRelationships holds the value of the contact_relationships edge.
  62. ContactRelationships []*LabelRelationship `json:"contact_relationships,omitempty"`
  63. // ContactMessages holds the value of the contact_messages edge.
  64. ContactMessages []*MessageRecords `json:"contact_messages,omitempty"`
  65. // loadedTypes holds the information for reporting if a
  66. // type was loaded (or requested) in eager-loading or not.
  67. loadedTypes [2]bool
  68. }
  69. // ContactRelationshipsOrErr returns the ContactRelationships value or an error if the edge
  70. // was not loaded in eager-loading.
  71. func (e ContactEdges) ContactRelationshipsOrErr() ([]*LabelRelationship, error) {
  72. if e.loadedTypes[0] {
  73. return e.ContactRelationships, nil
  74. }
  75. return nil, &NotLoadedError{edge: "contact_relationships"}
  76. }
  77. // ContactMessagesOrErr returns the ContactMessages value or an error if the edge
  78. // was not loaded in eager-loading.
  79. func (e ContactEdges) ContactMessagesOrErr() ([]*MessageRecords, error) {
  80. if e.loadedTypes[1] {
  81. return e.ContactMessages, nil
  82. }
  83. return nil, &NotLoadedError{edge: "contact_messages"}
  84. }
  85. // scanValues returns the types for scanning values from sql.Rows.
  86. func (*Contact) scanValues(columns []string) ([]any, error) {
  87. values := make([]any, len(columns))
  88. for i := range columns {
  89. switch columns[i] {
  90. case contact.FieldID, contact.FieldStatus, contact.FieldType, contact.FieldSex, contact.FieldDontseeit, contact.FieldDontseeme:
  91. values[i] = new(sql.NullInt64)
  92. case contact.FieldWxWxid, contact.FieldWxid, contact.FieldAccount, contact.FieldNickname, contact.FieldMarkname, contact.FieldHeadimg, contact.FieldStarrole, contact.FieldLag, contact.FieldGid, contact.FieldGname, contact.FieldV3:
  93. values[i] = new(sql.NullString)
  94. case contact.FieldCreatedAt, contact.FieldUpdatedAt, contact.FieldDeletedAt:
  95. values[i] = new(sql.NullTime)
  96. default:
  97. values[i] = new(sql.UnknownType)
  98. }
  99. }
  100. return values, nil
  101. }
  102. // assignValues assigns the values that were returned from sql.Rows (after scanning)
  103. // to the Contact fields.
  104. func (c *Contact) assignValues(columns []string, values []any) error {
  105. if m, n := len(values), len(columns); m < n {
  106. return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
  107. }
  108. for i := range columns {
  109. switch columns[i] {
  110. case contact.FieldID:
  111. value, ok := values[i].(*sql.NullInt64)
  112. if !ok {
  113. return fmt.Errorf("unexpected type %T for field id", value)
  114. }
  115. c.ID = uint64(value.Int64)
  116. case contact.FieldCreatedAt:
  117. if value, ok := values[i].(*sql.NullTime); !ok {
  118. return fmt.Errorf("unexpected type %T for field created_at", values[i])
  119. } else if value.Valid {
  120. c.CreatedAt = value.Time
  121. }
  122. case contact.FieldUpdatedAt:
  123. if value, ok := values[i].(*sql.NullTime); !ok {
  124. return fmt.Errorf("unexpected type %T for field updated_at", values[i])
  125. } else if value.Valid {
  126. c.UpdatedAt = value.Time
  127. }
  128. case contact.FieldStatus:
  129. if value, ok := values[i].(*sql.NullInt64); !ok {
  130. return fmt.Errorf("unexpected type %T for field status", values[i])
  131. } else if value.Valid {
  132. c.Status = uint8(value.Int64)
  133. }
  134. case contact.FieldDeletedAt:
  135. if value, ok := values[i].(*sql.NullTime); !ok {
  136. return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
  137. } else if value.Valid {
  138. c.DeletedAt = value.Time
  139. }
  140. case contact.FieldWxWxid:
  141. if value, ok := values[i].(*sql.NullString); !ok {
  142. return fmt.Errorf("unexpected type %T for field wx_wxid", values[i])
  143. } else if value.Valid {
  144. c.WxWxid = value.String
  145. }
  146. case contact.FieldType:
  147. if value, ok := values[i].(*sql.NullInt64); !ok {
  148. return fmt.Errorf("unexpected type %T for field type", values[i])
  149. } else if value.Valid {
  150. c.Type = int(value.Int64)
  151. }
  152. case contact.FieldWxid:
  153. if value, ok := values[i].(*sql.NullString); !ok {
  154. return fmt.Errorf("unexpected type %T for field wxid", values[i])
  155. } else if value.Valid {
  156. c.Wxid = value.String
  157. }
  158. case contact.FieldAccount:
  159. if value, ok := values[i].(*sql.NullString); !ok {
  160. return fmt.Errorf("unexpected type %T for field account", values[i])
  161. } else if value.Valid {
  162. c.Account = value.String
  163. }
  164. case contact.FieldNickname:
  165. if value, ok := values[i].(*sql.NullString); !ok {
  166. return fmt.Errorf("unexpected type %T for field nickname", values[i])
  167. } else if value.Valid {
  168. c.Nickname = value.String
  169. }
  170. case contact.FieldMarkname:
  171. if value, ok := values[i].(*sql.NullString); !ok {
  172. return fmt.Errorf("unexpected type %T for field markname", values[i])
  173. } else if value.Valid {
  174. c.Markname = value.String
  175. }
  176. case contact.FieldHeadimg:
  177. if value, ok := values[i].(*sql.NullString); !ok {
  178. return fmt.Errorf("unexpected type %T for field headimg", values[i])
  179. } else if value.Valid {
  180. c.Headimg = value.String
  181. }
  182. case contact.FieldSex:
  183. if value, ok := values[i].(*sql.NullInt64); !ok {
  184. return fmt.Errorf("unexpected type %T for field sex", values[i])
  185. } else if value.Valid {
  186. c.Sex = int(value.Int64)
  187. }
  188. case contact.FieldStarrole:
  189. if value, ok := values[i].(*sql.NullString); !ok {
  190. return fmt.Errorf("unexpected type %T for field starrole", values[i])
  191. } else if value.Valid {
  192. c.Starrole = value.String
  193. }
  194. case contact.FieldDontseeit:
  195. if value, ok := values[i].(*sql.NullInt64); !ok {
  196. return fmt.Errorf("unexpected type %T for field dontseeit", values[i])
  197. } else if value.Valid {
  198. c.Dontseeit = int(value.Int64)
  199. }
  200. case contact.FieldDontseeme:
  201. if value, ok := values[i].(*sql.NullInt64); !ok {
  202. return fmt.Errorf("unexpected type %T for field dontseeme", values[i])
  203. } else if value.Valid {
  204. c.Dontseeme = int(value.Int64)
  205. }
  206. case contact.FieldLag:
  207. if value, ok := values[i].(*sql.NullString); !ok {
  208. return fmt.Errorf("unexpected type %T for field lag", values[i])
  209. } else if value.Valid {
  210. c.Lag = value.String
  211. }
  212. case contact.FieldGid:
  213. if value, ok := values[i].(*sql.NullString); !ok {
  214. return fmt.Errorf("unexpected type %T for field gid", values[i])
  215. } else if value.Valid {
  216. c.Gid = value.String
  217. }
  218. case contact.FieldGname:
  219. if value, ok := values[i].(*sql.NullString); !ok {
  220. return fmt.Errorf("unexpected type %T for field gname", values[i])
  221. } else if value.Valid {
  222. c.Gname = value.String
  223. }
  224. case contact.FieldV3:
  225. if value, ok := values[i].(*sql.NullString); !ok {
  226. return fmt.Errorf("unexpected type %T for field v3", values[i])
  227. } else if value.Valid {
  228. c.V3 = value.String
  229. }
  230. default:
  231. c.selectValues.Set(columns[i], values[i])
  232. }
  233. }
  234. return nil
  235. }
  236. // Value returns the ent.Value that was dynamically selected and assigned to the Contact.
  237. // This includes values selected through modifiers, order, etc.
  238. func (c *Contact) Value(name string) (ent.Value, error) {
  239. return c.selectValues.Get(name)
  240. }
  241. // QueryContactRelationships queries the "contact_relationships" edge of the Contact entity.
  242. func (c *Contact) QueryContactRelationships() *LabelRelationshipQuery {
  243. return NewContactClient(c.config).QueryContactRelationships(c)
  244. }
  245. // QueryContactMessages queries the "contact_messages" edge of the Contact entity.
  246. func (c *Contact) QueryContactMessages() *MessageRecordsQuery {
  247. return NewContactClient(c.config).QueryContactMessages(c)
  248. }
  249. // Update returns a builder for updating this Contact.
  250. // Note that you need to call Contact.Unwrap() before calling this method if this Contact
  251. // was returned from a transaction, and the transaction was committed or rolled back.
  252. func (c *Contact) Update() *ContactUpdateOne {
  253. return NewContactClient(c.config).UpdateOne(c)
  254. }
  255. // Unwrap unwraps the Contact entity that was returned from a transaction after it was closed,
  256. // so that all future queries will be executed through the driver which created the transaction.
  257. func (c *Contact) Unwrap() *Contact {
  258. _tx, ok := c.config.driver.(*txDriver)
  259. if !ok {
  260. panic("ent: Contact is not a transactional entity")
  261. }
  262. c.config.driver = _tx.drv
  263. return c
  264. }
  265. // String implements the fmt.Stringer.
  266. func (c *Contact) String() string {
  267. var builder strings.Builder
  268. builder.WriteString("Contact(")
  269. builder.WriteString(fmt.Sprintf("id=%v, ", c.ID))
  270. builder.WriteString("created_at=")
  271. builder.WriteString(c.CreatedAt.Format(time.ANSIC))
  272. builder.WriteString(", ")
  273. builder.WriteString("updated_at=")
  274. builder.WriteString(c.UpdatedAt.Format(time.ANSIC))
  275. builder.WriteString(", ")
  276. builder.WriteString("status=")
  277. builder.WriteString(fmt.Sprintf("%v", c.Status))
  278. builder.WriteString(", ")
  279. builder.WriteString("deleted_at=")
  280. builder.WriteString(c.DeletedAt.Format(time.ANSIC))
  281. builder.WriteString(", ")
  282. builder.WriteString("wx_wxid=")
  283. builder.WriteString(c.WxWxid)
  284. builder.WriteString(", ")
  285. builder.WriteString("type=")
  286. builder.WriteString(fmt.Sprintf("%v", c.Type))
  287. builder.WriteString(", ")
  288. builder.WriteString("wxid=")
  289. builder.WriteString(c.Wxid)
  290. builder.WriteString(", ")
  291. builder.WriteString("account=")
  292. builder.WriteString(c.Account)
  293. builder.WriteString(", ")
  294. builder.WriteString("nickname=")
  295. builder.WriteString(c.Nickname)
  296. builder.WriteString(", ")
  297. builder.WriteString("markname=")
  298. builder.WriteString(c.Markname)
  299. builder.WriteString(", ")
  300. builder.WriteString("headimg=")
  301. builder.WriteString(c.Headimg)
  302. builder.WriteString(", ")
  303. builder.WriteString("sex=")
  304. builder.WriteString(fmt.Sprintf("%v", c.Sex))
  305. builder.WriteString(", ")
  306. builder.WriteString("starrole=")
  307. builder.WriteString(c.Starrole)
  308. builder.WriteString(", ")
  309. builder.WriteString("dontseeit=")
  310. builder.WriteString(fmt.Sprintf("%v", c.Dontseeit))
  311. builder.WriteString(", ")
  312. builder.WriteString("dontseeme=")
  313. builder.WriteString(fmt.Sprintf("%v", c.Dontseeme))
  314. builder.WriteString(", ")
  315. builder.WriteString("lag=")
  316. builder.WriteString(c.Lag)
  317. builder.WriteString(", ")
  318. builder.WriteString("gid=")
  319. builder.WriteString(c.Gid)
  320. builder.WriteString(", ")
  321. builder.WriteString("gname=")
  322. builder.WriteString(c.Gname)
  323. builder.WriteString(", ")
  324. builder.WriteString("v3=")
  325. builder.WriteString(c.V3)
  326. builder.WriteByte(')')
  327. return builder.String()
  328. }
  329. // Contacts is a parsable slice of Contact.
  330. type Contacts []*Contact