From 915560d36bc2334c384eece8a05ec784212cb352 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Sun, 14 Jun 2020 11:50:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E5=87=86=E5=8C=96=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=B6=88=E6=81=AF;=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=A7=9F=E6=88=B7=E5=88=9B=E5=BB=BA=E9=80=9A=E7=9F=A5;?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A7=9F=E6=88=B7=E5=88=9B=E5=BB=BA=E5=90=8E?= =?UTF-8?q?=E5=86=99=E5=85=A5=E4=BA=86=E5=B1=9E=E4=BA=8E=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E6=9D=83=E9=99=90=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SignalRNotificationPublishProvider.cs | 10 +- ...GYUN.Abp.Notifications.WeChat.WeApp.csproj | 8 + .../WeChatWeAppNotificationPublishProvider.cs | 6 +- .../WeApp/WeChatWeAppSendNotificationData.cs | 16 ++ .../INotificationDefinitionContext.cs | 2 +- .../INotificationDefinitionManager.cs | 4 +- .../Notifications/INotificationDispatcher.cs | 2 +- .../Abp/Notifications/INotificationStore.cs | 2 + .../INotificationSubscriptionManager.cs | 7 + .../Internal/DefaultNotificationDispatcher.cs | 81 +++++++-- .../NotificationSubscriptionManager.cs | 5 + .../Abp/Notifications/NotificationData.cs | 78 +++++++++ .../Notifications/NotificationDefinition.cs | 17 +- .../NotificationDefinitionContext.cs | 6 +- .../NotificationDefinitionManager.cs | 12 +- .../Abp/Notifications/NotificationInfo.cs | 11 ++ .../Abp/Notifications/NotificationName.cs | 14 ++ .../NotificationNameNormalizer.cs | 15 ++ .../EventBus/Tenants/CreateEventData.cs | 2 + .../MultiTenancy/TenantNotificationNames.cs | 9 + .../UserNotificationNames.cs | 2 +- .../UserCreateSendWelcomeEventHandler.cs | 12 +- .../Localization/Resources/en.json | 1 + .../Localization/Resources/zh-Hans.json | 1 + ...geServiceNotificationDefinitionProvider.cs | 8 +- .../Notifications/NotificationStore.cs | 155 ++++++++++-------- .../Notifications/UserNotification.cs | 3 +- .../Subscriptions/IUserSubscribeRepository.cs | 2 + .../MessageService/Subscriptions/Subscribe.cs | 3 +- .../Subscriptions/UserSubscribe.cs | 3 +- .../EfCoreUserSubscribeRepository.cs | 13 ++ .../Abp/TenantManagement/TenantAppService.cs | 6 +- .../AuthIdentityServerModule.cs | 12 +- .../AuthServer.Host/AuthServer.Host.csproj | 1 + .../Handlers/TenantCreateEventHandler.cs | 66 ++++++-- aspnet-core/services/cleanup-logs.bat | 1 + .../Controllers/NotificationController.cs | 4 +- .../Distributed/TenantCreateEventHandler.cs | 75 +++++++++ ...YUN.Abp.MessageService.HttpApi.Host.csproj | 12 ++ .../AbpMessageServiceHttpApiHostModule.cs | 17 +- .../Localization/HttpApiHost/en.json | 7 + .../Localization/HttpApiHost/zh-Hans.json | 7 + .../Handlers/TenantCreateEventHandler.cs | 5 +- .../Handlers/TenantDeleteEventHandler.cs | 16 +- .../LINGYUN.Platform.HttpApi.Host.csproj | 1 + .../PlatformHttpApiHostModule.cs | 12 +- vueJs/src/utils/request.ts | 8 +- 47 files changed, 604 insertions(+), 156 deletions(-) create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationName.cs create mode 100644 aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationNameNormalizer.cs create mode 100644 aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/MultiTenancy/TenantNotificationNames.cs rename aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/{Notifications => }/UserNotificationNames.cs (82%) create mode 100644 aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/TenantCreateEventHandler.cs create mode 100644 aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/en.json create mode 100644 aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/zh-Hans.json diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs index 79263e96f..414eb0c64 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs @@ -2,7 +2,6 @@ using LINGYUN.Abp.RealTime.Client; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; using System; using System.Collections.Generic; using System.Threading.Tasks; @@ -11,8 +10,6 @@ namespace LINGYUN.Abp.Notifications.SignalR { public class SignalRNotificationPublishProvider : NotificationPublishProvider { - public ILogger Logger { protected get; set; } - public override string Name => "SignalR"; private readonly IOnlineClientManager _onlineClientManager; @@ -27,13 +24,14 @@ namespace LINGYUN.Abp.Notifications.SignalR { _hubContext = hubContext; _onlineClientManager = onlineClientManager; - - Logger = NullLogger.Instance; } public override async Task PublishAsync(NotificationInfo notification, IEnumerable identifiers) { - foreach(var identifier in identifiers) + // 返回标准数据给前端 + notification.Data = NotificationData.ToStandardData(notification.Data); + + foreach (var identifier in identifiers) { var onlineClientContext = new OnlineClientContext(notification.TenantId, identifier.UserId); var onlineClients = _onlineClientManager.GetAllByContext(onlineClientContext); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN.Abp.Notifications.WeChat.WeApp.csproj b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN.Abp.Notifications.WeChat.WeApp.csproj index 56fffe29c..e84d5cac5 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN.Abp.Notifications.WeChat.WeApp.csproj +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN.Abp.Notifications.WeChat.WeApp.csproj @@ -3,6 +3,14 @@ netstandard2.0 + false + true + 2.9.0 + 通知接口的微信小程序发布者实现 + + + + D:\LocalNuget diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs index f30a14580..6b71643f6 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs @@ -55,8 +55,10 @@ namespace LINGYUN.Abp.Notifications.WeChat.WeApp var weChatWeAppNotificationData = new WeChatWeAppSendNotificationData(identifier.UserName, templateId, redirect, weAppState, weAppLang); + // 写入模板数据 - weChatWeAppNotificationData.WriteData(Options.DefaultMsgPrefix, notification.Data.Properties); + weChatWeAppNotificationData.WriteStandardData(NotificationData.ToStandardData(Options.DefaultMsgPrefix, notification.Data)); + // weChatWeAppNotificationData.WriteData(Options.DefaultMsgPrefix, notification.Data.Properties); Logger.LogDebug($"Sending wechat weapp notification: {notification.Name}"); // 发送小程序订阅消息 @@ -73,7 +75,7 @@ namespace LINGYUN.Abp.Notifications.WeChat.WeApp if (data.Properties.TryGetValue(key, out object value)) { // 取得了数据就删除对应键值 - data.Properties.Remove(key); + // data.Properties.Remove(key); return value.ToString(); } return defaultValue; diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppSendNotificationData.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppSendNotificationData.cs index bf71c952a..5f190f7c4 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppSendNotificationData.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppSendNotificationData.cs @@ -49,6 +49,22 @@ namespace LINGYUN.Abp.Notifications.WeChat.WeApp data = new Dictionary(); } + /// + /// 写入标准数据 + /// + /// + /// + public WeChatWeAppSendNotificationData WriteStandardData(NotificationData writeData) + { + foreach (var kv in writeData.Properties) + { + if (!data.ContainsKey(kv.Key)) + { + data.Add(kv.Key, new WeChatNotificationData(kv.Value)); + } + } + return this; + } public WeChatWeAppSendNotificationData WriteData(string prefix, string key, object value) { diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionContext.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionContext.cs index d46ea70ef..00aaf52e6 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionContext.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionContext.cs @@ -2,7 +2,7 @@ { public interface INotificationDefinitionContext { - NotificationDefinition GetOrNull(string name); + NotificationDefinition GetOrNull(string category); void Add(params NotificationDefinition[] definitions); } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs index 87829d683..ab958ee8f 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs @@ -6,10 +6,10 @@ namespace LINGYUN.Abp.Notifications public interface INotificationDefinitionManager { [NotNull] - NotificationDefinition Get([NotNull] string name); + NotificationDefinition Get([NotNull] string category); IReadOnlyList GetAll(); - NotificationDefinition GetOrNull(string name); + NotificationDefinition GetOrNull(string category); } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDispatcher.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDispatcher.cs index 5e8e3b6da..99e189f7d 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDispatcher.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDispatcher.cs @@ -24,7 +24,7 @@ namespace LINGYUN.Abp.Notifications /// 租户 /// 级别 /// - Task DispatchAsync(string notificationName, NotificationData data, Guid? tenantId = null, + Task DispatchAsync(NotificationName notificationName, NotificationData data, Guid? tenantId = null, NotificationSeverity notificationSeverity = NotificationSeverity.Info); } } 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 dc9f81ca9..fa7c266ca 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 @@ -16,6 +16,8 @@ namespace LINGYUN.Abp.Notifications Task> GetUserSubscriptionsAsync(Guid? tenantId, Guid userId); + Task> GetUserSubscriptionsAsync(Guid? tenantId, string userName); + Task IsSubscribedAsync(Guid? tenantId, Guid userId, string notificationName); Task InsertNotificationAsync(NotificationInfo notification); 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 f1d820598..796e729c5 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 @@ -55,5 +55,12 @@ namespace LINGYUN.Abp.Notifications /// 用户标识 /// Task> GetUserSubscriptionsAsync(Guid? tenantId, Guid userId); + /// + /// 获取用户订阅列表 + /// + /// 租户 + /// 用户名 + /// + Task> GetUserSubscriptionsAsync(Guid? tenantId, string userName); } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs index b53ae524e..a28d9dbfe 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs @@ -8,15 +8,34 @@ using Volo.Abp.BackgroundJobs; namespace LINGYUN.Abp.Notifications.Internal { + /// + /// Implements . + /// internal class DefaultNotificationDispatcher : INotificationDispatcher { + /// + /// Reference to . + /// public ILogger Logger { get; set; } - + /// + /// Reference to . + /// private readonly IBackgroundJobManager _backgroundJobManager; - + /// + /// Reference to . + /// private readonly INotificationStore _notificationStore; + /// + /// Reference to . + /// private readonly INotificationDefinitionManager _notificationDefinitionManager; + /// + /// Reference to . + /// private readonly INotificationPublishProviderManager _notificationPublishProviderManager; + /// + /// Initializes a new instance of the class. + /// public DefaultNotificationDispatcher( IBackgroundJobManager backgroundJobManager, @@ -32,23 +51,30 @@ namespace LINGYUN.Abp.Notifications.Internal Logger = NullLogger.Instance; } - - public virtual async Task DispatchAsync(string notificationName, NotificationData data, Guid? tenantId = null, + /// + /// 发送通知 + /// + /// 通知名称 + /// 通知数据 + /// 租户 + /// 级别 + /// + public virtual async Task DispatchAsync(NotificationName notificationName, NotificationData data, Guid? tenantId = null, NotificationSeverity notificationSeverity = NotificationSeverity.Info) { // 获取自定义的通知 - var defineNotification = _notificationDefinitionManager.GetOrNull(notificationName); + var defineNotification = _notificationDefinitionManager.Get(notificationName.CateGory); - // 没有定义的通知,应该也要能发布、订阅, - // 比如订单之类的,是以订单编号为通知名称,这是动态的,没法自定义 - if(defineNotification == null) - { - defineNotification = new NotificationDefinition(notificationName); - } + //// 没有定义的通知,应该也要能发布、订阅, + //// 比如订单之类的,是以订单编号为通知名称,这是动态的,没法自定义 + //if(defineNotification == null) + //{ + // defineNotification = new NotificationDefinition(notificationName.CateGory); + //} var notificationInfo = new NotificationInfo { - Name = defineNotification.Name, + Name = notificationName.Name, CreationTime = DateTime.Now, NotificationSeverity = notificationSeverity, NotificationType = defineNotification.NotificationType, @@ -66,14 +92,22 @@ namespace LINGYUN.Abp.Notifications.Internal await PublishFromProvidersAsync(providers, notificationInfo); } - + /// + /// 发送通知 + /// + /// 通知信息 + /// public virtual async Task DispatchAsync(NotificationInfo notification) { // 获取自定义的通知 - var defineNotification = _notificationDefinitionManager.Get(notification.Name); + var defineNotification = _notificationDefinitionManager.GetOrNull(notification.Name); - notification.NotificationType = defineNotification.NotificationType; - notification.Name = defineNotification.Name; + // 没有定义的通知,应该也要能发布、订阅, + // 比如订单之类的,是以订单编号为通知名称,这是动态的,没法自定义 + if (defineNotification == null) + { + defineNotification = new NotificationDefinition(notification.Name); + } var providers = Enumerable .Reverse(_notificationPublishProviderManager.Providers); @@ -86,6 +120,12 @@ namespace LINGYUN.Abp.Notifications.Internal await PublishFromProvidersAsync(providers, notification); } + /// + /// 指定提供者发布通知 + /// + /// 提供者列表 + /// 通知信息 + /// protected async Task PublishFromProvidersAsync(IEnumerable providers, NotificationInfo notificationInfo) { @@ -116,7 +156,13 @@ namespace LINGYUN.Abp.Notifications.Internal // await PublishAsync(provider, notificationInfo, subscriptionUserIdentifiers); //}); } - + /// + /// 发布通知 + /// + /// 通知发布者 + /// 通知信息 + /// 订阅用户列表 + /// protected async Task PublishAsync(INotificationPublishProvider provider, NotificationInfo notificationInfo, IEnumerable subscriptionUserIdentifiers) { @@ -124,6 +170,7 @@ namespace LINGYUN.Abp.Notifications.Internal { Logger.LogDebug($"Sending notification with provider {provider.Name}"); + // 发布 await provider.PublishAsync(notificationInfo, subscriptionUserIdentifiers); Logger.LogDebug($"Send notification {notificationInfo.Name} with provider {provider.Name} was successful"); 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 508b400ef..bbf93a311 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 @@ -25,6 +25,11 @@ namespace LINGYUN.Abp.Notifications.Internal return await _store.GetUserSubscriptionsAsync(tenantId, userId); } + public virtual async Task> GetUserSubscriptionsAsync(Guid? tenantId, string userName) + { + return await _store.GetUserSubscriptionsAsync(tenantId, userName); + } + public virtual async Task IsSubscribedAsync(Guid? tenantId, Guid userId, string notificationName) { return await _store.IsSubscribedAsync(tenantId, userId, notificationName); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs index 2ed903b2d..ea6e40578 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs @@ -45,5 +45,83 @@ namespace LINGYUN.Abp.Notifications { _properties = new Dictionary(); } + /// + /// 写入标准数据 + /// + /// 标题 + /// 内容 + /// 创建时间 + /// 来源用户 + /// + public NotificationData WriteStandardData(string title, string message, DateTime createTime, string formUser) + { + TrySetData("title", title); + TrySetData("message", message); + TrySetData("formUser", formUser); + TrySetData("createTime", createTime); + return this; + } + /// + /// 写入标准数据 + /// + /// 数据前缀 + /// 标识 + /// 数据内容 + /// + public NotificationData WriteStandardData(string prefix, string key, object value) + { + TrySetData(string.Concat(prefix, key), value); + return this; + } + /// + /// 转换为标准数据 + /// + /// 原始数据 + /// + public static NotificationData ToStandardData(NotificationData sourceData) + { + var data = new NotificationData(); + data.TrySetData("title", sourceData.TryGetData("title")); + data.TrySetData("message", sourceData.TryGetData("message")); + data.TrySetData("formUser", sourceData.TryGetData("formUser")); + data.TrySetData("createTime", sourceData.TryGetData("createTime")); + return data; + } + /// + /// 转换为标准数据 + /// + /// 数据前缀 + /// 原始数据 + /// + public static NotificationData ToStandardData(string prefix, NotificationData sourceData) + { + var data = ToStandardData(sourceData); + + foreach(var property in sourceData.Properties) + { + if (property.Key.StartsWith(prefix)) + { + var key = property.Key.Replace(prefix, ""); + data.TrySetData(key, property.Value); + } + } + return data; + } + + public object TryGetData(string key) + { + if (Properties.TryGetValue(key, out object value)) + { + return value; + } + return null; + } + public void TrySetData(string key, object value) + { + if (value != null && !Properties.ContainsKey(key)) + { + Properties[key] = value; + } + } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinition.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinition.cs index 3ccfd9534..d43ec8ec0 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinition.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinition.cs @@ -4,15 +4,22 @@ using System.Collections.Generic; using Volo.Abp; using Volo.Abp.Localization; +/* + * 通知系统的设计不应该定死通知名称 + * 而是规范通知的一些属性,因此不应该是自定义通知名称,而是定义通知的类目,类似于Catalog + * 或者Prefix + * + */ + namespace LINGYUN.Abp.Notifications { public class NotificationDefinition { /// - /// 通知名称 + /// 通知类目 /// [NotNull] - public string Name { get; set; } + public string CateGory { get; set; } /// /// 通知显示名称 /// @@ -42,14 +49,14 @@ namespace LINGYUN.Abp.Notifications public List Providers { get; } public NotificationDefinition( - string name, + string category, ILocalizableString displayName = null, ILocalizableString description = null, NotificationType notificationType = NotificationType.Application, bool allowSubscriptionToClients = false) { - Name = name; - DisplayName = displayName ?? new FixedLocalizableString(name); + CateGory = category; + DisplayName = displayName ?? new FixedLocalizableString(category); Description = description; NotificationType = notificationType; AllowSubscriptionToClients = allowSubscriptionToClients; diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionContext.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionContext.cs index 9edf15535..db8b40bdc 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionContext.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionContext.cs @@ -21,13 +21,13 @@ namespace LINGYUN.Abp.Notifications foreach (var definition in definitions) { - Notifications[definition.Name] = definition; + Notifications[definition.CateGory] = definition; } } - public NotificationDefinition GetOrNull(string name) + public NotificationDefinition GetOrNull(string category) { - return Notifications.GetOrDefault(name); + return Notifications.GetOrDefault(category); } } } diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs index 3dde7bc3c..6c92aa695 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs @@ -28,15 +28,15 @@ namespace LINGYUN.Abp.Notifications NotificationDefinitions = new Lazy>(CreateNotificationDefinitions, true); } - public virtual NotificationDefinition Get([NotNull] string name) + public virtual NotificationDefinition Get([NotNull] string category) { - Check.NotNull(name, nameof(name)); + Check.NotNull(category, nameof(category)); - var notification = GetOrNull(name); + var notification = GetOrNull(category); if (notification == null) { - throw new AbpException("Undefined notification: " + name); + throw new AbpException("Undefined notification category: " + category); } return notification; @@ -47,9 +47,9 @@ namespace LINGYUN.Abp.Notifications return NotificationDefinitions.Value.Values.ToImmutableList(); } - public virtual NotificationDefinition GetOrNull(string name) + public virtual NotificationDefinition GetOrNull(string category) { - return NotificationDefinitions.Value.GetOrDefault(name); + return NotificationDefinitions.Value.GetOrDefault(category); } protected virtual IDictionary CreateNotificationDefinitions() diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationInfo.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationInfo.cs index 6f4d96b21..cd6911dde 100644 --- a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationInfo.cs +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationInfo.cs @@ -21,6 +21,17 @@ namespace LINGYUN.Abp.Notifications CreationTime = DateTime.Now; } + public long SetId(long id) + { + if (Id.IsNullOrWhiteSpace()) + { + Id = id.ToString(); + return id; + } + + return GetId(); + } + public long GetId() { return long.Parse(Id); diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationName.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationName.cs new file mode 100644 index 000000000..057259ded --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationName.cs @@ -0,0 +1,14 @@ +namespace LINGYUN.Abp.Notifications +{ + public class NotificationName + { + public string CateGory { get; } + public string Name { get; } + + public NotificationName(string cateGory, string name) + { + Name = name; + CateGory = cateGory; + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationNameNormalizer.cs b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationNameNormalizer.cs new file mode 100644 index 000000000..1d4ada3d1 --- /dev/null +++ b/aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationNameNormalizer.cs @@ -0,0 +1,15 @@ +namespace LINGYUN.Abp.Notifications +{ + public static class NotificationNameNormalizer + { + public static NotificationName NormalizerName(string name) + { + return new NotificationName(name, name); + } + public static NotificationName NormalizerName(string category, string name) + { + var notifyName = string.Concat(category, ":", name); + return new NotificationName(category, notifyName); + } + } +} diff --git a/aspnet-core/modules/common/LINGYUN.Common.EventBus/LINGYUN/Common/EventBus/Tenants/CreateEventData.cs b/aspnet-core/modules/common/LINGYUN.Common.EventBus/LINGYUN/Common/EventBus/Tenants/CreateEventData.cs index 09b6d2cc8..5585cb3b9 100644 --- a/aspnet-core/modules/common/LINGYUN.Common.EventBus/LINGYUN/Common/EventBus/Tenants/CreateEventData.cs +++ b/aspnet-core/modules/common/LINGYUN.Common.EventBus/LINGYUN/Common/EventBus/Tenants/CreateEventData.cs @@ -10,6 +10,8 @@ namespace LINGYUN.Common.EventBus.Tenants public string Name { get; set; } + public Guid AdminUserId { get; set; } + public string AdminEmailAddress { get; set; } public string AdminPassword { get; set; } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/MultiTenancy/TenantNotificationNames.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/MultiTenancy/TenantNotificationNames.cs new file mode 100644 index 000000000..e7bea5455 --- /dev/null +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/MultiTenancy/TenantNotificationNames.cs @@ -0,0 +1,9 @@ +namespace Volo.Abp.MultiTenancy +{ + public class TenantNotificationNames + { + public const string GroupName = "Volo.Abp.MultiTenancy"; + + public const string NewTenantRegistered = GroupName + ".NewTenantRegistered"; + } +} diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/Notifications/UserNotificationNames.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/UserNotificationNames.cs similarity index 82% rename from aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/Notifications/UserNotificationNames.cs rename to aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/UserNotificationNames.cs index dc8063377..877517c08 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/Notifications/UserNotificationNames.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/UserNotificationNames.cs @@ -1,4 +1,4 @@ -namespace Volo.Abp.Users.Notifications +namespace Volo.Abp.Users { public class UserNotificationNames { diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateSendWelcomeEventHandler.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateSendWelcomeEventHandler.cs index d676d9e38..672f1cb08 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateSendWelcomeEventHandler.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateSendWelcomeEventHandler.cs @@ -10,7 +10,6 @@ using Volo.Abp.EventBus; using Volo.Abp.Localization; using Volo.Abp.Settings; using Volo.Abp.Users; -using Volo.Abp.Users.Notifications; namespace LINGYUN.Abp.MessageService.EventBus { @@ -64,11 +63,16 @@ namespace LINGYUN.Abp.MessageService.EventBus var userWelcomeNotifictionData = new NotificationData(); + userWelcomeNotifictionData.WriteStandardData( + L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName), + L("WelcomeToApplicationFormUser", eventData.Entity.Name ?? eventData.Entity.UserName), + DateTime.Now, eventData.Entity.UserName); + // 换成用户名称,而不是用户名 - userWelcomeNotifictionData.Properties["message"] = L("WelcomeToApplicationFormUser", eventData.Entity.Name); + // userWelcomeNotifictionData.Properties["message"] = L("WelcomeToApplicationFormUser", eventData.Entity.Name); - await _notificationDispatcher.DispatchAsync(UserNotificationNames.WelcomeToApplication, - userWelcomeNotifictionData, eventData.Entity.TenantId); + var noticeNormalizerName = NotificationNameNormalizer.NormalizerName(UserNotificationNames.WelcomeToApplication); + await _notificationDispatcher.DispatchAsync(noticeNormalizerName, userWelcomeNotifictionData, eventData.Entity.TenantId); } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/en.json b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/en.json index f44750a3b..4571524e1 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/en.json +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/en.json @@ -8,6 +8,7 @@ "Messages:User:1002": "The user has rejected all messages!", "Messages:User:1003": "The user rejects the message you sent!", "WelcomeToApplicationNotification": "User Welcome Notice", + "NewTenantRegisterdNotification": "Tenants create notification", "WelcomeToApplicationFormUser": "User :{0} welcome to join us!" } } \ No newline at end of file diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/zh-Hans.json b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/zh-Hans.json index cf9f546ac..bfc60566f 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/zh-Hans.json +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/zh-Hans.json @@ -8,6 +8,7 @@ "Messages:User:1002": "用户已拒接所有消息!", "Messages:User:1003": "用户拒绝您发送的消息!", "WelcomeToApplicationNotification": "用户欢迎通知", + "NewTenantRegisterdNotification": "租户创建通知", "WelcomeToApplicationFormUser": "用户:{0} 欢迎您的加入!" } } \ No newline at end of file diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs index c2c37f881..4b7098ed6 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs @@ -1,7 +1,8 @@ using LINGYUN.Abp.MessageService.Localization; using LINGYUN.Abp.Notifications; using Volo.Abp.Localization; -using Volo.Abp.Users.Notifications; +using Volo.Abp.MultiTenancy; +using Volo.Abp.Users; namespace LINGYUN.Abp.MessageService.Notifications { @@ -14,6 +15,11 @@ namespace LINGYUN.Abp.MessageService.Notifications L("WelcomeToApplicationNotification"), L("WelcomeToApplicationNotification"), allowSubscriptionToClients: true)); + context.Add(new NotificationDefinition( + TenantNotificationNames.NewTenantRegistered, + L("NewTenantRegisterdNotification"), + L("NewTenantRegisterdNotification"), + allowSubscriptionToClients: true)); } protected LocalizableString L(string name) 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 238131f83..407aca566 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 @@ -43,13 +43,11 @@ namespace LINGYUN.Abp.MessageService.Notifications public async Task ChangeUserNotificationReadStateAsync(Guid? tenantId, Guid userId, long notificationId, NotificationReadState readState) { using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(tenantId)) { - using (CurrentTenant.Change(tenantId)) - { - await UserNotificationRepository.ChangeUserNotificationReadStateAsync(userId, notificationId, readState); + await UserNotificationRepository.ChangeUserNotificationReadStateAsync(userId, notificationId, readState); - await unitOfWork.SaveChangesAsync(); - } + await unitOfWork.SaveChangesAsync(); } } @@ -57,14 +55,12 @@ namespace LINGYUN.Abp.MessageService.Notifications public async Task DeleteNotificationAsync(NotificationInfo notification) { using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(notification.TenantId)) { - using (CurrentTenant.Change(notification.TenantId)) - { - var notify = await NotificationRepository.GetByIdAsync(notification.GetId()); - await NotificationRepository.DeleteAsync(notify.Id); + var notify = await NotificationRepository.GetByIdAsync(notification.GetId()); + await NotificationRepository.DeleteAsync(notify.Id); - await unitOfWork.SaveChangesAsync(); - } + await unitOfWork.SaveChangesAsync(); } } @@ -72,14 +68,12 @@ namespace LINGYUN.Abp.MessageService.Notifications public async Task DeleteUserNotificationAsync(Guid? tenantId, Guid userId, long notificationId) { using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(tenantId)) { - using (CurrentTenant.Change(tenantId)) - { - var notify = await UserNotificationRepository.GetByIdAsync(userId, notificationId); - await UserNotificationRepository.DeleteAsync(notify.Id); + var notify = await UserNotificationRepository.GetByIdAsync(userId, notificationId); + await UserNotificationRepository.DeleteAsync(notify.Id); - await unitOfWork.SaveChangesAsync(); - } + await unitOfWork.SaveChangesAsync(); } } @@ -87,14 +81,12 @@ namespace LINGYUN.Abp.MessageService.Notifications public async Task DeleteUserSubscriptionAsync(Guid? tenantId, Guid userId, string notificationName) { using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(tenantId)) { - using (CurrentTenant.Change(tenantId)) - { - var userSubscribe = await UserSubscribeRepository.GetUserSubscribeAsync(notificationName, userId); - await UserSubscribeRepository.DeleteAsync(userSubscribe.Id); + var userSubscribe = await UserSubscribeRepository.GetUserSubscribeAsync(notificationName, userId); + await UserSubscribeRepository.DeleteAsync(userSubscribe.Id); - await unitOfWork.SaveChangesAsync(); - } + await unitOfWork.SaveChangesAsync(); } } @@ -148,33 +140,52 @@ namespace LINGYUN.Abp.MessageService.Notifications } } + public virtual async Task> GetUserSubscriptionsAsync(Guid? tenantId, string userName) + { + using (CurrentTenant.Change(tenantId)) + { + var userSubscriptions = await UserSubscribeRepository.GetUserSubscribesByNameAsync(userName); + + var userSubscriptionInfos = new List(); + + userSubscriptions.ForEach(us => userSubscriptionInfos.Add( + new NotificationSubscriptionInfo + { + UserId = us.UserId, + TenantId = us.TenantId, + NotificationName = us.NotificationName + })); + + return userSubscriptionInfos; + } + } + [UnitOfWork] public async Task InsertNotificationAsync(NotificationInfo notification) { using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(notification.TenantId)) { - using (CurrentTenant.Change(notification.TenantId)) + // var notifyId = notification.GetId(); + var notifyId = SnowflakeIdGenerator.Create(); + // 保存主键,防止前端js long类型溢出 + // notification.Data["id"] = notifyId.ToString(); + + var notify = new Notification(notifyId, notification.Name, + notification.Data.GetType().AssemblyQualifiedName, + JsonSerializer.Serialize(notification.Data), notification.NotificationSeverity) { - var notifyId = SnowflakeIdGenerator.Create(); - // 保存主键,防止前端js long类型溢出 - notification.Data["id"] = notifyId.ToString(); - - var notify = new Notification(notifyId, notification.Name, - notification.Data.GetType().AssemblyQualifiedName, - JsonSerializer.Serialize(notification.Data), notification.NotificationSeverity) - { - CreationTime = Clock.Now, - Type = notification.NotificationType, - ExpirationTime = Clock.Now.AddDays(60) - }; - notify.SetTenantId(notification.TenantId); + CreationTime = Clock.Now, + Type = notification.NotificationType, + ExpirationTime = Clock.Now.AddDays(60) + }; + notify.SetTenantId(notification.TenantId); - await NotificationRepository.InsertAsync(notify); + await NotificationRepository.InsertAsync(notify); - notification.Id = notify.NotificationId.ToString(); + notification.Id = notify.NotificationId.ToString(); - await unitOfWork.SaveChangesAsync(); - } + await unitOfWork.SaveChangesAsync(); } } @@ -182,14 +193,12 @@ namespace LINGYUN.Abp.MessageService.Notifications public async Task InsertUserNotificationAsync(NotificationInfo notification, Guid userId) { using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(notification.TenantId)) { - using (CurrentTenant.Change(notification.TenantId)) - { - var userNotification = new UserNotification(notification.GetId(), userId); - await UserNotificationRepository.InsertAsync(userNotification); + var userNotification = new UserNotification(notification.GetId(), userId, notification.TenantId); + await UserNotificationRepository.InsertAsync(userNotification); - await unitOfWork.SaveChangesAsync(); - } + await unitOfWork.SaveChangesAsync(); } } @@ -197,19 +206,17 @@ namespace LINGYUN.Abp.MessageService.Notifications public async Task InsertUserSubscriptionAsync(Guid? tenantId, UserIdentifier identifier, string notificationName) { using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(tenantId)) { - using (CurrentTenant.Change(tenantId)) - { - var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName) - { - CreationTime = Clock.Now - }; + var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId) + { + CreationTime = Clock.Now + }; - await UserSubscribeRepository.InsertAsync(userSubscription); + await UserSubscribeRepository.InsertAsync(userSubscription); - await unitOfWork.SaveChangesAsync(); - } + await unitOfWork.SaveChangesAsync(); } } @@ -217,20 +224,18 @@ namespace LINGYUN.Abp.MessageService.Notifications public async Task InsertUserSubscriptionAsync(Guid? tenantId, IEnumerable identifiers, string notificationName) { using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(tenantId)) { - using (CurrentTenant.Change(tenantId)) - { - var userSubscribes = new List(); + var userSubscribes = new List(); - foreach(var identifier in identifiers) - { - userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName)); - } + foreach (var identifier in identifiers) + { + userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId)); + } - await UserSubscribeRepository.InsertUserSubscriptionAsync(userSubscribes); + await UserSubscribeRepository.InsertUserSubscriptionAsync(userSubscribes); - await unitOfWork.SaveChangesAsync(); - } + await unitOfWork.SaveChangesAsync(); } } @@ -240,15 +245,23 @@ namespace LINGYUN.Abp.MessageService.Notifications return await UserSubscribeRepository.UserSubscribeExistsAysnc(notificationName, userId); } + [UnitOfWork] public async Task InsertUserNotificationsAsync(NotificationInfo notification, IEnumerable userIds) { - var userNofitications = new List(); - foreach(var userId in userIds) + // 添加工作单元 + using (var unitOfWork = _unitOfWorkManager.Begin()) + using (CurrentTenant.Change(notification.TenantId)) { - var userNofitication = new UserNotification(notification.GetId(), userId); - userNofitications.Add(userNofitication); + var userNofitications = new List(); + foreach (var userId in userIds) + { + var userNofitication = new UserNotification(notification.GetId(), userId, notification.TenantId); + userNofitications.Add(userNofitication); + } + await UserNotificationRepository.InsertUserNotificationsAsync(userNofitications); + + await unitOfWork.SaveChangesAsync(); } - await UserNotificationRepository.InsertUserNotificationsAsync(userNofitications); } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/UserNotification.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/UserNotification.cs index 2099b4d06..871866eff 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/UserNotification.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/UserNotification.cs @@ -12,11 +12,12 @@ namespace LINGYUN.Abp.MessageService.Notifications public virtual long NotificationId { get; protected set; } public virtual NotificationReadState ReadStatus { get; protected set; } protected UserNotification() { } - public UserNotification(long notificationId, Guid userId) + public UserNotification(long notificationId, Guid userId, Guid? tenantId = null) { UserId = userId; NotificationId = notificationId; ReadStatus = NotificationReadState.UnRead; + TenantId = tenantId; } public void ChangeReadState(NotificationReadState readStatus) 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 0615db628..0c5588c3f 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 @@ -15,6 +15,8 @@ namespace LINGYUN.Abp.MessageService.Subscriptions Task> GetUserSubscribesAsync(Guid userId); + Task> GetUserSubscribesByNameAsync(string userName); + Task> GetUserSubscribesAsync(string notificationName); Task InsertUserSubscriptionAsync(IEnumerable userSubscribes); diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/Subscribe.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/Subscribe.cs index 4fb6dbc1e..e3fd97d74 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/Subscribe.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/Subscribe.cs @@ -13,9 +13,10 @@ namespace LINGYUN.Abp.MessageService.Subscriptions protected Subscribe() { } - protected Subscribe(string notificationName) + protected Subscribe(string notificationName, Guid? tenantId = null) { NotificationName = notificationName; + TenantId = tenantId; } } } diff --git a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/UserSubscribe.cs b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/UserSubscribe.cs index 08ad897e2..b6726644e 100644 --- a/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/UserSubscribe.cs +++ b/aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/UserSubscribe.cs @@ -8,7 +8,8 @@ namespace LINGYUN.Abp.MessageService.Subscriptions public virtual Guid UserId { get; set; } public virtual string UserName { get; set; } protected UserSubscribe() { } - public UserSubscribe(string notificationName, Guid userId, string userName) : base(notificationName) + public UserSubscribe(string notificationName, Guid userId, string userName, Guid? tenantId = null) + : base(notificationName, tenantId) { UserId = userId; UserName = userName; 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 66fe146e3..4e0621219 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 @@ -24,6 +24,7 @@ namespace LINGYUN.Abp.MessageService.Subscriptions var userSubscribes = await DbSet .Distinct() .Where(x => x.NotificationName.Equals(notificationName)) + .AsNoTracking() .ToListAsync(); return userSubscribes; @@ -33,6 +34,7 @@ namespace LINGYUN.Abp.MessageService.Subscriptions { var userSubscribe = await DbSet .Where(x => x.UserId.Equals(userId) && x.NotificationName.Equals(notificationName)) + .AsNoTracking() .FirstOrDefaultAsync(); return userSubscribe; @@ -49,6 +51,17 @@ namespace LINGYUN.Abp.MessageService.Subscriptions return userSubscribeNames; } + public async Task> GetUserSubscribesByNameAsync(string userName) + { + var userSubscribeNames = await DbSet + .Distinct() + .Where(x => x.UserName.Equals(userName)) + .AsNoTracking() + .ToListAsync(); + + return userSubscribeNames; + } + public async Task> GetUserSubscribesAsync(string notificationName) { var subscribeUsers = await DbSet diff --git a/aspnet-core/modules/tenants/LINGYUN.Abp.TenantManagement.Application/LINGYUN/Abp/TenantManagement/TenantAppService.cs b/aspnet-core/modules/tenants/LINGYUN.Abp.TenantManagement.Application/LINGYUN/Abp/TenantManagement/TenantAppService.cs index 4e4c38adf..f45750382 100644 --- a/aspnet-core/modules/tenants/LINGYUN.Abp.TenantManagement.Application/LINGYUN/Abp/TenantManagement/TenantAppService.cs +++ b/aspnet-core/modules/tenants/LINGYUN.Abp.TenantManagement.Application/LINGYUN/Abp/TenantManagement/TenantAppService.cs @@ -63,6 +63,7 @@ namespace LINGYUN.Abp.TenantManagement { Id = tenant.Id, Name = tenant.Name, + AdminUserId = GuidGenerator.Create(), AdminEmailAddress = input.AdminEmailAddress, AdminPassword = input.AdminPassword }; @@ -99,12 +100,7 @@ namespace LINGYUN.Abp.TenantManagement { return; } - var deleteEventData = new DeleteEventData - { - Id = id - }; await TenantRepository.DeleteAsync(tenant); - await EventBus.PublishAsync(deleteEventData); } [Authorize(TenantManagementPermissions.Tenants.ManageConnectionStrings)] diff --git a/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs b/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs index b6736cfe2..46ff7dcb9 100644 --- a/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs +++ b/aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs @@ -18,6 +18,7 @@ using Volo.Abp; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.Auditing; using Volo.Abp.Autofac; +using Volo.Abp.Caching; using Volo.Abp.Data; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; @@ -64,7 +65,8 @@ namespace AuthServer.Host .UseRabbitMQ(rabbitMQOptions => { configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); - }); + }) + .UseDashboard(); }); } @@ -78,6 +80,14 @@ namespace AuthServer.Host options.UseMySQL(); }); + Configure(options => + { + // 滑动过期30天 + options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); + // 绝对过期60天 + options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); + }); + Configure(options => { options.Languages.Add(new LanguageInfo("en", "en", "English")); diff --git a/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj b/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj index 9c6ba8c5e..45c5bef4f 100644 --- a/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj +++ b/aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj @@ -6,6 +6,7 @@ + diff --git a/aspnet-core/services/account/AuthServer.Host/EventBus/Handlers/TenantCreateEventHandler.cs b/aspnet-core/services/account/AuthServer.Host/EventBus/Handlers/TenantCreateEventHandler.cs index 7181c07ee..dcc69e2e9 100644 --- a/aspnet-core/services/account/AuthServer.Host/EventBus/Handlers/TenantCreateEventHandler.cs +++ b/aspnet-core/services/account/AuthServer.Host/EventBus/Handlers/TenantCreateEventHandler.cs @@ -1,10 +1,16 @@ using LINGYUN.Common.EventBus.Tenants; +using Microsoft.AspNetCore.Identity; +using Microsoft.Extensions.Logging; +using System; using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; using Volo.Abp.EventBus.Distributed; +using Volo.Abp.Guids; using Volo.Abp.Identity; -using Volo.Abp.DependencyInjection; -using Microsoft.Extensions.Logging; using Volo.Abp.MultiTenancy; +using Volo.Abp.Uow; +using IdentityRole = Volo.Abp.Identity.IdentityRole; +using IdentityUser = Volo.Abp.Identity.IdentityUser; namespace AuthServer.Host.EventBus.Handlers { @@ -12,32 +18,70 @@ namespace AuthServer.Host.EventBus.Handlers { protected ILogger Logger { get; } protected ICurrentTenant CurrentTenant { get; } - protected IIdentityDataSeeder IdentityDataSeeder { get; } + protected IGuidGenerator GuidGenerator { get; } + protected IdentityUserManager IdentityUserManager { get; } + protected IdentityRoleManager IdentityRoleManager { get; } public TenantCreateEventHandler( ICurrentTenant currentTenant, - IIdentityDataSeeder identityDataSeeder, + IGuidGenerator guidGenerator, + IdentityUserManager identityUserManager, + IdentityRoleManager identityRoleManager, ILogger logger) { Logger = logger; CurrentTenant = currentTenant; - IdentityDataSeeder = identityDataSeeder; + GuidGenerator = guidGenerator; + IdentityUserManager = identityUserManager; + IdentityRoleManager = identityRoleManager; } + [UnitOfWork] public async Task HandleEventAsync(CreateEventData eventData) { using (CurrentTenant.Change(eventData.Id, eventData.Name)) { - var identitySeedResult = await IdentityDataSeeder - .SeedAsync(eventData.AdminEmailAddress, eventData.AdminPassword, eventData.Id); - if (!identitySeedResult.CreatedAdminUser) + const string tenantAdminRoleName = "admin"; + var tenantAdminRoleId = Guid.Empty; ; + + if (!await IdentityRoleManager.RoleExistsAsync(tenantAdminRoleName)) { - Logger.LogWarning("Tenant {0} admin user {1} not created!", eventData.Name, eventData.AdminEmailAddress); + tenantAdminRoleId = GuidGenerator.Create(); + var tenantAdminRole = new IdentityRole(tenantAdminRoleId, tenantAdminRoleName, eventData.Id) + { + IsStatic = true, + IsPublic = true + }; + (await IdentityRoleManager.CreateAsync(tenantAdminRole)).CheckErrors(); } - if (!identitySeedResult.CreatedAdminRole) + else { - Logger.LogWarning("Tenant {0} admin role not created!", eventData.Name); + var tenantAdminRole = await IdentityRoleManager.FindByNameAsync(tenantAdminRoleName); + tenantAdminRoleId = tenantAdminRole.Id; + } + + var tenantAdminUser = await IdentityUserManager.FindByNameAsync(eventData.AdminEmailAddress); + if (tenantAdminUser == null) + { + tenantAdminUser = new IdentityUser(eventData.AdminUserId, eventData.AdminEmailAddress, + eventData.AdminEmailAddress, eventData.Id); + + tenantAdminUser.AddRole(tenantAdminRoleId); + + // 创建租户管理用户 + (await IdentityUserManager.CreateAsync(tenantAdminUser)).CheckErrors(); + (await IdentityUserManager.AddPasswordAsync(tenantAdminUser, eventData.AdminPassword)).CheckErrors(); } + //var identitySeedResult = await IdentityDataSeeder + // .SeedAsync(eventData.AdminEmailAddress, eventData.AdminPassword, eventData.Id); + //if (!identitySeedResult.CreatedAdminUser) + //{ + // Logger.LogWarning("Tenant {0} admin user {1} not created!", eventData.Name, eventData.AdminEmailAddress); + //} + //if (!identitySeedResult.CreatedAdminRole) + //{ + // Logger.LogWarning("Tenant {0} admin role not created!", eventData.Name); + //} } } } diff --git a/aspnet-core/services/cleanup-logs.bat b/aspnet-core/services/cleanup-logs.bat index 06212d776..4afd1f6ef 100644 --- a/aspnet-core/services/cleanup-logs.bat +++ b/aspnet-core/services/cleanup-logs.bat @@ -8,4 +8,5 @@ del .\platform\LINGYUN.Platform.HttpApi.Host\Logs /Q del .\apigateway\LINGYUN.ApiGateway.Host\Logs /Q del .\apigateway\LINGYUN.ApiGateway.HttpApi.Host\Logs /Q del .\account\AuthServer.Host\Logs /Q +del .\messages\LINGYUN.Abp.MessageService.HttpApi.Host\Logs /Q diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Controllers/NotificationController.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Controllers/NotificationController.cs index 6ff6f3732..ba1909d8e 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Controllers/NotificationController.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Controllers/NotificationController.cs @@ -42,7 +42,9 @@ namespace LINGYUN.Abp.MessageService.Controllers notificationData.Properties.AddIfNotContains(notification.Data); - await _notificationDispatcher.DispatchAsync("TestApplicationNotofication", notificationData, + var notificationName = NotificationNameNormalizer.NormalizerName("TestApplicationNotofication"); + + await _notificationDispatcher.DispatchAsync(notificationName, notificationData, notificationSeverity: notification.Severity); // await _notificationDispatcher.DispatcheAsync(notificationInfo); diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/TenantCreateEventHandler.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/TenantCreateEventHandler.cs new file mode 100644 index 000000000..48e62bcc3 --- /dev/null +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/TenantCreateEventHandler.cs @@ -0,0 +1,75 @@ +using LINGYUN.Common.EventBus.Tenants; +using System.Threading.Tasks; +using Volo.Abp.EventBus.Distributed; +using Volo.Abp.DependencyInjection; +using Microsoft.Extensions.Logging; +using Volo.Abp.MultiTenancy; +using LINGYUN.Abp.Notifications; +using Microsoft.Extensions.Localization; +using LINGYUN.Abp.MessageService.Localization; +using System; +using Volo.Abp.Settings; +using Volo.Abp.Localization; +using System.Globalization; + +namespace LINGYUN.Abp.MessageService.EventBus.Distributed +{ + public class TenantCreateEventHandler : IDistributedEventHandler, ITransientDependency + { + protected ILogger Logger { get; } + protected ICurrentTenant CurrentTenant { get; } + protected ISettingProvider SettingProvider { get; } + protected IStringLocalizer StringLocalizer { get; } + protected INotificationDispatcher NotificationDispatcher { get; } + protected INotificationSubscriptionManager NotificationSubscriptionManager { get; } + + public TenantCreateEventHandler( + ICurrentTenant currentTenant, + ISettingProvider settingProvider, + INotificationDispatcher notificationDispatcher, + INotificationSubscriptionManager notificationSubscriptionManager, + IStringLocalizer stringLocalizer, + ILogger logger) + { + Logger = logger; + CurrentTenant = currentTenant; + SettingProvider = settingProvider; + StringLocalizer = stringLocalizer; + NotificationDispatcher = notificationDispatcher; + NotificationSubscriptionManager = notificationSubscriptionManager; + } + + public async Task HandleEventAsync(CreateEventData eventData) + { + var userDefaultCultureName = await SettingProvider.GetOrNullAsync(LocalizationSettingNames.DefaultLanguage); + if (userDefaultCultureName.IsNullOrWhiteSpace()) + { + userDefaultCultureName = CultureInfo.CurrentUICulture.Name; + } + // 使用系统区域语言发布通知 + using (CultureHelper.Use(userDefaultCultureName, userDefaultCultureName)) + { + var noticeNormalizerName = NotificationNameNormalizer.NormalizerName(TenantNotificationNames.NewTenantRegistered); + var tenantAdminUserIdentifier = new UserIdentifier(eventData.AdminUserId, eventData.AdminEmailAddress); + + // 管理用户订阅租户创建通知 + await NotificationSubscriptionManager.SubscribeAsync(eventData.Id, tenantAdminUserIdentifier, noticeNormalizerName.Name); + + var notificationData = new NotificationData(); + notificationData.WriteStandardData( + L("NewTenantRegisteredNotificationTitle"), + L("NewTenantRegisteredNotificationMessage", eventData.Name), + DateTime.Now, eventData.AdminEmailAddress); + + // 发布租户创建通知 + await NotificationDispatcher.DispatchAsync(noticeNormalizerName, notificationData, + eventData.Id, NotificationSeverity.Success); + } + } + + protected string L(string name, params object[] args) + { + return StringLocalizer[name, args]?.Value; + } + } +} diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj index 95c765ebd..f557962e3 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj @@ -6,6 +6,17 @@ + + + + + + + + + + + @@ -36,6 +47,7 @@ + diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs index 7d4e7e8bc..f23bf4fc2 100644 --- a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs @@ -3,6 +3,7 @@ using IdentityModel; using LINGYUN.Abp.EventBus.CAP; using LINGYUN.Abp.IM.SignalR; using LINGYUN.Abp.MessageService.EntityFrameworkCore; +using LINGYUN.Abp.MessageService.Localization; using LINGYUN.Abp.MessageService.MultiTenancy; using LINGYUN.Abp.Notifications.SignalR; using LINGYUN.Abp.Notifications.WeChat.WeApp; @@ -19,6 +20,7 @@ using Volo.Abp; using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.Autofac; +using Volo.Abp.Caching; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.Localization; using Volo.Abp.Modularity; @@ -58,7 +60,8 @@ namespace LINGYUN.Abp.MessageService .UseRabbitMQ(rabbitMQOptions => { configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); - }); + }) + .UseDashboard(); }); } @@ -72,6 +75,14 @@ namespace LINGYUN.Abp.MessageService options.UseMySQL(); }); + Configure(options => + { + // 滑动过期30天 + options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); + // 绝对过期60天 + options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); + }); + Configure(options => { options.FileSets.AddEmbedded("LINGYUN.Abp.MessageService"); @@ -102,6 +113,10 @@ namespace LINGYUN.Abp.MessageService { options.Languages.Add(new LanguageInfo("en", "en", "English")); options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); + + options.Resources + .Get() + .AddVirtualJson("/LINGYUN/Abp/MessageService/Localization/HttpApiHost"); }); context.Services.AddAuthentication("Bearer") diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/en.json b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/en.json new file mode 100644 index 000000000..2716c4a9b --- /dev/null +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/en.json @@ -0,0 +1,7 @@ +{ + "culture": "en", + "texts": { + "NewTenantRegisteredNotificationTitle": "Tenants create notification", + "NewTenantRegisteredNotificationMessage": "New tenants to create success, the tenant name: {0}!" + } +} \ No newline at end of file diff --git a/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/zh-Hans.json b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/zh-Hans.json new file mode 100644 index 000000000..175a73b94 --- /dev/null +++ b/aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/zh-Hans.json @@ -0,0 +1,7 @@ +{ + "culture": "zh-Hans", + "texts": { + "NewTenantRegisteredNotificationTitle": "租户创建通知", + "NewTenantRegisteredNotificationMessage": "新租户创建成功,租户名称:{0}!" + } +} \ No newline at end of file diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantCreateEventHandler.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantCreateEventHandler.cs index 2eb2c586d..622776b8a 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantCreateEventHandler.cs +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantCreateEventHandler.cs @@ -1,7 +1,6 @@ using LINGYUN.Common.EventBus.Tenants; using Microsoft.EntityFrameworkCore; using System; -using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -45,7 +44,9 @@ namespace LINGYUN.Platform.EventBus.Handlers using (CurrentTenant.Change(eventData.Id, eventData.Name)) { var definitionPermissions = PermissionDefinitionManager.GetPermissions(); - var grantPermissions = definitionPermissions.Select(p => p.Name).ToArray(); + var grantPermissions = definitionPermissions + .Where(p => p.MultiTenancySide.HasFlag(MultiTenancySides.Tenant)) + .Select(p => p.Name).ToArray(); //var grantPermissions = new List(); //foreach (var permission in definitionPermissions) //{ diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantDeleteEventHandler.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantDeleteEventHandler.cs index d642b1eea..92f2b29cf 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantDeleteEventHandler.cs +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantDeleteEventHandler.cs @@ -1,19 +1,20 @@ -using LINGYUN.Common.EventBus.Tenants; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using System; using System.Text; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Entities.Events.Distributed; using Volo.Abp.Domain.Repositories; using Volo.Abp.EventBus.Distributed; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; using Volo.Abp.PermissionManagement; +using Volo.Abp.TenantManagement; using Volo.Abp.Uow; namespace LINGYUN.Platform.EventBus.Handlers { - public class TenantDeleteEventHandler : IDistributedEventHandler, ITransientDependency + public class TenantDeleteEventHandler : IDistributedEventHandler>, ITransientDependency { protected ICurrentTenant CurrentTenant { get; } protected IGuidGenerator GuidGenerator { get; } @@ -31,12 +32,13 @@ namespace LINGYUN.Platform.EventBus.Handlers PermissionGrantRepository = permissionGrantRepository; } - public async Task HandleEventAsync(DeleteEventData eventData) + public async Task HandleEventAsync(EntityDeletedEto eventData) { using var unitOfWork = UnitOfWorkManager.Begin(); // 订阅租户删除事件,删除管理员角色所有权限 // TODO: 租户貌似不存在了,删除应该会失败 - using (CurrentTenant.Change(eventData.Id)) + // 有缓存存在的话,可以获取到租户连接字符串 + using (CurrentTenant.Change(eventData.Entity.Id)) { // var grantPermissions = await PermissionGrantRepository.GetListAsync("R", "admin"); @@ -47,11 +49,11 @@ namespace LINGYUN.Platform.EventBus.Handlers var batchRmovePermissionSql = string.Empty; if (PermissionGrantRepository.GetDbContext().Database.IsMySql()) { - batchRmovePermissionSql = BuildMySqlBatchDeleteScript(permissionTableName, eventData.Id); + batchRmovePermissionSql = BuildMySqlBatchDeleteScript(permissionTableName, eventData.Entity.Id); } else { - batchRmovePermissionSql = BuildSqlServerBatchDeleteScript(permissionTableName, eventData.Id); + batchRmovePermissionSql = BuildSqlServerBatchDeleteScript(permissionTableName, eventData.Entity.Id); } await PermissionGrantRepository.GetDbContext().Database diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj index ac2db12c1..258bf3ddc 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj @@ -23,6 +23,7 @@ + diff --git a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs index ce7ce9139..2dc4d3ea9 100644 --- a/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs +++ b/aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs @@ -26,6 +26,7 @@ using Volo.Abp.AspNetCore.Authentication.JwtBearer; using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy; using Volo.Abp.Autofac; +using Volo.Abp.Caching; using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore.MySQL; using Volo.Abp.Identity; @@ -94,7 +95,8 @@ namespace LINGYUN.Platform .UseRabbitMQ(rabbitMQOptions => { configuration.GetSection("CAP:RabbitMQ").Bind(rabbitMQOptions); - }); + }) + .UseDashboard(); }); PreConfigure(builder => @@ -113,6 +115,14 @@ namespace LINGYUN.Platform options.UseMySQL(); }); + Configure(options => + { + // 滑动过期30天 + options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30); + // 绝对过期60天 + options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60); + }); + Configure(options => { options.FileSets.AddEmbedded("LINGYUN.Platform"); diff --git a/vueJs/src/utils/request.ts b/vueJs/src/utils/request.ts index 3e3a71927..c6b9e41a2 100644 --- a/vueJs/src/utils/request.ts +++ b/vueJs/src/utils/request.ts @@ -14,6 +14,10 @@ const service = axios.create({ // Request interceptors service.interceptors.request.use( (config) => { + const tenantId = getTenant() + if (tenantId) { + config.headers.__tenant = tenantId + } if (config.url === '/connect/token') { return config } @@ -21,10 +25,6 @@ service.interceptors.request.use( if (UserModule.token) { config.headers.Authorization = UserModule.token } - const tenantId = getTenant() - if (tenantId) { - config.headers.__tenant = tenantId - } // abp官方类库用的 zh-Hans 的简体中文包 这里直接粗暴一点 const language = getLanguage() if (language?.indexOf('zh') !== -1) {