Skip to content

Commit

Permalink
同步admin.core1.6.2版本支持多租户独立数据库
Browse files Browse the repository at this point in the history
  • Loading branch information
zhontai committed Jun 12, 2021
1 parent 6f1a416 commit ba4cb76
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 47 deletions.
7 changes: 4 additions & 3 deletions Admin.IdentityServer/Account/AdminProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public virtual async Task GetProfileDataAsync(ProfileDataRequestContext context)
new Claim(ClaimAttributes.UserNickName, user.NickName ?? ""),
new Claim(ClaimAttributes.TenantId, user.TenantId?.ToString() ?? "")
};
if (_appSettings.TenantDbType == TenantDbType.Share)
if (_appSettings.Tenant)
{
var tenantType = await _tenantRepository.Select.WhereDynamic(user.TenantId).ToOneAsync(a => a.TenantType);
claims.Add(new Claim(ClaimAttributes.TenantType, tenantType?.ToString() ?? ""));
var tenant = await _tenantRepository.Select.WhereDynamic(user.TenantId).ToOneAsync(a => new { a.TenantType, a.DataIsolationType });
claims.Add(new Claim(ClaimAttributes.TenantType, tenant.TenantType?.ToString() ?? ""));
claims.Add(new Claim(ClaimAttributes.DataIsolationType, tenant.DataIsolationType.ToString()));
}

context.IssuedClaims = claims;
Expand Down
9 changes: 7 additions & 2 deletions Admin.IdentityServer/Account/ClaimAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ public static class ClaimAttributes
/// <summary>
/// 租户Id
/// </summary>
public const string TenantId = "tenantid";
public const string TenantId = "ti";

/// <summary>
/// 租户类型
/// </summary>
public const string TenantType = "tenanttype";
public const string TenantType = "tt";

/// <summary>
/// 数据隔离
/// </summary>
public const string DataIsolationType = "dit";
}
}
51 changes: 33 additions & 18 deletions Admin.IdentityServer/Admin.IdentityServer.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions Admin.IdentityServer/Configs/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@

namespace Admin.IdentityServer.Configs
{
/// <summary>
/// 租户数据库类型
/// </summary>
public enum TenantDbType
{
/// <summary>
/// 无租户
/// </summary>
None,
/// <summary>
/// 共享数据库
/// </summary>
Share,
/// <summary>
/// 独立数据库
/// </summary>
Own
}

public class AppSettings
{
/// <summary>
Expand Down Expand Up @@ -52,7 +33,7 @@ public class AppSettings
/// <summary>
/// 租户类型
/// </summary>
public TenantDbType TenantDbType { get; set; } = TenantDbType.Share;
public bool Tenant { get; set; }

/// <summary>
/// 数据库
Expand Down
35 changes: 35 additions & 0 deletions Admin.IdentityServer/Domain/Admin/DataIsolationType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

using System.ComponentModel;

namespace Admin.IdentityServer.Domain.Admin
{
/// <summary>
/// 数据隔离类型
/// </summary>
public enum DataIsolationType
{
/// <summary>
/// 独立数据库
/// </summary>
[Description("独立数据库")]
OwnDb = 1,

/// <summary>
/// 独立数据表
/// </summary>
[Description("独立数据表")]
OwnDt = 2,

/// <summary>
/// 共享数据库,独立架构
/// </summary>
[Description("独立架构")]
Schema = 3,

/// <summary>
/// 共享数据库
/// </summary>
[Description("共享数据库")]
Share = 4
}
}
5 changes: 5 additions & 0 deletions Admin.IdentityServer/Domain/Admin/TenantEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public class TenantEntity : EntityBase
/// </summary>
public TenantType? TenantType { get; set; } = Admin.TenantType.Tenant;

/// <summary>
/// 数据隔离类型
/// </summary>
public DataIsolationType DataIsolationType { get; set; } = DataIsolationType.OwnDb;

/// <summary>
/// 数据库
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Admin.IdentityServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"swagger": false,
//健康检查
"health": false,
//租户数据库类型:None无租户, Share共享数据库, Own独立数据库
"tenantDbType": "Share",
//租户
"tenant": true,
"db": {
//监听Curd操作
"curd": false,
Expand Down
3 changes: 1 addition & 2 deletions Admin.IdentityServer/wwwroot/js/jquery.min.js

Large diffs are not rendered by default.

0 comments on commit ba4cb76

Please sign in to comment.