Browse Source

[fix]全部接口支持按地点保存到不同数据库

master
贾荣国Home 3 years ago
parent
commit
50051deb12
  1. 11
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/RouteConsts.cs
  2. 10
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs
  3. 9
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs
  4. 13
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs
  5. 10
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs
  6. 26
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs
  7. 183
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/MultiTenantConnectionStringResolver.cs
  8. 32
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/WebApiHttpApiHostModule.cs
  9. 17
      WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json
  10. 2
      WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Parts/TA_PART.cs

11
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/RouteConsts.cs

@ -11,15 +11,4 @@ namespace Win_in.Sfs.Scp.WebApi
public const string Supplier = "api/scp/supplier"; public const string Supplier = "api/scp/supplier";
public const string UnplannedReceipt = "api/scp/unplanned-receipt"; public const string UnplannedReceipt = "api/scp/unplanned-receipt";
} }
public class SiteConsts
{
public static readonly Dictionary<string, Guid> SiteDict = new Dictionary<string, Guid>
{
{"T8",Guid.Parse("446a5211-3d72-4339-9adc-845151f8ada0")},
{"T9",Guid.Parse("25388015-ef1c-4355-9c18-f6b6ddbaf89d")}
};
}
} }

10
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs

@ -16,8 +16,10 @@ using Volo.Abp.Uow;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Clients; using Volo.Abp.Clients;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration; using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
using Volo.Abp.TenantManagement;
namespace Win_in.Sfs.Scp.WebApi namespace Win_in.Sfs.Scp.WebApi
{ {
@ -32,16 +34,19 @@ namespace Win_in.Sfs.Scp.WebApi
{ {
private readonly IPartRepository _partRepository; private readonly IPartRepository _partRepository;
private readonly ITaPartRepository _taPartRepository; private readonly ITaPartRepository _taPartRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES; private readonly string _validSites = Validator.VALID_SITES;
public PartAppService( public PartAppService(
IPartRepository repository IPartRepository repository
, ITaPartRepository taPartRepository , ITaPartRepository taPartRepository
, ITenantStore tenantStore
, IConfiguration configuration , IConfiguration configuration
) : base(repository) ) : base(repository)
{ {
_partRepository = repository; _partRepository = repository;
_taPartRepository = taPartRepository; _taPartRepository = taPartRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"]; _validSites = configuration["ValidSites"];
} }
@ -118,10 +123,9 @@ namespace Win_in.Sfs.Scp.WebApi
//使用AutoMapper执行类型转换 //使用AutoMapper执行类型转换
var taPart = ObjectMapper.Map<Part, TA_PART>(entity); var taPart = ObjectMapper.Map<Part, TA_PART>(entity);
var tenantId = SiteConsts.SiteDict.GetValueOrDefault(taPart.Site); var tenant =await _tenantStore.FindAsync(taPart.Site);
using (CurrentTenant.Change(tenantId,taPart.Site)) using (CurrentTenant.Change(tenant.Id,tenant.Name))
{ {
taPart.TenantId = tenantId;
//根据传入数据新增或修改SCP数据 //根据传入数据新增或修改SCP数据
await _taPartRepository.UpsertAsync(taPart); await _taPartRepository.UpsertAsync(taPart);
} }

9
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs

@ -7,6 +7,8 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
@ -24,6 +26,7 @@ namespace Win_in.Sfs.Scp.WebApi
private readonly ITbPoRepository _tbPoRepository; private readonly ITbPoRepository _tbPoRepository;
private readonly ITbPoDetailRepository _tbPoDetailRepository; private readonly ITbPoDetailRepository _tbPoDetailRepository;
private readonly ITaVenderRepository _taVenderRepository; private readonly ITaVenderRepository _taVenderRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES; private readonly string _validSites = Validator.VALID_SITES;
public PurchaseOrderAppService( public PurchaseOrderAppService(
@ -31,6 +34,7 @@ namespace Win_in.Sfs.Scp.WebApi
, ITbPoRepository tbPoRepository , ITbPoRepository tbPoRepository
, ITbPoDetailRepository tbPoDetailRepository , ITbPoDetailRepository tbPoDetailRepository
, ITaVenderRepository taVenderRepository , ITaVenderRepository taVenderRepository
, ITenantStore tenantStore
, IConfiguration configuration , IConfiguration configuration
) : base(repository) ) : base(repository)
{ {
@ -38,6 +42,7 @@ namespace Win_in.Sfs.Scp.WebApi
_tbPoRepository = tbPoRepository; _tbPoRepository = tbPoRepository;
_tbPoDetailRepository = tbPoDetailRepository; _tbPoDetailRepository = tbPoDetailRepository;
_taVenderRepository = taVenderRepository; _taVenderRepository = taVenderRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"]; _validSites = configuration["ValidSites"];
} }
@ -123,6 +128,9 @@ namespace Win_in.Sfs.Scp.WebApi
{ {
//使用AutoMapper执行类型转换 //使用AutoMapper执行类型转换
var tbPo = ObjectMapper.Map<PurchaseOrder, TB_PO>(entity); var tbPo = ObjectMapper.Map<PurchaseOrder, TB_PO>(entity);
var tenant =await _tenantStore.FindAsync(tbPo.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
//根据传入数据新增或修改SCP数据 //根据传入数据新增或修改SCP数据
await _tbPoRepository.UpsertAsync(tbPo); await _tbPoRepository.UpsertAsync(tbPo);
@ -141,4 +149,5 @@ namespace Win_in.Sfs.Scp.WebApi
} }
} }
} }
}
} }

