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.
68 lines
2.5 KiB
68 lines
2.5 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Tyrp;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Outgoing;
|
|
|
|
public class WmsoutmWriter : IWriter
|
|
{
|
|
private readonly IWmsoutmManager _wmsoutdManager;
|
|
private readonly IOutgoingToExternalManager _outgoingToExternalManager;
|
|
|
|
public WmsoutmWriter(
|
|
IWmsoutmManager wmsoutdManager
|
|
, IOutgoingToExternalManager outgoingToExternalManager)
|
|
{
|
|
_wmsoutdManager = wmsoutdManager;
|
|
_outgoingToExternalManager = outgoingToExternalManager;
|
|
}
|
|
/// <summary>
|
|
/// 写入数据
|
|
/// </summary>
|
|
/// <param name="outgoingDataList"></param>
|
|
/// <returns></returns>
|
|
public virtual async Task WriteAsync(List<OutgoingToExternal> outgoingDataList)
|
|
{
|
|
var groups = outgoingDataList.GroupBy(r => r.SourceDataGroupCode);
|
|
foreach (var group in groups)
|
|
{
|
|
var dataInterfaceList = new List<Wmsoutm>();
|
|
var dataInterfaceDetailList = new List<Wmsoutd>();
|
|
var entitys = group.ToList();
|
|
|
|
foreach (var entity in entitys)
|
|
{
|
|
if (entity.TableType == EnumExchangeTableType.MainTable)//主表(MainTable)
|
|
{
|
|
var receipt = JsonSerializer.Deserialize<Wmsoutm>(entity.DestinationDataContent);
|
|
dataInterfaceList.Add(receipt);
|
|
}
|
|
else if (entity.TableType == EnumExchangeTableType.DetailTable) // 子表(DetailTable)
|
|
{
|
|
var receiptDetail = JsonSerializer.Deserialize<Wmsoutd>(entity.DestinationDataContent);
|
|
dataInterfaceDetailList.Add(receiptDetail);
|
|
}
|
|
}
|
|
try
|
|
{
|
|
//dataInterface分主子表分别写入ERP
|
|
await _wmsoutdManager.PostListAsync(dataInterfaceList, dataInterfaceDetailList).ConfigureAwait(false);
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
foreach (var item in entitys)
|
|
{
|
|
item.SetError(EnumExchangeDataErrorCode.Exception, ex.Message, ex.ToString());
|
|
}
|
|
}
|
|
|
|
}
|
|
//将数据归档
|
|
await _outgoingToExternalManager.ArchiveManyAsync(outgoingDataList).ConfigureAwait(false);
|
|
}
|
|
|
|
}
|
|
|