浏览代码

fix:未读消息数走redis修改

duxin 1 年之前
父节点
当前提交
06405bc84f
共有 1 个文件被更改,包括 11 次插入7 次删除
  1. 11 7
      rpc/internal/common/messageService.go

+ 11 - 7
rpc/internal/common/messageService.go

@@ -65,14 +65,18 @@ func (service *MessageService) CountUnread(userId string) int64 {
 	var count int64
 	var msgTypes []string
 	for _, v := range entity.MessageColumn {
-		msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, qutil.InterfaceToStr(v["group_id"])))
+		if qutil.IntAll(v["group_id"]) > 0 && qutil.IntAll(v["group_id"]) < 999 {
+			msgTypes = append(msgTypes, fmt.Sprintf(`"%s"`, qutil.InterfaceToStr(v["group_id"])))
+		}
 	}
-	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)
-	if query != nil && len(*query) > 0 {
-		for _, v := range *query {
-			count += qutil.Int64All(v["count"])
-			key := fmt.Sprintf(MsgCountKey, userId, qutil.IntAll(v["group_id"]))
-			redis.Put(redisModule, key, qutil.Int64All(v["count"]), -1)
+	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)
+		if query != nil && len(*query) > 0 {
+			for _, v := range *query {
+				count += qutil.Int64All(v["count"])
+				key := fmt.Sprintf(MsgCountKey, userId, qutil.IntAll(v["group_id"]))
+				redis.Put(redisModule, key, qutil.Int64All(v["count"]), -1)
+			}
 		}
 	}