13
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs

@ -7,6 +7,7 @@ using System.Threading.Tasks;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
@ -25,6 +26,7 @@ namespace Win_in.Sfs.Scp.WebApi
private readonly ITbReceiptRepository _tbReceiptRepository; private readonly ITbReceiptRepository _tbReceiptRepository;
private readonly ITbReceiptDetailRepository _tbReceiptDetailRepository; private readonly ITbReceiptDetailRepository _tbReceiptDetailRepository;
private readonly ITaVenderRepository _taVenderRepository; private readonly ITaVenderRepository _taVenderRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES; private readonly string _validSites = Validator.VALID_SITES;
public ReceiptAppService( public ReceiptAppService(
@ -32,6 +34,7 @@ namespace Win_in.Sfs.Scp.WebApi
,ITbReceiptRepository tbReceiptRepository ,ITbReceiptRepository tbReceiptRepository
,ITbReceiptDetailRepository tbReceiptDetailRepository ,ITbReceiptDetailRepository tbReceiptDetailRepository
,ITaVenderRepository taVenderRepository ,ITaVenderRepository taVenderRepository
, ITenantStore tenantStore
, IConfiguration configuration , IConfiguration configuration
) : base(repository) ) : base(repository)
{ {
@ -39,6 +42,7 @@ namespace Win_in.Sfs.Scp.WebApi
_tbReceiptRepository = tbReceiptRepository; _tbReceiptRepository = tbReceiptRepository;
_tbReceiptDetailRepository = tbReceiptDetailRepository; _tbReceiptDetailRepository = tbReceiptDetailRepository;
_taVenderRepository = taVenderRepository; _taVenderRepository = taVenderRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"]; _validSites = configuration["ValidSites"];
} }
@ -117,14 +121,19 @@ namespace Win_in.Sfs.Scp.WebApi
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(Receipt entity) private async Task UpsertTbReceiptAndTbReceiptDetailAsync(Receipt entity)
{ {
//使用AutoMapper执行类型转换
var tbReceipt = ObjectMapper.Map<Receipt, TB_RECEIVE_QAD>(entity); var tbReceipt = ObjectMapper.Map<Receipt, TB_RECEIVE_QAD>(entity);
var tbReceiveDetail = ObjectMapper.Map<Receipt, TB_RECEIVE_DETAIL_QAD>(entity);
var tenant = await _tenantStore.FindAsync(tbReceipt.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
//根据传入数据新增或修改SCP数据 //根据传入数据新增或修改SCP数据
await _tbReceiptRepository.UpsertAsync(tbReceipt); await _tbReceiptRepository.UpsertAsync(tbReceipt);
//使用AutoMapper执行类型转换
var tbReceiveDetail = ObjectMapper.Map<Receipt, TB_RECEIVE_DETAIL_QAD>(entity);
//根据传入数据新增或修改SCP数据 //根据传入数据新增或修改SCP数据
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail); await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
} }
} }
}
} }

10
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs

@ -8,6 +8,7 @@ using FluentValidation;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
@ -25,16 +26,19 @@ namespace Win_in.Sfs.Scp.WebApi
{ {
private readonly ISupplierRepository _supplierRepository; private readonly ISupplierRepository _supplierRepository;
private readonly ITaVenderRepository _taVenderRepository; private readonly ITaVenderRepository _taVenderRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES; private readonly string _validSites = Validator.VALID_SITES;
public SuppliersAppService( public SuppliersAppService(
ISupplierRepository repository ISupplierRepository repository
,ITaVenderRepository taVenderRepository ,ITaVenderRepository taVenderRepository
,ITenantStore tenantStore
, IConfiguration configuration , IConfiguration configuration
) : base(repository) ) : base(repository)
{ {
_supplierRepository = repository; _supplierRepository = repository;
_taVenderRepository = taVenderRepository; _taVenderRepository = taVenderRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"]; _validSites = configuration["ValidSites"];
} }
@ -111,8 +115,14 @@ namespace Win_in.Sfs.Scp.WebApi
{ {
//使用AutoMapper执行类型转换 //使用AutoMapper执行类型转换
var taVender = ObjectMapper.Map<Supplier, TA_VENDER>(entity); var taVender = ObjectMapper.Map<Supplier, TA_VENDER>(entity);
var tenant =await _tenantStore.FindAsync(taVender.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
//根据传入数据新增或修改SCP数据 //根据传入数据新增或修改SCP数据
await _taVenderRepository.UpsertAsync(taVender); await _taVenderRepository.UpsertAsync(taVender);
} }
} }
}
} }

26
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs

@ -8,6 +8,7 @@ using FluentValidation;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow; using Volo.Abp.Uow;
using Volo.Abp.Validation; using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain; using Win_in.Sfs.Scp.v1.Domain;
@ -20,12 +21,14 @@ namespace Win_in.Sfs.Scp.WebApi
[Authorize] [Authorize]
[Route(RouteConsts.UnplannedReceipt)] [Route(RouteConsts.UnplannedReceipt)]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)] [ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
public class UnplannedReceiptAppService : ReadOnlyAppService<UnplannedReceipt, UnplannedReceiptDTO, Guid,RequestDTO>, IUnplannedReceiptAppService public class UnplannedReceiptAppService :
ReadOnlyAppService<UnplannedReceipt, UnplannedReceiptDTO, Guid, RequestDTO>, IUnplannedReceiptAppService
{ {
private readonly IUnplannedReceiptRepository _unplannedReceiptRepository; private readonly IUnplannedReceiptRepository _unplannedReceiptRepository;
private readonly ITbReceiptRepository _tbReceiptRepository; private readonly ITbReceiptRepository _tbReceiptRepository;
private readonly ITbReceiptDetailRepository _tbReceiptDetailRepository; private readonly ITbReceiptDetailRepository _tbReceiptDetailRepository;
private readonly ITaVenderRepository _taVenderRepository; private readonly ITaVenderRepository _taVenderRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES; private readonly string _validSites = Validator.VALID_SITES;
public UnplannedReceiptAppService( public UnplannedReceiptAppService(
@ -33,6 +36,7 @@ namespace Win_in.Sfs.Scp.WebApi
, ITbReceiptRepository tbReceiptRepository , ITbReceiptRepository tbReceiptRepository
, ITbReceiptDetailRepository tbReceiptDetailRepository , ITbReceiptDetailRepository tbReceiptDetailRepository
, ITaVenderRepository taVenderRepository , ITaVenderRepository taVenderRepository
, ITenantStore tenantStore
, IConfiguration configuration , IConfiguration configuration
) : base(repository) ) : base(repository)
{ {
@ -40,6 +44,7 @@ namespace Win_in.Sfs.Scp.WebApi
_tbReceiptRepository = tbReceiptRepository; _tbReceiptRepository = tbReceiptRepository;
_tbReceiptDetailRepository = tbReceiptDetailRepository; _tbReceiptDetailRepository = tbReceiptDetailRepository;
_taVenderRepository = taVenderRepository; _taVenderRepository = taVenderRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"]; _validSites = configuration["ValidSites"];
} }
@ -78,15 +83,16 @@ namespace Win_in.Sfs.Scp.WebApi
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[Route("")] [Route("")]
public virtual async Task<ActionResult<UnplannedReceiptDTO>> CreateAsync(UnplannedReceiptCreateDTO receiptCreateDTO) public virtual async Task<ActionResult<UnplannedReceiptDTO>> CreateAsync(
UnplannedReceiptCreateDTO receiptCreateDTO)
{ {
var entity = ObjectMapper.Map<UnplannedReceiptCreateDTO, UnplannedReceipt>(receiptCreateDTO); var entity = ObjectMapper.Map<UnplannedReceiptCreateDTO, UnplannedReceipt>(receiptCreateDTO);
try try
{ {
Validator.CheckSite(_validSites,entity.Site); Validator.CheckSite(_validSites, entity.Site);
Validator.CheckSite(_validSites,entity.Company); Validator.CheckSite(_validSites, entity.Company);
Validator.CheckSupplierCode(_taVenderRepository,entity.Site, entity.Address); Validator.CheckSupplierCode(_taVenderRepository, entity.Site, entity.Address);
await UpsertTbReceiptAndTbReceiptDetailAsync(entity); await UpsertTbReceiptAndTbReceiptDetailAsync(entity);
await CurrentUnitOfWork.SaveChangesAsync(); await CurrentUnitOfWork.SaveChangesAsync();
@ -118,14 +124,20 @@ namespace Win_in.Sfs.Scp.WebApi
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity) private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity)
{ {
//使用AutoMapper执行类型转换
var tbReceipt = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_QAD>(entity); var tbReceipt = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_QAD>(entity);
var tbReceiveDetail = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_DETAIL_QAD>(entity);
var tenant = await _tenantStore.FindAsync(tbReceipt.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
//根据传入数据新增或修改SCP数据 //根据传入数据新增或修改SCP数据
await _tbReceiptRepository.UpsertAsync(tbReceipt); await _tbReceiptRepository.UpsertAsync(tbReceipt);
//使用AutoMapper执行类型转换
var tbReceiveDetail = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_DETAIL_QAD>(entity);
//根据传入数据新增或修改SCP数据 //根据传入数据新增或修改SCP数据
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail); await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
} }
} }
}
} }

