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.
 
 
 
 
 
 

111 lines
4.9 KiB

using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using Volo.Abp.ObjectMapping;
using Win_in.Sfs.Wms.DataExchange.Domain;
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.EOS;
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
using Win_in.Sfs.Wms.DataExchange.WMS.PurchaseReceipt;
using Win_in.Sfs.Wms.Store.Application.Contracts;
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.EosAgent;
public class ArriveConverter : IOutgoingConverter
{
private readonly IOutgoingFromWmsManager _outgoingFromWmsManager;
private readonly IOutgoingToExternalManager _outgoingToExternalManager;
private readonly ISupplierAsnAppService _supplierAsnAppService;
private readonly IObjectMapper _objectMapper;
public ArriveConverter(
IOutgoingFromWmsManager outgoingFromWmsManager
, IOutgoingToExternalManager outgoingToExternalManager
, ISupplierAsnAppService supplierAsnAppService
, IObjectMapper objectMapper
)
{
_outgoingFromWmsManager = outgoingFromWmsManager;
_outgoingToExternalManager = outgoingToExternalManager;
_supplierAsnAppService = supplierAsnAppService;
_objectMapper = objectMapper;
}
public virtual async Task<List<OutgoingToExternal>> ConvertAsync()
{
var outgoingToExternalList = new List<OutgoingToExternal>();
var outgoingFromWmsList = await _outgoingFromWmsManager.GetToBeProcessedListAsync(EnumOutgoingDataType.PurchaseReceipt, EnumSystemType.EOS).ConfigureAwait(false);
foreach (var outgoingFromWms in outgoingFromWmsList)
{
var wmsReceipt = JsonSerializer.Deserialize<PurchaseReceiptNoteDTO>(outgoingFromWms.DataContent);
foreach (var detail in wmsReceipt.Details)
{
var outgoingToExternal = new OutgoingToExternal()
{
DataType = outgoingFromWms.DataType,
DataAction = outgoingFromWms.DataAction,
SourceSystem = EnumSystemType.WMS.ToString(),
SourceDataId = detail.Id.ToString(),
SourceDataGroupCode = wmsReceipt.Number,
SourceDataDetailCode = detail.PackingCode,
Writer = nameof(EosOutgoingBackgroundWorker),
DestinationSystem = EnumSystemType.SCP.ToString(),
DestinationDataId = "",
};
outgoingToExternal.SetEffectiveDate(outgoingFromWms.EffectiveDate);
var exchangeReceipt = await BuildPurchaseReceiptExchangeDtoAsync(wmsReceipt, detail).ConfigureAwait(false);
outgoingToExternal.SourceDataContent = JsonSerializer.Serialize(exchangeReceipt);
var arrive = BuildArrive(exchangeReceipt);
outgoingToExternal.DestinationDataContent = JsonSerializer.Serialize(arrive);
outgoingToExternalList.Add(outgoingToExternal);
}
}
await _outgoingToExternalManager.CreateManyAsync(outgoingToExternalList).ConfigureAwait(false);
//将outgoingFromWms数据归档
await _outgoingFromWmsManager.ArchiveManyAsync(outgoingFromWmsList).ConfigureAwait(false);
return outgoingToExternalList;
}
private static ArriveNote BuildArrive(PurchaseReceiptNoteExchangeDto exchangeReceipt)
{
var detail = exchangeReceipt.Detail;
var arrive = new ArriveNote()
{
PlanBillNo = exchangeReceipt.PoNumber,
ShipBillNo = exchangeReceipt.AsnNumber,
DocNo = exchangeReceipt.Number,
DetailMatNo = detail.PackingCode,
ERP = detail.ItemCode,
Qty = detail.Qty,
HgQty = detail.Qty,
ProductDate = detail.ProduceDate,
ProductBatch = detail.Lot,
Loc = detail.LocationErpCode,
ShipDate = exchangeReceipt.ShipDate,
ShipBillState = 0,
SupplierCode = exchangeReceipt.SupplierCode,
PlanUserCode = exchangeReceipt.ContactName,
EosState = 0,
// EosDate = DateTime.MinValue,
WmsDate = DateTime.Now,
Remark = detail.Remark
};
return arrive;
}
private async Task<PurchaseReceiptNoteExchangeDto> BuildPurchaseReceiptExchangeDtoAsync(PurchaseReceiptNoteDTO wmsReceipt, PurchaseReceiptNoteDetailDTO wmsReceiptDetail)
{
var exchangeReceipt = _objectMapper.Map<PurchaseReceiptNoteDTO, PurchaseReceiptNoteExchangeDto>(wmsReceipt);
var exchangeReceiptDetail = _objectMapper.Map<PurchaseReceiptNoteDetailDTO, PurchaseReceiptNoteDetailExchangeDto>(wmsReceiptDetail);
var asn = await _supplierAsnAppService.GetByNumberAsync(exchangeReceipt.AsnNumber).ConfigureAwait(false);
exchangeReceipt.ShipDate = asn?.ShipDate;
exchangeReceipt.ContactName = asn == null ? "" : asn.ContactName;
exchangeReceipt.Detail = exchangeReceiptDetail;
return exchangeReceipt;
}
}