get_label_list_logic.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package label
  2. import (
  3. "context"
  4. "wechat-api/ent"
  5. "wechat-api/ent/label"
  6. "wechat-api/ent/predicate"
  7. "wechat-api/internal/svc"
  8. "wechat-api/internal/types"
  9. "wechat-api/internal/utils/dberrorhandler"
  10. "github.com/suyuan32/simple-admin-common/msg/errormsg"
  11. "github.com/suyuan32/simple-admin-common/utils/pointy"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type GetLabelListLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewGetLabelListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLabelListLogic {
  20. return &GetLabelListLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. func convertContactToContactInfo(label *ent.Contact) types.ContactInfo {
  27. return types.ContactInfo{
  28. BaseIDInfo: types.BaseIDInfo{
  29. Id: &label.ID,
  30. CreatedAt: pointy.GetPointer(label.CreatedAt.UnixMilli()),
  31. UpdatedAt: pointy.GetPointer(label.UpdatedAt.UnixMilli()),
  32. },
  33. Status: &label.Status,
  34. WxWxid: &label.WxWxid,
  35. Type: &label.Type,
  36. Wxid: &label.Wxid,
  37. Account: &label.Account,
  38. Nickname: &label.Nickname,
  39. Markname: &label.Markname,
  40. Headimg: &label.Headimg,
  41. Sex: &label.Sex,
  42. Starrole: &label.Starrole,
  43. Dontseeit: &label.Dontseeit,
  44. Dontseeme: &label.Dontseeme,
  45. Lag: &label.Lag,
  46. Gid: &label.Gid,
  47. Gname: &label.Gname,
  48. V3: &label.V3,
  49. }
  50. }
  51. func (l *GetLabelListLogic) GetLabelList(req *types.LabelListReq) (*types.LabelListResp, error) {
  52. var predicates []predicate.Label
  53. if req.Type != nil {
  54. predicates = append(predicates, label.TypeEQ(*req.Type))
  55. }
  56. if req.Name != nil {
  57. predicates = append(predicates, label.NameContains(*req.Name))
  58. }
  59. if req.From != nil {
  60. predicates = append(predicates, label.FromEQ(*req.From))
  61. }
  62. if req.Mode != nil {
  63. predicates = append(predicates, label.ModeEQ(*req.Mode))
  64. }
  65. data, err := l.svcCtx.DB.Label.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
  66. if err != nil {
  67. return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
  68. }
  69. resp := &types.LabelListResp{}
  70. resp.Msg = errormsg.Success
  71. resp.Data.Total = data.PageDetails.Total
  72. for _, v := range data.List {
  73. resp.Data.Data = append(resp.Data.Data,
  74. types.LabelInfo{
  75. BaseIDInfo: types.BaseIDInfo{
  76. Id: &v.ID,
  77. CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
  78. UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
  79. },
  80. Status: &v.Status,
  81. Type: &v.Type,
  82. Name: &v.Name,
  83. From: &v.From,
  84. Mode: &v.Mode,
  85. Conditions: &v.Conditions,
  86. })
  87. }
  88. return resp, nil
  89. }