From b728ab5e4865cf438e726ddce6ac008a116a554c Mon Sep 17 00:00:00 2001 From: Leufolium Date: Thu, 29 Feb 2024 11:20:25 +0800 Subject: [PATCH 1/2] by Robin at 20240229; fix --- .../proto/contact_customer_service_op.go | 1 + app/mix/dao/mongo.go | 18 ++++++++++++ .../service/logic/contact_customer_service.go | 9 ++++++ app/mix/service/utilservice.go | 28 +++++++++++++------ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/api/proto/contact_customer_service/proto/contact_customer_service_op.go b/api/proto/contact_customer_service/proto/contact_customer_service_op.go index 31762084..a113dda3 100644 --- a/api/proto/contact_customer_service/proto/contact_customer_service_op.go +++ b/api/proto/contact_customer_service/proto/contact_customer_service_op.go @@ -37,6 +37,7 @@ type OpUpdateByIdsResp struct { // op 查询所有未读 type OpListReq struct { base.BaseRequest + IsRead *int64 `json:"is_read"` //是否已读 CtUpperBound *int64 `json:"ct_upper_bound"` //创建时间上界,闭区间 CtLowerBound *int64 `json:"ct_lower_bound"` //创建时间下界,开区间,可为0 } diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index f4d03d2e..7ff1516f 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -2432,6 +2432,9 @@ func (m *Mongo) GetContactCustomerServiceList(ctx *gin.Context, req *contact_cus "predicate": consts.ContactCustomerService_FromUser, "del_flag": 0, } + if req.IsRead != nil { + query["is_read"] = util.DerefInt64(req.IsRead) + } filterInClause := []qmgo.M{} if req.CtLowerBound != nil { filterInClause = append(filterInClause, qmgo.M{ @@ -2475,6 +2478,21 @@ func (m *Mongo) GetUnreadContactCustomerServiceList(ctx *gin.Context, req *conta return list, err } +func (m *Mongo) GetUnreadContactCustomerServiceCount(ctx *gin.Context) (int64, error) { + col := m.getColContactCustomerService() + query := qmgo.M{ + "is_read": consts.ContactCustomerService_NotRead, + "predicate": consts.ContactCustomerService_FromUser, + "del_flag": 0, + } + count, err := col.Find(ctx, query).Count() + if err == qmgo.ErrNoSuchDocuments { + err = nil + return 0, err + } + return count, err +} + func (m *Mongo) GetContactCustomerServiceListBySessionId(ctx *gin.Context, req *contact_customer_service_proto.OpListBySessionIdReq) ([]*dbstruct.ContactCustomerService, error) { list := make([]*dbstruct.ContactCustomerService, 0) col := m.getColContactCustomerService() diff --git a/app/mix/service/logic/contact_customer_service.go b/app/mix/service/logic/contact_customer_service.go index 8876b907..05552362 100644 --- a/app/mix/service/logic/contact_customer_service.go +++ b/app/mix/service/logic/contact_customer_service.go @@ -81,6 +81,15 @@ func (p *ContactCustomerService) OpListUnread(ctx *gin.Context, req *contact_cus return list, nil } +func (p *ContactCustomerService) OpCountUnread(ctx *gin.Context) (int64, error) { + count, err := p.store.GetUnreadContactCustomerServiceCount(ctx) + if err != nil { + logger.Error("GetUnreadContactCustomerServiceCount fail, err: %v", err) + return 0, err + } + return count, nil +} + func (p *ContactCustomerService) OpListBySessionId(ctx *gin.Context, req *contact_customer_serviceproto.OpListBySessionIdReq) ([]*dbstruct.ContactCustomerService, error) { list, err := p.store.GetContactCustomerServiceListBySessionId(ctx, req) if err != nil { diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index aed576eb..d07cf3c2 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -588,10 +588,23 @@ func (s *Service) utilStringifyContactCustomerServices(ctx *gin.Context, contact return } + countUnread, err := _DefaultContactCustomerService.OpCountUnread(ctx) + if err != nil { + logger.Error("OpCountUnread fail, err: %v", err) + return + } + msgBuilder := &strings.Builder{} - msgBuilder.WriteString("上分钟收到的联系客服消息:\n\n") + msgBuilder.WriteString(fmt.Sprintf("上分钟收到的联系客服消息:%v\n", len(contactCustomerServices))) + msgBuilder.WriteString(fmt.Sprintf("当前总未读消息数:%v\n\n", countUnread)) + msgBuilder.WriteString("当前未读消息:\n") for i, contactCustomerService := range contactCustomerServices { + isRead := util.DerefInt64(contactCustomerService.IsRead) + if isRead == consts.ContactCustomerService_Read { + continue + } + sessionId := util.DerefInt64(contactCustomerService.SessionId) account, err1 := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{ Mid: sessionMap[sessionId].SubMid, @@ -601,16 +614,13 @@ func (s *Service) utilStringifyContactCustomerServices(ctx *gin.Context, contact err = err1 return } - isRead := util.DerefInt64(contactCustomerService.IsRead) - message := util.DerefString(contactCustomerService.Message) ct := util.DerefInt64(contactCustomerService.Ct) createtime := time.Unix(ct, 0).Format(time.DateTime) - if isRead == consts.ContactCustomerService_NotRead { - msgBuilder.WriteString(fmt.Sprintf("%v. 接收到未读消息:\n", i)) - } else { - msgBuilder.WriteString(fmt.Sprintf("%v. 该条消息已读:\n", i)) - } - msgBuilder.WriteString(fmt.Sprintf("user_id: %v, session_id: %v, message: \"%v\", ct: %v\n\n", util.DerefInt64(account.UserId), sessionId, message, createtime)) + msgBuilder.WriteString(fmt.Sprintf("%v\n", i+1)) + msgBuilder.WriteString(fmt.Sprintf("用户id: %v\n", util.DerefInt64(account.UserId))) + msgBuilder.WriteString(fmt.Sprintf("发送内容: %v\n", util.DerefString(contactCustomerService.Message))) + msgBuilder.WriteString(fmt.Sprintf("发送时间: %v\n\n", createtime)) + } msg = msgBuilder.String() From b41aad7e4e8ebd22b706e9038a7887b383ef2db5 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Thu, 29 Feb 2024 11:22:33 +0800 Subject: [PATCH 2/2] 1 --- app/mix/service/utilservice.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index d07cf3c2..08bb0755 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -597,7 +597,7 @@ func (s *Service) utilStringifyContactCustomerServices(ctx *gin.Context, contact msgBuilder := &strings.Builder{} msgBuilder.WriteString(fmt.Sprintf("上分钟收到的联系客服消息:%v\n", len(contactCustomerServices))) msgBuilder.WriteString(fmt.Sprintf("当前总未读消息数:%v\n\n", countUnread)) - msgBuilder.WriteString("当前未读消息:\n") + msgBuilder.WriteString("新增未读消息:\n") for i, contactCustomerService := range contactCustomerServices { isRead := util.DerefInt64(contactCustomerService.IsRead)