This commit is contained in:
18631081161 2026-01-29 15:50:30 +08:00
parent 7b0bfa9963
commit 5d03eeecea

View File

@ -856,6 +856,7 @@ public class InteractService : IInteractService
// 统计各类互动的新增数量
// 看过我统计首次查看时间CreateTime在上次已读之后的新用户数量
// 这样同一用户多次查看只计算一次(首次查看时)
// 注意:使用 > 而不是 >= 来避免边界情况但需要在标记已读时加1秒的缓冲
var viewedMeCount = await _viewRepository.CountAsync(v =>
v.TargetUserId == userId && v.CreateTime > user.LastViewedMeReadTime);
@ -882,7 +883,8 @@ public class InteractService : IInteractService
throw new BusinessException(ErrorCodes.UserNotFound, "用户不存在");
}
var now = DateTime.Now;
// 加1秒缓冲避免因时间精度问题导致刚标记已读的记录仍被统计为未读
var now = DateTime.Now.AddSeconds(1);
switch (type.ToLower())
{
@ -899,10 +901,10 @@ public class InteractService : IInteractService
throw new BusinessException(ErrorCodes.InvalidParameter, "无效的互动类型");
}
user.UpdateTime = now;
user.UpdateTime = DateTime.Now;
await _userRepository.UpdateAsync(user);
_logger.LogInformation("标记互动已读: UserId={UserId}, Type={Type}", userId, type);
_logger.LogInformation("标记互动已读: UserId={UserId}, Type={Type}, ReadTime={ReadTime}", userId, type, now);
}
#endregion