Browse Source

标准化通知数据消息;增加租户创建通知;修复租户创建后写入了属于主机权限的bug

pull/7/head
cKey 6 years ago
parent
commit
915560d36b
  1. 10
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.SignalR/LINGYUN/Abp/Notifications/SignalR/SignalRNotificationPublishProvider.cs
  2. 8
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN.Abp.Notifications.WeChat.WeApp.csproj
  3. 6
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppNotificationPublishProvider.cs
  4. 16
      aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN/Abp/Notifications/WeChat/WeApp/WeChatWeAppSendNotificationData.cs
  5. 2
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionContext.cs
  6. 4
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDefinitionManager.cs
  7. 2
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDispatcher.cs
  8. 2
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs
  9. 7
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSubscriptionManager.cs
  10. 81
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/DefaultNotificationDispatcher.cs
  11. 5
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/Internal/NotificationSubscriptionManager.cs
  12. 78
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs
  13. 17
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinition.cs
  14. 6
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionContext.cs
  15. 12
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs
  16. 11
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationInfo.cs
  17. 14
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationName.cs
  18. 15
      aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationNameNormalizer.cs
  19. 2
      aspnet-core/modules/common/LINGYUN.Common.EventBus/LINGYUN/Common/EventBus/Tenants/CreateEventData.cs
  20. 9
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/MultiTenancy/TenantNotificationNames.cs
  21. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/UserNotificationNames.cs
  22. 12
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/EventBus/Local/UserCreateSendWelcomeEventHandler.cs
  23. 1
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/en.json
  24. 1
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Localization/Resources/zh-Hans.json
  25. 8
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/AbpMessageServiceNotificationDefinitionProvider.cs
  26. 59
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs
  27. 3
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/UserNotification.cs
  28. 2
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs
  29. 3
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/Subscribe.cs
  30. 3
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/UserSubscribe.cs
  31. 13
      aspnet-core/modules/message/LINGYUN.Abp.MessageService.EntityFrameworkCore/LINGYUN/Abp/MessageService/Subscriptions/EfCoreUserSubscribeRepository.cs
  32. 6
      aspnet-core/modules/tenants/LINGYUN.Abp.TenantManagement.Application/LINGYUN/Abp/TenantManagement/TenantAppService.cs
  33. 12
      aspnet-core/services/account/AuthServer.Host/AuthIdentityServerModule.cs
  34. 1
      aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj
  35. 66
      aspnet-core/services/account/AuthServer.Host/EventBus/Handlers/TenantCreateEventHandler.cs
  36. 1
      aspnet-core/services/cleanup-logs.bat
  37. 4
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/Controllers/NotificationController.cs
  38. 75
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/EventBus/Distributed/TenantCreateEventHandler.cs
  39. 12
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj
  40. 17
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/AbpMessageServiceHttpApiHostModule.cs
  41. 7
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/en.json
  42. 7
      aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN/Abp/MessageService/Localization/HttpApiHost/zh-Hans.json
  43. 5
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantCreateEventHandler.cs
  44. 16
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/EventBus/Handlers/TenantDeleteEventHandler.cs
  45. 1
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj
  46. 12
      aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/PlatformHttpApiHostModule.cs
  47. 8
      vueJs/src/utils/request.ts

10
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<SignalRNotificationPublishProvider> 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<SignalRNotificationPublishProvider>.Instance;
}
public override async Task PublishAsync(NotificationInfo notification, IEnumerable<UserIdentifier> 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);

8
aspnet-core/modules/common/LINGYUN.Abp.Notifications.WeChat/LINGYUN.Abp.Notifications.WeChat.WeApp.csproj

@ -3,6 +3,14 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace />
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.9.0</Version>
<Description>通知接口的微信小程序发布者实现</Description>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>D:\LocalNuget</OutputPath>
</PropertyGroup>
<ItemGroup>

6
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;

16
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<string, WeChatNotificationData>();
}
/// <summary>
/// 写入标准数据
/// </summary>
/// <param name="writeData"></param>
/// <returns></returns>
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)
{

2
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);
}

4
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<NotificationDefinition> GetAll();
NotificationDefinition GetOrNull(string name);
NotificationDefinition GetOrNull(string category);
}
}

2
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationDispatcher.cs

