|
|
@ -1,20 +1,47 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.EventBus; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
using Win_in.Sfs.Basedata.Application.Contracts; |
|
|
|
using Win_in.Sfs.Label.Application.Contracts; |
|
|
|
using Win_in.Sfs.Label.Domain.Shared; |
|
|
|
using Win_in.Sfs.Shared.Domain; |
|
|
|
using Win_in.Sfs.Shared.Domain.Shared; |
|
|
|
using Win_in.Sfs.Shared.Event; |
|
|
|
using Win_in.Sfs.Wms.Inventory.Domain.Acl.ItemBasic; |
|
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts; |
|
|
|
using Win_in.Sfs.Wms.Store.Domain; |
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.Store.Event.Orders; |
|
|
|
|
|
|
|
public class PurchaseOrderEventHandler |
|
|
|
: StoreEventHandlerBase |
|
|
|
, ILocalEventHandler<SfsCreatedEntityEventData<PurchaseOrder>> |
|
|
|
, ILocalEventHandler<SfsCreatedEntityEventData<List<PurchaseOrder>>> |
|
|
|
: StoreEventHandlerBase |
|
|
|
, ILocalEventHandler<SfsCreatedEntityEventData<PurchaseOrder>> |
|
|
|
, ILocalEventHandler<SfsCreatedEntityEventData<List<PurchaseOrder>>> |
|
|
|
{ |
|
|
|
private const EnumExchangeDataType ExchangeDataType = EnumExchangeDataType.PurchaseOrder; |
|
|
|
private readonly ISupplierAsnAppService _supplierAsnAppService; |
|
|
|
private readonly ILabelDefinitionAppService _labelDefinitionAppService; |
|
|
|
private readonly IItemBasicAppService _itemBasicAppService; |
|
|
|
private readonly IItemPackAppService _itemPackAppService; |
|
|
|
private readonly ISupplierItemAppService _supplierItemAppService; |
|
|
|
private readonly IDockAppService _dockAppService; |
|
|
|
|
|
|
|
public PurchaseOrderEventHandler(ISupplierAsnAppService supplierAsnAppService, |
|
|
|
ILabelDefinitionAppService labelDefinitionAppService, |
|
|
|
IItemBasicAppService itemBasicAppService, |
|
|
|
IItemPackAppService itemPackAppService, |
|
|
|
ISupplierItemAppService supplierItemAppService, |
|
|
|
IDockAppService dockAppService) |
|
|
|
{ |
|
|
|
_supplierAsnAppService = supplierAsnAppService; |
|
|
|
_labelDefinitionAppService = labelDefinitionAppService; |
|
|
|
_itemBasicAppService = itemBasicAppService; |
|
|
|
_itemPackAppService = itemPackAppService; |
|
|
|
_supplierItemAppService = supplierItemAppService; |
|
|
|
_dockAppService = dockAppService; |
|
|
|
} |
|
|
|
|
|
|
|
//创建采购订单
|
|
|
|
[UnitOfWork] |
|
|
@ -22,7 +49,7 @@ public class PurchaseOrderEventHandler |
|
|
|
{ |
|
|
|
var entity = eventData.Entity; |
|
|
|
|
|
|
|
await CreateSupplierAsn(entity); |
|
|
|
await CreateSupplierAsnAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
//批量创建
|
|
|
@ -31,17 +58,86 @@ public class PurchaseOrderEventHandler |
|
|
|
{ |
|
|
|
var entities = eventData.Entity; |
|
|
|
|
|
|
|
entities.ForEach(async p => |
|
|
|
foreach (var entity in entities) |
|
|
|
{ |
|
|
|
await CreateSupplierAsn(p).ConfigureAwait(false); |
|
|
|
}); |
|
|
|
await CreateSupplierAsnAsync(entity).ConfigureAwait(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#region 业务 创建采购订单后>创建收货单
|
|
|
|
#region 业务 创建采购订单后 > 创建收货单
|
|
|
|
|
|
|
|
private async Task CreateSupplierAsn(PurchaseOrder purchaseOrder) |
|
|
|
//创建供应商到货
|
|
|
|
private async Task CreateSupplierAsnAsync(PurchaseOrder purchaseOrder) |
|
|
|
{ |
|
|
|
var supplierAsnDto = await BuildSupplierAsnAsync(purchaseOrder).ConfigureAwait(false); |
|
|
|
|
|
|
|
await _supplierAsnAppService.CreateAsync(supplierAsnDto).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
|
//构造供应商到货DTO
|
|
|
|
private async Task<SupplierAsnEditInput> BuildSupplierAsnAsync(PurchaseOrder purchaseOrder) |
|
|
|
{ |
|
|
|
var supplierAsnEditInput= ObjectMapper.Map<PurchaseOrder, SupplierAsnEditInput>(purchaseOrder); |
|
|
|
|
|
|
|
//收货口 //todo 处理有问题是否要和供应商关联
|
|
|
|
var dock = await _dockAppService.GetAllListByFilterAsync( |
|
|
|
new SfsBaseDataRequestInputBase() { Condition = new Condition(), MaxResultCount = 99, SkipCount = 0, Sorting = string.Empty }, true).ConfigureAwait(false); |
|
|
|
supplierAsnEditInput.DockCode = dock.First().Code; |
|
|
|
|
|
|
|
//要货单号
|
|
|
|
supplierAsnEditInput.RpNumber = "无"; |
|
|
|
|
|
|
|
//生效日期
|
|
|
|
supplierAsnEditInput.ActiveDate = Clock.Now; |
|
|
|
|
|
|
|
//一次性返回所有箱码
|
|
|
|
var generateManyAsync =await _labelDefinitionAppService |
|
|
|
.GenerateManyAsync(EnumLabelType.PurchaseLabel.ToString(), Clock.Now.ToString(SharedConst.TimeFormat), |
|
|
|
supplierAsnEditInput.Details.Count).ConfigureAwait(false); |
|
|
|
|
|
|
|
//所有的物品Code
|
|
|
|
var itemCodes = purchaseOrder.Details.GroupBy(p => p.ItemCode).Select(p => p.Key); |
|
|
|
|
|
|
|
//一次性返回所有物品信息
|
|
|
|
var itemBasicDtos=await _itemBasicAppService.GetByCodesAsync(itemCodes).ConfigureAwait(false); |
|
|
|
var ItemPacks = new List<ItemPackDTO>();//一次性返回所有物品包装信息
|
|
|
|
var supplierItemDtos = new List<SupplierItemDTO>();//一次性返回所有供应商物品信息
|
|
|
|
|
|
|
|
foreach (var itemCode in itemCodes)//查询
|
|
|
|
{ |
|
|
|
var itemPackDtos = await _itemPackAppService.GetListByItemCodeAsync(itemCode).ConfigureAwait(false); |
|
|
|
var itemPackDto = itemPackDtos.First(); |
|
|
|
var supplierItem = await _supplierItemAppService.GetBySupplierCodeAndItemCodeAsync(purchaseOrder.SupplierCode, itemCode).ConfigureAwait(false); |
|
|
|
ItemPacks.Add(itemPackDto); |
|
|
|
supplierItemDtos.Add(supplierItem); |
|
|
|
} |
|
|
|
|
|
|
|
//赋值 详情表
|
|
|
|
supplierAsnEditInput.Details.ForEach(detail => |
|
|
|
{ |
|
|
|
//添加箱码
|
|
|
|
var pakcingCode=generateManyAsync.First(); |
|
|
|
detail.PackingCode = pakcingCode; |
|
|
|
generateManyAsync.Remove(pakcingCode); |
|
|
|
|
|
|
|
//添加物品信息
|
|
|
|
var itemBasicDto= itemBasicDtos.First(p=>p.Code==detail.ItemCode); |
|
|
|
detail.ItemName= itemBasicDto.Name; |
|
|
|
detail.ItemDesc1 = itemBasicDto.Desc1; |
|
|
|
detail.ItemDesc2= itemBasicDto.Desc2; |
|
|
|
|
|
|
|
//标包
|
|
|
|
var itemPack = ItemPacks.First(p => p.ItemCode == detail.ItemCode); //todo 一个物品多个包装?怎么取值
|
|
|
|
detail.StdPackQty = itemPack.Qty; |
|
|
|
|
|
|
|
//供应商物品
|
|
|
|
var supplierItemDto=supplierItemDtos.First(p => |
|
|
|
p.ItemCode == detail.ItemCode && p.SupplierCode == supplierAsnEditInput.SupplierCode); |
|
|
|
detail.SupplierPackQty = supplierItemDto.SupplierPackQty; |
|
|
|
detail.SupplierPackUom= supplierItemDto.SupplierPackUom; |
|
|
|
}); |
|
|
|
|
|
|
|
return supplierAsnEditInput; |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|