diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/SetBatchReadInput.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/SetBatchReadInput.cs new file mode 100644 index 00000000..36576c60 --- /dev/null +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/SetBatchReadInput.cs @@ -0,0 +1,7 @@ +namespace Lion.AbpPro.NotificationManagement.Notifications.Dtos +{ + public class SetBatchReadInput + { + public List Ids { get; set; } + } +} \ No newline at end of file diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/INotificationAppService.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/INotificationAppService.cs index e8b0def2..07516a3b 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/INotificationAppService.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/INotificationAppService.cs @@ -37,6 +37,11 @@ public interface INotificationAppService : IApplicationService /// Task SetReadAsync(SetReadInput input); + /// + /// 批量设置已读 + /// + Task SetBatchReadAsync(SetBatchReadInput input); + /// /// 分页获取消息 /// diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application/Notifications/NotificationAppService.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application/Notifications/NotificationAppService.cs index e778f6e4..3995d8f4 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application/Notifications/NotificationAppService.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application/Notifications/NotificationAppService.cs @@ -88,7 +88,13 @@ 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}); + } + } /// /// 分页获取消息 /// @@ -96,6 +102,16 @@ public virtual async Task> PageNotifica { 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(totalCount, ObjectMapper.Map, List>(list)); } diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionManager.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionManager.cs index 5d5215c1..0a49987f 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionManager.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionManager.cs @@ -32,4 +32,6 @@ Task GetPagingCountAsync( DateTime? startReadTime, DateTime? endReadTime, CancellationToken cancellationToken = default); + + Task> GetListAsync(List notificationId, Guid receiverUserId, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionRepository.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionRepository.cs index c3325fdf..329d6d80 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionRepository.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionRepository.cs @@ -30,5 +30,13 @@ Task GetPagingCountAsync( CancellationToken cancellationToken = default); Task FindAsync(Guid receiverUserId, Guid notificationId, CancellationToken cancellationToken = default); + + /// + /// 分页获取消息 + /// + Task> GetListAsync( + List notificationId, + Guid receiverUserId, + CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationSubscriptionManager.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationSubscriptionManager.cs index c3b8f163..bdeb56ff 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationSubscriptionManager.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationSubscriptionManager.cs @@ -29,6 +29,12 @@ public async Task> GetPagingListAsync(Guid not return ObjectMapper.Map, List>(list); } + public async Task> GetListAsync(List notificationId, Guid receiverUserId, CancellationToken cancellationToken = default) + { + var list = await _notificationSubscriptionRepository.GetListAsync(notificationId, receiverUserId, cancellationToken); + return ObjectMapper.Map, List>(list); + } + public async Task GetPagingCountAsync(Guid notificationId, Guid? receiverUserId, string receiverUserName, DateTime? startReadTime, DateTime? endReadTime, CancellationToken cancellationToken = default) { return await _notificationSubscriptionRepository.GetPagingCountAsync(notificationId, receiverUserId, receiverUserName, startReadTime, endReadTime, cancellationToken); diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.EntityFrameworkCore/EntityFrameworkCore/Notifications/EfCoreNotificationSubscriptionRepository.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.EntityFrameworkCore/EntityFrameworkCore/Notifications/EfCoreNotificationSubscriptionRepository.cs index 0b96a570..c9351693 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.EntityFrameworkCore/EntityFrameworkCore/Notifications/EfCoreNotificationSubscriptionRepository.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.EntityFrameworkCore/EntityFrameworkCore/Notifications/EfCoreNotificationSubscriptionRepository.cs @@ -36,4 +36,12 @@ public async Task FindAsync(Guid receiverUserId, Guid { return await (await GetDbSetAsync()).FirstOrDefaultAsync(e => e.ReceiveUserId == receiverUserId && e.NotificationId == notificationId, GetCancellationToken(cancellationToken)); } + + public async Task> GetListAsync(List notificationId, Guid receiverUserId, CancellationToken cancellationToken = default) + { + return await (await GetDbSetAsync()) + .Where(e => e.ReceiveUserId == receiverUserId) + .Where(e => notificationId.Contains(e.NotificationId)) + .ToListAsync(GetCancellationToken(cancellationToken)); + } } \ No newline at end of file diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.HttpApi/Notifications/NotificationController.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.HttpApi/Notifications/NotificationController.cs index 9ecee9f4..7e6bf6e8 100644 --- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.HttpApi/Notifications/NotificationController.cs +++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.HttpApi/Notifications/NotificationController.cs @@ -12,6 +12,8 @@ public NotificationController( } + + /// /// 分页获取文本消息 /// x @@ -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); + } } } \ No newline at end of file