Browse Source

[fix]使用租户信息进行Site验证

master
贾荣国Home 3 years ago
parent
commit
06f251259e
  1. 29
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Parts/PartAppService.cs
  2. 59
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/PurchaseOrders/PurchaseOrderAppService.cs
  3. 47
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Receipts/ReceiptAppService.cs
  4. 37
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Suppliers/SuppliersAppService.cs
  5. 40
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/UnplannedReceipts/UnplannedReceiptAppService.cs
  6. 29
      WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Validator.cs
  7. 2
      WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Parts/TA_PART.cs
  8. 2
      WebApiService/src/Win_in.Sfs.Scp.v1.Domain/PurchaseOrders/TB_PO.cs
  9. 2
      WebApiService/src/Win_in.Sfs.Scp.v1.Domain/PurchaseOrders/TB_PO_DETAIL.cs
  10. 2
      WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Receipts/TB_RECEIVE_DETAIL_QAD.cs
  11. 2
      WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Receipts/TB_RECEIVE_QAD.cs
  12. 2
      WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Suppliers/TA_VENDER.cs

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

@ -35,19 +35,19 @@ namespace Win_in.Sfs.Scp.WebApi
private readonly IPartRepository _partRepository;
private readonly ITaPartRepository _taPartRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES;
private readonly ITenantRepository _tenantRepository;
public PartAppService(
IPartRepository repository
, ITaPartRepository taPartRepository
, ITenantStore tenantStore
, IConfiguration configuration
, ITenantRepository tenantRepository
) : base(repository)
{
_partRepository = repository;
_taPartRepository = taPartRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"];
_tenantRepository = tenantRepository;
}
/// <summary>
@ -89,10 +89,14 @@ namespace Win_in.Sfs.Scp.WebApi
try
{
Validator.CheckSite(_validSites, entity.Site);
Validator.CheckSite(_validSites, entity.Company);
await UpsertTaPartAsync(entity);
await CurrentUnitOfWork.SaveChangesAsync();
Validator.CheckSite(_tenantRepository, entity.Site);
Validator.CheckSite(_tenantRepository, entity.Company);
var tenant = await _tenantStore.FindAsync(entity.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
await UpsertTaPartAsync(entity, tenant.Id);
await CurrentUnitOfWork.SaveChangesAsync();
}
}
catch (Exception ex)
{
@ -118,17 +122,14 @@ namespace Win_in.Sfs.Scp.WebApi
}
}
private async Task UpsertTaPartAsync(Part entity)
private async Task UpsertTaPartAsync(Part entity, Guid tenantId)
{
//使用AutoMapper执行类型转换
var taPart = ObjectMapper.Map<Part, TA_PART>(entity);
var tenant =await _tenantStore.FindAsync(taPart.Site);
using (CurrentTenant.Change(tenant.Id,tenant.Name))
{
//根据传入数据新增或修改SCP数据
await _taPartRepository.UpsertAsync(taPart);
}
taPart.TenantId = tenantId;
//根据传入数据新增或修改SCP数据
await _taPartRepository.UpsertAsync(taPart);
}
}
}

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

