|
@ -3,7 +3,6 @@ using System.Collections.Generic; |
|
|
using System.ComponentModel.DataAnnotations; |
|
|
using System.ComponentModel.DataAnnotations; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
@ -21,9 +20,9 @@ namespace Win_in.Sfs.Wms.Store.Application; |
|
|
|
|
|
|
|
|
[Authorize] |
|
|
[Authorize] |
|
|
[Route($"{StoreConsts.RootPath}purchase-order")] |
|
|
[Route($"{StoreConsts.RootPath}purchase-order")] |
|
|
|
|
|
|
|
|
public class PurchaseOrderAppService : |
|
|
public class PurchaseOrderAppService : |
|
|
SfsStoreWithDetailsAppServiceBase<PurchaseOrder, PurchaseOrderDTO, SfsStoreRequestInputBase, PurchaseOrderEditInput, PurchaseOrderDetail, PurchaseOrderDetailDTO, SfsStoreRequestInputBase, PurchaseOrderImportInput>, |
|
|
SfsStoreWithDetailsAppServiceBase<PurchaseOrder, PurchaseOrderDTO, SfsStoreRequestInputBase, PurchaseOrderEditInput, |
|
|
|
|
|
PurchaseOrderDetail, PurchaseOrderDetailDTO, SfsStoreRequestInputBase, PurchaseOrderImportInput>, |
|
|
IPurchaseOrderAppService |
|
|
IPurchaseOrderAppService |
|
|
{ |
|
|
{ |
|
|
private new readonly IPurchaseOrderRepository _repository; |
|
|
private new readonly IPurchaseOrderRepository _repository; |
|
@ -32,10 +31,9 @@ public class PurchaseOrderAppService : |
|
|
|
|
|
|
|
|
public PurchaseOrderAppService( |
|
|
public PurchaseOrderAppService( |
|
|
IPurchaseOrderRepository repository, |
|
|
IPurchaseOrderRepository repository, |
|
|
|
|
|
|
|
|
IPurchaseOrderManager purchaseOrderManager |
|
|
IPurchaseOrderManager purchaseOrderManager |
|
|
, ISupplierAppService supplierAppService |
|
|
, ISupplierAppService supplierAppService |
|
|
) : base(repository) |
|
|
) : base(repository) |
|
|
{ |
|
|
{ |
|
|
_repository = repository; |
|
|
_repository = repository; |
|
|
_purchaseOrderManager = purchaseOrderManager; |
|
|
_purchaseOrderManager = purchaseOrderManager; |
|
@ -51,13 +49,14 @@ public class PurchaseOrderAppService : |
|
|
/// <param name="input"></param>
|
|
|
/// <param name="input"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("")] |
|
|
[HttpPost("")] |
|
|
//[Authorize(PurchaseOrderPermissions.Create)]
|
|
|
|
|
|
public override async Task<PurchaseOrderDTO> CreateAsync(PurchaseOrderEditInput input) |
|
|
public override async Task<PurchaseOrderDTO> CreateAsync(PurchaseOrderEditInput input) |
|
|
{ |
|
|
{ |
|
|
if (string.IsNullOrWhiteSpace(input.Number)) |
|
|
if (string.IsNullOrWhiteSpace(input.Number)) |
|
|
{ |
|
|
{ |
|
|
input.Number = await _purchaseOrderManager.GenerateNumberAsync(nameof(PurchaseOrder), Clock.Normalize(input.ActiveDate)).ConfigureAwait(false); |
|
|
input.Number = await _purchaseOrderManager |
|
|
|
|
|
.GenerateNumberAsync(nameof(PurchaseOrder), Clock.Normalize(input.ActiveDate)).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var entity = ObjectMapper.Map<PurchaseOrderEditInput, PurchaseOrder>(input); |
|
|
var entity = ObjectMapper.Map<PurchaseOrderEditInput, PurchaseOrder>(input); |
|
|
|
|
|
|
|
|
await _purchaseOrderManager.CreateAsync(entity).ConfigureAwait(false); |
|
|
await _purchaseOrderManager.CreateAsync(entity).ConfigureAwait(false); |
|
@ -65,68 +64,76 @@ public class PurchaseOrderAppService : |
|
|
return ObjectMapper.Map<PurchaseOrder, PurchaseOrderDTO>(entity); |
|
|
return ObjectMapper.Map<PurchaseOrder, PurchaseOrderDTO>(entity); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[HttpPost("{id}/detail")] |
|
|
|
|
|
public virtual async Task UpdateDetailsAsync(string number, List<PurchaseOrderDetailUpdateInput> inputs) |
|
|
|
|
|
{ |
|
|
|
|
|
var entity = await _repository.FindAsync(p => p.Number == number).ConfigureAwait(false); |
|
|
|
|
|
if (entity == null || !entity.Details.Any()) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var input in inputs) |
|
|
|
|
|
{ |
|
|
|
|
|
var detail = entity.Details.FirstOrDefault(p => |
|
|
|
|
|
(string.IsNullOrEmpty(p.PoLine) || p.PoLine == input.PoLine) |
|
|
|
|
|
&& p.ItemCode == input.ItemCode); |
|
|
|
|
|
if (detail == null) |
|
|
|
|
|
{ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
detail.ShippedQty += input.ShippedQty; |
|
|
|
|
|
detail.ReceivedQty += input.ReceivedQty; |
|
|
|
|
|
detail.ReturnedQty += input.ReturnedQty; |
|
|
|
|
|
detail.PutAwayQty += input.PutAwayQty; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await _repository.UpdateAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 【批量创建】到货通知 (收货单)
|
|
|
/// 【批量创建】采购订单
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="inputs"></param>
|
|
|
/// <param name="inputs"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost("create-many")] |
|
|
[HttpPost("create-many")] |
|
|
public async Task<List<PurchaseOrderDTO>> CreateManyAsync(List<PurchaseOrderEditInput> inputs) |
|
|
public async Task<List<PurchaseOrderDTO>> CreateManyAsync(List<PurchaseOrderEditInput> inputs) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
foreach (var input in inputs) |
|
|
foreach (var input in inputs) |
|
|
{ |
|
|
{ |
|
|
if (string.IsNullOrWhiteSpace(input.Number)) |
|
|
if (string.IsNullOrWhiteSpace(input.Number)) |
|
|
{ |
|
|
{ |
|
|
input.Number = await _purchaseOrderManager.GenerateNumberAsync(nameof(PurchaseOrder), Clock.Normalize(input.ActiveDate)).ConfigureAwait(false); |
|
|
input.Number = await _purchaseOrderManager |
|
|
|
|
|
.GenerateNumberAsync(nameof(PurchaseOrder), Clock.Normalize(input.ActiveDate)) |
|
|
|
|
|
.ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var entityList = ObjectMapper.Map<List<PurchaseOrderEditInput>, List<PurchaseOrder>>(inputs); |
|
|
var entityList = ObjectMapper.Map<List<PurchaseOrderEditInput>, List<PurchaseOrder>>(inputs); |
|
|
|
|
|
|
|
|
await _purchaseOrderManager.CreateManyAsync(entityList).ConfigureAwait(false); |
|
|
await _purchaseOrderManager.CreateManyAsync(entityList).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
return ObjectMapper.Map<List<PurchaseOrder>, List<PurchaseOrderDTO>>(entityList); |
|
|
return ObjectMapper.Map<List<PurchaseOrder>, List<PurchaseOrderDTO>>(entityList); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 用来重写 导入数据时可以加工数据
|
|
|
/// 用来重写 导入数据时可以加工数据
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="dictionary"></param>
|
|
|
/// <param name="dictionary"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
protected override Task<Dictionary<PurchaseOrder, EntityState>> ImportProcessingEntityAsync(Dictionary<PurchaseOrder, EntityState> dictionary) |
|
|
protected override Task<Dictionary<PurchaseOrder, EntityState>> ImportProcessingEntityAsync( |
|
|
|
|
|
Dictionary<PurchaseOrder, EntityState> dictionary) |
|
|
{ |
|
|
{ |
|
|
return base.ImportProcessingEntityAsync(dictionary); |
|
|
return base.ImportProcessingEntityAsync(dictionary); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id}/detail")] |
|
|
|
|
|
public virtual async Task UpdateDetailsAsync(string number, List<PurchaseOrderDetailUpdateInput> inputs) |
|
|
|
|
|
{ |
|
|
|
|
|
var entity = await _repository.FindAsync(p => p.Number == number).ConfigureAwait(false); |
|
|
|
|
|
if (entity == null || !entity.Details.Any()) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var input in inputs) |
|
|
|
|
|
{ |
|
|
|
|
|
var detail = entity.Details.FirstOrDefault(p => |
|
|
|
|
|
(string.IsNullOrEmpty(p.PoLine) || p.PoLine == input.PoLine) |
|
|
|
|
|
&& p.ItemCode == input.ItemCode); |
|
|
|
|
|
if (detail == null) |
|
|
|
|
|
{ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
detail.ShippedQty += input.ShippedQty; |
|
|
|
|
|
detail.ReceivedQty += input.ReceivedQty; |
|
|
|
|
|
detail.ReturnedQty += input.ReturnedQty; |
|
|
|
|
|
detail.PutAwayQty += input.PutAwayQty; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await _repository.UpdateAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#region Function
|
|
|
#region Function
|
|
|
|
|
|
|
|
|
[HttpPost("complete/{number}")] |
|
|
[HttpPost("complete/{number}")] |
|
@ -166,12 +173,14 @@ public class PurchaseOrderAppService : |
|
|
await _repository.UpsertAsync(entity).ConfigureAwait(false); |
|
|
await _repository.UpsertAsync(entity).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected virtual async Task CheckImportInputBusinessAsync(PurchaseOrderImportInput importInput, EnumImportMethod importMethod, List<ValidationResult> validationRresult) |
|
|
protected virtual async Task CheckImportInputBusinessAsync(PurchaseOrderImportInput importInput, |
|
|
|
|
|
EnumImportMethod importMethod, List<ValidationResult> validationRresult) |
|
|
{ |
|
|
{ |
|
|
await CheckItemBasicAsync(importInput).ConfigureAwait(false); |
|
|
await CheckItemBasicAsync(importInput).ConfigureAwait(false); |
|
|
await CheckWarehourseAsync(importInput).ConfigureAwait(false); |
|
|
await CheckWarehourseAsync(importInput).ConfigureAwait(false); |
|
|
await CheckSupplierAsync(importInput).ConfigureAwait(false); |
|
|
await CheckSupplierAsync(importInput).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected async Task CheckItemBasicAsync(PurchaseOrderImportInput importInput) |
|
|
protected async Task CheckItemBasicAsync(PurchaseOrderImportInput importInput) |
|
|
{ |
|
|
{ |
|
|
var item = await ItemBasicAclService.GetByCodeAsync(importInput.ItemCode).ConfigureAwait(false); |
|
|
var item = await ItemBasicAclService.GetByCodeAsync(importInput.ItemCode).ConfigureAwait(false); |
|
@ -185,6 +194,7 @@ public class PurchaseOrderAppService : |
|
|
|
|
|
|
|
|
Check.NotNull(item, "仓库代码", "仓库不存在"); |
|
|
Check.NotNull(item, "仓库代码", "仓库不存在"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected async Task CheckSupplierAsync(PurchaseOrderImportInput importInput) |
|
|
protected async Task CheckSupplierAsync(PurchaseOrderImportInput importInput) |
|
|
{ |
|
|
{ |
|
|
var item = await _supplierAppService.GetByCodeAsync(importInput.SupplierCode).ConfigureAwait(false); |
|
|
var item = await _supplierAppService.GetByCodeAsync(importInput.SupplierCode).ConfigureAwait(false); |
|
@ -210,7 +220,8 @@ public class PurchaseOrderAppService : |
|
|
[HttpGet("get-list-by-item-code")] |
|
|
[HttpGet("get-list-by-item-code")] |
|
|
public virtual async Task<List<PurchaseOrderDTO>> GetListByItemCodeAsync(string itemCode) |
|
|
public virtual async Task<List<PurchaseOrderDTO>> GetListByItemCodeAsync(string itemCode) |
|
|
{ |
|
|
{ |
|
|
var entitys = await _repository.GetListAsync(p => p.Details.Any(y => y.ItemCode == itemCode)).ConfigureAwait(false); |
|
|
var entitys = await _repository.GetListAsync(p => p.Details.Any(y => y.ItemCode == itemCode)) |
|
|
|
|
|
.ConfigureAwait(false); |
|
|
|
|
|
|
|
|
var dtos = ObjectMapper.Map<List<PurchaseOrder>, List<PurchaseOrderDTO>>(entitys); |
|
|
var dtos = ObjectMapper.Map<List<PurchaseOrder>, List<PurchaseOrderDTO>>(entitys); |
|
|
|
|
|
|
|
|