From 611dcc159209a3a08e56c9b370535e2a3dd3abf4 Mon Sep 17 00:00:00 2001
From: Hanpaopao <510423039@qq.com>
Date: Wed, 19 Feb 2025 20:23:33 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=88=A0=E9=99=A4?=
=?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Notifications/Dtos/DeleteMessageInput.cs | 13 ++++++++
.../Notifications/INotificationAppService.cs | 2 ++
.../Notifications/NotificationAppService.cs | 31 ++++++++++++++++---
.../Notifications/INotificationManager.cs | 4 ++-
.../Notifications/INotificationRepository.cs | 1 +
.../INotificationSubscriptionManager.cs | 8 +++++
.../INotificationSubscriptionRepository.cs | 1 +
.../Notifications/NotificationManager.cs | 9 +++++-
.../NotificationSubscriptionManager.cs | 16 +++++++++-
.../Notifications/NotificationController.cs | 10 ++++++
10 files changed, 88 insertions(+), 7 deletions(-)
create mode 100644 aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/DeleteMessageInput.cs
diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/DeleteMessageInput.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Application.Contracts/Notifications/Dtos/DeleteMessageInput.cs
new file mode 100644
index 00000000..2045ad26
--- /dev/null
+++ b/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; }
+
+
+ ///
+ /// 接受者Id
+ ///
+ public Guid? ReceiverUserId { 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 07516a3b..325a1eaf 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
@@ -48,5 +48,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
Task> PageNotificationAsync(PagingNotificationInput input);
Task> PageNotificationSubscriptionAsync(PagingNotificationSubscriptionInput input);
+
+ Task DeleteAsync(DeleteMessageInput input);
}
}
\ No newline at end of file
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 3995d8f4..30327250 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
@@ -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 });
}
}
+
///
/// 分页获取消息
///
public virtual async Task> 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);
+ // }
+ // }
+ }
}
}
\ No newline at end of file
diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationManager.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationManager.cs
index 2fe25dd8..8027bf4c 100644
--- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationManager.cs
+++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationManager.cs
@@ -63,7 +63,9 @@ public interface INotificationManager
/// 消息Id
Task SetReadAsync(Guid id);
- Task FindAsync(Guid id);
+ Task GetAsync(Guid id);
Task> GetListAsync(List ids);
+
+ Task DeleteAsync(Guid id);
}
\ No newline at end of file
diff --git a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationRepository.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationRepository.cs
index f2ecc957..ca602663 100644
--- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/INotificationRepository.cs
+++ b/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> GetListAsync(List ids);
+
}
}
\ No newline at end of file
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 0a49987f..f28862dd 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
@@ -34,4 +34,12 @@ public interface INotificationSubscriptionManager
CancellationToken cancellationToken = default);
Task> GetListAsync(List notificationId, Guid receiverUserId, CancellationToken cancellationToken = default);
+
+
+ Task FindAsync(Guid receiveUserId, Guid notificationId, CancellationToken cancellationToken = default);
+
+ ///
+ /// 删除消息
+ ///
+ Task DeleteAsync(Guid id, 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 329d6d80..40632c90 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
@@ -38,5 +38,6 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
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/NotificationManager.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs
index 25785622..038feb30 100644
--- a/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs
+++ b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.Domain/Notifications/NotificationManager.cs
@@ -85,7 +85,7 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
}
- public async Task FindAsync(Guid id)
+ public async Task 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>(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);
+ }
+
///
/// 消息设置为已读
///
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 bdeb56ff..8b6a2d4e 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
@@ -23,7 +23,8 @@ public class NotificationSubscriptionManager : NotificationManagementDomainServi
await _notificationSubscriptionRepository.InsertAsync(subscription);
}
- public async Task> GetPagingListAsync(Guid notificationId, Guid? receiverUserId, string receiverUserName, DateTime? startReadTime, DateTime? endReadTime, int maxResultCount = 10, int skipCount = 0, CancellationToken cancellationToken = default)
+ public async Task> 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>(list);
@@ -35,6 +36,19 @@ public class NotificationSubscriptionManager : NotificationManagementDomainServi
return ObjectMapper.Map, List>(list);
}
+ public async Task FindAsync(Guid receiveUserId, Guid notificationId, CancellationToken cancellationToken = default)
+ {
+ var subscription = await _notificationSubscriptionRepository.FindAsync(receiveUserId, notificationId, cancellationToken);
+ return ObjectMapper.Map(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 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.HttpApi/Notifications/NotificationController.cs b/aspnet-core/modules/NotificationManagement/src/Lion.AbpPro.NotificationManagement.HttpApi/Notifications/NotificationController.cs
index 7e6bf6e8..2c41d3ab 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
@@ -34,6 +34,16 @@ namespace Lion.AbpPro.NotificationManagement.Notifications
return _notificationAppService.PageNotificationSubscriptionAsync(input);
}
+ ///
+ /// 删除消息
+ /// x
+ [HttpPost("Delete")]
+ [SwaggerOperation(summary: "删除消息", Tags = new[] { "Notification" })]
+ public Task DeleteAsync(DeleteMessageInput input)
+ {
+ return _notificationAppService.DeleteAsync(input);
+ }
+
[HttpPost("SendCommonWarningMessage")]
[SwaggerOperation(summary: "发送警告文本消息", Tags = new[] { "Notification" })]