|
|
@ -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.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); |
|
|
|
await CurrentUnitOfWork.SaveChangesAsync(); |
|
|
|
|
|
|
|
|
|
|
|
await UpsertTbPoAndTbPoDetailAsync(entity, tenant.Id); |
|
|
|
await CurrentUnitOfWork.SaveChangesAsync(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
@ -124,13 +131,12 @@ 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)) |
|
|
|
{ |
|
|
|
tbPo.TenantId = tenantId; |
|
|
|
|
|
|
|
//根据传入数据新增或修改SCP数据
|
|
|
|
await _tbPoRepository.UpsertAsync(tbPo); |
|
|
|
|
|
|
@ -144,10 +150,11 @@ namespace Win_in.Sfs.Scp.WebApi |
|
|
|
tbPoDetail.Site = tbPo.Site; |
|
|
|
tbPoDetail.BeginTime = tbPo.BeginTime; |
|
|
|
tbPoDetail.EndTime = tbPo.EndTime; |
|
|
|
tbPoDetail.TenantId = tenantId; |
|
|
|
//根据传入数据新增或修改SCP数据
|
|
|
|
await _tbPoDetailRepository.UpsertAsync(tbPoDetail); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |