get_contact_list_logic.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package Contact
  2. import (
  3. "context"
  4. "wechat-api/ent/contact"
  5. "wechat-api/ent/predicate"
  6. "wechat-api/internal/svc"
  7. "wechat-api/internal/types"
  8. "wechat-api/internal/utils/dberrorhandler"
  9. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  10. "github.com/suyuan32/simple-admin-common/utils/pointy"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type GetContactListLogic struct {
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. logx.Logger
  17. }
  18. func NewGetContactListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetContactListLogic {
  19. return &GetContactListLogic{
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. Logger: logx.WithContext(ctx),
  23. }
  24. }
  25. func (l *GetContactListLogic) GetContactList(req *types.ContactListReq) (*types.ContactListResp, error) {
  26. var predicates []predicate.Contact
  27. if req.WxWxid != nil {
  28. predicates = append(predicates, contact.WxWxidContains(*req.WxWxid))
  29. }
  30. if req.Wxid != nil {
  31. predicates = append(predicates, contact.WxidContains(*req.Wxid))
  32. }
  33. if req.Account != nil {
  34. predicates = append(predicates, contact.AccountContains(*req.Account))
  35. }
  36. data, err := l.svcCtx.DB.Contact.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
  37. if err != nil {
  38. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  39. }
  40. resp := &types.ContactListResp{}
  41. resp.Msg = errormsg.Success
  42. resp.Data.Total = data.PageDetails.Total
  43. for _, v := range data.List {
  44. resp.Data.Data = append(resp.Data.Data,
  45. types.ContactInfo{
  46. BaseIDInfo: types.BaseIDInfo{
  47. Id: &v.ID,
  48. CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
  49. UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
  50. },
  51. Status: &v.Status,
  52. WxWxid: &v.WxWxid,
  53. Type: &v.Type,
  54. Wxid: &v.Wxid,
  55. Account: &v.Account,
  56. Nickname: &v.Nickname,
  57. Markname: &v.Markname,
  58. Headimg: &v.Headimg,
  59. Sex: &v.Sex,
  60. Starrole: &v.Starrole,
  61. Dontseeit: &v.Dontseeit,
  62. Dontseeme: &v.Dontseeme,
  63. Lag: &v.Lag,
  64. Gid: &v.Gid,
  65. Gname: &v.Gname,
  66. V3: &v.V3,
  67. })
  68. }
  69. return resp, nil
  70. }