From 321988d149dc21fe090a4a87b789891ba12bca25 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Thu, 12 Sep 2024 16:06:31 +0800 Subject: [PATCH] by Robin at 20240912 --- .../contact_customer_service_session_api.go | 15 +++++++++++++++ .../contact_customer_service_session_op.go | 15 +++++++++++++++ app/mix/controller/init.go | 2 ++ app/mix/service/apiservice.go | 11 ++++++++++- app/mix/service/service.go | 15 ++++++++++++++- 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/app/mix/controller/contact_customer_service_session_api.go b/app/mix/controller/contact_customer_service_session_api.go index 4eebc656..638e4657 100644 --- a/app/mix/controller/contact_customer_service_session_api.go +++ b/app/mix/controller/contact_customer_service_session_api.go @@ -40,3 +40,18 @@ func ApiGetContactCustomerServiceSessionListByMid(ctx *gin.Context) { } ReplyOk(ctx, data) } + +func ApiGetUnreadContactCustomerServiceCountByMid(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*contact_customer_service_sessionproto.ApiCountUnreadByMidReq) + unreadCount, ec := service.DefaultService.ApiGetUnreadContactCustomerServiceCountByMid(ctx, req) + if ec != errcode.ErrCodeContactCustomerServiceSessionSrvOk { + logger.Error("ApiGetUnreadContactCustomerServiceCountByMid fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &contact_customer_service_sessionproto.ApiCountUnreadByMidData{ + UnreadCount: unreadCount, + } + ReplyOk(ctx, data) +} diff --git a/app/mix/controller/contact_customer_service_session_op.go b/app/mix/controller/contact_customer_service_session_op.go index 925c1873..0117e820 100644 --- a/app/mix/controller/contact_customer_service_session_op.go +++ b/app/mix/controller/contact_customer_service_session_op.go @@ -70,3 +70,18 @@ func OpGetContactCustomerServiceSessionList(ctx *gin.Context) { } ReplyOk(ctx, data) } + +func OpGetUnreadContactCustomerServiceCountByMid(ctx *gin.Context) { + req := ctx.MustGet("client_req").(*contact_customer_service_sessionproto.OpCountUnreadByMidReq) + unreadCount, ec := service.DefaultService.OpGetUnreadContactCustomerServiceCountByMid(ctx, req) + if ec != errcode.ErrCodeContactCustomerServiceSessionSrvOk { + logger.Error("OpGetUnreadContactCustomerServiceCountByMid fail, req: %v, ec: %v", util.ToJson(req), ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + data := &contact_customer_service_sessionproto.OpCountUnreadByMidData{ + UnreadCount: unreadCount, + } + ReplyOk(ctx, data) +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index 6eff858d..be5e8636 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -205,6 +205,7 @@ func Init(r *gin.Engine) { apiContactCustomerServiceSessionGroup := r.Group("/api/contact_customer_service_session", PrepareToC()) apiContactCustomerServiceSessionGroup.POST("create", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiCreateReq{}), middleware.JwtAuthenticator(), ApiCreateContactCustomerServiceSession) apiContactCustomerServiceSessionGroup.POST("list_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiListByMidReq{}), middleware.JwtAuthenticator(), ApiGetContactCustomerServiceSessionListByMid) + apiContactCustomerServiceSessionGroup.POST("get_unread_count_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.ApiCountUnreadByMidReq{}), middleware.JwtAuthenticator(), ApiGetUnreadContactCustomerServiceCountByMid) // 应用配置表 apiAppConfigGroup := r.Group("/api/app_config", PrepareToC()) @@ -497,6 +498,7 @@ func Init(r *gin.Engine) { opContactCustomerServiceSessionGroup.POST("create", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpCreateReq{}), middleware.JwtAuthenticator(), OpCreateContactCustomerServiceSession) opContactCustomerServiceSessionGroup.POST("list_by_mid", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpListByMidReq{}), middleware.JwtAuthenticator(), OpGetContactCustomerServiceSessionListByMid) opContactCustomerServiceSessionGroup.POST("list", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpListReq{}), middleware.JwtAuthenticator(), OpGetContactCustomerServiceSessionList) + opContactCustomerServiceSessionGroup.POST("get_unread_count", middleware.JSONParamValidator(contact_customer_service_sessionproto.OpCountUnreadByMidReq{}), middleware.JwtAuthenticator(), OpGetUnreadContactCustomerServiceCountByMid) // 图片审核任务 opImageAuditTaskGroup := r.Group("/op/image_audit_task", PrepareOp()) diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 3f7c3125..822c7d43 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2007,7 +2007,7 @@ func (s *Service) ApiCreateContactCustomerService(ctx *gin.Context, req *contact ec = errcode.ErrCodeContactCustomerServiceCountRedisCacheInvalid return } - _, err = redis.GetRedisClient().Incr(consts.RedisContactCustomerServicePrefix + "sup_total_unread_count") + _, err = redis.GetRedisClient().Incr(consts.RedisContactCustomerServicePrefix + "from_sup_total_unread_count") if err != nil { logger.Error("Redis Incr fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeContactCustomerServiceCountRedisCacheInvalid @@ -2171,6 +2171,15 @@ func (s *Service) ApiGetContactCustomerServiceSessionListByMid(ctx *gin.Context, return } +func (s *Service) ApiGetUnreadContactCustomerServiceCountByMid(ctx *gin.Context, req *contact_customer_service_sessionproto.ApiCountUnreadByMidReq) (unreadCount int64, ec errcode.ErrCode) { + ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk + + key := logic.GetCreateContactCustomerServiceCountIdForRedis(util.DerefInt64(req.SessionId), consts.ContactCustomerService_FromSupportor) + unreadCount, _ = redis.GetRedisClient().GetInt64(key) + + return +} + // Moment func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode, acctPunEndTime string) { ec = errcode.ErrCodeMomentSrvOk diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 84cd459d..3670b337 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -3135,7 +3135,7 @@ func (s *Service) OpUpdateContactCustomerServiceByIds(ctx *gin.Context, req *con } } // 去掉总量 - _, err = redis.GetRedisClient().DecrBy(consts.RedisContactCustomerServicePrefix+"sup_total_unread_count", int64(len(req.Ids))) + _, err = redis.GetRedisClient().DecrBy(consts.RedisContactCustomerServicePrefix+"from_sup_total_unread_count", int64(len(req.Ids))) if err != nil { logger.Error("Redis DecrBy fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeContactCustomerServiceCountRedisCacheInvalid @@ -3648,6 +3648,19 @@ func (s *Service) OpGetContactCustomerServiceSessionList(ctx *gin.Context, req * return } +func (s *Service) OpGetUnreadContactCustomerServiceCountByMid(ctx *gin.Context, req *contact_customer_service_sessionproto.OpCountUnreadByMidReq) (unreadCount int64, ec errcode.ErrCode) { + ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk + + if req.SessionId != nil { + key := logic.GetCreateContactCustomerServiceCountIdForRedis(util.DerefInt64(req.SessionId), consts.ContactCustomerService_FromUser) + unreadCount, _ = redis.GetRedisClient().GetInt64(key) + } else { + unreadCount, _ = redis.GetRedisClient().GetInt64(consts.RedisContactCustomerServicePrefix + "from_sup_total_unread_count") + } + + return +} + // DailyStatement func (s *Service) OpGetDailyStatementList(ctx *gin.Context, req *daily_statementproto.OpListReq) (list []*dbstruct.DailyStatement, ec errcode.ErrCode) { ec = errcode.ErrCodeDailyStatementSrvOk