@ -24,7 +24,7 @@ namespace LINGYUN.Abp.Notifications
/// <param name="tenantId">租户</param>
/// <param name="notificationSeverity">级别</param>
/// <returns></returns>
Task DispatchAsync(string notificationName, NotificationData data, Guid? tenantId = null,
Task DispatchAsync(NotificationName notificationName, NotificationData data, Guid? tenantId = null,
NotificationSeverity notificationSeverity = NotificationSeverity.Info);
}
}

2
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationStore.cs

@ -16,6 +16,8 @@ namespace LINGYUN.Abp.Notifications
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync(Guid? tenantId, Guid userId);
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync(Guid? tenantId, string userName);
Task<bool> IsSubscribedAsync(Guid? tenantId, Guid userId, string notificationName);
Task InsertNotificationAsync(NotificationInfo notification);

7
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/INotificationSubscriptionManager.cs

@ -55,5 +55,12 @@ namespace LINGYUN.Abp.Notifications
/// <param name="userId">用户标识</param>
/// <returns></returns>
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync(Guid? tenantId, Guid userId);
/// <summary>
/// 获取用户订阅列表
/// </summary>
/// <param name="tenantId">租户</param>
/// <param name="userName">用户名</param>
/// <returns></returns>
Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync(Guid? tenantId, string userName);
}
}

81
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
{
/// <summary>
/// Implements <see cref="INotificationDispatcher"/>.
/// </summary>
internal class DefaultNotificationDispatcher : INotificationDispatcher
{
/// <summary>
/// Reference to <see cref="ILogger<DefaultNotificationDispatcher>"/>.
/// </summary>
public ILogger<DefaultNotificationDispatcher> Logger { get; set; }
/// <summary>
/// Reference to <see cref="IBackgroundJobManager"/>.
/// </summary>
private readonly IBackgroundJobManager _backgroundJobManager;
/// <summary>
/// Reference to <see cref="INotificationStore"/>.
/// </summary>
private readonly INotificationStore _notificationStore;
/// <summary>
/// Reference to <see cref="INotificationDefinitionManager"/>.
/// </summary>
private readonly INotificationDefinitionManager _notificationDefinitionManager;
/// <summary>
/// Reference to <see cref="INotificationPublishProviderManager"/>.
/// </summary>
private readonly INotificationPublishProviderManager _notificationPublishProviderManager;
/// <summary>
/// Initializes a new instance of the <see cref="DefaultNotificationDispatcher"/> class.
/// </summary>
public DefaultNotificationDispatcher(
IBackgroundJobManager backgroundJobManager,
@ -32,23 +51,30 @@ namespace LINGYUN.Abp.Notifications.Internal
Logger = NullLogger<DefaultNotificationDispatcher>.Instance;
}
public virtual async Task DispatchAsync(string notificationName, NotificationData data, Guid? tenantId = null,
/// <summary>
/// 发送通知
/// </summary>
/// <param name="notificationName">通知名称</param>
/// <param name="data">通知数据</param>
/// <param name="tenantId">租户</param>
/// <param name="notificationSeverity">级别</param>
/// <returns></returns>
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);
}
/// <summary>
/// 发送通知
/// </summary>
/// <param name="notification">通知信息</param>
/// <returns></returns>
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);
}
/// <summary>
/// 指定提供者发布通知
/// </summary>
/// <param name="providers">提供者列表</param>
/// <param name="notificationInfo">通知信息</param>
/// <returns></returns>
protected async Task PublishFromProvidersAsync(IEnumerable<INotificationPublishProvider> providers,
NotificationInfo notificationInfo)
{
@ -116,7 +156,13 @@ namespace LINGYUN.Abp.Notifications.Internal
// await PublishAsync(provider, notificationInfo, subscriptionUserIdentifiers);
//});
}
/// <summary>
/// 发布通知
/// </summary>
/// <param name="provider">通知发布者</param>
/// <param name="notificationInfo">通知信息</param>
/// <param name="subscriptionUserIdentifiers">订阅用户列表</param>
/// <returns></returns>
protected async Task PublishAsync(INotificationPublishProvider provider, NotificationInfo notificationInfo,
IEnumerable<UserIdentifier> 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");

5
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<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync(Guid? tenantId, string userName)
{
return await _store.GetUserSubscriptionsAsync(tenantId, userName);
}
public virtual async Task<bool> IsSubscribedAsync(Guid? tenantId, Guid userId, string notificationName)
{
return await _store.IsSubscribedAsync(tenantId, userId, notificationName);

78
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationData.cs

@ -45,5 +45,83 @@ namespace LINGYUN.Abp.Notifications
{
_properties = new Dictionary<string, object>();
}
/// <summary>
/// 写入标准数据
/// </summary>
/// <param name="title">标题</param>
/// <param name="message">内容</param>
/// <param name="createTime">创建时间</param>
/// <param name="formUser">来源用户</param>
/// <returns></returns>
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;
}
/// <summary>
/// 写入标准数据
/// </summary>
/// <param name="prefix">数据前缀</param>
/// <param name="key">标识</param>
/// <param name="value">数据内容</param>
/// <returns></returns>
public NotificationData WriteStandardData(string prefix, string key, object value)
{
TrySetData(string.Concat(prefix, key), value);
return this;
}
/// <summary>
/// 转换为标准数据
/// </summary>
/// <param name="sourceData">原始数据</param>
/// <returns></returns>
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;
}
/// <summary>
/// 转换为标准数据
/// </summary>
/// <param name="prefix">数据前缀</param>
/// <param name="sourceData">原始数据</param>
/// <returns></returns>
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;
}
}
}
}

