From 73f8bf2d31e8155599bc0450f48c93a08985359e Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Mon, 15 Jun 2020 21:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E8=AE=A2?= =?UTF-8?q?=E9=98=85=E7=9B=B8=E5=85=B3api;=E5=88=9B=E5=BB=BAnuget=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Abp/Notifications/INotificationStore.cs | 4 +++ .../INotificationSubscriptionManager.cs | 15 +++++++++ .../NotificationSubscriptionManager.cs | 10 ++++++ ...UN.Abp.MessageService.Domain.Shared.csproj | 7 +++++ .../LINGYUN.Abp.MessageService.Domain.csproj | 7 +++++ .../Notifications/NotificationStore.cs | 31 +++++++++++++++++++ .../Subscriptions/IUserSubscribeRepository.cs | 2 ++ ....MessageService.EntityFrameworkCore.csproj | 8 +++++ .../EfCoreUserSubscribeRepository.cs | 6 ++++ 9 files changed, 90 insertions(+) diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs index fa7c266ca..951537cb8 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs @@ -12,6 +12,10 @@ namespace LINGYUN.Abp.Notifications Task DeleteUserSubscriptionAsync(Guid? tenantId, Guid userId, string notificationName); + Task DeleteAllUserSubscriptionAsync(Guid? tenantId, string notificationName); + + Task DeleteUserSubscriptionAsync(Guid? tenantId, IEnumerable identifiers, string notificationName); + Task> GetSubscriptionsAsync(Guid? tenantId, string notificationName); Task> GetUserSubscriptionsAsync(Guid? tenantId, Guid userId); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSubscriptionManager.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSubscriptionManager.cs index 796e729c5..2754a872a 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSubscriptionManager.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSubscriptionManager.cs @@ -34,6 +34,13 @@ namespace LINGYUN.Abp.Notifications /// Task SubscribeAsync(Guid? tenantId, IEnumerable identifiers, string notificationName); /// + /// 取消所有用户订阅 + /// + /// 租户 + /// 通知名称 + /// + Task UnsubscribeAllAsync(Guid? tenantId, string notificationName); + /// /// 取消订阅 /// /// 租户 @@ -42,6 +49,14 @@ namespace LINGYUN.Abp.Notifications /// Task UnsubscribeAsync(Guid? tenantId, UserIdentifier identifier, string notificationName); /// + /// 取消订阅 + /// + /// 租户 + /// 用户标识列表 + /// 通知名称 + /// + Task UnsubscribeAsync(Guid? tenantId, IEnumerable identifiers, string notificationName); + /// /// 获取通知被订阅用户列表 /// /// 租户 diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSubscriptionManager.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSubscriptionManager.cs index bbf93a311..3754d72d3 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSubscriptionManager.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSubscriptionManager.cs @@ -56,5 +56,15 @@ namespace LINGYUN.Abp.Notifications.Internal { await _store.DeleteUserSubscriptionAsync(tenantId, identifier.UserId, notificationName); } + + public virtual async Task UnsubscribeAllAsync(Guid? tenantId, string notificationName) + { + await _store.DeleteAllUserSubscriptionAsync(tenantId, notificationName); + } + + public virtual async Task UnsubscribeAsync(Guid? tenantId, IEnumerable identifiers, string notificationName) + { + await _store.DeleteUserSubscriptionAsync(tenantId, identifiers, notificationName); + } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN.Abp.MessageService.Domain.Shared.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN.Abp.MessageService.Domain.Shared.csproj index 71e468153..8d337c0be 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN.Abp.MessageService.Domain.Shared.csproj +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN.Abp.MessageService.Domain.Shared.csproj @@ -3,6 +3,13 @@ netstandard2.0 + true + 2.9.0 + LINGYUN + + + + D:\LocalNuget diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN.Abp.MessageService.Domain.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN.Abp.MessageService.Domain.csproj index 8ae03890c..576b98e94 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN.Abp.MessageService.Domain.csproj +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN.Abp.MessageService.Domain.csproj @@ -3,6 +3,13 @@ netstandard2.0 + true + 2.9.0 + LINGYUN + + + + D:\LocalNuget diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs index 407aca566..2530351ec 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs @@ -3,6 +3,7 @@ using LINGYUN.Abp.MessageService.Utils; using LINGYUN.Abp.Notifications; using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Volo.Abp.Domain.Services; using Volo.Abp.Json; @@ -77,6 +78,20 @@ namespace LINGYUN.Abp.MessageService.Notifications } } + [UnitOfWork] + public async Task DeleteAllUserSubscriptionAsync(Guid? tenantId, string notificationName) + { + using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(tenantId)) + { + var userSubscribes = await UserSubscribeRepository.GetSubscribesAsync(notificationName); + + await UserSubscribeRepository.DeleteUserSubscriptionAsync(userSubscribes); + + await unitOfWork.SaveChangesAsync(); + } + } + [UnitOfWork] public async Task DeleteUserSubscriptionAsync(Guid? tenantId, Guid userId, string notificationName) { @@ -90,6 +105,22 @@ namespace LINGYUN.Abp.MessageService.Notifications } } + [UnitOfWork] + public async Task DeleteUserSubscriptionAsync(Guid? tenantId, IEnumerable identifiers, string notificationName) + { + using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(tenantId)) + { + var userSubscribes = await UserSubscribeRepository.GetSubscribesAsync(notificationName); + + var removeUserSubscribes = userSubscribes.Where(us => identifiers.Any(id => id.UserId.Equals(us.UserId))); + + await UserSubscribeRepository.DeleteUserSubscriptionAsync(removeUserSubscribes); + + await unitOfWork.SaveChangesAsync(); + } + } + public async Task GetNotificationOrNullAsync(Guid? tenantId, long notificationId) { using (CurrentTenant.Change(tenantId)) diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs index 0c5588c3f..090e738a3 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs @@ -20,5 +20,7 @@ namespace LINGYUN.Abp.MessageService.Subscriptions Task> GetUserSubscribesAsync(string notificationName); Task InsertUserSubscriptionAsync(IEnumerable userSubscribes); + + Task DeleteUserSubscriptionAsync(IEnumerable userSubscribes); } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj index f2ad8207b..57518a766 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj @@ -3,6 +3,14 @@ netstandard2.0 + false + true + 2.9.0 + LINGYUN + + + + D:\LocalNuget diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs index 4e0621219..621be16b3 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs @@ -78,6 +78,12 @@ namespace LINGYUN.Abp.MessageService.Subscriptions await DbSet.AddRangeAsync(userSubscribes); } + public Task DeleteUserSubscriptionAsync(IEnumerable userSubscribes) + { + DbSet.RemoveRange(userSubscribes); + return Task.CompletedTask; + } + public async Task UserSubscribeExistsAysnc(string notificationName, Guid userId) { return await DbSet.AnyAsync(x => x.UserId.Equals(userId) && x.NotificationName.Equals(notificationName));