183
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/MultiTenantConnectionStringResolver.cs

@ -1,183 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
namespace Win_in.Sfs.Scp.WebApi;
public class AAA:DefaultConnectionStringResolver
{
public AAA(IOptionsSnapshot<AbpDbConnectionOptions> options) : base(options)
{
}
public override Task<string> ResolveAsync(string connectionStringName = null)
{
return base.ResolveAsync(connectionStringName);
}
}
[Dependency(ReplaceServices = true)]
public class MultiTenantConnectionStringResolver : DefaultConnectionStringResolver
{
private readonly ICurrentTenant _currentTenant;
private readonly IServiceProvider _serviceProvider;
public MultiTenantConnectionStringResolver(
IOptionsSnapshot<AbpDbConnectionOptions> options,
ICurrentTenant currentTenant,
IServiceProvider serviceProvider)
: base(options)
{
_currentTenant = currentTenant;
_serviceProvider = serviceProvider;
}
public override async Task<string> ResolveAsync(string connectionStringName = null)
{
if (_currentTenant.Id == null)
{
//No current tenant, fallback to default logic
return await base.ResolveAsync(connectionStringName);
}
var tenant = await FindTenantConfigurationAsync(_currentTenant.Id.Value);
if (tenant == null || tenant.ConnectionStrings.IsNullOrEmpty())
{
//Tenant has not defined any connection string, fallback to default logic
return await base.ResolveAsync(connectionStringName);
}
var tenantDefaultConnectionString = tenant.ConnectionStrings.Default;
//Requesting default connection string...
if (connectionStringName == null ||
connectionStringName == ConnectionStrings.DefaultConnectionStringName)
{
//Return tenant's default or global default
return !tenantDefaultConnectionString.IsNullOrWhiteSpace()
? tenantDefaultConnectionString
: Options.ConnectionStrings.Default;
}
//Requesting specific connection string...
var connString = tenant.ConnectionStrings.GetOrDefault(connectionStringName);
if (!connString.IsNullOrWhiteSpace())
{
//Found for the tenant
return connString;
}
//Fallback to the mapped database for the specific connection string
var database = Options.Databases.GetMappedDatabaseOrNull(connectionStringName);
if (database != null && database.IsUsedByTenants)
{
connString = tenant.ConnectionStrings.GetOrDefault(database.DatabaseName);
if (!connString.IsNullOrWhiteSpace())
{
//Found for the tenant
return connString;
}
}
//Fallback to tenant's default connection string if available
if (!tenantDefaultConnectionString.IsNullOrWhiteSpace())
{
return tenantDefaultConnectionString;
}
return await base.ResolveAsync(connectionStringName);
}
[Obsolete("Use ResolveAsync method.")]
public override string Resolve(string connectionStringName = null)
{
if (_currentTenant.Id == null)
{
//No current tenant, fallback to default logic
return base.Resolve(connectionStringName);
}
var tenant = FindTenantConfiguration(_currentTenant.Id.Value);
if (tenant == null || tenant.ConnectionStrings.IsNullOrEmpty())
{
//Tenant has not defined any connection string, fallback to default logic
return base.Resolve(connectionStringName);
}
var tenantDefaultConnectionString = tenant.ConnectionStrings.Default;
//Requesting default connection string...
if (connectionStringName == null ||
connectionStringName == ConnectionStrings.DefaultConnectionStringName)
{
//Return tenant's default or global default
return !tenantDefaultConnectionString.IsNullOrWhiteSpace()
? tenantDefaultConnectionString
: Options.ConnectionStrings.Default;
}
//Requesting specific connection string...
var connString = tenant.ConnectionStrings.GetOrDefault(connectionStringName);
if (!connString.IsNullOrWhiteSpace())
{
//Found for the tenant
return connString;
}
//Fallback to tenant's default connection string if available
if (!tenantDefaultConnectionString.IsNullOrWhiteSpace())
{
return tenantDefaultConnectionString;
}
//Try to find the specific connection string for given name
var connStringInOptions = Options.ConnectionStrings.GetOrDefault(connectionStringName);
if (!connStringInOptions.IsNullOrWhiteSpace())
{
return connStringInOptions;
}
//Fallback to the global default connection string
var defaultConnectionString = Options.ConnectionStrings.Default;
if (!defaultConnectionString.IsNullOrWhiteSpace())
{
return defaultConnectionString;
}
throw new AbpException("No connection string defined!");
}
protected virtual async Task<TenantConfiguration> FindTenantConfigurationAsync(Guid tenantId)
{
using (var serviceScope = _serviceProvider.CreateScope())
{
var tenantStore = serviceScope
.ServiceProvider
.GetRequiredService<ITenantStore>();
return await tenantStore.FindAsync(tenantId);
}
}
[Obsolete("Use FindTenantConfigurationAsync method.")]
protected virtual TenantConfiguration FindTenantConfiguration(Guid tenantId)
{
using (var serviceScope = _serviceProvider.CreateScope())
{
var tenantStore = serviceScope
.ServiceProvider
.GetRequiredService<ITenantStore>();
return tenantStore.Find(tenantId);
}
}
}

