|
@ -13,6 +13,7 @@ using Win_in.Sfs.Shared.Event; |
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts; |
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts; |
|
|
using Win_in.Sfs.Wms.Store.Domain; |
|
|
using Win_in.Sfs.Wms.Store.Domain; |
|
|
using Win_in.Sfs.Wms.Store.Domain.Shared; |
|
|
using Win_in.Sfs.Wms.Store.Domain.Shared; |
|
|
|
|
|
using static Win_in.Sfs.Wms.Store.Domain.Shared.StoreSettings; |
|
|
using SupplierAsn = Win_in.Sfs.Wms.Store.Domain.SupplierAsn; |
|
|
using SupplierAsn = Win_in.Sfs.Wms.Store.Domain.SupplierAsn; |
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.Store.Event.Stores; |
|
|
namespace Win_in.Sfs.Wms.Store.Event.Stores; |
|
@ -54,22 +55,11 @@ public class SupplierAsnEventHandler |
|
|
{ |
|
|
{ |
|
|
var entity = eventData.Entity; |
|
|
var entity = eventData.Entity; |
|
|
|
|
|
|
|
|
switch (entity.CreateType) |
|
|
//更新采购订单收货数量
|
|
|
{ |
|
|
await UpdatePurchaseOrderAsync(entity).ConfigureAwait(false); |
|
|
case EnumSupplierAsnCreateType.Import: |
|
|
|
|
|
//创建标签
|
|
|
|
|
|
await CreateLabelAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumSupplierAsnCreateType.AppService: |
|
|
|
|
|
case EnumSupplierAsnCreateType.ExternalInterface: |
|
|
|
|
|
default: |
|
|
|
|
|
//更新订单已收货数量
|
|
|
|
|
|
await UpdatePurchaseOrderAsync(entity).ConfigureAwait(false); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//创建收货请求(到货通知)
|
|
|
//创建收货请求(到货通知)
|
|
|
//await CreatePurchaseReceiptRequestAsync(entity).ConfigureAwait(false);
|
|
|
await CreatePurchaseReceiptRequestAsync(entity).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -84,23 +74,8 @@ public class SupplierAsnEventHandler |
|
|
|
|
|
|
|
|
foreach (var supplierAsn in entityList) |
|
|
foreach (var supplierAsn in entityList) |
|
|
{ |
|
|
{ |
|
|
switch (supplierAsn.CreateType) |
|
|
//更新采购订单收货数量
|
|
|
{ |
|
|
await UpdatePurchaseOrderAsync(supplierAsn).ConfigureAwait(false); |
|
|
case EnumSupplierAsnCreateType.Import: |
|
|
|
|
|
|
|
|
|
|
|
//创建采购订单
|
|
|
|
|
|
await CreatePurchaseOrderAsync(supplierAsn).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
//创建标签
|
|
|
|
|
|
await CreateLabelAsync(supplierAsn).ConfigureAwait(false); |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumSupplierAsnCreateType.AppService: |
|
|
|
|
|
case EnumSupplierAsnCreateType.ExternalInterface: |
|
|
|
|
|
default: |
|
|
|
|
|
//更新订单已收货数量
|
|
|
|
|
|
await UpdatePurchaseOrderAsync(supplierAsn).ConfigureAwait(false); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//创建收货请求(到货通知)
|
|
|
//创建收货请求(到货通知)
|
|
|
await CreatePurchaseReceiptRequestAsync(supplierAsn).ConfigureAwait(false); |
|
|
await CreatePurchaseReceiptRequestAsync(supplierAsn).ConfigureAwait(false); |
|
@ -109,12 +84,7 @@ public class SupplierAsnEventHandler |
|
|
|
|
|
|
|
|
#region 私有
|
|
|
#region 私有
|
|
|
|
|
|
|
|
|
#region 收货请求
|
|
|
// 创建 收货请求(到货通知)
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建 收货请求(到货通知)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="supplierAsn"></param>
|
|
|
|
|
|
private async Task CreatePurchaseReceiptRequestAsync(SupplierAsn supplierAsn) |
|
|
private async Task CreatePurchaseReceiptRequestAsync(SupplierAsn supplierAsn) |
|
|
{ |
|
|
{ |
|
|
//开关控制 创建收货请求(到货通知)
|
|
|
//开关控制 创建收货请求(到货通知)
|
|
@ -126,205 +96,33 @@ public class SupplierAsnEventHandler |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
// 构造 收货请求
|
|
|
/// 构造 收货请求
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="supplierAsn"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private PurchaseReceiptRequestEditInput BuildPurchaseReceiptRequestCreateInput(SupplierAsn supplierAsn) |
|
|
private PurchaseReceiptRequestEditInput BuildPurchaseReceiptRequestCreateInput(SupplierAsn supplierAsn) |
|
|
{ |
|
|
{ |
|
|
var input = ObjectMapper.Map<SupplierAsn, PurchaseReceiptRequestEditInput>(supplierAsn); |
|
|
var input = ObjectMapper.Map<SupplierAsn, PurchaseReceiptRequestEditInput>(supplierAsn); |
|
|
return input; |
|
|
return input; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endregion
|
|
|
// 更新采购订单中的发货数量
|
|
|
|
|
|
private async Task UpdatePurchaseOrderAsync(SupplierAsn entity) |
|
|
#region 采购订单
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建 采购订单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="supplierAsn"></param>
|
|
|
|
|
|
private async Task<PurchaseOrderDTO> CreatePurchaseOrderAsync(SupplierAsn supplierAsn) |
|
|
|
|
|
{ |
|
|
|
|
|
//开关控制 创建采购订单
|
|
|
|
|
|
if (await SettingManager.IsTrueAsync(StoreSettings.SupplierAsn.AutoCreatePurchaseOrder).ConfigureAwait(false)) |
|
|
|
|
|
{ |
|
|
|
|
|
var createInput = await BulidPurchaseOrderAsync(supplierAsn).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
return await _purchaseOrderAppService.CreateAsync(createInput).ConfigureAwait(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构造 采购订单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="inputEntity"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private async Task<PurchaseOrderEditInput> BulidPurchaseOrderAsync(SupplierAsn inputEntity) |
|
|
|
|
|
{ |
|
|
{ |
|
|
await Task.CompletedTask.ConfigureAwait(false); |
|
|
var purchaseOrderDetailUpdateInputs = new List<PurchaseOrderDetailUpdateInput>(); |
|
|
//创建采购订单
|
|
|
|
|
|
var purchaseOrderCreateInput = ObjectMapper.Map<SupplierAsn, PurchaseOrderEditInput>(inputEntity); |
|
|
|
|
|
|
|
|
|
|
|
var group = inputEntity.Details.GroupBy(p => new { p.ItemCode, p.RecommendErpCode, p.PoLine, p.ProjectCode }); |
|
|
foreach (var detail in entity.Details) |
|
|
foreach (var groupKey in group) |
|
|
|
|
|
{ |
|
|
{ |
|
|
//样板数据
|
|
|
var purchaseOrderDetailUpdateInput=new PurchaseOrderDetailUpdateInput() |
|
|
var templateData = inputEntity.Details.First(p => |
|
|
|
|
|
groupKey.Key.ItemCode == p.ItemCode && |
|
|
|
|
|
groupKey.Key.RecommendErpCode == p.RecommendErpCode && |
|
|
|
|
|
p.PoLine == groupKey.Key.PoLine && |
|
|
|
|
|
p.ProjectCode == groupKey.Key.ProjectCode); |
|
|
|
|
|
//汇总数量
|
|
|
|
|
|
var sumQty = inputEntity.Details.Where(p => |
|
|
|
|
|
groupKey.Key.ItemCode == p.ItemCode && |
|
|
|
|
|
groupKey.Key.RecommendErpCode == p.RecommendErpCode && |
|
|
|
|
|
p.PoLine == groupKey.Key.PoLine && |
|
|
|
|
|
p.ProjectCode == groupKey.Key.ProjectCode) |
|
|
|
|
|
.Sum(p => p.Qty); |
|
|
|
|
|
//创建明细
|
|
|
|
|
|
var purchaseOrderDetailInput = new PurchaseOrderDetailInput() |
|
|
|
|
|
{ |
|
|
{ |
|
|
ItemCode = groupKey.Key.ItemCode, |
|
|
PoLine = detail.PoLine, |
|
|
Qty = sumQty, |
|
|
ItemCode = detail.ItemCode, |
|
|
Uom = templateData.Uom, |
|
|
ShippedQty = detail.Qty, |
|
|
ItemName = templateData.ItemName, |
|
|
|
|
|
Remark = templateData.Remark, |
|
|
|
|
|
ItemDesc2 = templateData.ItemDesc2, |
|
|
|
|
|
ItemDesc1 = templateData.ItemDesc1, |
|
|
|
|
|
LocationErpCode = groupKey.Key.RecommendErpCode, |
|
|
|
|
|
StdPackQty = templateData.StdPackQty, |
|
|
|
|
|
ConvertRate = 0, |
|
|
|
|
|
IsConsignment = true, |
|
|
|
|
|
LineStatus = EnumOrderStatus.Open, |
|
|
|
|
|
PoLine = templateData.PoLine, |
|
|
|
|
|
ProjectCode = templateData.ProjectCode, |
|
|
|
|
|
SupplierPackQty = templateData.SupplierPackQty, |
|
|
|
|
|
SupplierPackUom = templateData.SupplierPackUom, |
|
|
|
|
|
ShippedQty = sumQty, |
|
|
|
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
purchaseOrderCreateInput.Details.Add(purchaseOrderDetailInput); |
|
|
purchaseOrderDetailUpdateInputs.Add(purchaseOrderDetailUpdateInput); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return purchaseOrderCreateInput; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 创建标签
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建 采购收货标签
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private async Task<List<InventoryLabelDto>> CreateLabelAsync(SupplierAsn supplierAsn) |
|
|
|
|
|
{ |
|
|
|
|
|
List<InventoryLabelDto> inventoryLabelDtos = new List<InventoryLabelDto>(); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var supplierAsnDetail in supplierAsn.Details) |
|
|
|
|
|
{ |
|
|
|
|
|
var inputLabel = await BuildInventoryLabelCreateInputAsync(supplierAsn, supplierAsnDetail).ConfigureAwait(false); |
|
|
|
|
|
var labelDto = await _inventoryLabelService.CreateAsync(inputLabel).ConfigureAwait(false); |
|
|
|
|
|
inventoryLabelDtos.Add(labelDto); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return inventoryLabelDtos; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 创建 构造标签
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="supplierAsn"></param>
|
|
|
|
|
|
/// <param name="supplierAsnDetail"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
private async Task<InventoryLabelEditInput> BuildInventoryLabelCreateInputAsync(SupplierAsn supplierAsn, SupplierAsnDetail supplierAsnDetail) |
|
|
|
|
|
{ |
|
|
|
|
|
var itemDto = await ItemBasicAclService.GetByCodeAsync(supplierAsnDetail.ItemCode).ConfigureAwait(false); |
|
|
|
|
|
var supplierItem = |
|
|
|
|
|
await _supplierItemAppService.GetBySupplierCodeAndItemCodeAsync(supplierAsn.SupplierCode, |
|
|
|
|
|
itemDto.Code).ConfigureAwait(false); |
|
|
|
|
|
var supplier = await _supplierAppService.GetByCodeAsync(supplierAsn.SupplierCode).ConfigureAwait(false); |
|
|
|
|
|
|
|
|
|
|
|
if (itemDto == null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"{supplierAsnDetail.ItemCode}零件信息为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (supplier == null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"{supplierAsn.SupplierCode}供应商为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (supplierItem == null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"{supplierAsn.SupplierCode}供应商零件或{itemDto.Code}零件信息为空"); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var inputLabel = new InventoryLabelEditInput() |
|
|
|
|
|
{ |
|
|
|
|
|
LabelType = EnumLabelType.PurchaseLabel, |
|
|
|
|
|
ArriveDate = DateTime.Now, |
|
|
|
|
|
Qty = supplierAsnDetail.Qty, |
|
|
|
|
|
PoNumber = supplierAsnDetail.PoNumber, |
|
|
|
|
|
Uom = supplierAsnDetail.Uom, |
|
|
|
|
|
ItemDesc2 = itemDto.Desc2, |
|
|
|
|
|
AsnNumber = supplierAsnDetail.Number, |
|
|
|
|
|
ItemCode = supplierAsnDetail.ItemCode, |
|
|
|
|
|
ItemName = supplierAsnDetail.ItemName, |
|
|
|
|
|
ItemDesc1 = itemDto.Desc1, |
|
|
|
|
|
SupplierBatch = supplierAsnDetail.SupplierBatch, |
|
|
|
|
|
ProduceDate = supplierAsnDetail.ProduceDate, |
|
|
|
|
|
ExpireDate = DateTime.Now.AddDays(itemDto.GetValidateDays()), |
|
|
|
|
|
FullBarcodeString = supplierAsnDetail.PackingCode, |
|
|
|
|
|
ExtraProperties = { }, |
|
|
|
|
|
LabelStatus = LabelStatus.Enable, |
|
|
|
|
|
LocationErpCode = supplierAsnDetail.RecommendErpCode, |
|
|
|
|
|
Lot = supplierAsnDetail.Lot, |
|
|
|
|
|
RecommendLocationCode = supplierAsnDetail.RecommendErpCode, |
|
|
|
|
|
Remark = supplierAsnDetail.Remark, |
|
|
|
|
|
Specifications = itemDto.Color, |
|
|
|
|
|
StdPackQty = supplierAsnDetail.StdPackQty, |
|
|
|
|
|
SupplierCode = supplierAsn.SupplierCode, |
|
|
|
|
|
SupplierItemCode = supplierItem.SupplierItemCode, |
|
|
|
|
|
SupplierItemName = supplierItem.ItemName, |
|
|
|
|
|
SupplierName = supplier.Name, |
|
|
|
|
|
SupplierSimpleName = supplier.ShortName, |
|
|
|
|
|
Team = null, |
|
|
|
|
|
ProdLine = null, |
|
|
|
|
|
QLevel = null, |
|
|
|
|
|
QualityFile = null, |
|
|
|
|
|
RpNumber = null, |
|
|
|
|
|
Shift = null, |
|
|
|
|
|
ContainerCode = null, |
|
|
|
|
|
Code = supplierAsnDetail.PackingCode |
|
|
|
|
|
}; |
|
|
|
|
|
return inputLabel; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
private async Task UpdatePurchaseOrderAsync(SupplierAsn entity) |
|
|
|
|
|
{ |
|
|
|
|
|
var purchaseOrderDetailUpdateInputs = entity.Details |
|
|
|
|
|
.Select(BuildPurchaseOrderDetailUpdateInput).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
await _purchaseOrderAppService.UpdateDetailsAsync(entity.PoNumber, purchaseOrderDetailUpdateInputs).ConfigureAwait(false); |
|
|
await _purchaseOrderAppService.UpdateDetailsAsync(entity.PoNumber, purchaseOrderDetailUpdateInputs).ConfigureAwait(false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static PurchaseOrderDetailUpdateInput BuildPurchaseOrderDetailUpdateInput(SupplierAsnDetail supplierAsnDetail) |
|
|
|
|
|
{ |
|
|
|
|
|
return new PurchaseOrderDetailUpdateInput() |
|
|
|
|
|
{ |
|
|
|
|
|
PoLine = supplierAsnDetail.PoLine, |
|
|
|
|
|
ItemCode = supplierAsnDetail.ItemCode, |
|
|
|
|
|
ShippedQty = supplierAsnDetail.Qty, |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|