@ -11,6 +11,7 @@ using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain;
using System.Security.Policy;
namespace Win_in.Sfs.Scp.WebApi
{
@ -27,7 +28,7 @@ namespace Win_in.Sfs.Scp.WebApi
private readonly ITbPoDetailRepository _tbPoDetailRepository;
private readonly ITaVenderRepository _taVenderRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES;
private readonly ITenantRepository _tenantRepository;
public PurchaseOrderAppService(
IPurchaseOrderRepository repository
@ -35,7 +36,7 @@ namespace Win_in.Sfs.Scp.WebApi
, ITbPoDetailRepository tbPoDetailRepository
, ITaVenderRepository taVenderRepository
, ITenantStore tenantStore
, IConfiguration configuration
, ITenantRepository tenantRepository
) : base(repository)
{
_purchaseOrderRepository = repository;
@ -43,7 +44,7 @@ namespace Win_in.Sfs.Scp.WebApi
_tbPoDetailRepository = tbPoDetailRepository;
_taVenderRepository = taVenderRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"];
_tenantRepository = tenantRepository;
}
@ -95,12 +96,18 @@ namespace Win_in.Sfs.Scp.WebApi
try
{
Validator.CheckSite(_validSites,entity.Site);
Validator.CheckSite(_validSites,entity.Company);
Validator.CheckSupplierCode(_taVenderRepository,entity.Site, entity.SupplierCode);
await UpsertTbPoAndTbPoDetailAsync(entity);
await CurrentUnitOfWork.SaveChangesAsync();
Validator.CheckSite(_tenantRepository, entity.Site);
Validator.CheckSite(_tenantRepository, entity.Company);
var tenant = await _tenantStore.FindAsync(entity.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
Validator.CheckSupplierCode(_taVenderRepository, entity.Site, entity.SupplierCode);
await UpsertTbPoAndTbPoDetailAsync(entity, tenant.Id);
await CurrentUnitOfWork.SaveChangesAsync();
}
}
catch (Exception ex)
{
@ -124,30 +131,30 @@ namespace Win_in.Sfs.Scp.WebApi
}
}
private async Task UpsertTbPoAndTbPoDetailAsync(PurchaseOrder entity)
private async Task UpsertTbPoAndTbPoDetailAsync(PurchaseOrder entity, Guid tenantId)
{
//使用AutoMapper执行类型转换
var tbPo = ObjectMapper.Map<PurchaseOrder, TB_PO>(entity);
var tenant =await _tenantStore.FindAsync(tbPo.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
//根据传入数据新增或修改SCP数据
await _tbPoRepository.UpsertAsync(tbPo);
tbPo.TenantId = tenantId;
var poDetails = entity.Details;
//根据传入数据新增或修改SCP数据
await _tbPoRepository.UpsertAsync(tbPo);
foreach (var poDetail in poDetails)
{
//使用AutoMapper执行类型转换
var tbPoDetail = ObjectMapper.Map<PurchaseOrderDetail, TB_PO_DETAIL>(poDetail);
//接口数据中没有Site,从主表中获取
tbPoDetail.Site = tbPo.Site;
tbPoDetail.BeginTime = tbPo.BeginTime;
tbPoDetail.EndTime = tbPo.EndTime;
//根据传入数据新增或修改SCP数据
await _tbPoDetailRepository.UpsertAsync(tbPoDetail);
}
var poDetails = entity.Details;
foreach (var poDetail in poDetails)
{
//使用AutoMapper执行类型转换
var tbPoDetail = ObjectMapper.Map<PurchaseOrderDetail, TB_PO_DETAIL>(poDetail);
//接口数据中没有Site,从主表中获取
tbPoDetail.Site = tbPo.Site;
tbPoDetail.BeginTime = tbPo.BeginTime;
tbPoDetail.EndTime = tbPo.EndTime;
tbPoDetail.TenantId = tenantId;
//根据传入数据新增或修改SCP数据
await _tbPoDetailRepository.UpsertAsync(tbPoDetail);
}
}
}
}

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

