Skip to content

Commit

Permalink
feat: 消息通知模块添加批量已读接口
Browse files Browse the repository at this point in the history
  • Loading branch information
WangJunZzz committed Nov 21, 2024
1 parent 259b1d6 commit 83339d3
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Lion.AbpPro.NotificationManagement.Notifications.Dtos
{
public class SetBatchReadInput
{
public List<Guid> Ids { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public interface INotificationAppService : IApplicationService
/// </summary>
Task SetReadAsync(SetReadInput input);

/// <summary>
/// 批量设置已读
/// </summary>
Task SetBatchReadAsync(SetBatchReadInput input);

/// <summary>
/// 分页获取消息
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,30 @@ public virtual async Task SetReadAsync(SetReadInput input)
}
}


public virtual async Task SetBatchReadAsync(SetBatchReadInput input)
{
foreach (var item in input.Ids)
{
await SetReadAsync(new SetReadInput(){Id = item});
}
}
/// <summary>
/// 分页获取消息
/// </summary>
public virtual async Task<PagedResultDto<PagingNotificationOutput>> PageNotificationAsync(PagingNotificationInput input)
{
var totalCount = await _notificationManager.GetPagingCountAsync(input.Title, input.Content, input.SenderUserId, input.SenderUserName, input.ReceiverUserId, input.ReceiverUserName, input.Read, input.StartReadTime, input.EndReadTime, input.MessageType,input.MessageLevel);
var list = await _notificationManager.GetPagingListAsync(input.Title, input.Content, input.SenderUserId, input.SenderUserName, input.ReceiverUserId, input.ReceiverUserName, input.Read, input.StartReadTime, input.EndReadTime, input.MessageType,input.MessageLevel, input.PageSize, input.SkipCount);
// var boardCastNotificationIds = list.Where(e => e.MessageType == MessageType.BroadCast).Select(e => e.Id).ToList();
// // 获取通告消息当前用户是否已读
// var boardCastNotificationSubscriptions = await _notificationSubscriptionManager.GetListAsync(boardCastNotificationIds, CurrentUser.GetId());
// foreach (var item in list)
// {
// var sub = boardCastNotificationSubscriptions.FirstOrDefault(e => e.NotificationId == item.Id);
// item.Read = sub != null;
// item.ReceiveUserId = sub?.ReceiveUserId;
// item.ReceiveUserName = sub?.ReceiveUserName;
// }
return new PagedResultDto<PagingNotificationOutput>(totalCount, ObjectMapper.Map<List<NotificationDto>, List<PagingNotificationOutput>>(list));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ Task<long> GetPagingCountAsync(
DateTime? startReadTime,
DateTime? endReadTime,
CancellationToken cancellationToken = default);

Task<List<NotificationSubscriptionDto>> GetListAsync(List<Guid> notificationId, Guid receiverUserId, CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@ Task<long> GetPagingCountAsync(
CancellationToken cancellationToken = default);

Task<NotificationSubscription> FindAsync(Guid receiverUserId, Guid notificationId, CancellationToken cancellationToken = default);

/// <summary>
/// 分页获取消息
/// </summary>
Task<List<NotificationSubscription>> GetListAsync(
List<Guid> notificationId,
Guid receiverUserId,
CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public async Task<List<NotificationSubscriptionDto>> GetPagingListAsync(Guid not
return ObjectMapper.Map<List<NotificationSubscription>, List<NotificationSubscriptionDto>>(list);
}

public async Task<List<NotificationSubscriptionDto>> GetListAsync(List<Guid> notificationId, Guid receiverUserId, CancellationToken cancellationToken = default)
{
var list = await _notificationSubscriptionRepository.GetListAsync(notificationId, receiverUserId, cancellationToken);
return ObjectMapper.Map<List<NotificationSubscription>, List<NotificationSubscriptionDto>>(list);
}

public async Task<long> GetPagingCountAsync(Guid notificationId, Guid? receiverUserId, string receiverUserName, DateTime? startReadTime, DateTime? endReadTime, CancellationToken cancellationToken = default)
{
return await _notificationSubscriptionRepository.GetPagingCountAsync(notificationId, receiverUserId, receiverUserName, startReadTime, endReadTime, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ public async Task<NotificationSubscription> FindAsync(Guid receiverUserId, Guid
{
return await (await GetDbSetAsync()).FirstOrDefaultAsync(e => e.ReceiveUserId == receiverUserId && e.NotificationId == notificationId, GetCancellationToken(cancellationToken));
}

public async Task<List<NotificationSubscription>> GetListAsync(List<Guid> notificationId, Guid receiverUserId, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(e => e.ReceiveUserId == receiverUserId)
.Where(e => notificationId.Contains(e.NotificationId))
.ToListAsync(GetCancellationToken(cancellationToken));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public NotificationController(
}




/// <summary>
/// 分页获取文本消息
/// </summary>x
Expand Down Expand Up @@ -81,5 +83,13 @@ public Task SetReadAsync(SetReadInput input)
{
return _notificationAppService.SetReadAsync(input);
}


[HttpPost("BatchRead")]
[SwaggerOperation(summary: "消息批量设置为已读", Tags = new[] { "Notification" })]
public Task SetBatchReadAsync(SetBatchReadInput input)
{
return _notificationAppService.SetBatchReadAsync(input);
}
}
}

0 comments on commit 83339d3

Please sign in to comment.