by Robin at 20241203

This commit is contained in:
Robin 2024-12-03 15:41:29 +08:00
parent 495980a255
commit 9a8483c295
4 changed files with 43 additions and 41 deletions

View File

@ -263,6 +263,7 @@ var ErrCodeMsgMap = map[ErrCode]string{
ErrCodeNotificationPushFail: "系统通知表推送失败",
ErrCodeNotificationPullFail: "系统通知表拉取失败",
ErrCodeNotificationWrongStatusForCancellation: "仅可撤销待推送的系统通知",
ErrCodeNotificationUrcUpdateFail: "未读数更新失败",
ErrCodeRavenIQTestSrvFail: "瑞文智商测试表服务错误",
ErrCodeRavenIQTestNotExist: "瑞文智商测试表不存在",
@ -631,6 +632,7 @@ const (
ErrCodeNotificationPushFail ErrCode = -46003 // 系统通知表推送失败
ErrCodeNotificationPullFail ErrCode = -46004 // 系统通知表拉取失败
ErrCodeNotificationWrongStatusForCancellation ErrCode = -46005 // 系统通知表状态错误
ErrCodeNotificationUrcUpdateFail ErrCode = -46006 // 系统通知表未读数更新失败
// FrontendRoute: 47xxx
ErrCodeFrontendRouteSrvOk ErrCode = ErrCodeOk

View File

@ -4690,18 +4690,10 @@ func (s *Service) ApiReadNotification(ctx *gin.Context, req *notificationproto.A
}
// 以真更新的条数decr
key := util.GetNotifUrcIdForRedis(req.BaseRequest.Mid, req.NType)
totalKey := util.GetNotifUrcTotalIdForRedis(req.BaseRequest.Mid)
_, err = redis.GetRedisClient().DecrBy(key, result.ModifiedCount)
err = s.utilDecrUrc(req.BaseRequest.Mid, req.NType, result.ModifiedCount)
if err != nil {
logger.Error("Redis DecrBy fail, err: %v", err)
ec = errcode.ErrCodeNotificationSrvFail
return
}
_, err = redis.GetRedisClient().DecrBy(totalKey, result.ModifiedCount)
if err != nil {
logger.Error("Redis DecrBy fail, err: %v", err)
ec = errcode.ErrCodeNotificationSrvFail
logger.Error("utilDecrUrc fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeNotificationUrcUpdateFail
return
}
@ -4711,8 +4703,6 @@ func (s *Service) ApiReadNotification(ctx *gin.Context, req *notificationproto.A
func (s *Service) ApiReadAllNotification(ctx *gin.Context, req *notificationproto.ApiReadAllReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeNotificationSrvOk
totalDecr := int64(0)
for _, nType := range req.NTypes {
// 标记已读
@ -4724,23 +4714,12 @@ func (s *Service) ApiReadAllNotification(ctx *gin.Context, req *notificationprot
}
// 以真更新的条数decr
key := util.GetNotifUrcIdForRedis(req.BaseRequest.Mid, nType)
_, err = redis.GetRedisClient().DecrBy(key, result.ModifiedCount)
err = s.utilDecrUrc(req.BaseRequest.Mid, nType, result.ModifiedCount)
if err != nil {
logger.Error("Redis DecrBy fail, err: %v", err)
ec = errcode.ErrCodeNotificationSrvFail
logger.Error("utilDecrUrc fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeNotificationUrcUpdateFail
return
}
totalDecr += result.ModifiedCount
}
totalKey := util.GetNotifUrcTotalIdForRedis(req.BaseRequest.Mid)
_, err := redis.GetRedisClient().DecrBy(totalKey, totalDecr)
if err != nil {
logger.Error("Redis DecrBy fail, err: %v", err)
ec = errcode.ErrCodeNotificationSrvFail
return
}
return

View File

@ -137,14 +137,10 @@ func (s *NotifBcstCenter) pushNotifsToMids(ctx *gin.Context, nids []int64, objMi
// 记录未读总数
for _, mid := range objMids {
for nType, total := range nTypeTotalMap {
_, err = redis.GetRedisClient().IncrBy(util.GetNotifUrcIdForRedis(mid, nType), total)
// 以真更新的条数incr
err = DefaultService.utilIncrUrc(mid, nType, total)
if err != nil {
logger.Error("Redis IncrBy fail, err: %v", err)
return err
}
_, err = redis.GetRedisClient().IncrBy(util.GetNotifUrcTotalIdForRedis(mid), total)
if err != nil {
logger.Error("Redis IncrBy fail, err: %v", err)
logger.Error("utilIncrUrc fail, err: %v", err)
return err
}
}
@ -245,14 +241,11 @@ func (s *NotifBcstCenter) pullAllBcstedNotifs(ctx *gin.Context, vers, receiveVer
// 记录未读总数
for nType, total := range nTypeTotalMap {
_, err = redis.GetRedisClient().IncrBy(util.GetNotifUrcIdForRedis(objMid, nType), total)
// 以真更新的条数incr
err = DefaultService.utilIncrUrc(objMid, nType, total)
if err != nil {
logger.Error("Redis IncrBy fail, err: %v", err)
return err
}
_, err = redis.GetRedisClient().IncrBy(util.GetNotifUrcTotalIdForRedis(objMid), total)
if err != nil {
logger.Error("Redis IncrBy fail, err: %v", err)
logger.Error("utilIncrUrc fail, err: %v", err)
return err
}
}

View File

@ -2335,3 +2335,31 @@ func (s *Service) utilBuildInwardHyperLink(ctx *gin.Context, frontendRouteId int
return hyperlinks, nil
}
func (s *Service) utilIncrUrc(mid, nType, incr int64) error {
_, err := redis.GetRedisClient().IncrBy(util.GetNotifUrcIdForRedis(mid, nType), incr)
if err != nil {
logger.Error("Redis IncrBy fail, err: %v", err)
return err
}
_, err = redis.GetRedisClient().IncrBy(util.GetNotifUrcTotalIdForRedis(mid), incr)
if err != nil {
logger.Error("Redis IncrBy fail, err: %v", err)
return err
}
return nil
}
func (s *Service) utilDecrUrc(mid, nType, incr int64) error {
_, err := redis.GetRedisClient().DecrBy(util.GetNotifUrcIdForRedis(mid, nType), incr)
if err != nil {
logger.Error("Redis DecrBy fail, err: %v", err)
return err
}
_, err = redis.GetRedisClient().DecrBy(util.GetNotifUrcTotalIdForRedis(mid), incr)
if err != nil {
logger.Error("Redis DecrBy fail, err: %v", err)
return err
}
return nil
}