17
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
{
/// <summary>
/// 通知名称
/// 通知类目
/// </summary>
[NotNull]
public string Name { get; set; }
public string CateGory { get; set; }
/// <summary>
/// 通知显示名称
/// </summary>
@ -42,14 +49,14 @@ namespace LINGYUN.Abp.Notifications
public List<string> 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;

6
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);
}
}
}

12
aspnet-core/modules/common/LINGYUN.Abp.Notifications/LINGYUN/Abp/Notifications/NotificationDefinitionManager.cs

@ -28,15 +28,15 @@ namespace LINGYUN.Abp.Notifications
NotificationDefinitions = new Lazy<IDictionary<string, NotificationDefinition>>(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<string, NotificationDefinition> CreateNotificationDefinitions()

11
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);

14
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;
}
}
}

15
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);
}
}
}

2
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; }

9
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";
}
}

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain.Shared/Volo/Abp/Users/Notifications/UserNotificationNames.cs → 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
{

12
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);
}
}

1
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!"
}
}

1
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} 欢迎您的加入!"
}
}

8
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)

59
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Notifications/NotificationStore.cs

@ -43,7 +43,6 @@ 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))
{
await UserNotificationRepository.ChangeUserNotificationReadStateAsync(userId, notificationId, readState);
@ -51,13 +50,11 @@ namespace LINGYUN.Abp.MessageService.Notifications
await unitOfWork.SaveChangesAsync();
}
}
}
[UnitOfWork]
public async Task DeleteNotificationAsync(NotificationInfo notification)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
using (CurrentTenant.Change(notification.TenantId))
{
var notify = await NotificationRepository.GetByIdAsync(notification.GetId());
@ -66,13 +63,11 @@ namespace LINGYUN.Abp.MessageService.Notifications
await unitOfWork.SaveChangesAsync();
}
}
}
[UnitOfWork]
public async Task DeleteUserNotificationAsync(Guid? tenantId, Guid userId, long notificationId)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
using (CurrentTenant.Change(tenantId))
{
var notify = await UserNotificationRepository.GetByIdAsync(userId, notificationId);
@ -81,13 +76,11 @@ namespace LINGYUN.Abp.MessageService.Notifications
await unitOfWork.SaveChangesAsync();
}
}
}
[UnitOfWork]
public async Task DeleteUserSubscriptionAsync(Guid? tenantId, Guid userId, string notificationName)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
using (CurrentTenant.Change(tenantId))
{
var userSubscribe = await UserSubscribeRepository.GetUserSubscribeAsync(notificationName, userId);
@ -96,7 +89,6 @@ namespace LINGYUN.Abp.MessageService.Notifications
await unitOfWork.SaveChangesAsync();
}
}
}
public async Task<NotificationInfo> GetNotificationOrNullAsync(Guid? tenantId, long notificationId)
{
@ -148,16 +140,36 @@ namespace LINGYUN.Abp.MessageService.Notifications
}
}
public virtual async Task<List<NotificationSubscriptionInfo>> GetUserSubscriptionsAsync(Guid? tenantId, string userName)
{
using (CurrentTenant.Change(tenantId))
{
var userSubscriptions = await UserSubscribeRepository.GetUserSubscribesByNameAsync(userName);
var userSubscriptionInfos = new List<NotificationSubscriptionInfo>();
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))
{
// var notifyId = notification.GetId();
var notifyId = SnowflakeIdGenerator.Create();
// 保存主键,防止前端js long类型溢出
notification.Data["id"] = notifyId.ToString();
// notification.Data["id"] = notifyId.ToString();
var notify = new Notification(notifyId, notification.Name,
notification.Data.GetType().AssemblyQualifiedName,
@ -176,32 +188,28 @@ namespace LINGYUN.Abp.MessageService.Notifications
await unitOfWork.SaveChangesAsync();
}
}
}
[UnitOfWork]
public async Task InsertUserNotificationAsync(NotificationInfo notification, Guid userId)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
using (CurrentTenant.Change(notification.TenantId))
{
var userNotification = new UserNotification(notification.GetId(), userId);
var userNotification = new UserNotification(notification.GetId(), userId, notification.TenantId);
await UserNotificationRepository.InsertAsync(userNotification);
await unitOfWork.SaveChangesAsync();
}
}
}
[UnitOfWork]
public async Task InsertUserSubscriptionAsync(Guid? tenantId, UserIdentifier identifier, string notificationName)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
using (CurrentTenant.Change(tenantId))
{
var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName)
var userSubscription = new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId)
{
CreationTime = Clock.Now
};
@ -211,20 +219,18 @@ namespace LINGYUN.Abp.MessageService.Notifications
await unitOfWork.SaveChangesAsync();
}
}
}
[UnitOfWork]
public async Task InsertUserSubscriptionAsync(Guid? tenantId, IEnumerable<UserIdentifier> identifiers, string notificationName)
{
using (var unitOfWork = _unitOfWorkManager.Begin())
{
using (CurrentTenant.Change(tenantId))
{
var userSubscribes = new List<UserSubscribe>();
foreach(var identifier in identifiers)
foreach (var identifier in identifiers)
{
userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName));
userSubscribes.Add(new UserSubscribe(notificationName, identifier.UserId, identifier.UserName, tenantId));
}
await UserSubscribeRepository.InsertUserSubscriptionAsync(userSubscribes);
@ -232,7 +238,6 @@ namespace LINGYUN.Abp.MessageService.Notifications
await unitOfWork.SaveChangesAsync();
}
}
}
public async Task<bool> IsSubscribedAsync(Guid? tenantId, Guid userId, string notificationName)
{
@ -240,15 +245,23 @@ namespace LINGYUN.Abp.MessageService.Notifications
return await UserSubscribeRepository.UserSubscribeExistsAysnc(notificationName, userId);
}
[UnitOfWork]
public async Task InsertUserNotificationsAsync(NotificationInfo notification, IEnumerable<Guid> userIds)
{
// 添加工作单元
using (var unitOfWork = _unitOfWorkManager.Begin())
using (CurrentTenant.Change(notification.TenantId))
{
var userNofitications = new List<UserNotification>();
foreach(var userId in userIds)
foreach (var userId in userIds)
{
var userNofitication = new UserNotification(notification.GetId(), userId);
var userNofitication = new UserNotification(notification.GetId(), userId, notification.TenantId);
userNofitications.Add(userNofitication);
}
await UserNotificationRepository.InsertUserNotificationsAsync(userNofitications);
await unitOfWork.SaveChangesAsync();
}
}
}
}

3
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)

2
aspnet-core/modules/message/LINGYUN.Abp.MessageService.Domain/LINGYUN/Abp/MessageService/Subscriptions/IUserSubscribeRepository.cs

@ -15,6 +15,8 @@ namespace LINGYUN.Abp.MessageService.Subscriptions
Task<List<string>> GetUserSubscribesAsync(Guid userId);
Task<List<UserSubscribe>> GetUserSubscribesByNameAsync(string userName);
Task<List<Guid>> GetUserSubscribesAsync(string notificationName);
Task InsertUserSubscriptionAsync(IEnumerable<UserSubscribe> userSubscribes);

3
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;
}
}
}

3
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;

13
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<List<UserSubscribe>> GetUserSubscribesByNameAsync(string userName)
{
var userSubscribeNames = await DbSet
.Distinct()
.Where(x => x.UserName.Equals(userName))
.AsNoTracking()
.ToListAsync();
return userSubscribeNames;
}
public async Task<List<Guid>> GetUserSubscribesAsync(string notificationName)
{
var subscribeUsers = await DbSet

6
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)]

12
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<AbpDistributedCacheOptions>(options =>
{
// 滑动过期30天
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
// 绝对过期60天
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
});
Configure<AbpLocalizationOptions>(options =>
{
options.Languages.Add(new LanguageInfo("en", "en", "English"));

1
aspnet-core/services/account/AuthServer.Host/AuthServer.Host.csproj

@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />

66
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<TenantCreateEventHandler> 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<TenantCreateEventHandler> 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))
{
tenantAdminRoleId = GuidGenerator.Create();
var tenantAdminRole = new IdentityRole(tenantAdminRoleId, tenantAdminRoleName, eventData.Id)
{
Logger.LogWarning("Tenant {0} admin user {1} not created!", eventData.Name, eventData.AdminEmailAddress);
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);
//}
}
}
}

1
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

4
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);

75
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<CreateEventData>, ITransientDependency
{
protected ILogger<TenantCreateEventHandler> 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<MessageServiceResource> stringLocalizer,
ILogger<TenantCreateEventHandler> 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;
}
}
}

12
aspnet-core/services/messages/LINGYUN.Abp.MessageService.HttpApi.Host/LINGYUN.Abp.MessageService.HttpApi.Host.csproj

@ -6,6 +6,17 @@
</PropertyGroup>
<ItemGroup>
<Content Remove="LINGYUN\Abp\MessageService\Localization\HttpApiHost\en.json" />
<Content Remove="LINGYUN\Abp\MessageService\Localization\HttpApiHost\zh-Hans.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="LINGYUN\Abp\MessageService\Localization\HttpApiHost\en.json" />
<EmbeddedResource Include="LINGYUN\Abp\MessageService\Localization\HttpApiHost\zh-Hans.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4">
@ -36,6 +47,7 @@
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.IM.SignalR\LINGYUN.Abp.IM.SignalR.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Notifications.SignalR\LINGYUN.Abp.Notifications.SignalR.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Abp.Notifications.WeChat\LINGYUN.Abp.Notifications.WeChat.WeApp.csproj" />
<ProjectReference Include="..\..\..\modules\common\LINGYUN.Common.EventBus\LINGYUN.Common.EventBus.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.EntityFrameworkCore\LINGYUN.Abp.MessageService.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\modules\message\LINGYUN.Abp.MessageService.HttpApi\LINGYUN.Abp.MessageService.HttpApi.csproj" />
</ItemGroup>

17
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<AbpDistributedCacheOptions>(options =>
{
// 滑动过期30天
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
// 绝对过期60天
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
});
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpMessageServiceHttpApiHostModule>("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<MessageServiceResource>()
.AddVirtualJson("/LINGYUN/Abp/MessageService/Localization/HttpApiHost");
});
context.Services.AddAuthentication("Bearer")

7
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}!"
}
}

7
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}!"
}
}

5
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<PermissionGrant>();
//foreach (var permission in definitionPermissions)
//{

16
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<DeleteEventData>, ITransientDependency
public class TenantDeleteEventHandler : IDistributedEventHandler<EntityDeletedEto<TenantEto>>, 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<TenantEto> 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

1
aspnet-core/services/platform/LINGYUN.Platform.HttpApi.Host/LINGYUN.Platform.HttpApi.Host.csproj

@ -23,6 +23,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="DotNetCore.CAP.Dashboard" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.MySql" Version="3.0.4" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4">

12
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<IdentityBuilder>(builder =>
@ -113,6 +115,14 @@ namespace LINGYUN.Platform
options.UseMySQL();
});
Configure<AbpDistributedCacheOptions>(options =>
{
// 滑动过期30天
options.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromDays(30);
// 绝对过期60天
options.GlobalCacheEntryOptions.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(60);
});
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<PlatformHttpApiHostModule>("LINGYUN.Platform");

8
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) {

Loading…
Cancel
Save