Browse Source

feat: 消息通知模块添加批量已读接口

production
hanpaopao 1 year ago
parent
commit
83339d3e33
  1. 7
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/SetBatchReadInput.cs
  2. 5
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/INotificationAppService.cs
  3. 18
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application/Notifications/NotificationAppService.cs
  4. 2
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionManager.cs
  5. 8
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionRepository.cs
  6. 6
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationSubscriptionManager.cs
  7. 8
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.EntityFrameworkCore/EntityFrameworkCore/Notifications/EfCoreNotificationSubscriptionRepository.cs
  8. 10
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.HttpApi/Notifications/NotificationController.cs

7
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<Guid> Ids { get; set; }
}
}

5
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/INotificationAppService.cs

@ -37,6 +37,11 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
/// </summary>
Task SetReadAsync(SetReadInput input);
/// <summary>
/// 批量设置已读
/// </summary>
Task SetBatchReadAsync(SetBatchReadInput input);
/// <summary>
/// 分页获取消息
/// </summary>

18
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});
}
}
/// <summary>
/// 分页获取消息
/// </summary>
@ -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<PagingNotificationOutput>(totalCount, ObjectMapper.Map<List<NotificationDto>, List<PagingNotificationOutput>>(list));
}

2
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<List<NotificationSubscriptionDto>> GetListAsync(List<Guid> notificationId, Guid receiverUserId, CancellationToken cancellationToken = default);
}

8
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<NotificationSubscription> FindAsync(Guid receiverUserId, Guid notificationId, CancellationToken cancellationToken = default);
/// <summary>
/// 分页获取消息
/// </summary>
Task<List<NotificationSubscription>> GetListAsync(
List<Guid> notificationId,
Guid receiverUserId,
CancellationToken cancellationToken = default);
}
}

6
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationSubscriptionManager.cs

@ -29,6 +29,12 @@ public class NotificationSubscriptionManager : NotificationManagementDomainServi
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);

8
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.EntityFrameworkCore/EntityFrameworkCore/Notifications/EfCoreNotificationSubscriptionRepository.cs

@ -36,4 +36,12 @@ public class EfCoreNotificationSubscriptionRepository : EfCoreRepository<INotifi
{
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));
}
}

10
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.HttpApi/Notifications/NotificationController.cs

@ -12,6 +12,8 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
}
/// <summary>
/// 分页获取文本消息
/// </summary>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);
}
}
}
Loading…
Cancel
Save