From 83339d3e33c70a30d3155f6c64716aa9cffb93a3 Mon Sep 17 00:00:00 2001 From: hanpaopao <510423039@qq.com> Date: Thu, 21 Nov 2024 10:56:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E6=B7=BB=E5=8A=A0=E6=89=B9=E9=87=8F=E5=B7=B2?= =?UTF-8?q?=E8=AF=BB=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Notifications/Dtos/SetBatchReadInput.cs | 7 +++++++ .../Notifications/INotificationAppService.cs | 5 +++++ .../Notifications/NotificationAppService.cs | 18 +++++++++++++++++- .../INotificationSubscriptionManager.cs | 2 ++ .../INotificationSubscriptionRepository.cs | 8 ++++++++ .../NotificationSubscriptionManager.cs | 6 ++++++ ...EfCoreNotificationSubscriptionRepository.cs | 8 ++++++++ .../Notifications/NotificationController.cs | 10 ++++++++++ 8 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/SetBatchReadInput.cs 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 @@ namespace Lion.AbpPro.NotificationManagement.Notifications /// 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 @@ namespace Lion.AbpPro.NotificationManagement.Notifications } } - + public virtual async Task SetBatchReadAsync(SetBatchReadInput input) + { + foreach (var item in input.Ids) + { + await SetReadAsync(new SetReadInput(){Id = item}); + } + } /// /// 分页获取消息 /// @@ -96,6 +102,16 @@ namespace Lion.AbpPro.NotificationManagement.Notifications { 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 @@ public interface INotificationSubscriptionManager 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 @@ namespace Lion.AbpPro.NotificationManagement.Notifications 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 class NotificationSubscriptionManager : NotificationManagementDomainServi 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 class EfCoreNotificationSubscriptionRepository : EfCoreRepository 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 @@ namespace Lion.AbpPro.NotificationManagement.Notifications } + + /// /// 分页获取文本消息 /// x @@ -81,5 +83,13 @@ namespace Lion.AbpPro.NotificationManagement.Notifications { 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