|
@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Volo.Abp; |
|
|
using Volo.Abp; |
|
|
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
using Win_in.Sfs.Shared.Domain.Shared; |
|
|
using Win_in.Sfs.Shared.Domain.Shared; |
|
@ -53,32 +54,90 @@ public class PurchaseOrderAppService : |
|
|
protected override async Task<Dictionary<PurchaseOrder, EntityState>> ImportProcessingEntityAsync( |
|
|
protected override async Task<Dictionary<PurchaseOrder, EntityState>> ImportProcessingEntityAsync( |
|
|
Dictionary<PurchaseOrder, EntityState> dictionary) |
|
|
Dictionary<PurchaseOrder, EntityState> dictionary) |
|
|
{ |
|
|
{ |
|
|
var addList = dictionary.Where(p => p.Value == EntityState.Added).Select(p => p.Key); |
|
|
var ImportData = dictionary.Select(p => p.Key); |
|
|
|
|
|
|
|
|
foreach (var purchaseOrder in addList) |
|
|
var supplierDtos = new List<SupplierDTO>(); |
|
|
|
|
|
#region 校验供应商
|
|
|
|
|
|
|
|
|
|
|
|
var allSupplierCode = ImportData.Select(p => p.SupplierCode).ToList();//所有供应商编号
|
|
|
|
|
|
supplierDtos = await CheckSupplierCodeAsync(allSupplierCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
var itemBasicDtos = new List<ItemBasicDTO>(); |
|
|
|
|
|
#region 校验物品
|
|
|
|
|
|
|
|
|
|
|
|
var allTempItemCode = ImportData.Select(p => p.Details.Select(p => p.ItemCode).ToList()).ToList(); |
|
|
|
|
|
var allItemCode = new List<string>(); |
|
|
|
|
|
allTempItemCode.ForEach(p => { allItemCode.AddRange(p); }); |
|
|
|
|
|
itemBasicDtos = await CheckItemCodeAsync(allItemCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var purchaseOrder in ImportData) |
|
|
{ |
|
|
{ |
|
|
purchaseOrder.CreatorId = CurrentUser.Id; |
|
|
purchaseOrder.CreatorId = CurrentUser.Id; |
|
|
purchaseOrder.Worker = CurrentUser.GetName(); |
|
|
purchaseOrder.Worker = CurrentUser.GetName(); |
|
|
|
|
|
|
|
|
var supplierDto = |
|
|
var supplierDto = supplierDtos.First(p => p.Code == purchaseOrder.SupplierCode); |
|
|
await _supplierAppService.GetByCodeAsync(purchaseOrder.SupplierCode).ConfigureAwait(false); |
|
|
|
|
|
purchaseOrder.SupplierCode = supplierDto.Code; |
|
|
purchaseOrder.SupplierCode = supplierDto.Code; |
|
|
purchaseOrder.SupplierAddress = supplierDto.Address; |
|
|
purchaseOrder.SupplierAddress = supplierDto.Address; |
|
|
purchaseOrder.SupplierName = supplierDto.Name; |
|
|
purchaseOrder.SupplierName = supplierDto.Name; |
|
|
|
|
|
|
|
|
foreach (var detail in purchaseOrder.Details) |
|
|
foreach (var detail in purchaseOrder.Details) |
|
|
{ |
|
|
{ |
|
|
var itemBasicDto = await _itemBasicAppService.GetByCodeAsync(detail.ItemCode).ConfigureAwait(false); |
|
|
var itemBasicDto = itemBasicDtos.First(p => p.Code == detail.ItemCode); |
|
|
|
|
|
|
|
|
detail.ItemName = itemBasicDto.Name; |
|
|
detail.ItemName = itemBasicDto.Name; |
|
|
detail.ItemDesc1 = itemBasicDto.Desc1; |
|
|
detail.ItemDesc1 = itemBasicDto.Desc1; |
|
|
detail.ItemDesc2 = itemBasicDto.Desc2; |
|
|
detail.ItemDesc2 = itemBasicDto.Desc2; |
|
|
|
|
|
detail.StdPackQty=itemBasicDto.StdPackQty; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return dictionary; |
|
|
return dictionary; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region 校验
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 校验所有供应商是否存在
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private async Task<List<SupplierDTO>> CheckSupplierCodeAsync(List<string> supplierCodes) |
|
|
|
|
|
{ |
|
|
|
|
|
supplierCodes = supplierCodes.Distinct().ToList(); |
|
|
|
|
|
var result = await _supplierAppService.GetByCodesAsync(supplierCodes).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var supplierCode in supplierCodes) |
|
|
|
|
|
{ |
|
|
|
|
|
if (result.All(p => p.Code != supplierCode)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"供应商代码【{supplierCode}】不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task<List<ItemBasicDTO>> CheckItemCodeAsync(List<string> itemCodes) |
|
|
|
|
|
{ |
|
|
|
|
|
itemCodes = itemCodes.Distinct().ToList(); |
|
|
|
|
|
var result = await _itemBasicAppService.GetByCodesAsync(itemCodes).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var itemCode in itemCodes) |
|
|
|
|
|
{ |
|
|
|
|
|
if (result.All(p => p.Code != itemCode)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"供应商代码【{itemCode}】不存在"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -237,12 +296,12 @@ public class PurchaseOrderAppService : |
|
|
[HttpGet("get-list-by-supplier-code-and-item-code")] |
|
|
[HttpGet("get-list-by-supplier-code-and-item-code")] |
|
|
public virtual async Task<List<PurchaseOrderDTO>> GetListBySupplierCodeAsync(string supplierCode, string itemCode) |
|
|
public virtual async Task<List<PurchaseOrderDTO>> GetListBySupplierCodeAsync(string supplierCode, string itemCode) |
|
|
{ |
|
|
{ |
|
|
var entitys = await _repository.GetListAsync(p => p.Details.Any(y => y.ItemCode == itemCode) && p.SupplierCode == supplierCode).ConfigureAwait(false); |
|
|
var entitys = await _repository |
|
|
|
|
|
.GetListAsync(p => p.Details.Any(y => y.ItemCode == itemCode) && p.SupplierCode == supplierCode) |
|
|
|
|
|
.ConfigureAwait(false); |
|
|
|
|
|
|
|
|
var dtos = ObjectMapper.Map<List<PurchaseOrder>, List<PurchaseOrderDTO>>(entitys); |
|
|
var dtos = ObjectMapper.Map<List<PurchaseOrder>, List<PurchaseOrderDTO>>(entitys); |
|
|
|
|
|
|
|
|
return dtos; |
|
|
return dtos; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|