From e0aba0f43a038419df7260f4bc4e8b8b3fd63cd8 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 2 Sep 2022 19:11:24 +0800 Subject: [PATCH] Support for dynamic notification definitions * Change INotificationDefinitionManager to asynchronous methods * Increase IStaticNotificationDefinitionStore interface for users to define static notice * Increase IDynamicNotificationDefinitionStore interface to get dynamic notification from other source definition * Increase DynamicNotificationDefinitionStore get dynamic notification from l3 cache * Add Entity NotificationDefinitionGroupRecord * Add Repository INotificationDefinitionGroupRecordRepository * Add Entity NotificationDefinitionRecord * Add Repository INotificationDefinitionRecordRepository --- aspnet-core/LINGYUN.MicroService.All.sln | 2 +- ...pNotificationTemplateDefinitionProvider.cs | 6 +- .../IDynamicNotificationDefinitionStore.cs | 13 + .../INotificationDefinitionManager.cs | 11 +- .../IStaticNotificationDefinitionStore.cs | 13 + .../Notifications/NotificationDefinition.cs | 2 +- .../NotificationDefinitionManager.cs | 157 ++-- .../NotificationGroupDefinition.cs | 8 + .../NullDynamicNotificationDefinitionStore.cs | 34 + .../StaticNotificationDefinitionStore.cs | 101 +++ .../IMyNotificationAppService.cs | 3 - .../Notifications/INotificationAppService.cs | 2 + .../Notifications/MyNotificationAppService.cs | 42 - .../Notifications/NotificationAppService.cs | 57 +- ...NotificationDefinitionGroupRecordConsts.cs | 10 + .../NotificationDefinitionRecordConsts.cs | 11 + .../AbpNotificationsManagementOptions.cs | 10 + .../DynamicNotificationDefinitionCache.cs | 287 +++++++ .../DynamicNotificationDefinitionStore.cs | 50 ++ .../IDynamicNotificationDefinitionCache.cs | 14 + ...ficationDefinitionGroupRecordRepository.cs | 8 + ...INotificationDefinitionRecordRepository.cs | 8 + .../NotificationDefinitionGroupRecord.cs | 89 +++ .../NotificationDefinitionGroupsCacheItem.cs | 53 ++ .../NotificationDefinitionRecord.cs | 127 +++ .../NotificationDefinitionsCacheItem.cs | 68 ++ ...MessageServiceEntityFrameworkCoreModule.cs | 2 + ...ServiceDbContextModelCreatingExtensions.cs | 42 + ...ficationDefinitionGroupRecordRepository.cs | 19 + ...eNotificationDefinitionRecordRepository.cs | 19 + .../Notifications/MyNotificationController.cs | 8 +- .../Notifications/NotificationController.cs | 7 + .../PushPlusNotificationPublishProvider.cs | 2 +- .../WxPusherNotificationPublishProvider.cs | 2 +- .../Distributed/NotificationEventHandler.cs | 5 +- ...04049_Add-Dynamic-Notification.Designer.cs | 720 ++++++++++++++++++ ...20220902104049_Add-Dynamic-Notification.cs | 76 ++ ...MessageMigrationsDbContextModelSnapshot.cs | 90 ++- 38 files changed, 2006 insertions(+), 172 deletions(-) create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/IDynamicNotificationDefinitionStore.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/IStaticNotificationDefinitionStore.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NullDynamicNotificationDefinitionStore.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/StaticNotificationDefinitionStore.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupRecordConsts.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionRecordConsts.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpNotificationsManagementOptions.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/DynamicNotificationDefinitionCache.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/DynamicNotificationDefinitionStore.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IDynamicNotificationDefinitionCache.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationDefinitionGroupRecordRepository.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationDefinitionRecordRepository.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupRecord.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupsCacheItem.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionRecord.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionsCacheItem.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationDefinitionGroupRecordRepository.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationDefinitionRecordRepository.cs create mode 100644 aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/20220902104049_Add-Dynamic-Notification.Designer.cs create mode 100644 aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/20220902104049_Add-Dynamic-Notification.cs diff --git a/aspnet-core/LINGYUN.MicroService.All.sln b/aspnet-core/LINGYUN.MicroService.All.sln index aecd2febd..64f8b664f 100644 --- a/aspnet-core/LINGYUN.MicroService.All.sln +++ b/aspnet-core/LINGYUN.MicroService.All.sln @@ -464,7 +464,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.P EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "realtime", "realtime", "{ECC8B9A9-9E92-4493-984D-2E350A49189D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Notifications.Core", "modules\common\LINGYUN.Abp.Notifications.Core\LINGYUN.Abp.Notifications.Core.csproj", "{62971DAE-CE71-4E9C-B6F5-514C8E2B915C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Core", "modules\common\LINGYUN.Abp.Notifications.Core\LINGYUN.Abp.Notifications.Core.csproj", "{62971DAE-CE71-4E9C-B6F5-514C8E2B915C}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINGYUN.Abp.Notifications.Jobs", "modules\common\LINGYUN.Abp.Notifications.Jobs\LINGYUN.Abp.Notifications.Jobs.csproj", "{3E9D07D8-963C-4A61-B720-BD47593BE752}" EndProject diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/AbpNotificationTemplateDefinitionProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/AbpNotificationTemplateDefinitionProvider.cs index ee203c028..2150a9236 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/AbpNotificationTemplateDefinitionProvider.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/AbpNotificationTemplateDefinitionProvider.cs @@ -14,8 +14,10 @@ public class AbpNotificationTemplateDefinitionProvider : TemplateDefinitionProvi public override void Define(ITemplateDefinitionContext context) { - var notifications = _notificationDefinitionManager.GetAll().Where(n => n.Template != null); - foreach (var notification in notifications) + var notifications = _notificationDefinitionManager + .GetNotificationsAsync().GetAwaiter().GetResult(); + + foreach (var notification in notifications.Where(n => n.Template != null)) { context.Add(notification.Template); } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/IDynamicNotificationDefinitionStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/IDynamicNotificationDefinitionStore.cs new file mode 100644 index 000000000..8e12169be --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/IDynamicNotificationDefinitionStore.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Notifications; + +public interface IDynamicNotificationDefinitionStore +{ + Task GetOrNullAsync(string name); + + Task> GetNotificationsAsync(); + + Task> GetGroupsAsync(); +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs index 0eb55cf4a..44c8f8c61 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs @@ -1,17 +1,18 @@ using JetBrains.Annotations; using System.Collections.Generic; - +using System.Threading.Tasks; + namespace LINGYUN.Abp.Notifications { public interface INotificationDefinitionManager { [NotNull] - NotificationDefinition Get([NotNull] string name); + Task GetAsync([NotNull] string name); - IReadOnlyList GetAll(); + Task> GetNotificationsAsync(); - NotificationDefinition GetOrNull(string name); + Task GetOrNullAsync(string name); - IReadOnlyList GetGroups(); + Task> GetGroupsAsync(); } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/IStaticNotificationDefinitionStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/IStaticNotificationDefinitionStore.cs new file mode 100644 index 000000000..0b2d329e9 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/IStaticNotificationDefinitionStore.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.Notifications; + +public interface IStaticNotificationDefinitionStore +{ + Task GetOrNullAsync(string name); + + Task> GetNotificationsAsync(); + + Task> GetGroupsAsync(); +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationDefinition.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationDefinition.cs index 199e4b9c7..968cd65a3 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationDefinition.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationDefinition.cs @@ -83,7 +83,7 @@ namespace LINGYUN.Abp.Notifications { if (!providers.IsNullOrEmpty()) { - Providers.AddRange(providers); + Providers.AddIfNotContains(providers); } return this; diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs index 1261c8db9..30c906889 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs @@ -1,111 +1,70 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; +using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.DependencyInjection; namespace LINGYUN.Abp.Notifications { - public class NotificationDefinitionManager : INotificationDefinitionManager, ISingletonDependency - { - protected AbpNotificationsOptions Options { get; } - - protected IDictionary NotificationGroupDefinitions => _lazyNotificationGroupDefinitions.Value; - private readonly Lazy> _lazyNotificationGroupDefinitions; - - protected IDictionary NotificationDefinitions => _lazyNotificationDefinitions.Value; - private readonly Lazy> _lazyNotificationDefinitions; - - private readonly IServiceScopeFactory _serviceScopeFactory; - - public NotificationDefinitionManager( - IOptions options, - IServiceScopeFactory serviceScopeFactory) - { - _serviceScopeFactory = serviceScopeFactory; - Options = options.Value; - - _lazyNotificationDefinitions = new Lazy>( - CreateNotificationDefinitions, - isThreadSafe: true - ); - - _lazyNotificationGroupDefinitions = new Lazy>( - CreateNotificationGroupDefinitions, - isThreadSafe: true - ); - } - - public virtual NotificationDefinition Get(string name) - { - Check.NotNull(name, nameof(name)); - - var feature = GetOrNull(name); - - if (feature == null) - { - throw new AbpException("Undefined notification: " + name); - } - - return feature; - } - - public virtual IReadOnlyList GetAll() - { - return NotificationDefinitions.Values.ToImmutableList(); + public class NotificationDefinitionManager : INotificationDefinitionManager, ITransientDependency + { + private readonly IStaticNotificationDefinitionStore _staticStore; + private readonly IDynamicNotificationDefinitionStore _dynamicStore; + + public NotificationDefinitionManager( + IStaticNotificationDefinitionStore staticStore, + IDynamicNotificationDefinitionStore dynamicStore) + { + _staticStore = staticStore; + _dynamicStore = dynamicStore; } - public virtual NotificationDefinition GetOrNull(string name) - { - return NotificationDefinitions.GetOrDefault(name); - } - - public IReadOnlyList GetGroups() - { - return NotificationGroupDefinitions.Values.ToImmutableList(); - } - - protected virtual Dictionary CreateNotificationDefinitions() - { - var notifications = new Dictionary(); - - foreach (var groupDefinition in NotificationGroupDefinitions.Values) - { - foreach (var notification in groupDefinition.Notifications) - { - if (notifications.ContainsKey(notification.Name)) - { - throw new AbpException("Duplicate notification name: " + notification.Name); - } - - notifications[notification.Name] = notification; - } - } - - return notifications; - } - - protected virtual Dictionary CreateNotificationGroupDefinitions() - { - var context = new NotificationDefinitionContext(); - - using (var scope = _serviceScopeFactory.CreateScope()) - { - var providers = Options - .DefinitionProviders - .Select(p => scope.ServiceProvider.GetRequiredService(p) as INotificationDefinitionProvider) - .ToList(); - - foreach (var provider in providers) - { - provider.Define(context); - } - } - - return context.Groups; + public virtual async Task GetAsync(string name) + { + var notification = await GetOrNullAsync(name); + if (notification == null) + { + throw new AbpException("Undefined notification: " + name); + } + + return notification; + } + + public virtual async Task GetOrNullAsync(string name) + { + Check.NotNull(name, nameof(name)); + + return await _staticStore.GetOrNullAsync(name) ?? + await _dynamicStore.GetOrNullAsync(name); + } + + public virtual async Task> GetNotificationsAsync() + { + var staticNotifications = await _staticStore.GetNotificationsAsync(); + var staticNotificationNames = staticNotifications + .Select(p => p.Name) + .ToImmutableHashSet(); + + var dynamicNotifications = await _dynamicStore.GetNotificationsAsync(); + + return staticNotifications + .Concat(dynamicNotifications.Where(d => !staticNotificationNames.Contains(d.Name))) + .ToImmutableList(); + } + + public async Task> GetGroupsAsync() + { + var staticGroups = await _staticStore.GetGroupsAsync(); + var staticGroupNames = staticGroups + .Select(p => p.Name) + .ToImmutableHashSet(); + + var dynamicGroups = await _dynamicStore.GetGroupsAsync(); + + return staticGroups + .Concat(dynamicGroups.Where(d => !staticGroupNames.Contains(d.Name))) + .ToImmutableList(); } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationGroupDefinition.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationGroupDefinition.cs index 019acdce1..5bf588373 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationGroupDefinition.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NotificationGroupDefinition.cs @@ -32,6 +32,14 @@ namespace LINGYUN.Abp.Notifications public IReadOnlyList Notifications => _notifications.ToImmutableList(); private readonly List _notifications; + public static NotificationGroupDefinition Create( + string name, + ILocalizableString displayName = null, + bool allowSubscriptionToClients = false) + { + return new NotificationGroupDefinition(name, displayName, allowSubscriptionToClients); + } + protected internal NotificationGroupDefinition( string name, ILocalizableString displayName = null, diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NullDynamicNotificationDefinitionStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NullDynamicNotificationDefinitionStore.cs new file mode 100644 index 000000000..7b70d6cff --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/NullDynamicNotificationDefinitionStore.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.Notifications; + +[Dependency(TryRegister = true)] +public class NullDynamicNotificationDefinitionStore : IDynamicNotificationDefinitionStore, ISingletonDependency +{ + private readonly static Task CachedNotificationResult = Task.FromResult((NotificationDefinition)null); + + private readonly static Task> CachedNotificationsResult = + Task.FromResult((IReadOnlyList)Array.Empty().ToImmutableList()); + + private readonly static Task> CachedGroupsResult = + Task.FromResult((IReadOnlyList)Array.Empty().ToImmutableList()); + + public Task GetOrNullAsync(string name) + { + return CachedNotificationResult; + } + + public Task> GetNotificationsAsync() + { + return CachedNotificationsResult; + } + + public Task> GetGroupsAsync() + { + return CachedGroupsResult; + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/StaticNotificationDefinitionStore.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/StaticNotificationDefinitionStore.cs new file mode 100644 index 000000000..d8083da07 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.Core/LINGYUN/Abp/Notifications/StaticNotificationDefinitionStore.cs @@ -0,0 +1,101 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.Notifications; + +public class StaticNotificationDefinitionStore : IStaticNotificationDefinitionStore, ISingletonDependency +{ + protected IDictionary NotificationGroupDefinitions => _lazyNotificationGroupDefinitions.Value; + private readonly Lazy> _lazyNotificationGroupDefinitions; + + protected IDictionary NotificationDefinitions => _lazyNotificationDefinitions.Value; + private readonly Lazy> _lazyNotificationDefinitions; + + protected AbpNotificationsOptions Options { get; } + + private readonly IServiceScopeFactory _serviceScopeFactory; + + public StaticNotificationDefinitionStore( + IServiceScopeFactory serviceScopeFactory, + IOptions options) + { + _serviceScopeFactory = serviceScopeFactory; + Options = options.Value; + + _lazyNotificationDefinitions = new Lazy>( + CreateNotificationDefinitions, + isThreadSafe: true + ); + + _lazyNotificationGroupDefinitions = new Lazy>( + CreateNotificationGroupDefinitions, + isThreadSafe: true + ); + } + + protected virtual Dictionary CreateNotificationDefinitions() + { + var notifications = new Dictionary(); + + foreach (var groupDefinition in NotificationGroupDefinitions.Values) + { + foreach (var notification in groupDefinition.Notifications) + { + if (notifications.ContainsKey(notification.Name)) + { + throw new AbpException("Duplicate notification name: " + notification.Name); + } + + notifications[notification.Name] = notification; + } + } + + return notifications; + } + + protected virtual Dictionary CreateNotificationGroupDefinitions() + { + var context = new NotificationDefinitionContext(); + + using (var scope = _serviceScopeFactory.CreateScope()) + { + var providers = Options + .DefinitionProviders + .Select(p => scope.ServiceProvider.GetRequiredService(p) as INotificationDefinitionProvider) + .ToList(); + + foreach (var provider in providers) + { + provider.Define(context); + } + } + + return context.Groups; + } + + public Task GetOrNullAsync(string name) + { + return Task.FromResult(NotificationDefinitions.GetOrDefault(name)); + } + + public virtual Task> GetNotificationsAsync() + { + return Task.FromResult>( + NotificationDefinitions.Values.ToImmutableList() + ); + } + + public Task> GetGroupsAsync() + { + return Task.FromResult>( + NotificationGroupDefinitions.Values.ToImmutableList() + ); + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/IMyNotificationAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/IMyNotificationAppService.cs index 05b5dbeae..72e3c352f 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/IMyNotificationAppService.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/IMyNotificationAppService.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; namespace LINGYUN.Abp.MessageService.Notifications @@ -14,7 +13,5 @@ namespace LINGYUN.Abp.MessageService.Notifications IDeleteAppService { Task MarkReadStateAsync(NotificationMarkReadStateInput input); - - Task> GetAssignableNotifiersAsync(); } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/INotificationAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/INotificationAppService.cs index 0782b12e3..4b228f922 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/INotificationAppService.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application.Contracts/LINGYUN/Abp/MessageService/Notifications/INotificationAppService.cs @@ -5,6 +5,8 @@ namespace LINGYUN.Abp.MessageService.Notifications { public interface INotificationAppService { + Task> GetAssignableNotifiersAsync(); + Task> GetAssignableTemplatesAsync(); Task SendAsync(NotificationSendDto input); diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/MyNotificationAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/MyNotificationAppService.cs index 6f485af7a..ff7e8fca5 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/MyNotificationAppService.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/MyNotificationAppService.cs @@ -49,48 +49,6 @@ namespace LINGYUN.Abp.MessageService.Notifications id); } - public virtual Task> GetAssignableNotifiersAsync() - { - var groups = new List(); - - foreach (var group in NotificationDefinitionManager.GetGroups()) - { - if (!group.AllowSubscriptionToClients) - { - continue; - - } - var notificationGroup = new NotificationGroupDto - { - Name = group.Name, - DisplayName = group.DisplayName.Localize(StringLocalizerFactory) - }; - - foreach (var notification in group.Notifications) - { - if (!notification.AllowSubscriptionToClients) - { - continue; - } - - var notificationChildren = new NotificationDto - { - Name = notification.Name, - DisplayName = notification.DisplayName.Localize(StringLocalizerFactory), - Description = notification.Description.Localize(StringLocalizerFactory), - Lifetime = notification.NotificationLifetime, - Type = notification.NotificationType - }; - - notificationGroup.Notifications.Add(notificationChildren); - } - - groups.Add(notificationGroup); - } - - return Task.FromResult(new ListResultDto(groups)); - } - public async virtual Task GetAsync(long id) { var notification = await UserNotificationRepository.GetByIdAsync(CurrentUser.GetId(), id); diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs index 9ca440640..af286e9e3 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Application/LINGYUN/Abp/MessageService/Notifications/NotificationAppService.cs @@ -28,10 +28,55 @@ namespace LINGYUN.Abp.MessageService.Notifications NotificationDefinitionManager = notificationDefinitionManager; } - public virtual Task> GetAssignableTemplatesAsync() + public async virtual Task> GetAssignableNotifiersAsync() + { + var groups = new List(); + var defineGroups = await NotificationDefinitionManager.GetGroupsAsync(); + + foreach (var group in defineGroups) + { + if (!group.AllowSubscriptionToClients) + { + continue; + + } + var notificationGroup = new NotificationGroupDto + { + Name = group.Name, + DisplayName = group.DisplayName.Localize(StringLocalizerFactory) + }; + + foreach (var notification in group.Notifications) + { + if (!notification.AllowSubscriptionToClients) + { + continue; + } + + var notificationChildren = new NotificationDto + { + Name = notification.Name, + DisplayName = notification.DisplayName.Localize(StringLocalizerFactory), + Description = notification.Description?.Localize(StringLocalizerFactory) ?? notification.Name, + Lifetime = notification.NotificationLifetime, + Type = notification.NotificationType + }; + + notificationGroup.Notifications.Add(notificationChildren); + } + + groups.Add(notificationGroup); + } + + return new ListResultDto(groups); + } + + public async virtual Task> GetAssignableTemplatesAsync() { var templates = new List(); - var notifications = NotificationDefinitionManager.GetAll().Where(n => n.Template != null); + var notifications = (await NotificationDefinitionManager + .GetNotificationsAsync()) + .Where(n => n.Template != null); foreach (var notification in notifications) { @@ -45,12 +90,12 @@ namespace LINGYUN.Abp.MessageService.Notifications }); } - return Task.FromResult(new ListResultDto(templates)); + return new ListResultDto(templates); } public async virtual Task SendAsync(NotificationSendDto input) { - var notification = GetNotificationDefinition(input.Name); + var notification = await GetNotificationDefinition(input.Name); UserIdentifier user = null; if (input.ToUserId.HasValue) @@ -71,9 +116,9 @@ namespace LINGYUN.Abp.MessageService.Notifications input.Severity); } - protected virtual NotificationDefinition GetNotificationDefinition(string name) + protected async virtual Task GetNotificationDefinition(string name) { - var notification = NotificationDefinitionManager.GetOrNull(name); + var notification = await NotificationDefinitionManager.GetOrNullAsync(name); if (notification == null || notification.Template == null) { throw new BusinessException( diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupRecordConsts.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupRecordConsts.cs new file mode 100644 index 000000000..5a1353517 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupRecordConsts.cs @@ -0,0 +1,10 @@ +namespace LINGYUN.Abp.MessageService.Notifications; + +public static class NotificationDefinitionGroupRecordConsts +{ + public static int MaxNameLength { get; set; } = 64; + public static int MaxDisplayNameLength { get; set; } = 255; + public static int MaxResourceNameLength { get; set; } = 64; + public static int MaxLocalizationLength { get; set; } = 128; + public static int MaxDescriptionLength { get; set; } = 255; +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionRecordConsts.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionRecordConsts.cs new file mode 100644 index 000000000..d84894f4b --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionRecordConsts.cs @@ -0,0 +1,11 @@ +namespace LINGYUN.Abp.MessageService.Notifications; + +public static class NotificationDefinitionRecordConsts +{ + public static int MaxNameLength { get; set; } = 64; + public static int MaxDisplayNameLength { get; set; } = 255; + public static int MaxResourceNameLength { get; set; } = 64; + public static int MaxLocalizationLength { get; set; } = 128; + public static int MaxDescriptionLength { get; set; } = 255; + public static int MaxProvidersLength { get; set; } = 200; +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpNotificationsManagementOptions.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpNotificationsManagementOptions.cs new file mode 100644 index 000000000..b3fa0f90c --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpNotificationsManagementOptions.cs @@ -0,0 +1,10 @@ +namespace LINGYUN.Abp.MessageService.Notifications; + +public class AbpNotificationsManagementOptions +{ + public bool IsDynamicNotificationStoreEnabled { get; set; } + public AbpNotificationsManagementOptions() + { + IsDynamicNotificationStoreEnabled = true; + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/DynamicNotificationDefinitionCache.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/DynamicNotificationDefinitionCache.cs new file mode 100644 index 000000000..f48fe8f58 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/DynamicNotificationDefinitionCache.cs @@ -0,0 +1,287 @@ +using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Globalization; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Caching; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Localization; +using Volo.Abp.Threading; + +namespace LINGYUN.Abp.MessageService.Notifications; + +public class DynamicNotificationDefinitionCache : IDynamicNotificationDefinitionCache, ISingletonDependency +{ + private readonly static ConcurrentDictionary _dynamicNotificationGroupL1Cache; + private readonly static ConcurrentDictionary _dynamicNotificationsL1Cache; + + private readonly static SemaphoreSlim _l2CacheSyncLock; + protected IMemoryCache DynamicNotificationL2Cache { get; } + + protected IDistributedCache DynamicNotificationGroupL3Cache { get; } + protected IDistributedCache DynamicNotificationsL3Cache { get; } + + + protected INotificationDefinitionGroupRecordRepository NotificationDefinitionGroupRecordRepository { get; } + protected INotificationDefinitionRecordRepository NotificationDefinitionRecordRepository { get; } + + protected AbpLocalizationOptions LocalizationOptions { get; } + protected IStringLocalizerFactory StringLocalizerFactory { get; } + + static DynamicNotificationDefinitionCache() + { + _l2CacheSyncLock = new SemaphoreSlim(1, 1); + _dynamicNotificationsL1Cache = new ConcurrentDictionary(); + _dynamicNotificationGroupL1Cache = new ConcurrentDictionary(); + } + + public DynamicNotificationDefinitionCache( + IMemoryCache dynamicNotificationL2Cache, + IDistributedCache dynamicNotificationGroupL3Cache, + IDistributedCache dynamicNotificationsL3Cache, + INotificationDefinitionGroupRecordRepository notificationDefinitionGroupRecordRepository, + INotificationDefinitionRecordRepository notificationDefinitionRecordRepository, + IOptions localizationOptions, + IStringLocalizerFactory stringLocalizerFactory) + { + DynamicNotificationL2Cache = dynamicNotificationL2Cache; + DynamicNotificationGroupL3Cache = dynamicNotificationGroupL3Cache; + DynamicNotificationsL3Cache = dynamicNotificationsL3Cache; + NotificationDefinitionGroupRecordRepository = notificationDefinitionGroupRecordRepository; + NotificationDefinitionRecordRepository = notificationDefinitionRecordRepository; + LocalizationOptions = localizationOptions.Value; + StringLocalizerFactory = stringLocalizerFactory; + } + + public async virtual Task> GetGroupsAsync() + { + var cacheKey = NotificationDefinitionGroupsCacheItem.CalculateCacheKey(CultureInfo.CurrentCulture.Name); + + if (!_dynamicNotificationGroupL1Cache.TryGetValue(cacheKey, out var cacheItem)) + { + cacheItem = await GetGroupsFormL2CacheAsync(cacheKey); + } + + return cacheItem.Groups + .Select(g => NotificationGroupDefinition + .Create(g.Name, new FixedLocalizableString(g.DisplayName), g.AllowSubscriptionToClients)) + .ToImmutableList(); + } + + public async virtual Task> GetNotificationsAsync() + { + var cacheKey = NotificationDefinitionsCacheItem.CalculateCacheKey(CultureInfo.CurrentCulture.Name); + + if (!_dynamicNotificationsL1Cache.TryGetValue(cacheKey, out var cacheItem)) + { + cacheItem = await GetNotificationsFormL2CacheAsync(cacheKey); + } + + return cacheItem.Notifications + .Select(n => new NotificationDefinition( + n.Name, + new FixedLocalizableString(n.DisplayName), + new FixedLocalizableString(n.Description), + n.NotificationType, + n.Lifetime, + n.AllowSubscriptionToClients)) + .ToImmutableList(); + } + + public async virtual Task GetOrNullAsync(string name) + { + var notifications = await GetNotificationsAsync(); + + return notifications.FirstOrDefault(n => n.Name.Equals(name)); + } + + protected async virtual Task GetGroupsFormL2CacheAsync(string cacheKey) + { + var cacheItem = DynamicNotificationL2Cache.Get(cacheKey); + + if (cacheItem == null) + { + using (await _l2CacheSyncLock.LockAsync()) + { + var l2cache = await GetGroupsFormL3CacheAsync(cacheKey); + + var options = new MemoryCacheEntryOptions(); + options.SetAbsoluteExpiration(TimeSpan.FromMinutes(5)); + options.SetPriority(CacheItemPriority.High); + options.RegisterPostEvictionCallback((key, value, reason, state) => + { + _dynamicNotificationGroupL1Cache.Clear(); + }); + + DynamicNotificationL2Cache.Set(cacheKey, l2cache, options); + + return l2cache; + } + } + + return cacheItem; + } + + protected async virtual Task GetGroupsFormL3CacheAsync(string cacheKey) + { + var cacheItem = await DynamicNotificationGroupL3Cache.GetAsync(cacheKey); + + if (cacheItem == null) + { + var records = await GetGroupsFormRepositoryAsync(); + var recordCaches = new List(); + + foreach (var record in records) + { + var displayName = record.DisplayName; + var description = record.Description; + + if (!record.ResourceName.IsNullOrWhiteSpace() && !record.Localization.IsNullOrWhiteSpace()) + { + var resource = GetResourceOrNull(record.ResourceName); + if (resource != null) + { + var localizer = StringLocalizerFactory.Create(resource.ResourceType); + + displayName = localizer[$"DisplayName:{record.Localization}"]; + description = localizer[$"Description:{record.Localization}"]; + } + } + + recordCaches.Add(new NotificationDefinitionGroupCacheItem( + record.Name, + displayName, + description, + record.AllowSubscriptionToClients)); + } + + cacheItem = new NotificationDefinitionGroupsCacheItem(recordCaches.ToArray()); + + await DynamicNotificationGroupL3Cache.SetAsync( + cacheKey, + cacheItem, + new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2), + SlidingExpiration = TimeSpan.FromHours(1), + }); + } + + return cacheItem; + } + + protected async virtual Task> GetGroupsFormRepositoryAsync() + { + var records = await NotificationDefinitionGroupRecordRepository.GetListAsync(); + + return records; + } + + + protected async virtual Task GetNotificationsFormL2CacheAsync(string cacheKey) + { + var cacheItem = DynamicNotificationL2Cache.Get(cacheKey); + + if (cacheItem == null) + { + using (await _l2CacheSyncLock.LockAsync()) + { + var l2cache = await GetNotificationsFormL3CacheAsync(cacheKey); + + var options = new MemoryCacheEntryOptions(); + options.SetAbsoluteExpiration(TimeSpan.FromMinutes(5)); + options.SetPriority(CacheItemPriority.High); + options.RegisterPostEvictionCallback((key, value, reason, state) => + { + _dynamicNotificationsL1Cache.Clear(); + }); + + DynamicNotificationL2Cache.Set(cacheKey, l2cache, options); + + return l2cache; + } + } + + return cacheItem; + } + + protected async virtual Task GetNotificationsFormL3CacheAsync(string cacheKey) + { + var cacheItem = await DynamicNotificationsL3Cache.GetAsync(cacheKey); + + if (cacheItem == null) + { + var records = await GetNotificationsFormRepositoryAsync(); + var recordCaches = new List(); + + foreach (var record in records) + { + var displayName = record.Name; + var description = record.Name; + var providers = new List(); + if (!record.Providers.IsNullOrWhiteSpace()) + { + providers = record.Providers.Split(';').ToList(); + } + + if (record.ResourceName.IsNullOrWhiteSpace() && record.Localization.IsNullOrWhiteSpace()) + { + var resource = GetResourceOrNull(record.ResourceName); + if (resource != null) + { + var localizer = StringLocalizerFactory.Create(resource.ResourceType); + + displayName = localizer[$"DisplayName:{record.Localization}"]; + description = localizer[$"Description:{record.Localization}"]; + } + } + + var recordCache = new NotificationDefinitionCacheItem( + record.Name, + displayName, + description, + record.NotificationLifetime, + record.NotificationType, + providers, + record.AllowSubscriptionToClients); + recordCache.Properties.AddIfNotContains(record.ExtraProperties); + + recordCaches.Add(recordCache); + } + + cacheItem = new NotificationDefinitionsCacheItem(recordCaches.ToArray()); + + await DynamicNotificationsL3Cache.SetAsync( + cacheKey, + cacheItem, + new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(2), + SlidingExpiration = TimeSpan.FromHours(1), + }); + } + + return cacheItem; + } + + protected async virtual Task> GetNotificationsFormRepositoryAsync() + { + var records = await NotificationDefinitionRecordRepository.GetListAsync(); + + return records; + } + + protected virtual LocalizationResource GetResourceOrNull(string resourceName) + { + return LocalizationOptions.Resources.Values + .FirstOrDefault(x => x.ResourceName.Equals(resourceName)); + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/DynamicNotificationDefinitionStore.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/DynamicNotificationDefinitionStore.cs new file mode 100644 index 000000000..74190cd4d --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/DynamicNotificationDefinitionStore.cs @@ -0,0 +1,50 @@ +using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.Options; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.MessageService.Notifications; + +[Dependency(ReplaceServices = true)] +public class DynamicNotificationDefinitionStore : IDynamicNotificationDefinitionStore, ITransientDependency +{ + private readonly AbpNotificationsManagementOptions _notificationsManagementOptions; + private readonly IDynamicNotificationDefinitionCache _dynamicNotificationDefinitionCache; + + public DynamicNotificationDefinitionStore( + IDynamicNotificationDefinitionCache dynamicNotificationDefinitionCache, + IOptions notificationsManagementOptions) + { + _dynamicNotificationDefinitionCache = dynamicNotificationDefinitionCache; + _notificationsManagementOptions = notificationsManagementOptions.Value; + } + + public async virtual Task> GetGroupsAsync() + { + if (!_notificationsManagementOptions.IsDynamicNotificationStoreEnabled) + { + return Array.Empty(); + } + return await _dynamicNotificationDefinitionCache.GetGroupsAsync(); + } + + public async virtual Task> GetNotificationsAsync() + { + if (!_notificationsManagementOptions.IsDynamicNotificationStoreEnabled) + { + return Array.Empty(); + } + return await _dynamicNotificationDefinitionCache.GetNotificationsAsync(); + } + + public async virtual Task GetOrNullAsync(string name) + { + if (!_notificationsManagementOptions.IsDynamicNotificationStoreEnabled) + { + return null; + } + return await _dynamicNotificationDefinitionCache.GetOrNullAsync(name); + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IDynamicNotificationDefinitionCache.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IDynamicNotificationDefinitionCache.cs new file mode 100644 index 000000000..cd6056cda --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/IDynamicNotificationDefinitionCache.cs @@ -0,0 +1,14 @@ +using LINGYUN.Abp.Notifications; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace LINGYUN.Abp.MessageService.Notifications; + +public interface IDynamicNotificationDefinitionCache +{ + Task GetOrNullAsync(string name); + + Task> GetNotificationsAsync(); + + Task> GetGroupsAsync(); +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationDefinitionGroupRecordRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationDefinitionGroupRecordRepository.cs new file mode 100644 index 000000000..0983e18c5 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationDefinitionGroupRecordRepository.cs @@ -0,0 +1,8 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace LINGYUN.Abp.MessageService.Notifications; + +public interface INotificationDefinitionGroupRecordRepository : IBasicRepository +{ +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationDefinitionRecordRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationDefinitionRecordRepository.cs new file mode 100644 index 000000000..caa1bddde --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/INotificationDefinitionRecordRepository.cs @@ -0,0 +1,8 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace LINGYUN.Abp.MessageService.Notifications; + +public interface INotificationDefinitionRecordRepository : IBasicRepository +{ +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupRecord.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupRecord.cs new file mode 100644 index 000000000..7dac326ac --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupRecord.cs @@ -0,0 +1,89 @@ +using System; +using Volo.Abp; +using Volo.Abp.Data; +using Volo.Abp.Domain.Entities; + +namespace LINGYUN.Abp.MessageService.Notifications; + +public class NotificationDefinitionGroupRecord : BasicAggregateRoot, IHasExtraProperties +{ + /// + /// 分组名称 + /// + public virtual string Name { get; set; } + /// + /// 显示名称 + /// + /// + /// 如果为空,回退到Name + /// + public virtual string DisplayName { get; set; } + /// + /// 描述 + /// + /// + /// 如果为空,回退到Name + /// + public virtual string Description { get; set; } + /// + /// 资源名称 + /// + /// + /// 如果不为空,作为参与本地化资源的名称 + /// DisplayName = L["DisplayName:Localization"] + /// Description = L["Description:Localization"] + /// + public virtual string ResourceName { get; protected set; } + /// + /// 本地化键值名称 + /// + /// + /// 如果不为空,作为参与本地化键值的名称 + /// DisplayName = L["DisplayName:Localization"] + /// Description = L["Description:Localization"] + /// + public virtual string Localization { get; protected set; } + /// + /// 允许客户端订阅 + /// + public virtual bool AllowSubscriptionToClients { get; set; } + + public ExtraPropertyDictionary ExtraProperties { get; protected set; } + + public NotificationDefinitionGroupRecord() + { + ExtraProperties = new ExtraPropertyDictionary(); + this.SetDefaultsForExtraProperties(); + } + + public NotificationDefinitionGroupRecord( + Guid id, + string name, + string displayName = null, + string description = null, + string resourceName = null, + string localization = null) + : base(id) + { + Name = Check.NotNullOrWhiteSpace(name, nameof(name), NotificationDefinitionGroupRecordConsts.MaxNameLength); + DisplayName = Check.Length(displayName, nameof(displayName), NotificationDefinitionGroupRecordConsts.MaxDisplayNameLength); + Description = Check.Length(description, nameof(description), NotificationDefinitionGroupRecordConsts.MaxDescriptionLength); + + SetLocalization(resourceName, localization); + + ExtraProperties = new ExtraPropertyDictionary(); + this.SetDefaultsForExtraProperties(); + + AllowSubscriptionToClients = true; + } + /// + /// 设置本地化资源 + /// + /// + /// + public void SetLocalization(string resourceName, string localization) + { + ResourceName = Check.Length(resourceName, nameof(resourceName), NotificationDefinitionGroupRecordConsts.MaxResourceNameLength); + Localization = Check.Length(localization, nameof(localization), NotificationDefinitionGroupRecordConsts.MaxLocalizationLength); + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupsCacheItem.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupsCacheItem.cs new file mode 100644 index 000000000..c23d3d1c9 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionGroupsCacheItem.cs @@ -0,0 +1,53 @@ +using System; +using Volo.Abp.MultiTenancy; + +namespace LINGYUN.Abp.MessageService.Notifications; + +[Serializable] +[IgnoreMultiTenancy] +public class NotificationDefinitionGroupsCacheItem +{ + private const string CacheKeyFormat = "n:Abp_Notifications_Groups;c:{0}"; + + public NotificationDefinitionGroupCacheItem[] Groups { get; set; } + + public NotificationDefinitionGroupsCacheItem() + { + Groups = new NotificationDefinitionGroupCacheItem[0]; + } + + public NotificationDefinitionGroupsCacheItem( + NotificationDefinitionGroupCacheItem[] groups) + { + Groups = groups; + } + + public static string CalculateCacheKey(string culture) + { + return string.Format(CacheKeyFormat, culture); + } +} + +public class NotificationDefinitionGroupCacheItem +{ + public string Name { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public bool AllowSubscriptionToClients { get; set; } + public NotificationDefinitionGroupCacheItem() + { + + } + + public NotificationDefinitionGroupCacheItem( + string name, + string displayName = null, + string description = null, + bool allowSubscriptionToClients = false) + { + Name = name; + DisplayName = displayName; + Description = description; + AllowSubscriptionToClients = allowSubscriptionToClients; + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionRecord.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionRecord.cs new file mode 100644 index 000000000..df7d721f1 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionRecord.cs @@ -0,0 +1,127 @@ +using LINGYUN.Abp.Notifications; +using System; +using System.Collections.Generic; +using System.Linq; +using Volo.Abp; +using Volo.Abp.Data; +using Volo.Abp.Domain.Entities; + +namespace LINGYUN.Abp.MessageService.Notifications; + +public class NotificationDefinitionRecord : BasicAggregateRoot, IHasExtraProperties +{ + /// + /// 名称 + /// + public virtual string Name { get; set; } + /// + /// 显示名称 + /// + /// + /// 如果为空,回退到Name + /// + public virtual string DisplayName { get; set; } + /// + /// 描述 + /// + /// + /// 如果为空,回退到Name + /// + public virtual string Description { get; set; } + /// + /// 资源名称 + /// + /// + /// 如果不为空,作为参与本地化资源的名称 + /// DisplayName = L["DisplayName:Localization"] + /// Description = L["Description:Localization"] + /// + public virtual string ResourceName { get; protected set; } + /// + /// 本地化键值名称 + /// + /// + /// 如果不为空,作为参与本地化键值的名称 + /// DisplayName = L["DisplayName:Localization"] + /// Description = L["Description:Localization"] + /// + public virtual string Localization { get; protected set; } + /// + /// 存活类型 + /// + public virtual NotificationLifetime NotificationLifetime { get; set; } + /// + /// 通知类型 + /// + public virtual NotificationType NotificationType { get; set; } + /// + /// 通知提供者 + /// + /// + /// 多个之间用;分隔 + /// + public virtual string Providers { get; protected set; } + /// + /// 允许客户端订阅 + /// + public virtual bool AllowSubscriptionToClients { get; set; } + public ExtraPropertyDictionary ExtraProperties { get; protected set; } + + public NotificationDefinitionRecord() + { + ExtraProperties = new ExtraPropertyDictionary(); + this.SetDefaultsForExtraProperties(); + } + + public NotificationDefinitionRecord( + Guid id, + string name, + string displayName = null, + string description = null, + string resourceName = null, + string localization = null, + NotificationLifetime lifetime = NotificationLifetime.Persistent, + NotificationType notificationType = NotificationType.Application) + : base(id) + { + Name = Check.NotNullOrWhiteSpace(name, nameof(name), NotificationDefinitionRecordConsts.MaxNameLength); + DisplayName = Check.Length(displayName, nameof(displayName), NotificationDefinitionRecordConsts.MaxDisplayNameLength); + Description = Check.Length(description, nameof(description), NotificationDefinitionRecordConsts.MaxDescriptionLength); + NotificationLifetime = lifetime; + NotificationType = notificationType; + + SetLocalization(resourceName, localization); + + ExtraProperties = new ExtraPropertyDictionary(); + this.SetDefaultsForExtraProperties(); + + AllowSubscriptionToClients = true; + } + /// + /// 设置本地化资源 + /// + /// + /// + public void SetLocalization(string resourceName, string localization) + { + ResourceName = Check.Length(resourceName, nameof(resourceName), NotificationDefinitionGroupRecordConsts.MaxResourceNameLength); + Localization = Check.Length(localization, nameof(localization), NotificationDefinitionGroupRecordConsts.MaxLocalizationLength); + } + + public void UseProviders(params string[] providers) + { + var currentProviders = Providers.IsNullOrWhiteSpace() + ? new List() + : Providers.Split(';').ToList(); + + if (!providers.IsNullOrEmpty()) + { + currentProviders.AddIfNotContains(providers); + } + + if (currentProviders.Any()) + { + Providers = currentProviders.JoinAsString(";"); + } + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionsCacheItem.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionsCacheItem.cs new file mode 100644 index 000000000..741ed140c --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationDefinitionsCacheItem.cs @@ -0,0 +1,68 @@ +using LINGYUN.Abp.Notifications; +using System; +using System.Collections.Generic; +using Volo.Abp.MultiTenancy; + +namespace LINGYUN.Abp.MessageService.Notifications; + +[Serializable] +[IgnoreMultiTenancy] +public class NotificationDefinitionsCacheItem +{ + private const string CacheKeyFormat = "n:Abp_Notifications;c:{0}"; + + public NotificationDefinitionCacheItem[] Notifications { get; set; } + + public NotificationDefinitionsCacheItem() + { + Notifications = new NotificationDefinitionCacheItem[0]; + } + + public NotificationDefinitionsCacheItem( + NotificationDefinitionCacheItem[] notifications) + { + Notifications = notifications; + } + + public static string CalculateCacheKey(string culture) + { + return string.Format(CacheKeyFormat, culture); + } +} + +public class NotificationDefinitionCacheItem +{ + public string Name { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public NotificationLifetime Lifetime { get; set; } + public NotificationType NotificationType { get; set; } + public List Providers { get; set; } + public bool AllowSubscriptionToClients { get; set; } + public Dictionary Properties { get; set; } + public NotificationDefinitionCacheItem() + { + Providers = new List(); + Properties = new Dictionary(); + } + + public NotificationDefinitionCacheItem( + string name, + string displayName = null, + string description = null, + NotificationLifetime lifetime = NotificationLifetime.Persistent, + NotificationType notificationType = NotificationType.Application, + List providers = null, + bool allowSubscriptionToClients = false) + { + Name = name; + DisplayName = displayName; + Description = description; + Lifetime = lifetime; + NotificationType = notificationType; + Providers = providers ?? new List(); + AllowSubscriptionToClients = allowSubscriptionToClients; + + Properties = new Dictionary(); + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs index 544802d7b..cd34fd4cc 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/AbpMessageServiceEntityFrameworkCoreModule.cs @@ -18,6 +18,8 @@ namespace LINGYUN.Abp.MessageService.EntityFrameworkCore context.Services.AddAbpDbContext(options => { options.AddRepository(); + options.AddRepository(); + options.AddRepository(); options.AddRepository(); options.AddRepository(); diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs index 26e6945b6..21e866867 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/EntityFrameworkCore/MessageServiceDbContextModelCreatingExtensions.cs @@ -186,6 +186,48 @@ namespace LINGYUN.Abp.MessageService.EntityFrameworkCore b.HasIndex(p => new { p.TenantId, p.GroupId, p.UserId }); }); + + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "NotificationDefinitionGroups", options.Schema); + + b.Property(p => p.Name) + .HasMaxLength(NotificationDefinitionGroupRecordConsts.MaxNameLength) + .IsRequired(); + + b.Property(p => p.DisplayName) + .HasMaxLength(NotificationDefinitionGroupRecordConsts.MaxDisplayNameLength); + b.Property(p => p.Description) + .HasMaxLength(NotificationDefinitionGroupRecordConsts.MaxDescriptionLength); + b.Property(p => p.ResourceName) + .HasMaxLength(NotificationDefinitionGroupRecordConsts.MaxResourceNameLength); + b.Property(p => p.Localization) + .HasMaxLength(NotificationDefinitionGroupRecordConsts.MaxLocalizationLength); + + b.ConfigureByConvention(); + }); + + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "NotificationDefinitions", options.Schema); + + b.Property(p => p.Name) + .HasMaxLength(NotificationDefinitionRecordConsts.MaxNameLength) + .IsRequired(); + + b.Property(p => p.DisplayName) + .HasMaxLength(NotificationDefinitionRecordConsts.MaxDisplayNameLength); + b.Property(p => p.Description) + .HasMaxLength(NotificationDefinitionRecordConsts.MaxDescriptionLength); + b.Property(p => p.ResourceName) + .HasMaxLength(NotificationDefinitionRecordConsts.MaxResourceNameLength); + b.Property(p => p.Localization) + .HasMaxLength(NotificationDefinitionRecordConsts.MaxLocalizationLength); + b.Property(p => p.Providers) + .HasMaxLength(NotificationDefinitionRecordConsts.MaxProvidersLength); + + b.ConfigureByConvention(); + }); } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationDefinitionGroupRecordRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationDefinitionGroupRecordRepository.cs new file mode 100644 index 000000000..df48ab133 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationDefinitionGroupRecordRepository.cs @@ -0,0 +1,19 @@ +using LINGYUN.Abp.MessageService.EntityFrameworkCore; +using System; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace LINGYUN.Abp.MessageService.Notifications; + +public class EfCoreNotificationDefinitionGroupRecordRepository : + EfCoreRepository, + INotificationDefinitionGroupRecordRepository, + ITransientDependency +{ + public EfCoreNotificationDefinitionGroupRecordRepository( + IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationDefinitionRecordRepository.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationDefinitionRecordRepository.cs new file mode 100644 index 000000000..410c9561b --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Notifications/EfCoreNotificationDefinitionRecordRepository.cs @@ -0,0 +1,19 @@ +using LINGYUN.Abp.MessageService.EntityFrameworkCore; +using System; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; + +namespace LINGYUN.Abp.MessageService.Notifications; + +public class EfCoreNotificationDefinitionRecordRepository : + EfCoreRepository, + INotificationDefinitionRecordRepository, + ITransientDependency +{ + public EfCoreNotificationDefinitionRecordRepository( + IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/MyNotificationController.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/MyNotificationController.cs index dc247ecab..875ab9b95 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/MyNotificationController.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/MyNotificationController.cs @@ -31,13 +31,7 @@ namespace LINGYUN.Abp.MessageService.Notifications { await MyNotificationAppService.DeleteAsync(id); } - - [HttpGet] - [Route("assignables")] - public async virtual Task> GetAssignableNotifiersAsync() - { - return await MyNotificationAppService.GetAssignableNotifiersAsync(); - } + [HttpGet] [Route("{id}")] diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/NotificationController.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/NotificationController.cs index 3e9b5250d..533d7a20d 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/NotificationController.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.HttpApi/LINGYUN/Abp/MessageService/Notifications/NotificationController.cs @@ -26,6 +26,13 @@ namespace LINGYUN.Abp.MessageService.Notifications await NotificationAppService.SendAsync(input); } + [HttpGet] + [Route("assignables")] + public async virtual Task> GetAssignableNotifiersAsync() + { + return await NotificationAppService.GetAssignableNotifiersAsync(); + } + [HttpGet] [Route("assignable-templates")] public async virtual Task> GetAssignableTemplatesAsync() diff --git a/aspnet-core/modules/pushplus/LINGYUN.Abp.Notifications.PushPlus/LINGYUN/Abp/Notifications/PushPlus/PushPlusNotificationPublishProvider.cs b/aspnet-core/modules/pushplus/LINGYUN.Abp.Notifications.PushPlus/LINGYUN/Abp/Notifications/PushPlus/PushPlusNotificationPublishProvider.cs index 4fc1746cc..aed531e4f 100644 --- a/aspnet-core/modules/pushplus/LINGYUN.Abp.Notifications.PushPlus/LINGYUN/Abp/Notifications/PushPlus/PushPlusNotificationPublishProvider.cs +++ b/aspnet-core/modules/pushplus/LINGYUN.Abp.Notifications.PushPlus/LINGYUN/Abp/Notifications/PushPlus/PushPlusNotificationPublishProvider.cs @@ -65,7 +65,7 @@ public class PushPlusNotificationPublishProvider : NotificationPublishProvider { var topic = ""; - var notificationDefine = NotificationDefinitionManager.GetOrNull(notification.Name); + var notificationDefine = await NotificationDefinitionManager.GetOrNullAsync(notification.Name); var topicDefine = notificationDefine?.GetTopicOrNull(); if (!topicDefine.IsNullOrWhiteSpace()) { diff --git a/aspnet-core/modules/wx-pusher/LINGYUN.Abp.Notifications.WxPusher/LINGYUN/Abp/Notifications/WxPusher/WxPusherNotificationPublishProvider.cs b/aspnet-core/modules/wx-pusher/LINGYUN.Abp.Notifications.WxPusher/LINGYUN/Abp/Notifications/WxPusher/WxPusherNotificationPublishProvider.cs index ee966ae20..b644b445e 100644 --- a/aspnet-core/modules/wx-pusher/LINGYUN.Abp.Notifications.WxPusher/LINGYUN/Abp/Notifications/WxPusher/WxPusherNotificationPublishProvider.cs +++ b/aspnet-core/modules/wx-pusher/LINGYUN.Abp.Notifications.WxPusher/LINGYUN/Abp/Notifications/WxPusher/WxPusherNotificationPublishProvider.cs @@ -72,7 +72,7 @@ public class WxPusherNotificationPublishProvider : NotificationPublishProvider var topics = await WxPusherUserStore.GetSubscribeTopicsAsync(subscribeUserIds, cancellationToken); var uids = await WxPusherUserStore.GetBindUidsAsync(subscribeUserIds, cancellationToken); - var notificationDefine = NotificationDefinitionManager.GetOrNull(notification.Name); + var notificationDefine = await NotificationDefinitionManager.GetOrNullAsync(notification.Name); var url = notification.Data.GetUrlOrNull() ?? notificationDefine?.GetUrlOrNull(); var topicDefine = notificationDefine?.GetTopics(); if (topicDefine.Any()) diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs index 45cc7e7fa..d2f45cf90 100644 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs +++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/EventBus/Distributed/NotificationEventHandler.cs @@ -109,7 +109,7 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed { using (CurrentTenant.Change(eventData.TenantId)) { - var notification = NotificationDefinitionManager.GetOrNull(eventData.Name); + var notification = await NotificationDefinitionManager.GetOrNullAsync(eventData.Name); if (notification == null) { return; @@ -177,8 +177,7 @@ namespace LY.MicroService.RealtimeMessage.EventBus.Distributed { using (CurrentTenant.Change(eventData.TenantId)) { - // 如果上面过滤了应用程序,这里可以使用Get方法,否则,最好使用GetOrNull加以判断 - var notification = NotificationDefinitionManager.GetOrNull(eventData.Name); + var notification = await NotificationDefinitionManager.GetOrNullAsync(eventData.Name); if (notification == null) { return; diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/20220902104049_Add-Dynamic-Notification.Designer.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/20220902104049_Add-Dynamic-Notification.Designer.cs new file mode 100644 index 000000000..127df24b0 --- /dev/null +++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/20220902104049_Add-Dynamic-Notification.Designer.cs @@ -0,0 +1,720 @@ +// +using System; +using LY.MicroService.RealtimeMessage.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Volo.Abp.EntityFrameworkCore; + +#nullable disable + +namespace LY.MicroService.RealtimeMessage.Migrations +{ + [DbContext(typeof(RealtimeMessageMigrationsDbContext))] + [Migration("20220902104049_Add-Dynamic-Notification")] + partial class AddDynamicNotification + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql) + .HasAnnotation("ProductVersion", "6.0.8") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatCard", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("AvatarUrl") + .HasMaxLength(512) + .HasColumnType("varchar(512)"); + + b.Property("Birthday") + .HasColumnType("datetime(6)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("Description") + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("LastModificationTime") + .HasColumnType("datetime(6)") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("char(36)") + .HasColumnName("LastModifierId"); + + b.Property("LastOnlineTime") + .HasColumnType("datetime(6)"); + + b.Property("NickName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("Sex") + .HasColumnType("int"); + + b.Property("Sign") + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("State") + .HasColumnType("int"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("UserId") + .HasColumnType("char(36)"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "UserId"); + + b.ToTable("AppUserChatCards", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatFriend", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Black") + .HasColumnType("tinyint(1)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("Description") + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("DontDisturb") + .HasColumnType("tinyint(1)"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("FrientId") + .HasColumnType("char(36)"); + + b.Property("IsStatic") + .HasColumnType("tinyint(1)"); + + b.Property("RemarkName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("SpecialFocus") + .HasColumnType("tinyint(1)"); + + b.Property("Status") + .HasColumnType("tinyint unsigned"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("UserId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "UserId", "FrientId"); + + b.ToTable("AppUserChatFriends", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("AllowAddFriend") + .HasColumnType("tinyint(1)"); + + b.Property("AllowAnonymous") + .HasColumnType("tinyint(1)"); + + b.Property("AllowReceiveMessage") + .HasColumnType("tinyint(1)"); + + b.Property("AllowSendMessage") + .HasColumnType("tinyint(1)"); + + b.Property("RequireAddFriendValition") + .HasColumnType("tinyint(1)"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("UserId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "UserId"); + + b.ToTable("AppUserChatSettings", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("Content") + .IsRequired() + .HasMaxLength(1048576) + .HasColumnType("longtext"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("MessageId") + .HasColumnType("bigint"); + + b.Property("ReceiveUserId") + .HasColumnType("char(36)"); + + b.Property("SendUserName") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("Source") + .HasColumnType("int"); + + b.Property("State") + .HasColumnType("tinyint"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "ReceiveUserId"); + + b.ToTable("AppUserMessages", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Groups.ChatGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Address") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("AdminUserId") + .HasColumnType("char(36)"); + + b.Property("AllowAnonymous") + .HasColumnType("tinyint(1)"); + + b.Property("AllowSendMessage") + .HasColumnType("tinyint(1)"); + + b.Property("AvatarUrl") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("Description") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("GroupId") + .HasColumnType("bigint"); + + b.Property("LastModificationTime") + .HasColumnType("datetime(6)") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("char(36)") + .HasColumnName("LastModifierId"); + + b.Property("MaxUserCount") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.Property("Notice") + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("Tag") + .HasMaxLength(512) + .HasColumnType("varchar(512)"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "Name"); + + b.ToTable("AppChatGroups", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Groups.GroupChatBlack", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("GroupId") + .HasColumnType("bigint"); + + b.Property("ShieldUserId") + .HasColumnType("char(36)"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "GroupId"); + + b.ToTable("AppGroupChatBlacks", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Groups.GroupMessage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("Content") + .IsRequired() + .HasMaxLength(1048576) + .HasColumnType("longtext"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("GroupId") + .HasColumnType("bigint"); + + b.Property("MessageId") + .HasColumnType("bigint"); + + b.Property("SendUserName") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("Source") + .HasColumnType("int"); + + b.Property("State") + .HasColumnType("tinyint"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "GroupId"); + + b.ToTable("AppGroupMessages", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Groups.UserChatGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("GroupId") + .HasColumnType("bigint"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("UserId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "GroupId", "UserId"); + + b.ToTable("AppUserChatGroups", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Groups.UserGroupCard", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasMaxLength(40) + .HasColumnType("varchar(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("char(36)") + .HasColumnName("CreatorId"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("IsAdmin") + .HasColumnType("tinyint(1)"); + + b.Property("LastModificationTime") + .HasColumnType("datetime(6)") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("char(36)") + .HasColumnName("LastModifierId"); + + b.Property("NickName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("SilenceEnd") + .HasColumnType("datetime(6)"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("UserId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "UserId"); + + b.ToTable("AppUserGroupCards", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("ExpirationTime") + .HasColumnType("datetime(6)"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("NotificationId") + .HasColumnType("bigint"); + + b.Property("NotificationName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("NotificationTypeName") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("varchar(512)"); + + b.Property("Severity") + .HasColumnType("tinyint"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "NotificationName"); + + b.ToTable("AppNotifications", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.NotificationDefinitionGroupRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("AllowSubscriptionToClients") + .HasColumnType("tinyint(1)"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("DisplayName") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("Localization") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("ResourceName") + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.HasKey("Id"); + + b.ToTable("AppNotificationDefinitionGroups", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.NotificationDefinitionRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("AllowSubscriptionToClients") + .HasColumnType("tinyint(1)"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("DisplayName") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("Localization") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("NotificationLifetime") + .HasColumnType("int"); + + b.Property("NotificationType") + .HasColumnType("int"); + + b.Property("Providers") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("ResourceName") + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.HasKey("Id"); + + b.ToTable("AppNotificationDefinitions", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.UserNotification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("NotificationId") + .HasColumnType("bigint"); + + b.Property("ReadStatus") + .HasColumnType("int"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("UserId") + .HasColumnType("char(36)"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "UserId", "NotificationId") + .HasDatabaseName("IX_Tenant_User_Notification_Id"); + + b.ToTable("AppUserNotifications", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Subscriptions.UserSubscribe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)") + .HasColumnName("CreationTime"); + + b.Property("NotificationName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("TenantId") + .HasColumnType("char(36)") + .HasColumnName("TenantId"); + + b.Property("UserId") + .HasColumnType("char(36)"); + + b.Property("UserName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(128) + .HasColumnType("varchar(128)") + .HasDefaultValue("/"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "UserId", "NotificationName") + .IsUnique() + .HasDatabaseName("IX_Tenant_User_Notification_Name"); + + b.ToTable("AppUserSubscribes", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/20220902104049_Add-Dynamic-Notification.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/20220902104049_Add-Dynamic-Notification.cs new file mode 100644 index 000000000..fb30570be --- /dev/null +++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/20220902104049_Add-Dynamic-Notification.cs @@ -0,0 +1,76 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LY.MicroService.RealtimeMessage.Migrations +{ + public partial class AddDynamicNotification : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AppNotificationDefinitionGroups", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Name = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DisplayName = table.Column(type: "varchar(255)", maxLength: 255, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "varchar(255)", maxLength: 255, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ResourceName = table.Column(type: "varchar(64)", maxLength: 64, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Localization = table.Column(type: "varchar(128)", maxLength: 128, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + AllowSubscriptionToClients = table.Column(type: "tinyint(1)", nullable: false), + ExtraProperties = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_AppNotificationDefinitionGroups", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "AppNotificationDefinitions", + columns: table => new + { + Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), + Name = table.Column(type: "varchar(64)", maxLength: 64, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DisplayName = table.Column(type: "varchar(255)", maxLength: 255, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Description = table.Column(type: "varchar(255)", maxLength: 255, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + ResourceName = table.Column(type: "varchar(64)", maxLength: 64, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Localization = table.Column(type: "varchar(128)", maxLength: 128, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + NotificationLifetime = table.Column(type: "int", nullable: false), + NotificationType = table.Column(type: "int", nullable: false), + Providers = table.Column(type: "varchar(200)", maxLength: 200, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + AllowSubscriptionToClients = table.Column(type: "tinyint(1)", nullable: false), + ExtraProperties = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_AppNotificationDefinitions", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AppNotificationDefinitionGroups"); + + migrationBuilder.DropTable( + name: "AppNotificationDefinitions"); + } + } +} diff --git a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/RealtimeMessageMigrationsDbContextModelSnapshot.cs b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/RealtimeMessageMigrationsDbContextModelSnapshot.cs index b11ea6638..4f945f7f2 100644 --- a/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/RealtimeMessageMigrationsDbContextModelSnapshot.cs +++ b/aspnet-core/services/LY.MicroService.RealtimeMessage.HttpApi.Host/Migrations/RealtimeMessageMigrationsDbContextModelSnapshot.cs @@ -18,7 +18,7 @@ namespace LY.MicroService.RealtimeMessage.Migrations #pragma warning disable 612, 618 modelBuilder .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql) - .HasAnnotation("ProductVersion", "5.0.12") + .HasAnnotation("ProductVersion", "6.0.8") .HasAnnotation("Relational:MaxIdentifierLength", 64); modelBuilder.Entity("LINGYUN.Abp.MessageService.Chat.UserChatCard", b => @@ -560,6 +560,94 @@ namespace LY.MicroService.RealtimeMessage.Migrations b.ToTable("AppNotifications", (string)null); }); + modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.NotificationDefinitionGroupRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("AllowSubscriptionToClients") + .HasColumnType("tinyint(1)"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("DisplayName") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("Localization") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("ResourceName") + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.HasKey("Id"); + + b.ToTable("AppNotificationDefinitionGroups", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.NotificationDefinitionRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("char(36)"); + + b.Property("AllowSubscriptionToClients") + .HasColumnType("tinyint(1)"); + + b.Property("Description") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("DisplayName") + .HasMaxLength(255) + .HasColumnType("varchar(255)"); + + b.Property("ExtraProperties") + .HasColumnType("longtext") + .HasColumnName("ExtraProperties"); + + b.Property("Localization") + .HasMaxLength(128) + .HasColumnType("varchar(128)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.Property("NotificationLifetime") + .HasColumnType("int"); + + b.Property("NotificationType") + .HasColumnType("int"); + + b.Property("Providers") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("ResourceName") + .HasMaxLength(64) + .HasColumnType("varchar(64)"); + + b.HasKey("Id"); + + b.ToTable("AppNotificationDefinitions", (string)null); + }); + modelBuilder.Entity("LINGYUN.Abp.MessageService.Notifications.UserNotification", b => { b.Property("Id")