看过
This commit is contained in:
parent
5d03eeecea
commit
6c16412fd6
|
|
@ -23,7 +23,7 @@ const ENV = {
|
|||
}
|
||||
|
||||
// 当前环境 - 开发时使用 development,打包时改为 production
|
||||
const CURRENT_ENV = 'production'
|
||||
const CURRENT_ENV = 'development'
|
||||
|
||||
// 导出配置
|
||||
export const config = {
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class InteractService : IInteractService
|
|||
|
||||
if (existingView != null)
|
||||
{
|
||||
// 更新浏览次数和时间
|
||||
// 更新浏览次数和时间(不重置IsRead状态,同一用户多次查看不重复计数)
|
||||
existingView.ViewCount++;
|
||||
existingView.ViewDate = today; // 更新为最新日期
|
||||
existingView.LastViewTime = DateTime.Now;
|
||||
|
|
@ -94,6 +94,7 @@ public class InteractService : IInteractService
|
|||
ViewDate = today,
|
||||
ViewCount = 1,
|
||||
LastViewTime = DateTime.Now,
|
||||
IsRead = false, // 新记录默认未读
|
||||
CreateTime = DateTime.Now,
|
||||
UpdateTime = DateTime.Now
|
||||
};
|
||||
|
|
@ -819,52 +820,18 @@ public class InteractService : IInteractService
|
|||
/// <inheritdoc />
|
||||
public async Task<InteractCountsResponse> GetInteractCountsAsync(long userId)
|
||||
{
|
||||
var user = await _userRepository.GetByIdAsync(userId);
|
||||
if (user == null)
|
||||
{
|
||||
return new InteractCountsResponse();
|
||||
}
|
||||
|
||||
// 如果用户从未查看过互动列表,初始化已读时间为当前时间
|
||||
// 这样只统计从现在开始的新互动,避免历史数据一直显示未读
|
||||
var needUpdate = false;
|
||||
var now = DateTime.Now;
|
||||
|
||||
if (user.LastViewedMeReadTime == null)
|
||||
{
|
||||
user.LastViewedMeReadTime = now;
|
||||
needUpdate = true;
|
||||
}
|
||||
if (user.LastFavoritedMeReadTime == null)
|
||||
{
|
||||
user.LastFavoritedMeReadTime = now;
|
||||
needUpdate = true;
|
||||
}
|
||||
if (user.LastUnlockedMeReadTime == null)
|
||||
{
|
||||
user.LastUnlockedMeReadTime = now;
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
if (needUpdate)
|
||||
{
|
||||
user.UpdateTime = now;
|
||||
await _userRepository.UpdateAsync(user);
|
||||
_logger.LogInformation("初始化用户互动已读时间: UserId={UserId}", userId);
|
||||
}
|
||||
|
||||
// 统计各类互动的新增数量
|
||||
// 看过我:统计首次查看时间(CreateTime)在上次已读之后的新用户数量
|
||||
// 这样同一用户多次查看只计算一次(首次查看时)
|
||||
// 注意:使用 > 而不是 >= 来避免边界情况,但需要在标记已读时加1秒的缓冲
|
||||
// 统计各类互动的未读数量(IsRead = false)
|
||||
var viewedMeCount = await _viewRepository.CountAsync(v =>
|
||||
v.TargetUserId == userId && v.CreateTime > user.LastViewedMeReadTime);
|
||||
v.TargetUserId == userId && !v.IsRead);
|
||||
|
||||
var favoritedMeCount = await _favoriteRepository.CountAsync(f =>
|
||||
f.TargetUserId == userId && f.CreateTime > user.LastFavoritedMeReadTime);
|
||||
f.TargetUserId == userId && !f.IsRead);
|
||||
|
||||
var unlockedMeCount = await _unlockRepository.CountAsync(u =>
|
||||
u.TargetUserId == userId && u.CreateTime > user.LastUnlockedMeReadTime);
|
||||
u.TargetUserId == userId && !u.IsRead);
|
||||
|
||||
_logger.LogInformation("获取互动统计: UserId={UserId}, ViewedMeCount={ViewedMeCount}, FavoritedMeCount={FavoritedMeCount}, UnlockedMeCount={UnlockedMeCount}",
|
||||
userId, viewedMeCount, favoritedMeCount, unlockedMeCount);
|
||||
|
||||
return new InteractCountsResponse
|
||||
{
|
||||
|
|
@ -877,34 +844,52 @@ public class InteractService : IInteractService
|
|||
/// <inheritdoc />
|
||||
public async Task MarkInteractAsReadAsync(long userId, string type)
|
||||
{
|
||||
var user = await _userRepository.GetByIdAsync(userId);
|
||||
if (user == null)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.UserNotFound, "用户不存在");
|
||||
}
|
||||
|
||||
// 加1秒缓冲,避免因时间精度问题导致刚标记已读的记录仍被统计为未读
|
||||
var now = DateTime.Now.AddSeconds(1);
|
||||
int updatedCount = 0;
|
||||
|
||||
switch (type.ToLower())
|
||||
{
|
||||
case "viewedme":
|
||||
user.LastViewedMeReadTime = now;
|
||||
// 批量更新所有未读的"看过我"记录
|
||||
var unreadViews = await _viewRepository.GetListAsync(v =>
|
||||
v.TargetUserId == userId && !v.IsRead);
|
||||
foreach (var view in unreadViews)
|
||||
{
|
||||
view.IsRead = true;
|
||||
view.UpdateTime = DateTime.Now;
|
||||
await _viewRepository.UpdateAsync(view);
|
||||
updatedCount++;
|
||||
}
|
||||
break;
|
||||
case "favoritedme":
|
||||
user.LastFavoritedMeReadTime = now;
|
||||
// 批量更新所有未读的"收藏我"记录
|
||||
var unreadFavorites = await _favoriteRepository.GetListAsync(f =>
|
||||
f.TargetUserId == userId && !f.IsRead);
|
||||
foreach (var favorite in unreadFavorites)
|
||||
{
|
||||
favorite.IsRead = true;
|
||||
favorite.UpdateTime = DateTime.Now;
|
||||
await _favoriteRepository.UpdateAsync(favorite);
|
||||
updatedCount++;
|
||||
}
|
||||
break;
|
||||
case "unlockedme":
|
||||
user.LastUnlockedMeReadTime = now;
|
||||
// 批量更新所有未读的"解锁我"记录
|
||||
var unreadUnlocks = await _unlockRepository.GetListAsync(u =>
|
||||
u.TargetUserId == userId && !u.IsRead);
|
||||
foreach (var unlock in unreadUnlocks)
|
||||
{
|
||||
unlock.IsRead = true;
|
||||
unlock.UpdateTime = DateTime.Now;
|
||||
await _unlockRepository.UpdateAsync(unlock);
|
||||
updatedCount++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new BusinessException(ErrorCodes.InvalidParameter, "无效的互动类型");
|
||||
}
|
||||
|
||||
user.UpdateTime = DateTime.Now;
|
||||
await _userRepository.UpdateAsync(user);
|
||||
|
||||
_logger.LogInformation("标记互动已读: UserId={UserId}, Type={Type}, ReadTime={ReadTime}", userId, type, now);
|
||||
_logger.LogInformation("标记互动已读: UserId={UserId}, Type={Type}, UpdatedCount={UpdatedCount}",
|
||||
userId, type, updatedCount);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -18,6 +18,11 @@ public class UserFavorite : BaseEntity
|
|||
/// </summary>
|
||||
public long TargetUserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被收藏者是否已读
|
||||
/// </summary>
|
||||
public bool IsRead { get; set; } = false;
|
||||
|
||||
#region 导航属性
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,11 @@ public class UserUnlock : BaseEntity
|
|||
/// </summary>
|
||||
public long TargetUserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被解锁者是否已读
|
||||
/// </summary>
|
||||
public bool IsRead { get; set; } = false;
|
||||
|
||||
#region 导航属性
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -34,6 +34,11 @@ public class UserView : BaseEntity
|
|||
/// </summary>
|
||||
public DateTime LastViewTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被浏览者是否已读
|
||||
/// </summary>
|
||||
public bool IsRead { get; set; } = false;
|
||||
|
||||
#region 导航属性
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user