contact.go 12 KB

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