|
|
@ -6,7 +6,9 @@ using System.Threading.Tasks; |
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Label.Application.Contracts; |
|
|
|
using Win_in.Sfs.Label.Domain; |
|
|
@ -14,6 +16,7 @@ using Win_in.Sfs.Shared.Application.Contracts; |
|
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
|
using Win_in.Sfs.Shared.Domain.Shared; |
|
|
|
using Win_in.Sfs.Wms.Inventory.Application.Contracts; |
|
|
|
using Win_in.Sfs.Wms.Inventory.Domain; |
|
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts; |
|
|
|
using Win_in.Sfs.Wms.Store.Domain; |
|
|
|
using Win_in.Sfs.Wms.Store.Domain.Shared; |
|
|
@ -30,18 +33,22 @@ public class PurchaseReturnRequestAppService : |
|
|
|
SfsStoreRequestAppServiceBase |
|
|
|
<PurchaseReturnRequest, PurchaseReturnRequestDTO, SfsStoreRequestInputBase, PurchaseReturnRequestEditInput, PurchaseReturnRequestDetail, PurchaseReturnRequestDetailDTO, SfsStoreRequestInputBase, PurchaseReturnRequestImportInput>, IPurchaseReturnRequestAppService |
|
|
|
{ |
|
|
|
private readonly IPurchaseReturnRequestManager _purchaseReturnRequestManager; |
|
|
|
|
|
|
|
private readonly IInventoryLabelAppService _inventoryLabelApp; |
|
|
|
private readonly ILocationAppService _locationAppService; |
|
|
|
private readonly ITransactionTypeAppService _transactionTypeAppService; |
|
|
|
private readonly IPurchaseReturnRequestManager _purchaseReturnRequestManager; |
|
|
|
|
|
|
|
public PurchaseReturnRequestAppService( |
|
|
|
IPurchaseReturnRequestRepository repository, |
|
|
|
IPurchaseReturnRequestManager purchaseReturnRequestManager, |
|
|
|
IInventoryLabelAppService inventoryLabelApp |
|
|
|
) : base(repository, purchaseReturnRequestManager) |
|
|
|
IInventoryLabelAppService inventoryLabelApp, |
|
|
|
ILocationAppService locationAppService, |
|
|
|
ITransactionTypeAppService transactionTypeAppService) : base(repository, purchaseReturnRequestManager) |
|
|
|
{ |
|
|
|
_purchaseReturnRequestManager = purchaseReturnRequestManager; |
|
|
|
this._inventoryLabelApp = inventoryLabelApp; |
|
|
|
_inventoryLabelApp = inventoryLabelApp; |
|
|
|
_locationAppService = locationAppService; |
|
|
|
_transactionTypeAppService = transactionTypeAppService; |
|
|
|
|
|
|
|
base.CreatePolicyName = PurchaseReturnRequestPermissions.Create; |
|
|
|
base.UpdatePolicyName = PurchaseReturnRequestPermissions.Update; |
|
|
@ -55,6 +62,102 @@ public class PurchaseReturnRequestAppService : |
|
|
|
throw new NotImplementedException(); |
|
|
|
} |
|
|
|
|
|
|
|
#region 东阳
|
|
|
|
|
|
|
|
protected override async Task<Dictionary<PurchaseReturnRequest, EntityState>> ImportProcessingEntityAsync(Dictionary<PurchaseReturnRequest, EntityState> dictionary) |
|
|
|
{ |
|
|
|
var addList = dictionary.Where(p => p.Value == EntityState.Added).Select(p => p.Key); |
|
|
|
|
|
|
|
foreach (var purchaseReturnRequest in addList) |
|
|
|
{ |
|
|
|
await SetRequestAutoPropertiesAsync(purchaseReturnRequest).ConfigureAwait(false); |
|
|
|
purchaseReturnRequest.Worker = CurrentUser.GetUserName(); |
|
|
|
purchaseReturnRequest.CreatorId = CurrentUser.Id; |
|
|
|
|
|
|
|
foreach (var detail in purchaseReturnRequest.Details) |
|
|
|
{ |
|
|
|
//通过箱标签 查找标签服务 构造其他字段
|
|
|
|
var labelDto = await _inventoryLabelApp.GetByCodeAsync(detail.PackingCode).ConfigureAwait(false); |
|
|
|
var balanceDto = await BalanceAclService.GetByPackingCodeAsync(detail.PackingCode).ConfigureAwait(false); |
|
|
|
var locationDto= await _locationAppService.GetByCodeAsync(balanceDto.LocationCode).ConfigureAwait(false); |
|
|
|
purchaseReturnRequest.AsnNumber = labelDto.AsnNumber; |
|
|
|
purchaseReturnRequest.RpNumber = labelDto.RpNumber; |
|
|
|
purchaseReturnRequest.ReturnTime=DateTime.Now; |
|
|
|
purchaseReturnRequest.SupplierCode= labelDto.SupplierCode; |
|
|
|
purchaseReturnRequest.ReturnType = EnumPurchaseReturnType.AfterPuton; |
|
|
|
purchaseReturnRequest.PoNumber = labelDto.PoNumber; |
|
|
|
await SetDetailPropertiesAsync(detail, labelDto, balanceDto,locationDto).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return dictionary; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 赋值Request业务属性
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="entity"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetRequestAutoPropertiesAsync(PurchaseReturnRequest entity) |
|
|
|
{ |
|
|
|
var tranType = await _transactionTypeAppService.GetByTransTypeAsync(EnumTransType.PurchaseReturn, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
|
|
|
|
Check.NotNull(tranType, "事务类型", "事务类型不存在"); |
|
|
|
|
|
|
|
entity.AutoCompleteJob = tranType.AutoCompleteJob; |
|
|
|
entity.AutoSubmit = tranType.AutoSubmitRequest; |
|
|
|
entity.AutoAgree = tranType.AutoAgreeRequest; |
|
|
|
entity.AutoHandle = tranType.AutoHandleRequest; |
|
|
|
entity.DirectCreateNote = tranType.DirectCreateNote; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 赋值详情
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="labelDto"></param>
|
|
|
|
/// <param name="balanceDto"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private async Task SetDetailPropertiesAsync( |
|
|
|
PurchaseReturnRequestDetail detail, |
|
|
|
InventoryLabelDto labelDto, |
|
|
|
BalanceDTO balanceDto, |
|
|
|
LocationDTO locationDto) |
|
|
|
{ |
|
|
|
if (labelDto != null) |
|
|
|
{ |
|
|
|
detail.PoNumber = labelDto.PoNumber; |
|
|
|
} |
|
|
|
|
|
|
|
if (balanceDto != null) |
|
|
|
{ |
|
|
|
detail.PackingCode = balanceDto.PackingCode; |
|
|
|
detail.ContainerCode = balanceDto.ContainerCode; |
|
|
|
|
|
|
|
detail.WarehouseCode = locationDto.WarehouseCode; |
|
|
|
detail.LocationCode = balanceDto.LocationCode; |
|
|
|
detail.LocationErpCode = locationDto.ErpLocationCode; |
|
|
|
detail.LocationArea = locationDto.AreaCode; |
|
|
|
detail.LocationGroup = locationDto.LocationGroupCode; |
|
|
|
|
|
|
|
detail.Status = balanceDto.Status; |
|
|
|
detail.Lot = balanceDto.Lot; |
|
|
|
detail.SupplierBatch = balanceDto.SupplierBatch; |
|
|
|
detail.Uom = balanceDto.Uom; |
|
|
|
detail.ArriveDate = balanceDto.ArriveDate; |
|
|
|
detail.ProduceDate = balanceDto.ProduceDate; |
|
|
|
detail.ExpireDate = balanceDto.ExpireDate; |
|
|
|
detail.ItemName = balanceDto.ItemName; |
|
|
|
detail.ItemDesc1 = balanceDto.ItemDesc1; |
|
|
|
detail.ItemDesc2 = balanceDto.ItemDesc2; |
|
|
|
detail.StdPackQty = balanceDto.StdPackQty; |
|
|
|
detail.Qty = balanceDto.Qty; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 校验
|
|
|
|
|
|
|
|
protected virtual async Task CheckImportInputBusinessAsync(PurchaseReturnRequestImportInput importInput, EnumImportMethod importMethod, List<ValidationResult> validationRresult) |
|
|
|
{ |
|
|
|
//await base.CheckImportInputBusinessAsync(importInput, importMethod);
|
|
|
@ -140,162 +243,6 @@ public class PurchaseReturnRequestAppService : |
|
|
|
return transactionType; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task ImportDataAsync(List<PurchaseReturnRequest> entites, List<PurchaseReturnRequest> deleteEntities) |
|
|
|
{ |
|
|
|
await _purchaseReturnRequestManager.ImportDataAsync(entites, deleteEntities).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
protected override Func<PurchaseReturnRequestImportInput, object> GetEntityExpression() |
|
|
|
{ |
|
|
|
return p => (1); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual async Task<(List<PurchaseReturnRequest> entites, List<PurchaseReturnRequest> deleteEntities)> BuildImportDataAsync(ImportResult<PurchaseReturnRequestImportInput> importResult, EnumImportMethod importMethod = EnumImportMethod.Update, bool isAllowPartImport = false) |
|
|
|
{ |
|
|
|
if (importResult.Data.Any(t => t.ReportStatus == EnumImportReportStatus.Failed)) |
|
|
|
{ |
|
|
|
if (!isAllowPartImport) |
|
|
|
{ |
|
|
|
return (null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var entites = new List<PurchaseReturnRequest>(); |
|
|
|
|
|
|
|
var details = new List<PurchaseReturnRequestDetail>(); |
|
|
|
|
|
|
|
var deleteEntites = new List<PurchaseReturnRequest>(); |
|
|
|
|
|
|
|
var entityExpression = GetEntityExpression(); |
|
|
|
|
|
|
|
var groupList = importResult.Data.ToList().GroupBy(entityExpression).Distinct().ToList(); |
|
|
|
|
|
|
|
foreach (var group in groupList) |
|
|
|
{ |
|
|
|
var input = group.FirstOrDefault(); |
|
|
|
|
|
|
|
var inputDetails = group.ToList(); |
|
|
|
|
|
|
|
if (!inputDetails.Any(t => t.ReportStatus == EnumImportReportStatus.Failed)) |
|
|
|
{ |
|
|
|
var exist = await GetEntityAsync(input).ConfigureAwait(false); |
|
|
|
|
|
|
|
var entity = ObjectMapper.Map<PurchaseReturnRequestImportInput, PurchaseReturnRequest>(input); |
|
|
|
|
|
|
|
await SetEntityPropertiesAsync(entity, input).ConfigureAwait(false); |
|
|
|
|
|
|
|
switch (importMethod) |
|
|
|
{ |
|
|
|
case EnumImportMethod.Update: |
|
|
|
if (exist != null) |
|
|
|
{ |
|
|
|
entity.SetId(exist.Id); |
|
|
|
} |
|
|
|
break; |
|
|
|
case EnumImportMethod.Replace: |
|
|
|
if (exist != null) |
|
|
|
{ |
|
|
|
deleteEntites.Add(exist); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var inputDetail in inputDetails) |
|
|
|
{ |
|
|
|
var detail = ObjectMapper.Map<PurchaseReturnRequestImportInput, PurchaseReturnRequestDetail>(inputDetail); |
|
|
|
|
|
|
|
detail.SetIdAndNumber(GuidGenerator, entity.Id, entity.Number); |
|
|
|
|
|
|
|
await SetDetailPropertiesAsync(detail, inputDetail).ConfigureAwait(false); |
|
|
|
entity.AddDetail(detail); |
|
|
|
} |
|
|
|
|
|
|
|
entites.Add(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return (entites, deleteEntites); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SetDetailPropertiesAsync( |
|
|
|
PurchaseReturnRequestDetail detail, |
|
|
|
PurchaseReturnRequestImportInput input) |
|
|
|
{ |
|
|
|
//通过箱标签 查找标签服务 构造其他字段
|
|
|
|
|
|
|
|
var label = await _inventoryLabelApp.GetByCodeAsync(input.PackingCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (label != null) |
|
|
|
{ |
|
|
|
detail.PoNumber = label.PoNumber; |
|
|
|
} |
|
|
|
|
|
|
|
var balance = await BalanceAclService.GetByPackingCodeAsync(input.PackingCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
if (balance != null) |
|
|
|
{ |
|
|
|
detail.PackingCode = balance.PackingCode; |
|
|
|
detail.ContainerCode = balance.ContainerCode; |
|
|
|
detail.LocationCode = balance.LocationCode; |
|
|
|
detail.LocationErpCode = balance.LocationErpCode; |
|
|
|
detail.WarehouseCode = balance.WarehouseCode; |
|
|
|
detail.Status = balance.Status; |
|
|
|
detail.Lot = balance.Lot; |
|
|
|
detail.SupplierBatch = balance.SupplierBatch; |
|
|
|
detail.ArriveDate = balance.ArriveDate; |
|
|
|
detail.ProduceDate = balance.ProduceDate; |
|
|
|
detail.ExpireDate = balance.ExpireDate; |
|
|
|
detail.ItemName = balance.ItemName; |
|
|
|
detail.ItemDesc1 = balance.ItemDesc1; |
|
|
|
detail.ItemDesc2 = balance.ItemDesc2; |
|
|
|
detail.StdPackQty = balance.StdPackQty; |
|
|
|
|
|
|
|
detail.Qty = balance.Qty; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SetEntityPropertiesAsync(PurchaseReturnRequest entity, PurchaseReturnRequestImportInput input) |
|
|
|
{ |
|
|
|
entity.Worker = CurrentUser.GetUserName(); |
|
|
|
|
|
|
|
//通过箱标签 查找标签服务 构造其他字段
|
|
|
|
|
|
|
|
var label = await _inventoryLabelApp.GetByCodeAsync(input.PackingCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
Check.NotNull(label, nameof(InventoryLabel)); |
|
|
|
|
|
|
|
entity.RpNumber = label.RpNumber; |
|
|
|
entity.AsnNumber = label.AsnNumber; |
|
|
|
entity.PoNumber = label.PoNumber; |
|
|
|
|
|
|
|
var balance = await BalanceAclService.GetByPackingCodeAsync(input.PackingCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
Check.NotNull(balance, nameof(BalanceDTO)); |
|
|
|
|
|
|
|
//var order = await this._orderAppService.GetByNumberAsync(label.PoNumber);
|
|
|
|
|
|
|
|
//Check.NotNull(order, nameof(PurchaseOrder));
|
|
|
|
|
|
|
|
entity.SupplierCode = label.SupplierCode; |
|
|
|
|
|
|
|
entity.ReturnTime = DateTime.Now; |
|
|
|
|
|
|
|
await SetRequestAutoPropertiesAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task SetRequestAutoPropertiesAsync(PurchaseReturnRequest entity) |
|
|
|
{ |
|
|
|
var tranType = await TransactionTypeAclService.GetByTransTypeAsync(EnumTransType.PurchaseReturn, EnumTransSubType.None).ConfigureAwait(false); |
|
|
|
|
|
|
|
Check.NotNull(tranType, "事务类型", "事务类型不存在"); |
|
|
|
|
|
|
|
entity.AutoCompleteJob = tranType.AutoCompleteJob; |
|
|
|
entity.AutoSubmit = tranType.AutoSubmitRequest; |
|
|
|
entity.AutoAgree = tranType.AutoAgreeRequest; |
|
|
|
entity.AutoHandle = tranType.AutoHandleRequest; |
|
|
|
entity.DirectCreateNote = tranType.DirectCreateNote; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 被 TransactionTypeHelper.CheckTransactionType()取代
|
|
|
|
/// </summary>
|
|
|
@ -375,4 +322,5 @@ public class PurchaseReturnRequestAppService : |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|