From 8e32e5ac4a9337c2ea457c734f1f7b5f2f5f4189 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Wed, 27 Dec 2023 18:29:49 +0800 Subject: [PATCH] by Robin at 20231227; fix --- .../proto/contact_customer_service_vo_op.go | 3 ++- .../contact_customer_service_session_op.go | 15 +++++++++++++++ app/mix/dao/mongo.go | 17 +++++++++++++++++ .../logic/contact_customer_service_session.go | 13 +++++++++++-- app/mix/service/service.go | 12 +++++++++++- app/mix/service/utilservice.go | 17 +++++++++++++++++ 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/api/proto/contact_customer_service/proto/contact_customer_service_vo_op.go b/api/proto/contact_customer_service/proto/contact_customer_service_vo_op.go index d2313f2f..9ff78ed9 100644 --- a/api/proto/contact_customer_service/proto/contact_customer_service_vo_op.go +++ b/api/proto/contact_customer_service/proto/contact_customer_service_vo_op.go @@ -3,6 +3,7 @@ package proto import "service/dbstruct" type ContactCustomerServiceOpUnreadVO struct { - SessionId int64 `json:"session_id"` // 待回复用户mid + SessionId int64 `json:"session_id"` // 待回复用户session_id + SubMid int64 `json:"sub_mid"` // 待回复用户mid List []*dbstruct.ContactCustomerService `json:"contents"` // 待回复用户内容 } diff --git a/api/proto/contact_customer_service_session/proto/contact_customer_service_session_op.go b/api/proto/contact_customer_service_session/proto/contact_customer_service_session_op.go index 8105949e..bc86348b 100644 --- a/api/proto/contact_customer_service_session/proto/contact_customer_service_session_op.go +++ b/api/proto/contact_customer_service_session/proto/contact_customer_service_session_op.go @@ -64,6 +64,21 @@ type OpListBySessionIdResp struct { Data *OpListBySessionIdData `json:"data"` } +// op 列表-session_id列表查询 +type OpListBySessionIdsReq struct { + base.BaseRequest + SessionIds []int64 `json:"session_ids"` +} + +type OpListBySessionIdsData struct { + List []*dbstruct.ContactCustomerServiceSession `json:"list"` +} + +type OpListBySessionIdsResp struct { + base.BaseResponse + Data *OpListBySessionIdsData `json:"data"` +} + // op 列出所有对话 type OpListReq struct { base.BaseRequest diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index e0102dcc..9fec59ff 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -2552,6 +2552,23 @@ func (m *Mongo) GetContactCustomerServiceSessionListByMid(ctx *gin.Context, req return session, err } +func (m *Mongo) GetContactCustomerServiceSessionListBySessionIds(ctx *gin.Context, req *contact_customer_service_sessionproto.OpListBySessionIdsReq) ([]*dbstruct.ContactCustomerServiceSession, error) { + list := make([]*dbstruct.ContactCustomerServiceSession, 0) + col := m.getColContactCustomerServiceSession() + query := qmgo.M{ + "_id": qmgo.M{ + "$in": req.SessionIds, + }, + "del_flag": 0, + } + err := col.Find(ctx, query).All(&list) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return nil, err + } + return list, err +} + func (m *Mongo) GetContactCustomerServiceSessionListBySessionId(ctx *gin.Context, req *contact_customer_service_sessionproto.OpListBySessionIdReq) (*dbstruct.ContactCustomerServiceSession, error) { session := &dbstruct.ContactCustomerServiceSession{} col := m.getColContactCustomerServiceSession() diff --git a/app/mix/service/logic/contact_customer_service_session.go b/app/mix/service/logic/contact_customer_service_session.go index 40116a78..0a47a52f 100644 --- a/app/mix/service/logic/contact_customer_service_session.go +++ b/app/mix/service/logic/contact_customer_service_session.go @@ -56,16 +56,25 @@ func (p *ContactCustomerServiceSession) OpUpdate(ctx *gin.Context, req *contact_ func (p *ContactCustomerServiceSession) OpListByMid(ctx *gin.Context, req *contact_customer_service_sessionproto.OpListByMidReq) (*dbstruct.ContactCustomerServiceSession, error) { session, err := p.store.GetContactCustomerServiceSessionListByMid(ctx, req) if err != nil { - logger.Error("GetContactCustomerServiceSessionList fail, err: %v", err) + logger.Error("GetContactCustomerServiceSessionListByMid fail, err: %v", err) return nil, err } return session, nil } +func (p *ContactCustomerServiceSession) OpListBySessionIds(ctx *gin.Context, req *contact_customer_service_sessionproto.OpListBySessionIdsReq) ([]*dbstruct.ContactCustomerServiceSession, error) { + list, err := p.store.GetContactCustomerServiceSessionListBySessionIds(ctx, req) + if err != nil { + logger.Error("GetContactCustomerServiceSessionListBySessionIds fail, err: %v", err) + return nil, err + } + return list, nil +} + func (p *ContactCustomerServiceSession) OpListBySessionId(ctx *gin.Context, req *contact_customer_service_sessionproto.OpListBySessionIdReq) (*dbstruct.ContactCustomerServiceSession, error) { session, err := p.store.GetContactCustomerServiceSessionListBySessionId(ctx, req) if err != nil { - logger.Error("GetContactCustomerServiceSessionList fail, err: %v", err) + logger.Error("GetContactCustomerServiceSessionListBySessionId fail, err: %v", err) return nil, err } return session, nil diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 1369403b..ea5b5d5d 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -2240,10 +2240,19 @@ func (s *Service) OpGetContactCustomerServiceListUnreadGroupByMid(ctx *gin.Conte } _map := make(map[int64][]*dbstruct.ContactCustomerService) - for _, contact_customer_service := range list { + sessionIds := make([]int64, len(list)) + for i, contact_customer_service := range list { sessionId := util.DerefInt64(contact_customer_service.SessionId) contents := _map[sessionId] _map[sessionId] = append(contents, contact_customer_service) + sessionIds[i] = util.DerefInt64(contact_customer_service.SessionId) + } + + sessionMap, err := s.utilGetContactCustomerServiceSessionMap(ctx, sessionIds) + if err != nil { + logger.Error("utilGetContactCustomerServiceSessionMap fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeContactCustomerServiceSessionSrvFail + return } index := 0 @@ -2251,6 +2260,7 @@ func (s *Service) OpGetContactCustomerServiceListUnreadGroupByMid(ctx *gin.Conte for sessionId, contents := range _map { volist[index] = &contact_customer_service_proto.ContactCustomerServiceOpUnreadVO{ SessionId: sessionId, + SubMid: util.DerefInt64(sessionMap[sessionId].SubMid), List: contents, } index++ diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 43f16a7d..513137e2 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -4,6 +4,7 @@ import ( "fmt" "service/api/errcode" accountproto "service/api/proto/account/proto" + contact_customer_service_sessionproto "service/api/proto/contact_customer_service_session/proto" loginproto "service/api/proto/login/proto" streamerproto "service/api/proto/streamer/proto" streamerlinkproto "service/api/proto/streamerlink/proto" @@ -203,3 +204,19 @@ func (s *Service) utilExtendAccountsIntoStreamerExts(ctx *gin.Context, accountLi return } + +// 提供session_id,返回session_id -> Session的Map +func (s *Service) utilGetContactCustomerServiceSessionMap(ctx *gin.Context, sessionIds []int64) (_map map[int64]*dbstruct.ContactCustomerServiceSession, err error) { + list, err := _DefaultContactCustomerServiceSession.OpListBySessionIds(ctx, &contact_customer_service_sessionproto.OpListBySessionIdsReq{ + SessionIds: sessionIds, + }) + if err != nil { + logger.Error("OpListBySessionIds fail: %v", err) + return + } + _map = make(map[int64]*dbstruct.ContactCustomerServiceSession) + for _, session := range list { + _map[util.DerefInt64(session.Id)] = session + } + return +}