@ -11,6 +11,7 @@ using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;
using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain;
using Volo.Abp.TenantManagement;
namespace Win_in.Sfs.Scp.WebApi
{
@ -20,22 +21,22 @@ namespace Win_in.Sfs.Scp.WebApi
[Authorize]
[Route(RouteConsts.Receipt)]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
public class ReceiptAppService : ReadOnlyAppService<Receipt, ReceiptDTO, Guid,RequestDTO>, IReceiptAppService
public class ReceiptAppService : ReadOnlyAppService<Receipt, ReceiptDTO, Guid, RequestDTO>, IReceiptAppService
{
private readonly IReceiptRepository _receiptRepository;
private readonly ITbReceiptRepository _tbReceiptRepository;
private readonly ITbReceiptDetailRepository _tbReceiptDetailRepository;
private readonly ITaVenderRepository _taVenderRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES;
private readonly ITenantRepository _tenantRepository;
public ReceiptAppService(
IReceiptRepository repository
,ITbReceiptRepository tbReceiptRepository
,ITbReceiptDetailRepository tbReceiptDetailRepository
,ITaVenderRepository taVenderRepository
, ITbReceiptRepository tbReceiptRepository
, ITbReceiptDetailRepository tbReceiptDetailRepository
, ITaVenderRepository taVenderRepository
, ITenantStore tenantStore
, IConfiguration configuration
, ITenantRepository tenantRepository
) : base(repository)
{
_receiptRepository = repository;
@ -43,8 +44,7 @@ namespace Win_in.Sfs.Scp.WebApi
_tbReceiptDetailRepository = tbReceiptDetailRepository;
_taVenderRepository = taVenderRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"];
_tenantRepository = tenantRepository;
}
@ -88,12 +88,16 @@ namespace Win_in.Sfs.Scp.WebApi
try
{
Validator.CheckSite(_validSites,entity.Site);
Validator.CheckSite(_validSites,entity.Company);
Validator.CheckSupplierCode(_taVenderRepository,entity.Site, entity.SupplierCode);
await UpsertTbReceiptAndTbReceiptDetailAsync(entity);
await CurrentUnitOfWork.SaveChangesAsync();
Validator.CheckSite(_tenantRepository, entity.Site);
Validator.CheckSite(_tenantRepository, entity.Company);
var tenant = await _tenantStore.FindAsync(entity.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
Validator.CheckSupplierCode(_taVenderRepository, entity.Site, entity.SupplierCode);
await UpsertTbReceiptAndTbReceiptDetailAsync(entity, tenant.Id);
await CurrentUnitOfWork.SaveChangesAsync();
}
}
catch (Exception ex)
{
@ -119,21 +123,18 @@ namespace Win_in.Sfs.Scp.WebApi
}
}
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(Receipt entity)
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(Receipt entity, Guid tenantId)
{
//使用AutoMapper执行类型转换
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数据
await _tbReceiptRepository.UpsertAsync(tbReceipt);
//根据传入数据新增或修改SCP数据
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
}
tbReceipt.TenantId = tenantId;
//根据传入数据新增或修改SCP数据
await _tbReceiptRepository.UpsertAsync(tbReceipt);
tbReceiveDetail.TenantId = tenantId;
//根据传入数据新增或修改SCP数据
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
}
}
}

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

@ -9,6 +9,7 @@ using Microsoft.Extensions.Configuration;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
using Volo.Abp.Uow;
using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain;
@ -22,25 +23,24 @@ namespace Win_in.Sfs.Scp.WebApi
[Authorize]
[Route(RouteConsts.Supplier)]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
public class SuppliersAppService : ReadOnlyAppService<Supplier, SupplierDTO, Guid,RequestDTO>, ISupplierAppService
public class SuppliersAppService : ReadOnlyAppService<Supplier, SupplierDTO, Guid, RequestDTO>, ISupplierAppService
{
private readonly ISupplierRepository _supplierRepository;
private readonly ITaVenderRepository _taVenderRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES;
private readonly ITenantRepository _tenantRepository;
public SuppliersAppService(
ISupplierRepository repository
,ITaVenderRepository taVenderRepository
,ITenantStore tenantStore
, IConfiguration configuration
, ITaVenderRepository taVenderRepository
, ITenantStore tenantStore
, ITenantRepository tenantRepository
) : base(repository)
{
_supplierRepository = repository;
_taVenderRepository = taVenderRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"];
_tenantRepository = tenantRepository;
}
@ -83,10 +83,13 @@ namespace Win_in.Sfs.Scp.WebApi
try
{
Validator.CheckSite(_validSites,entity.Company);
UpsertTaVenderAsync(entity).Wait();
await CurrentUnitOfWork.SaveChangesAsync();
Validator.CheckSite(_tenantRepository, entity.Company);
var tenant = await _tenantStore.FindAsync(entity.Company);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
await UpsertTaVenderAsync(entity, tenant.Id);
await CurrentUnitOfWork.SaveChangesAsync();
}
}
catch (Exception ex)
{
@ -111,18 +114,14 @@ namespace Win_in.Sfs.Scp.WebApi
}
}
private async Task UpsertTaVenderAsync(Supplier entity)
private async Task UpsertTaVenderAsync(Supplier entity, Guid tenantId)
{
//使用AutoMapper执行类型转换
var taVender = ObjectMapper.Map<Supplier, TA_VENDER>(entity);
var tenant =await _tenantStore.FindAsync(taVender.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
//根据传入数据新增或修改SCP数据
await _taVenderRepository.UpsertAsync(taVender);
}
taVender.TenantId = tenantId;
//根据传入数据新增或修改SCP数据
await _taVenderRepository.UpsertAsync(taVender);
}
}
}

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

@ -12,6 +12,7 @@ using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;
using Volo.Abp.Validation;
using Win_in.Sfs.Scp.v1.Domain;
using Volo.Abp.TenantManagement;
namespace Win_in.Sfs.Scp.WebApi
{
@ -29,7 +30,7 @@ namespace Win_in.Sfs.Scp.WebApi
private readonly ITbReceiptDetailRepository _tbReceiptDetailRepository;
private readonly ITaVenderRepository _taVenderRepository;
private readonly ITenantStore _tenantStore;
private readonly string _validSites = Validator.VALID_SITES;
private readonly ITenantRepository _tenantRepository;
public UnplannedReceiptAppService(
IUnplannedReceiptRepository repository
@ -37,7 +38,7 @@ namespace Win_in.Sfs.Scp.WebApi
, ITbReceiptDetailRepository tbReceiptDetailRepository
, ITaVenderRepository taVenderRepository
, ITenantStore tenantStore
, IConfiguration configuration
, ITenantRepository tenantRepository
) : base(repository)
{
_unplannedReceiptRepository = repository;
@ -45,8 +46,7 @@ namespace Win_in.Sfs.Scp.WebApi
_tbReceiptDetailRepository = tbReceiptDetailRepository;
_taVenderRepository = taVenderRepository;
_tenantStore = tenantStore;
_validSites = configuration["ValidSites"];
_tenantRepository = tenantRepository;
}
@ -90,13 +90,16 @@ namespace Win_in.Sfs.Scp.WebApi
try
{
Validator.CheckSite(_validSites, entity.Site);
Validator.CheckSite(_validSites, entity.Company);
Validator.CheckSupplierCode(_taVenderRepository, entity.Site, entity.Address);
await UpsertTbReceiptAndTbReceiptDetailAsync(entity);
await CurrentUnitOfWork.SaveChangesAsync();
Validator.CheckSite(_tenantRepository, entity.Site);
Validator.CheckSite(_tenantRepository, entity.Company);
var tenant = await _tenantStore.FindAsync(entity.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
Validator.CheckSupplierCode(_taVenderRepository, entity.Site, entity.Address);
await UpsertTbReceiptAndTbReceiptDetailAsync(entity, tenant.Id);
await CurrentUnitOfWork.SaveChangesAsync();
}
}
catch (Exception ex)
{
@ -122,22 +125,19 @@ namespace Win_in.Sfs.Scp.WebApi
}
}
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity)
private async Task UpsertTbReceiptAndTbReceiptDetailAsync(UnplannedReceipt entity, Guid tenantId)
{
//使用AutoMapper执行类型转换
var tbReceipt = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_QAD>(entity);
var tbReceiveDetail = ObjectMapper.Map<UnplannedReceipt, TB_RECEIVE_DETAIL_QAD>(entity);
tbReceipt.TenantId = tenantId;
var tenant = await _tenantStore.FindAsync(tbReceipt.Site);
using (CurrentTenant.Change(tenant.Id, tenant.Name))
{
//根据传入数据新增或修改SCP数据
await _tbReceiptRepository.UpsertAsync(tbReceipt);
//根据传入数据新增或修改SCP数据
await _tbReceiptRepository.UpsertAsync(tbReceipt);
//根据传入数据新增或修改SCP数据
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
}
tbReceiveDetail.TenantId = tenantId;
//根据传入数据新增或修改SCP数据
await _tbReceiptDetailRepository.UpsertAsync(tbReceiveDetail);
}
}
}

