Przeglądaj źródła

fix:初始化redis未读数修改

duxin 1 rok temu
rodzic
commit
0604a1b586
1 zmienionych plików z 9 dodań i 6 usunięć
  1. 9 6
      rpc/internal/common/messageService.go

+ 9 - 6
rpc/internal/common/messageService.go

@@ -85,12 +85,15 @@ func (service *MessageService) CountUnread(userId string, isRedis bool) (map[str
 		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 {
-				data[qutil.InterfaceToStr(v["group_id"])] = qutil.Int64All(v["count"])
-				count += qutil.Int64All(v["count"])
-				if isRedis {
-					key := fmt.Sprintf(MsgCountKey, userId, qutil.IntAll(v["group_id"]))
-					redis.Put(redisModule, key, qutil.Int64All(v["count"]), -1)
-				}
+				unread := qutil.Int64All(v["count"])
+				data[qutil.InterfaceToStr(v["group_id"])] = unread
+				count += unread
+			}
+		}
+		if isRedis { //初始化未读数
+			for _, v1 := range msgTypes {
+				key := fmt.Sprintf(MsgCountKey, userId, qutil.IntAll(v1))
+				redis.Put(redisModule, key, data[v1], -1)
 			}
 		}
 	}