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.
108 lines
5.1 KiB
108 lines
5.1 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.Tyrp;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
|
|
using Win_in.Sfs.Wms.DataExchange.WMS.ProductReceiptNote;
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Outgoing;
|
|
|
|
public class ProductReceiptNoteConverter : IOutgoingConverter
|
|
{
|
|
private readonly IOutgoingFromWmsManager _outgoingFromWmsManager;
|
|
private readonly IOutgoingToExternalManager _outgoingToExternalManager;
|
|
private readonly IObjectMapper _objectMapper;
|
|
|
|
public ProductReceiptNoteConverter(
|
|
IOutgoingFromWmsManager outgoingFromWmsManager
|
|
, IOutgoingToExternalManager outgoingToExternalManager
|
|
, IObjectMapper objectMapper
|
|
)
|
|
{
|
|
_outgoingFromWmsManager = outgoingFromWmsManager;
|
|
_outgoingToExternalManager = outgoingToExternalManager;
|
|
_objectMapper = objectMapper;
|
|
}
|
|
|
|
|
|
|
|
public virtual async Task<List<OutgoingToExternal>> ConvertAsync()
|
|
{
|
|
var outgoingToExternalList = new List<OutgoingToExternal>();
|
|
|
|
var outgoingFromWmsList = await _outgoingFromWmsManager.GetToBeProcessedListAsync(EnumOutgoingDataType.ProductReceipt, EnumSystemType.ERP).ConfigureAwait(false);
|
|
|
|
foreach (var outgoingFromWms in outgoingFromWmsList)
|
|
{
|
|
string tyrpNumber = outgoingFromWms.TyrpNumber;
|
|
var wmsReceipt = JsonSerializer.Deserialize<ProductReceiptNoteDTO>(outgoingFromWms.DataContent);
|
|
int index=0;//为了处理相同number下存在相同零件号的问题。系统自动在number后添加index,如果只有一条明细就不添加。
|
|
foreach (var detail in wmsReceipt.Details)
|
|
{
|
|
// string number = index > 0 ? wmsReceipt.Number + index.ToString() : wmsReceipt.Number;
|
|
string number = index > 0 ? tyrpNumber + index.ToString() : tyrpNumber;
|
|
var outgoingToExternal = new OutgoingToExternal()
|
|
{
|
|
DataType = outgoingFromWms.DataType,
|
|
DataAction = outgoingFromWms.DataAction,
|
|
SourceSystem = EnumSystemType.WMS.ToString(),
|
|
SourceDataId = detail.Id.ToString(),
|
|
SourceDataGroupCode = number,
|
|
SourceDataDetailCode = detail.PackingCode,
|
|
Writer = nameof(TyrpOutgoingBackgroundWorker),
|
|
DestinationSystem = EnumSystemType.ERP.ToString(),
|
|
DestinationDataId = "",
|
|
};
|
|
outgoingToExternal.SetEffectiveDate(outgoingFromWms.EffectiveDate);
|
|
|
|
var exchangeReceipt = await BuildProductReceiptNoteExchangeDtoAsync(wmsReceipt, detail).ConfigureAwait(false);
|
|
outgoingToExternal.SourceDataContent = JsonSerializer.Serialize(exchangeReceipt);
|
|
var ret = BuildProductReceiptNote(exchangeReceipt, number);
|
|
outgoingToExternal.DestinationDataContent = JsonSerializer.Serialize(ret);
|
|
|
|
outgoingToExternalList.Add(outgoingToExternal);
|
|
index++;
|
|
}
|
|
}
|
|
//插入到中间表OutgoingToExternal
|
|
await _outgoingToExternalManager.CreateManyAsync(outgoingToExternalList).ConfigureAwait(false);
|
|
//将outgoingFromWms数据归档
|
|
await _outgoingFromWmsManager.ArchiveManyAsync(outgoingFromWmsList).ConfigureAwait(false);
|
|
return outgoingToExternalList;
|
|
}
|
|
|
|
private ProductReceiptNote BuildProductReceiptNote(ProductReceiptNoteExchangeDto exchangeProductReceiptNote,string number)
|
|
{
|
|
var detail = exchangeProductReceiptNote.Detail;
|
|
var ret = new ProductReceiptNote()
|
|
{
|
|
mesout_ref_nbr = number,//exchangeProductReceiptNote.Number,
|
|
mesout_id = string.IsNullOrEmpty(detail.RawLocationCode)?"": detail.RawLocationCode,
|
|
mesout_part = detail.ItemCode,
|
|
// mesout_date = exchangeProductReceiptNote.ActiveDate.ToString("yyyyMMdd"),
|
|
mesout_date = DateTime.Now.ToString("yyyyMMdd"),
|
|
mesout_bad = detail.ReturnQty,
|
|
mesout_move = detail.ReturnQty != 0 ? 0 : detail.Qty,
|
|
mesout_unable = 0,
|
|
mesout_loc = detail.LocationErpCode,
|
|
//mesout_dt = exchangeProductReceiptNote.CompleteTime.ToString("yyyyMMdd HH:mm:ss"),
|
|
mesout_dt = DateTime.Now.ToString("yyyyMMdd HH:mm:ss"),
|
|
memo = string.IsNullOrEmpty(detail.Remark)?"": detail.Remark,
|
|
refno = "",
|
|
|
|
};
|
|
return ret;
|
|
}
|
|
|
|
private async Task<ProductReceiptNoteExchangeDto> BuildProductReceiptNoteExchangeDtoAsync(ProductReceiptNoteDTO wmsReceipt, ProductReceiptNoteDetailDTO wmsReceiptDetail)
|
|
{
|
|
var exchangeReceipt = _objectMapper.Map<ProductReceiptNoteDTO, ProductReceiptNoteExchangeDto>(wmsReceipt);
|
|
var exchangeReceiptDetail = _objectMapper.Map<ProductReceiptNoteDetailDTO, ProductReceiptNoteDetailExchangeDto>(wmsReceiptDetail);
|
|
exchangeReceipt.Detail = exchangeReceiptDetail;
|
|
return exchangeReceipt;
|
|
}
|
|
}
|
|
|