소스 검색

Merge branch 'fixbug/20250322' into debug

jimmyyem 1 개월 전
부모
커밋
6a28c4e2af

+ 28 - 0
desc/wechat/contact.api

@@ -18,6 +18,30 @@ type (
         Data  []ContactInfo  `json:"data"`
     }
 
+	ContactSimpleListResp {
+		BaseDataInfo
+
+		// Contact list data | Contact列表数据
+		Data ContactSimpleListInfo `json:"data"`
+	}
+
+	ContactSimpleListInfo {
+		BaseListInfo
+
+		// The API list data | Contact列表数据
+		Data  []ContactSimpleInfo  `json:"data"`
+	}
+
+	ContactSimpleInfo {
+		BaseIDInfo
+
+		// 微信id 公众号微信ID
+		Wxid  *string `json:"wxid,optional"`
+
+		// 微信昵称 群备注名称
+		Nickname  *string `json:"nickname,optional"`
+	}
+
     // Get contact list request params | Contact列表请求参数
     ContactListReq {
         PageInfo
@@ -127,6 +151,10 @@ service Wechat {
     @handler getContactList
     post /contact/list (ContactListReq) returns (ContactListResp)
 
+	// Get contact list | 获取Contact列表
+	@handler getContactSimpleList
+	post /contact/simple (ContactListReq) returns (ContactSimpleListResp)
+
     // Get contact by ID | 通过ID获取Contact
     @handler getContactById
     post /contact (IDReq) returns (ContactInfoResp)

+ 44 - 0
internal/handler/contact/get_contact_simple_list_handler.go

@@ -0,0 +1,44 @@
+package contact
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/contact"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /contact/simple contact GetContactSimpleList
+//
+// Get contact list | 获取Contact列表
+//
+// Get contact list | 获取Contact列表
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: ContactListReq
+//
+// Responses:
+//  200: ContactListResp
+
+func GetContactSimpleListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.ContactListReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := contact.NewGetContactSimpleListLogic(r.Context(), svcCtx)
+		resp, err := l.GetContactSimpleList(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 5 - 0
internal/handler/routes.go

@@ -369,6 +369,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				},
 				{
 					Method:  http.MethodPost,
+					Path:    "/contact/simple",
+					Handler: contact.GetContactSimpleListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
 					Path:    "/contact",
 					Handler: contact.GetContactByIdHandler(serverCtx),
 				},

+ 94 - 0
internal/logic/contact/get_contact_simple_list_logic.go

@@ -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
+}

+ 23 - 0
internal/types/types.go

@@ -987,6 +987,29 @@ type ContactListInfo struct {
 	Data []ContactInfo `json:"data"`
 }
 
+// swagger:model ContactSimpleListResp
+type ContactSimpleListResp struct {
+	BaseDataInfo
+	// Contact list data | Contact列表数据
+	Data ContactSimpleListInfo `json:"data"`
+}
+
+// swagger:model ContactSimpleListInfo
+type ContactSimpleListInfo struct {
+	BaseListInfo
+	// The API list data | Contact列表数据
+	Data []ContactSimpleInfo `json:"data"`
+}
+
+// swagger:model ContactSimpleInfo
+type ContactSimpleInfo struct {
+	BaseIDInfo
+	// 微信id 公众号微信ID
+	Wxid *string `json:"wxid,optional"`
+	// 微信昵称 群备注名称
+	Nickname *string `json:"nickname,optional"`
+}
+
 // Get contact list request params | Contact列表请求参数
 // swagger:model ContactListReq
 type ContactListReq struct {