32
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/WebApiHttpApiHostModule.cs

@ -81,38 +81,6 @@ namespace Win_in.Sfs.Scp.WebApi
private void ConfigureMultiTenancy(IConfiguration configuration) private void ConfigureMultiTenancy(IConfiguration configuration)
{ {
Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = true; }); Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = true; });
// Configure<AbpDefaultTenantStoreOptions>(configuration);
// Configure<AbpDefaultTenantStoreOptions>(options =>
// {
// options.Tenants = new[]
// {
// new TenantConfiguration(
// Guid.Parse("446a5211-3d72-4339-9adc-845151f8ada0"), //Id
// "T8" //Name
// )
// {
// //tenant1 有单独的数据库连接字符串
// ConnectionStrings =
// {
// {V1ScpConsts.ConnectionStringName, "Server=127.0.0.1;Database=SCP_HZ;User ID=sa;Password=Microsoft2008;connection timeout=600;"}
// }
// }
// ,
// new TenantConfiguration(
// Guid.Parse("25388015-ef1c-4355-9c18-f6b6ddbaf89d"), //Id
// "T9" //Name
// )
// {
// //tenant2 有单独的数据库连接字符串
// ConnectionStrings =
// {
// {V1ScpConsts.ConnectionStringName, "Server=127.0.0.1;Database=SCP_TJ;User ID=sa;Password=Microsoft2008;connection timeout=600;"}
// }
// }
// };
// });
} }
private static void ConfigureAuthorization(ServiceConfigurationContext context, IConfiguration configuration) private static void ConfigureAuthorization(ServiceConfigurationContext context, IConfiguration configuration)

17
WebApiService/src/Win_in.Sfs.Scp.WebApi.HttpApi.Host/appsettings.json

@ -34,23 +34,6 @@
} }
} }
}, },
"Tenants": [
{
"Id": "446a5211-3d72-4339-9adc-845151f8ada0",
"Name": "T8",
"ConnectionStrings": {
"V1Scp": "Server=127.0.0.1;Database=SCP_HZ;User ID=sa;Password=Microsoft2008;connection timeout=600;"
}
},
{
"Id": "25388015-ef1c-4355-9c18-f6b6ddbaf89d",
"Name": "T9",
"ConnectionStrings": {
"V1Scp": "Server=127.0.0.1;Database=SCP_TJ;User ID=sa;Password=Microsoft2008;connection timeout=600;"
}
}
],
"AlwaysAllowAuthorization": true, "AlwaysAllowAuthorization": true,
"ValidSites": "T8,T9" "ValidSites": "T8,T9"
} }

2
WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Parts/TA_PART.cs

@ -42,6 +42,6 @@ namespace Win_in.Sfs.Scp.v1.Domain
public bool? Ischeck { get; set; } public bool? Ischeck { get; set; }
public Guid? TenantId { get; set; } public Guid? TenantId { get; }
} }
} }
Loading…
Cancel
Save