Ver código fonte

fix:未读消息数走redis修改

duxin 1 ano atrás
pai
commit
5cbe2c8e71

+ 1 - 1
rpc/internal/common/messageService.go

@@ -70,7 +70,7 @@ func (service *MessageService) CountUnread(userId string) int64 {
 		}
 	}
 	if len(msgTypes) > 0 {
-		query := entity.Mysql.SelectBySql(fmt.Sprintf("SELECT group_id,COUNT(CASE WHEN isRead=0 THEN 1 END) as count  FROM message where receive_userid=? and isdel=1 GROUP BY group_id  ORDER BY FIELD(`group_id`,%s)", strings.Join(msgTypes, ",")), userId)
+		query := entity.Mysql.SelectBySql(fmt.Sprintf("SELECT group_id,COUNT(CASE WHEN isRead=0 THEN 1 END) as count  FROM message where receive_userid=? and isdel=1 and group_id IS NOT NULL GROUP BY group_id  ORDER BY FIELD(`group_id`,%s)", strings.Join(msgTypes, ",")), userId)
 		if query != nil && len(*query) > 0 {
 			for _, v := range *query {
 				count += qutil.Int64All(v["count"])

+ 10 - 7
rpc/internal/common/sendMsg.go

@@ -102,15 +102,18 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
 	)
 	data := new(message.UserMsgList)
 	if !this.IsMsgList && !this.IsColumnNewMsg && !this.IsColumn { //消息未读数统计
-		var isUnread int
+		var isUnread, isColumn int
 		for _, v := range entity.MessageColumn {
-			key := fmt.Sprintf(MsgCountKey, this.UserId, util.IntAll(v["group_id"]))
-			if exists, _ := redis.Exists(redisModule, key); exists {
-				isUnread++
-				unread += util.Int64All(redis.GetInt(redisModule, key))
+			if util.IntAll(v["group_id"]) > 0 && util.IntAll(v["group_id"]) < 999 {
+				isColumn++ //去除全部与私信
+				key := fmt.Sprintf(MsgCountKey, this.UserId, util.IntAll(v["group_id"]))
+				if exists, _ := redis.Exists(redisModule, key); exists {
+					isUnread++
+					unread += util.Int64All(redis.GetInt(redisModule, key))
+				}
 			}
 		}
-		if isUnread != len(entity.MessageColumn) {
+		if isUnread != isColumn {
 			m := &MessageService{}
 			unread = m.CountUnread(this.UserId)
 		}
@@ -181,7 +184,7 @@ func UserMsgList(this *message.UserMsgListReq) *message.UserMsgList {
 			column.MsgType = common.Int64All(v["group_id"])
 			if column.Name == "私信" {
 				column.UnreadMessages = unreadMsg(this)
-			} else {
+			} else if common.IntAll(v["group_id"]) > 0 {
 				//消息未读数
 				msgType := common.InterfaceToStr(v["group_id"])
 				column.UnreadMessages = util.Int64All(redis.GetInt(redisModule, fmt.Sprintf(MsgCountKey, this.UserId, util.IntAll(msgType))))