You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
9.4 KiB
223 lines
9.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.ObjectMapping;
|
|
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.Wms.DataExchange.Domain;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
|
|
using Win_in.Sfs.Wms.DataExchange.WMS.SuppplierAsn;
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
using Win_in.Sfs.Wms.Store.Domain;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent;
|
|
|
|
public class ShipConverter : IIncomingConverter
|
|
{
|
|
private readonly IIncomingFromExternalManager _incomingFromExternalManager;
|
|
private readonly IIncomingToWmsManager _incomingToWmsManager;
|
|
private readonly IObjectMapper _objectMapper;
|
|
private readonly IItemBasicAppService _itemBasicAppService;
|
|
private readonly IItemPackAppService _itemPackAppService;
|
|
private readonly ILogger<ShipConverter> _logger;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ISupplierAppService _supplierAppService;
|
|
|
|
|
|
public ShipConverter(
|
|
IIncomingToWmsManager incomingToWmsManager
|
|
, IObjectMapper objectMapper
|
|
, IItemBasicAppService itemBasicAppService
|
|
, IItemPackAppService itemPackAppService
|
|
, ILogger<ShipConverter> logger,
|
|
IConfiguration configuration,
|
|
IIncomingFromExternalManager incomingFromExternalManager,
|
|
ISupplierAppService supplierAppService)
|
|
{
|
|
_incomingFromExternalManager = incomingFromExternalManager;
|
|
_incomingToWmsManager = incomingToWmsManager;
|
|
_objectMapper = objectMapper;
|
|
_itemBasicAppService = itemBasicAppService;
|
|
_itemPackAppService = itemPackAppService;
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
_supplierAppService = supplierAppService;
|
|
|
|
}
|
|
|
|
public virtual async Task ConvertAsync(List<IncomingFromExternal> incomingFromExternalList)
|
|
{
|
|
if (!incomingFromExternalList.Any())
|
|
{
|
|
_logger.LogInformation("no ships");
|
|
return;
|
|
}
|
|
|
|
//按ShipBillNo合并SupplierAsn
|
|
var supplierAsnList = await BuildIncomingToWmsOfSupplierAsnAsync(incomingFromExternalList).ConfigureAwait(false);
|
|
await _incomingToWmsManager.CreateManyAsync(supplierAsnList).ConfigureAwait(false);
|
|
|
|
var purchaseLabelList = await BuildIncomingToWmsOfPurchaseLabelAsync(incomingFromExternalList).ConfigureAwait(false);
|
|
await _incomingToWmsManager.CreateManyAsync(purchaseLabelList).ConfigureAwait(false);
|
|
//归档
|
|
await _incomingFromExternalManager.ArchiveManyAsync(incomingFromExternalList).ConfigureAwait(false);
|
|
}
|
|
|
|
private async Task<List<IncomingToWms>> BuildIncomingToWmsOfPurchaseLabelAsync(List<IncomingFromExternal> incomingFromExternalList)
|
|
{
|
|
var incomingToWmsList = new List<IncomingToWms>();
|
|
|
|
foreach (var incomingFromExternal in incomingFromExternalList)
|
|
{
|
|
var incomingToWms = new IncomingToWms()
|
|
{
|
|
DataType = EnumIncomingDataType.PurchaseLabel.ToString(),
|
|
DataAction = incomingFromExternal.DataAction,
|
|
SourceSystem = incomingFromExternal.SourceSystem,
|
|
DataIdentityCode = incomingFromExternal.SourceDataDetailCode,
|
|
};
|
|
incomingToWms.SetEffectiveDate(incomingFromExternal.EffectiveDate);
|
|
var exchangeAsn = JsonSerializer.Deserialize<SupplierAsnExchangeDto>(incomingFromExternal.DestinationDataContent);
|
|
var purchaseLabel = await BuildPurchaseLabelCreateDto(exchangeAsn).ConfigureAwait(false);
|
|
incomingToWms.DataContent = JsonSerializer.Serialize(purchaseLabel);
|
|
incomingToWmsList.Add(incomingToWms);
|
|
|
|
}
|
|
|
|
return incomingToWmsList;
|
|
}
|
|
|
|
private async Task<InventoryLabelEditInput> BuildPurchaseLabelCreateDto(SupplierAsnExchangeDto exchangeAsn)
|
|
{
|
|
var purchaseLabel = _objectMapper.Map<SupplierAsnDetailExchangeDto, InventoryLabelEditInput>(exchangeAsn.Detail);
|
|
purchaseLabel.AsnNumber = exchangeAsn.Number;
|
|
purchaseLabel.RpNumber = "";
|
|
var item = await _itemBasicAppService.GetByCodeAsync(purchaseLabel.ItemCode).ConfigureAwait(false);
|
|
if (item != null)
|
|
{
|
|
purchaseLabel.ItemName = item.Name;
|
|
purchaseLabel.ItemDesc1 = item.Desc1;
|
|
purchaseLabel.Uom = item.BasicUom;
|
|
purchaseLabel.ItemDesc2 = item.Desc2;
|
|
}
|
|
else
|
|
{
|
|
purchaseLabel.ItemName = "";
|
|
purchaseLabel.ItemDesc1 = "";
|
|
purchaseLabel.Uom = "";
|
|
purchaseLabel.ItemDesc2 = "";
|
|
}
|
|
purchaseLabel.LabelType = EnumLabelType.PurchaseLabel;
|
|
var supplierDto = await _supplierAppService.GetByCodeAsync(exchangeAsn.SupplierCode).ConfigureAwait(false);
|
|
purchaseLabel.SupplierCode = exchangeAsn.SupplierCode;
|
|
purchaseLabel.PoNumber = exchangeAsn.Number;
|
|
purchaseLabel.Qty = exchangeAsn.Detail.Qty;
|
|
|
|
|
|
|
|
purchaseLabel.ProduceDate = exchangeAsn.Detail.ProduceDate;
|
|
purchaseLabel.ArriveDate = exchangeAsn.Detail.ArriveDate;
|
|
purchaseLabel.FullBarcodeString = exchangeAsn.Detail.PackingCode;
|
|
purchaseLabel.LocationErpCode = exchangeAsn.Detail.LocationErpCode;
|
|
purchaseLabel.Lot = exchangeAsn.Detail.Lot;
|
|
purchaseLabel.RecommendLocationCode = exchangeAsn.Detail.LocationErpCode;
|
|
purchaseLabel.Remark = exchangeAsn.Detail.Remark;
|
|
purchaseLabel.Code = exchangeAsn.Detail.PackingCode;
|
|
purchaseLabel.PlanArriveDate = exchangeAsn.PlanArriveDate;
|
|
|
|
purchaseLabel.SupplierItemCode = exchangeAsn.Detail.SupplierItemCode;
|
|
purchaseLabel.SupplierItemName = exchangeAsn.Detail.SupplierItemName;
|
|
|
|
|
|
purchaseLabel.ExpireDate = DateTime.Now.AddDays(item.GetValidateDays());
|
|
purchaseLabel.ExtraProperties = new ExtraPropertyDictionary();
|
|
purchaseLabel.LabelStatus = LabelStatus.Enable;
|
|
purchaseLabel.Specifications = item.Color;
|
|
purchaseLabel.StdPackQty = item.StdPackQty;
|
|
purchaseLabel.SupplierName = supplierDto.Name;
|
|
purchaseLabel.SupplierSimpleName = supplierDto.ShortName;
|
|
purchaseLabel.Team = string.Empty;
|
|
purchaseLabel.ProdLine = string.Empty;
|
|
purchaseLabel.QLevel = string.Empty;
|
|
purchaseLabel.QualityFile = string.Empty;
|
|
purchaseLabel.Shift = string.Empty;
|
|
purchaseLabel.ContainerCode = string.Empty;
|
|
|
|
purchaseLabel.RpNumber = string.Empty;
|
|
purchaseLabel.SupplierBatch = string.Empty;
|
|
|
|
return purchaseLabel;
|
|
}
|
|
|
|
private async Task<List<IncomingToWms>> BuildIncomingToWmsOfSupplierAsnAsync(List<IncomingFromExternal> incomingDataList)
|
|
{
|
|
var incomingToWmsList = new List<IncomingToWms>();
|
|
var groups = incomingDataList.GroupBy(p => p.SourceDataGroupCode);
|
|
foreach (var group in groups)
|
|
{
|
|
var first = group.First();
|
|
var incomingToWms = new IncomingToWms()
|
|
{
|
|
DataType = first.DataType,
|
|
DataAction = first.DataAction,
|
|
SourceSystem = first.SourceSystem,
|
|
DataIdentityCode = first.SourceDataGroupCode,
|
|
};
|
|
incomingToWms.SetEffectiveDate(first.EffectiveDate);
|
|
var exchangeAsn = JsonSerializer.Deserialize<SupplierAsnExchangeDto>(first.DestinationDataContent);
|
|
var wmsAsn = await BuildSupplierAsnCreateInput(exchangeAsn, group).ConfigureAwait(false);
|
|
incomingToWms.DataContent = JsonSerializer.Serialize(wmsAsn);
|
|
incomingToWmsList.Add(incomingToWms);
|
|
}
|
|
return incomingToWmsList;
|
|
}
|
|
|
|
private async Task<SupplierAsnEditInput> BuildSupplierAsnCreateInput(SupplierAsnExchangeDto exchangeAsn, IGrouping<string, IncomingFromExternal> group)
|
|
{
|
|
var wmsAsn = _objectMapper.Map<SupplierAsnExchangeDto, SupplierAsnEditInput>(exchangeAsn);
|
|
wmsAsn.Details = new List<SupplierAsnDetailInput>();
|
|
wmsAsn.RpNumber = "";
|
|
wmsAsn.DockCode = "";
|
|
wmsAsn.Remark = "";
|
|
wmsAsn.TimeWindow = "";
|
|
|
|
foreach (var incomingFromExternal in group.ToList())
|
|
{
|
|
var asn = JsonSerializer.Deserialize<SupplierAsnExchangeDto>(incomingFromExternal.DestinationDataContent);
|
|
var wmsAsnDetail = await BuildSupplierAsnDetailInput(asn).ConfigureAwait(false);
|
|
|
|
wmsAsn.Details.Add(wmsAsnDetail);
|
|
}
|
|
|
|
return wmsAsn;
|
|
}
|
|
|
|
private async Task<SupplierAsnDetailInput> BuildSupplierAsnDetailInput(SupplierAsnExchangeDto asn)
|
|
{
|
|
var wmsAsnDetail = _objectMapper.Map<SupplierAsnDetailExchangeDto, SupplierAsnDetailInput>(asn.Detail);
|
|
wmsAsnDetail.PoLine = "";
|
|
wmsAsnDetail.ConvertRate = 1;
|
|
wmsAsnDetail.ExpireDate = DateTime.MaxValue;
|
|
|
|
var item = await _itemBasicAppService.GetByCodeAsync(wmsAsnDetail.ItemCode).ConfigureAwait(false);
|
|
|
|
if (item != null)
|
|
{
|
|
wmsAsnDetail.ItemName = item.Name;
|
|
wmsAsnDetail.ItemDesc1 = item.Desc1;
|
|
wmsAsnDetail.ItemDesc2 = item.Desc2;
|
|
wmsAsnDetail.SupplierPackUom = item.BasicUom;
|
|
wmsAsnDetail.SupplierPackQty = item.StdPackQty;
|
|
wmsAsnDetail.StdPackQty = item.StdPackQty;
|
|
|
|
}
|
|
|
|
return wmsAsnDetail;
|
|
}
|
|
}
|
|
|