29
WebApiService/src/Win_in.Sfs.Scp.WebApi.Application/Validator.cs

@ -2,28 +2,41 @@
using System.Linq;
using System.Linq.Dynamic.Core;
using Volo.Abp;
using Volo.Abp.MultiTenancy;
using Volo.Abp.TenantManagement;
using Win_in.Sfs.Scp.v1.Domain;
namespace Win_in.Sfs.Scp.WebApi;
public static class Validator
{
public const string VALID_SITES = "T8";
private static string VALID_SITES = "";
public static void CheckSite(string validSites,string site)
public static void CheckSite(ITenantRepository tenantRepository,string site)
{
if (!validSites.Contains(site) )
if (string.IsNullOrEmpty(VALID_SITES))
{
var tenants = tenantRepository.GetListAsync().GetAwaiter().GetResult();
VALID_SITES = tenants.Select(p => p.Name).JoinAsString(",");
}
if (!VALID_SITES.Contains(site) )
{
throw new UserFriendlyException($"Site must be in [{validSites}]");
throw new UserFriendlyException($"Site must be in [{VALID_SITES}]");
}
}
public static void CheckSupplierCode(ITaVenderRepository taVenderRepository, string site, string supplierCode)
{
if (!taVenderRepository.Any(p =>p.Site==site && p.VendId == supplierCode))
{
throw new UserFriendlyException($"Wrong supplier code: [{supplierCode}] of Site: [{site}]");
}
if (!taVenderRepository.Any(p => p.Site == site && p.VendId == supplierCode))
{
throw new UserFriendlyException($"Wrong supplier code: [{supplierCode}] of Site: [{site}]");
}
}
}

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 Guid? TenantId { get; }
public Guid? TenantId { get; set; }
}
}

2
WebApiService/src/Win_in.Sfs.Scp.v1.Domain/PurchaseOrders/TB_PO.cs

@ -32,6 +32,6 @@ namespace Win_in.Sfs.Scp.v1.Domain
public bool IsDeleted { get; set; }
public Guid GUID { get; set; }
public Guid? TenantId { get; }
public Guid? TenantId { get; set; }
}
}

2
WebApiService/src/Win_in.Sfs.Scp.v1.Domain/PurchaseOrders/TB_PO_DETAIL.cs

@ -42,6 +42,6 @@ namespace Win_in.Sfs.Scp.v1.Domain
public Guid GUID { get; set; }
public Guid? TenantId { get; }
public Guid? TenantId { get; set; }
}
}

2
WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Receipts/TB_RECEIVE_DETAIL_QAD.cs

@ -43,6 +43,6 @@ namespace Win_in.Sfs.Scp.v1.Domain
public string Extend2 { get; set; }
public string Extend3 { get; set; }
public string SubSite { get; set; }
public Guid? TenantId { get; }
public Guid? TenantId { get; set; }
}
}

2
WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Receipts/TB_RECEIVE_QAD.cs

@ -31,6 +31,6 @@ namespace Win_in.Sfs.Scp.v1.Domain
public string SubSite { get; set; }
public Guid? TenantId { get; }
public Guid? TenantId { get; set; }
}
}

2
WebApiService/src/Win_in.Sfs.Scp.v1.Domain/Suppliers/TA_VENDER.cs

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