|
@@ -0,0 +1,94 @@
|
|
|
+package contact
|
|
|
+
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
|
+ "github.com/suyuan32/simple-admin-common/utils/pointy"
|
|
|
+ "wechat-api/ent"
|
|
|
+ "wechat-api/ent/contact"
|
|
|
+ "wechat-api/ent/label"
|
|
|
+ "wechat-api/ent/labelrelationship"
|
|
|
+ "wechat-api/ent/predicate"
|
|
|
+ "wechat-api/internal/utils/dberrorhandler"
|
|
|
+
|
|
|
+ "wechat-api/internal/svc"
|
|
|
+ "wechat-api/internal/types"
|
|
|
+
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
|
+)
|
|
|
+
|
|
|
+type GetContactSimpleListLogic struct {
|
|
|
+ logx.Logger
|
|
|
+ ctx context.Context
|
|
|
+ svcCtx *svc.ServiceContext
|
|
|
+}
|
|
|
+
|
|
|
+func NewGetContactSimpleListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetContactSimpleListLogic {
|
|
|
+ return &GetContactSimpleListLogic{
|
|
|
+ Logger: logx.WithContext(ctx),
|
|
|
+ ctx: ctx,
|
|
|
+ svcCtx: svcCtx}
|
|
|
+}
|
|
|
+
|
|
|
+func (l *GetContactSimpleListLogic) GetContactSimpleList(req *types.ContactListReq) (*types.ContactSimpleListResp, error) {
|
|
|
+ organizationId := l.ctx.Value("organizationId").(uint64)
|
|
|
+ var predicates []predicate.Contact
|
|
|
+ predicates = append(predicates, contact.OrganizationIDEQ(organizationId))
|
|
|
+
|
|
|
+ var ctype uint64 = 1
|
|
|
+ if req.Ctype != nil {
|
|
|
+ ctype = *req.Ctype
|
|
|
+ }
|
|
|
+ predicates = append(predicates, contact.Ctype(ctype))
|
|
|
+ if len(req.LabelIDs) > 0 {
|
|
|
+ predicates = append(predicates, contact.HasContactRelationshipsWith(
|
|
|
+ labelrelationship.HasLabelsWith(
|
|
|
+ label.IDIn(req.LabelIDs...),
|
|
|
+ ),
|
|
|
+ ))
|
|
|
+ }
|
|
|
+ if req.WxWxid != nil {
|
|
|
+ predicates = append(predicates, contact.WxWxidContains(*req.WxWxid))
|
|
|
+ }
|
|
|
+ if req.Wxid != nil {
|
|
|
+ predicates = append(predicates, contact.WxidContains(*req.Wxid))
|
|
|
+ }
|
|
|
+ if req.Account != nil {
|
|
|
+ predicates = append(predicates, contact.AccountContains(*req.Account))
|
|
|
+ }
|
|
|
+ if req.Nickname != nil {
|
|
|
+ predicates = append(predicates, contact.NicknameContains(*req.Nickname))
|
|
|
+ }
|
|
|
+ if req.Type != nil {
|
|
|
+ predicates = append(predicates, contact.TypeEQ(*req.Type))
|
|
|
+ } else {
|
|
|
+ predicates = append(predicates, contact.Or(contact.TypeEQ(1), contact.TypeEQ(2)))
|
|
|
+ }
|
|
|
+
|
|
|
+ data, err := l.svcCtx.DB.Contact.Query().Where(predicates...).WithContactRelationships(func(query *ent.LabelRelationshipQuery) {
|
|
|
+ query.WithLabels()
|
|
|
+ }).Page(l.ctx, req.Page, req.PageSize)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := &types.ContactSimpleListResp{}
|
|
|
+ resp.Msg = errormsg.Success
|
|
|
+ resp.Data.Total = data.PageDetails.Total
|
|
|
+
|
|
|
+ for _, v := range data.List {
|
|
|
+ resp.Data.Data = append(resp.Data.Data,
|
|
|
+ types.ContactSimpleInfo{
|
|
|
+ BaseIDInfo: types.BaseIDInfo{
|
|
|
+ Id: &v.ID,
|
|
|
+ CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
|
|
|
+ UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
|
|
|
+ },
|
|
|
+ Wxid: &v.Wxid,
|
|
|
+ Nickname: &v.Nickname,
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return resp, nil
|
|
|
+}
|