chore 优化代码
This commit is contained in:
@ -5,4 +5,4 @@ namespace KonSoft.TenantManagement.Data;
|
||||
public interface ITenantManagementDbSchemaMigrator
|
||||
{
|
||||
Task MigrateAsync();
|
||||
}
|
||||
}
|
||||
@ -12,4 +12,4 @@ public class NullTenantManagementDbSchemaMigrator : ITenantManagementDbSchemaMig
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -17,12 +17,11 @@ namespace KonSoft.TenantManagement.Data;
|
||||
|
||||
public class TenantManagementDbMigrationService : ITransientDependency
|
||||
{
|
||||
public ILogger<TenantManagementDbMigrationService> Logger { get; set; }
|
||||
private readonly ICurrentTenant _currentTenant;
|
||||
|
||||
private readonly IDataSeeder _dataSeeder;
|
||||
private readonly IEnumerable<ITenantManagementDbSchemaMigrator> _dbSchemaMigrators;
|
||||
private readonly ITenantRepository _tenantRepository;
|
||||
private readonly ICurrentTenant _currentTenant;
|
||||
|
||||
public TenantManagementDbMigrationService(
|
||||
IDataSeeder dataSeeder,
|
||||
@ -38,6 +37,8 @@ public class TenantManagementDbMigrationService : ITransientDependency
|
||||
Logger = NullLogger<TenantManagementDbMigrationService>.Instance;
|
||||
}
|
||||
|
||||
public ILogger<TenantManagementDbMigrationService> Logger { get; set; }
|
||||
|
||||
public async Task MigrateAsync()
|
||||
{
|
||||
var initialMigrationAdded = AddInitialMigrationIfNotExist();
|
||||
@ -52,7 +53,7 @@ public class TenantManagementDbMigrationService : ITransientDependency
|
||||
await MigrateDatabaseSchemaAsync();
|
||||
await SeedDataAsync();
|
||||
|
||||
Logger.LogInformation($"Successfully completed host database migrations.");
|
||||
Logger.LogInformation("Successfully completed host database migrations.");
|
||||
|
||||
var tenants = await _tenantRepository.GetListAsync(includeDetails: true);
|
||||
|
||||
@ -101,8 +102,10 @@ public class TenantManagementDbMigrationService : ITransientDependency
|
||||
Logger.LogInformation($"Executing {(tenant == null ? "host" : tenant.Name + " tenant")} database seed...");
|
||||
|
||||
await _dataSeeder.SeedAsync(new DataSeedContext(tenant?.Id)
|
||||
.WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName, IdentityDataSeedContributor.AdminEmailDefaultValue)
|
||||
.WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName, IdentityDataSeedContributor.AdminPasswordDefaultValue)
|
||||
.WithProperty(IdentityDataSeedContributor.AdminEmailPropertyName,
|
||||
IdentityDataSeedContributor.AdminEmailDefaultValue)
|
||||
.WithProperty(IdentityDataSeedContributor.AdminPasswordPropertyName,
|
||||
IdentityDataSeedContributor.AdminPasswordDefaultValue)
|
||||
);
|
||||
}
|
||||
|
||||
@ -127,10 +130,8 @@ public class TenantManagementDbMigrationService : ITransientDependency
|
||||
AddInitialMigration();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -149,7 +150,8 @@ public class TenantManagementDbMigrationService : ITransientDependency
|
||||
private bool MigrationsFolderExists()
|
||||
{
|
||||
var dbMigrationsProjectFolder = GetEntityFrameworkCoreProjectFolderPath();
|
||||
return dbMigrationsProjectFolder != null && Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations"));
|
||||
return dbMigrationsProjectFolder != null &&
|
||||
Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations"));
|
||||
}
|
||||
|
||||
private void AddInitialMigration()
|
||||
@ -207,7 +209,8 @@ public class TenantManagementDbMigrationService : ITransientDependency
|
||||
{
|
||||
currentDirectory = Directory.GetParent(currentDirectory.FullName);
|
||||
|
||||
if (currentDirectory != null && Directory.GetFiles(currentDirectory.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null)
|
||||
if (currentDirectory != null &&
|
||||
Directory.GetFiles(currentDirectory.FullName).FirstOrDefault(f => f.EndsWith(".sln")) != null)
|
||||
{
|
||||
return currentDirectory.FullName;
|
||||
}
|
||||
@ -215,4 +218,4 @@ public class TenantManagementDbMigrationService : ITransientDependency
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Identity;
|
||||
|
||||
namespace KonSoft.TenantManagement.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// 家政服务工人实体
|
||||
/// </summary>
|
||||
public class HouseholdWorker:IdentityUser
|
||||
{
|
||||
/// <summary>
|
||||
/// 接单数
|
||||
/// </summary>
|
||||
public int OrderCount { get; set; }
|
||||
/// <summary>
|
||||
/// 职业
|
||||
/// </summary>
|
||||
public required string Profession { get; set; }
|
||||
/// <summary>
|
||||
/// 能力范围
|
||||
/// </summary>
|
||||
public required string ScopeOfCompetence { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using KonSoft.TenantManagement.Entities;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
|
||||
namespace KonSoft.TenantManagement.IRepositories
|
||||
{
|
||||
public interface IHouseholdWorkerRepository: EfCoreRepository<AdminDbContext, Order>, IRepository<HouseholdWorker>
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
|
||||
@ -23,12 +23,12 @@ namespace KonSoft.TenantManagement.OpenIddict;
|
||||
*/
|
||||
public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDependency
|
||||
{
|
||||
private readonly IAbpApplicationManager _applicationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IOpenIddictApplicationRepository _openIddictApplicationRepository;
|
||||
private readonly IAbpApplicationManager _applicationManager;
|
||||
private readonly IOpenIddictScopeRepository _openIddictScopeRepository;
|
||||
private readonly IOpenIddictScopeManager _scopeManager;
|
||||
private readonly IPermissionDataSeeder _permissionDataSeeder;
|
||||
private readonly IOpenIddictScopeManager _scopeManager;
|
||||
private readonly IStringLocalizer<OpenIddictResponse> L;
|
||||
|
||||
public OpenIddictDataSeedContributor(
|
||||
@ -38,7 +38,7 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
IOpenIddictScopeRepository openIddictScopeRepository,
|
||||
IOpenIddictScopeManager scopeManager,
|
||||
IPermissionDataSeeder permissionDataSeeder,
|
||||
IStringLocalizer<OpenIddictResponse> l )
|
||||
IStringLocalizer<OpenIddictResponse> l)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_openIddictApplicationRepository = openIddictApplicationRepository;
|
||||
@ -60,7 +60,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
{
|
||||
if (await _openIddictScopeRepository.FindByNameAsync("TenantManagement") == null)
|
||||
{
|
||||
await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor {
|
||||
await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor
|
||||
{
|
||||
Name = "TenantManagement", DisplayName = "TenantManagement API", Resources = { "TenantManagement" }
|
||||
});
|
||||
}
|
||||
@ -68,7 +69,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
|
||||
private async Task CreateApplicationsAsync()
|
||||
{
|
||||
var commonScopes = new List<string> {
|
||||
var commonScopes = new List<string>
|
||||
{
|
||||
OpenIddictConstants.Permissions.Scopes.Address,
|
||||
OpenIddictConstants.Permissions.Scopes.Email,
|
||||
OpenIddictConstants.Permissions.Scopes.Phone,
|
||||
@ -80,10 +82,6 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
var configurationSection = _configuration.GetSection("OpenIddict:Applications");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Swagger Client
|
||||
var swaggerClientId = configurationSection["TenantManagement_Swagger:ClientId"];
|
||||
if (!swaggerClientId.IsNullOrWhiteSpace())
|
||||
@ -91,13 +89,13 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
var swaggerRootUrl = configurationSection["TenantManagement_Swagger:RootUrl"]?.TrimEnd('/');
|
||||
|
||||
await CreateApplicationAsync(
|
||||
name: swaggerClientId!,
|
||||
type: OpenIddictConstants.ClientTypes.Public,
|
||||
consentType: OpenIddictConstants.ConsentTypes.Implicit,
|
||||
displayName: "Swagger Application",
|
||||
secret: null,
|
||||
grantTypes: [OpenIddictConstants.GrantTypes.AuthorizationCode],
|
||||
scopes: commonScopes,
|
||||
swaggerClientId!,
|
||||
OpenIddictConstants.ClientTypes.Public,
|
||||
OpenIddictConstants.ConsentTypes.Implicit,
|
||||
"Swagger Application",
|
||||
null,
|
||||
[OpenIddictConstants.GrantTypes.AuthorizationCode],
|
||||
commonScopes,
|
||||
redirectUri: $"{swaggerRootUrl}/swagger/oauth2-redirect.html",
|
||||
clientUri: swaggerRootUrl
|
||||
);
|
||||
@ -131,13 +129,14 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
|
||||
var client = await _openIddictApplicationRepository.FindByClientIdAsync(name);
|
||||
|
||||
var application = new AbpApplicationDescriptor {
|
||||
var application = new AbpApplicationDescriptor
|
||||
{
|
||||
ClientId = name,
|
||||
ClientType = type,
|
||||
ClientSecret = secret,
|
||||
ConsentType = consentType,
|
||||
DisplayName = displayName,
|
||||
ClientUri = clientUri,
|
||||
ClientUri = clientUri
|
||||
};
|
||||
|
||||
Check.NotNullOrEmpty(grantTypes, nameof(grantTypes));
|
||||
@ -160,7 +159,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
application.Permissions.Add(OpenIddictConstants.Permissions.Endpoints.Logout);
|
||||
}
|
||||
|
||||
var buildInGrantTypes = new[] {
|
||||
var buildInGrantTypes = new[]
|
||||
{
|
||||
OpenIddictConstants.GrantTypes.Implicit, OpenIddictConstants.GrantTypes.Password,
|
||||
OpenIddictConstants.GrantTypes.AuthorizationCode, OpenIddictConstants.GrantTypes.ClientCredentials,
|
||||
OpenIddictConstants.GrantTypes.DeviceCode, OpenIddictConstants.GrantTypes.RefreshToken
|
||||
@ -233,7 +233,8 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
}
|
||||
}
|
||||
|
||||
var buildInScopes = new[] {
|
||||
var buildInScopes = new[]
|
||||
{
|
||||
OpenIddictConstants.Permissions.Scopes.Address, OpenIddictConstants.Permissions.Scopes.Email,
|
||||
OpenIddictConstants.Permissions.Scopes.Phone, OpenIddictConstants.Permissions.Scopes.Profile,
|
||||
OpenIddictConstants.Permissions.Scopes.Roles
|
||||
@ -289,8 +290,7 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
await _permissionDataSeeder.SeedAsync(
|
||||
ClientPermissionValueProvider.ProviderName,
|
||||
name,
|
||||
permissions,
|
||||
null
|
||||
permissions
|
||||
);
|
||||
}
|
||||
|
||||
@ -302,8 +302,10 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
|
||||
if (!HasSameRedirectUris(client, application))
|
||||
{
|
||||
client.RedirectUris = JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
client.PostLogoutRedirectUris = JsonSerializer.Serialize(application.PostLogoutRedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
client.RedirectUris =
|
||||
JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
client.PostLogoutRedirectUris =
|
||||
JsonSerializer.Serialize(application.PostLogoutRedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
|
||||
await _applicationManager.UpdateAsync(client.ToModel());
|
||||
}
|
||||
@ -317,11 +319,13 @@ public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDep
|
||||
|
||||
private bool HasSameRedirectUris(OpenIddictApplication existingClient, AbpApplicationDescriptor application)
|
||||
{
|
||||
return existingClient.RedirectUris == JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
return existingClient.RedirectUris ==
|
||||
JsonSerializer.Serialize(application.RedirectUris.Select(q => q.ToString().TrimEnd('/')));
|
||||
}
|
||||
|
||||
private bool HasSameScopes(OpenIddictApplication existingClient, AbpApplicationDescriptor application)
|
||||
{
|
||||
return existingClient.Permissions == JsonSerializer.Serialize(application.Permissions.Select(q => q.ToString().TrimEnd('/')));
|
||||
return existingClient.Permissions ==
|
||||
JsonSerializer.Serialize(application.Permissions.Select(q => q.ToString().TrimEnd('/')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.Domain.Tests")]
|
||||
[assembly:InternalsVisibleToAttribute("KonSoft.TenantManagement.TestBase")]
|
||||
|
||||
[assembly: InternalsVisibleToAttribute("KonSoft.TenantManagement.Domain.Tests")]
|
||||
[assembly: InternalsVisibleToAttribute("KonSoft.TenantManagement.TestBase")]
|
||||
@ -9,4 +9,4 @@ public class TenantManagementSettingDefinitionProvider : SettingDefinitionProvid
|
||||
//Define your own settings here. Example:
|
||||
//context.Add(new SettingDefinition(TenantManagementSettings.MySetting1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,4 +6,4 @@ public static class TenantManagementSettings
|
||||
|
||||
//Add your own setting names here. Example:
|
||||
//public const string MySetting1 = Prefix + ".MySetting1";
|
||||
}
|
||||
}
|
||||
@ -5,4 +5,4 @@ public static class TenantManagementConsts
|
||||
public const string DbTablePrefix = "App";
|
||||
|
||||
public const string DbSchema = null;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using KonSoft.TenantManagement.MultiTenancy;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using KonSoft.TenantManagement.MultiTenancy;
|
||||
using Volo.Abp.AuditLogging;
|
||||
using Volo.Abp.BackgroundJobs;
|
||||
using Volo.Abp.Emailing;
|
||||
@ -56,13 +56,10 @@ public class TenantManagementDomainModule : AbpModule
|
||||
options.Languages.Add(new LanguageInfo("es", "es", "Español"));
|
||||
});
|
||||
|
||||
Configure<AbpMultiTenancyOptions>(options =>
|
||||
{
|
||||
options.IsEnabled = MultiTenancyConsts.IsEnabled;
|
||||
});
|
||||
Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = MultiTenancyConsts.IsEnabled; });
|
||||
|
||||
#if DEBUG
|
||||
context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user