|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |