Browse Source

feat: 添加删除消息接口

feat/cap
Hanpaopao 1 year ago
parent
commit
611dcc1592
  1. 13
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/DeleteMessageInput.cs
  2. 2
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/INotificationAppService.cs
  3. 31
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application/Notifications/NotificationAppService.cs
  4. 4
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationManager.cs
  5. 1
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationRepository.cs
  6. 8
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionManager.cs
  7. 1
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionRepository.cs
  8. 9
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs
  9. 16
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationSubscriptionManager.cs
  10. 10
      aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.HttpApi/Notifications/NotificationController.cs

13
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/DeleteMessageInput.cs

@ -0,0 +1,13 @@
namespace Lion.AbpPro.NotificationManagement.Notifications.Dtos
{
public class DeleteMessageInput
{
public Guid Id { get; set; }
/// <summary>
/// 接受者Id
/// </summary>
public Guid? ReceiverUserId { get; set; }
}
}

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

@ -48,5 +48,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
Task<PagedResultDto<PagingNotificationOutput>> PageNotificationAsync(PagingNotificationInput input);
Task<PagedResultDto<PagingNotificationSubscriptionOutput>> PageNotificationSubscriptionAsync(PagingNotificationSubscriptionInput input);
Task DeleteAsync(DeleteMessageInput input);
}
}

31
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application/Notifications/NotificationAppService.cs

@ -66,7 +66,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
public virtual async Task SetReadAsync(SetReadInput input)
{
var notification = await _notificationManager.FindAsync(input.Id);
var notification = await _notificationManager.GetAsync(input.Id);
if (notification == null)
{
@ -92,16 +92,19 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
{
foreach (var item in input.Ids)
{
await SetReadAsync(new SetReadInput(){Id = item});
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 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());
@ -144,5 +147,25 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
return result;
}
public async Task DeleteAsync(DeleteMessageInput input)
{
var notification = await _notificationManager.GetAsync(input.Id);
// 判断消息类型
if (notification.MessageType == MessageType.Common)
{
await _notificationManager.DeleteAsync(notification.Id);
return;
}
// todo 暂时只删除普通文本消息
// if (notification.MessageType == MessageType.BroadCast && input.ReceiverUserId.HasValue)
// {
// var subscription = await _notificationSubscriptionManager.FindAsync(input.ReceiverUserId.Value, input.Id);
// if (subscription != null)
// {
// await _notificationSubscriptionManager.DeleteAsync(subscription.Id);
// }
// }
}
}
}

4
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationManager.cs

@ -63,7 +63,9 @@ public interface INotificationManager
/// <param name="id">消息Id</param>
Task SetReadAsync(Guid id);
Task<NotificationDto> FindAsync(Guid id);
Task<NotificationDto> GetAsync(Guid id);
Task<List<NotificationDto>> GetListAsync(List<Guid> ids);
Task DeleteAsync(Guid id);
}

1
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationRepository.cs

@ -42,5 +42,6 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
CancellationToken cancellationToken = default);
Task<List<Notification>> GetListAsync(List<Guid> ids);
}
}

8
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionManager.cs

@ -34,4 +34,12 @@ public interface INotificationSubscriptionManager
CancellationToken cancellationToken = default);
Task<List<NotificationSubscriptionDto>> GetListAsync(List<Guid> notificationId, Guid receiverUserId, CancellationToken cancellationToken = default);
Task<NotificationSubscriptionDto> FindAsync(Guid receiveUserId, Guid notificationId, CancellationToken cancellationToken = default);
/// <summary>
/// 删除消息
/// </summary>
Task DeleteAsync(Guid id, CancellationToken cancellationToken = default);
}

1
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationSubscriptionRepository.cs

@ -38,5 +38,6 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
List<Guid> notificationId,
Guid receiverUserId,
CancellationToken cancellationToken = default);
}
}

9
aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs

@ -85,7 +85,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
}
public async Task<NotificationDto> FindAsync(Guid id)
public async Task<NotificationDto> GetAsync(Guid id)
{
var notification = await _notificationRepository.FindAsync(id);
if (notification == null) throw new NotificationManagementDomainException(NotificationManagementErrorCodes.MessageNotExist);
@ -98,6 +98,13 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
return ObjectMapper.Map<List<Notification>, List<NotificationDto>>(notifications);
}
public async Task DeleteAsync(Guid id)
{
var notification = await _notificationRepository.FindAsync(id);
if (notification == null) throw new NotificationManagementDomainException(NotificationManagementErrorCodes.MessageNotExist);
await _notificationRepository.DeleteAsync(notification.Id);
}
/// <summary>
/// 消息设置为已读
/// </summary>

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

@ -23,7 +23,8 @@ public class NotificationSubscriptionManager : NotificationManagementDomainServi
await _notificationSubscriptionRepository.InsertAsync(subscription);
}
public async Task<List<NotificationSubscriptionDto>> GetPagingListAsync(Guid notificationId, Guid? receiverUserId, string receiverUserName, DateTime? startReadTime, DateTime? endReadTime, int maxResultCount = 10, int skipCount = 0, CancellationToken cancellationToken = default)
public async Task<List<NotificationSubscriptionDto>> GetPagingListAsync(Guid notificationId, Guid? receiverUserId, string receiverUserName, DateTime? startReadTime, DateTime? endReadTime, int maxResultCount = 10, int skipCount = 0,
CancellationToken cancellationToken = default)
{
var list = await _notificationSubscriptionRepository.GetPagingListAsync(notificationId, receiverUserId, receiverUserName, startReadTime, endReadTime, maxResultCount, skipCount, cancellationToken);
return ObjectMapper.Map<List<NotificationSubscription>, List<NotificationSubscriptionDto>>(list);
@ -35,6 +36,19 @@ public class NotificationSubscriptionManager : NotificationManagementDomainServi
return ObjectMapper.Map<List<NotificationSubscription>, List<NotificationSubscriptionDto>>(list);
}
public async Task<NotificationSubscriptionDto> FindAsync(Guid receiveUserId, Guid notificationId, CancellationToken cancellationToken = default)
{
var subscription = await _notificationSubscriptionRepository.FindAsync(receiveUserId, notificationId, cancellationToken);
return ObjectMapper.Map<NotificationSubscription, NotificationSubscriptionDto>(subscription);
}
public async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default)
{
var subscription = await _notificationSubscriptionRepository.FindAsync(id, false, cancellationToken);
if (subscription == null) throw new NotificationManagementDomainException(NotificationManagementErrorCodes.MessageNotExist);
await _notificationSubscriptionRepository.DeleteAsync(subscription.Id, false, cancellationToken);
}
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);

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

@ -34,6 +34,16 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
return _notificationAppService.PageNotificationSubscriptionAsync(input);
}
/// <summary>
/// 删除消息
/// </summary>x
[HttpPost("Delete")]
[SwaggerOperation(summary: "删除消息", Tags = new[] { "Notification" })]
public Task DeleteAsync(DeleteMessageInput input)
{
return _notificationAppService.DeleteAsync(input);
}
[HttpPost("SendCommonWarningMessage")]
[SwaggerOperation(summary: "发送警告文本消息", Tags = new[] { "Notification" })]

Loading…
Cancel
Save