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.
131 lines
5.4 KiB
131 lines
5.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.Guids;
|
|
using Volo.Abp.ObjectMapping;
|
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
|
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.StdCostPrice;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Incoming;
|
|
public class StdCostPriceReader : IReader
|
|
{
|
|
private readonly IProductManager _productManager;
|
|
private readonly IIncomingFromExternalManager _incomingFromExternalManager;
|
|
private readonly ILogger<StdCostPriceReader> _logger;
|
|
private readonly IGuidGenerator _guidGenerator;
|
|
private readonly IConfiguration _configuration;
|
|
private readonly IStdCostPriceSheetAppService _StdCostPriceAppService;
|
|
private readonly IObjectMapper _objectMapper;
|
|
public StdCostPriceReader(
|
|
IProductManager productManager
|
|
, IIncomingFromExternalManager incomingFromExternalManager
|
|
, IGuidGenerator guidGenerator
|
|
, ILogger<StdCostPriceReader> logger
|
|
, IConfiguration configuration,
|
|
IStdCostPriceSheetAppService StdCostPriceSheetAppService,
|
|
IObjectMapper objectMapper
|
|
)
|
|
{
|
|
_guidGenerator = guidGenerator;
|
|
_configuration = configuration;
|
|
_productManager = productManager;
|
|
_incomingFromExternalManager = incomingFromExternalManager;
|
|
_logger = logger;
|
|
_StdCostPriceAppService = StdCostPriceSheetAppService;
|
|
_objectMapper = objectMapper;
|
|
}
|
|
|
|
public virtual async Task<List<IncomingFromExternal>> ReadAsync()
|
|
{
|
|
//从ERP读取待处理part
|
|
var toBeProcessedProducts = await _productManager.GetToBeProcessedListAsync().ConfigureAwait(false);
|
|
if (!toBeProcessedProducts.Any())
|
|
{
|
|
_logger.LogInformation("no StdCostPrices");
|
|
return new List<IncomingFromExternal>();
|
|
}
|
|
//获取wms标准成本单价数据
|
|
SfsBaseDataRequestInputBase input = new SfsBaseDataRequestInputBase();
|
|
var wmsStdCostPrices = await _StdCostPriceAppService.GetAllListByFilterAsync(input).ConfigureAwait(false);
|
|
var wmsToStdCostPriceExchangeDtos = _objectMapper.Map<List<StdCostPriceSheetDTO>, List<StdCostPriceExchangeDto>>(wmsStdCostPrices);
|
|
List<StdCostPriceExchangeDto> eosToBomExchangeDtos = new List<StdCostPriceExchangeDto>();
|
|
foreach (var toBeProcessedProduct in toBeProcessedProducts)
|
|
{
|
|
var StdCostPrice = BuildScrapNoteOrderExchangeMes(toBeProcessedProduct);
|
|
eosToBomExchangeDtos.Add(StdCostPrice);
|
|
}
|
|
//和wms和eos数据进行比较,获取需要处理得数据
|
|
var updateDatas = eosToBomExchangeDtos.Except(wmsToStdCostPriceExchangeDtos).ToList();
|
|
if (!updateDatas.Any())
|
|
{
|
|
_logger.LogInformation("no StdCostPrices");
|
|
return new List<IncomingFromExternal>();
|
|
}
|
|
//StdCostPrice逐一转换为StdCostPrice
|
|
var incomingDataList = BuildIncomingFromExternalFromBomAsync(updateDatas, toBeProcessedProducts);
|
|
await _incomingFromExternalManager.CreateBulkAsync(incomingDataList).ConfigureAwait(false);
|
|
return incomingDataList;
|
|
}
|
|
private List<IncomingFromExternal> BuildIncomingFromExternalFromBomAsync(List<StdCostPriceExchangeDto> updateDatas, List<mes_product> toBeProcessedProducts)
|
|
{
|
|
var incomingDataList = new List<IncomingFromExternal>();
|
|
foreach (var data in updateDatas)
|
|
{
|
|
var item = toBeProcessedProducts.FirstOrDefault(r => r.mes_product_part == data.ItemCode);
|
|
var incomingData = BuildIncomingFromExternal(item);
|
|
|
|
incomingData.SetEffectiveDate(DateTime.Now);
|
|
|
|
try
|
|
{
|
|
incomingData.DestinationDataContent = JsonSerializer.Serialize(data);
|
|
incomingData.SetId(_guidGenerator.Create());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
incomingData.SetError(EnumExchangeDataErrorCode.Exception, ex.Message, ex.ToString());
|
|
}
|
|
|
|
incomingDataList.Add(incomingData);
|
|
|
|
}
|
|
return incomingDataList;
|
|
}
|
|
private IncomingFromExternal BuildIncomingFromExternal(mes_product product)
|
|
{
|
|
var incomingData = new IncomingFromExternal()
|
|
{
|
|
|
|
DataType = EnumIncomingDataType.StdCostPrice.ToString(),
|
|
DataAction = EnumExchangeDataAction.Add,
|
|
SourceSystem = EnumSystemType.ERP.ToString(),
|
|
SourceDataId = product.mes_product_part_ser.ToString(),
|
|
SourceDataGroupCode = product.mes_product_part,
|
|
SourceDataDetailCode = product.mes_product_part,
|
|
SourceDataContent = JsonSerializer.Serialize(product),
|
|
WriteTime = DateTime.Now,
|
|
Writer = nameof(TyrpIncomingBackgroundWorker),
|
|
DestinationSystem = EnumSystemType.ERP.ToString(),
|
|
};
|
|
return incomingData;
|
|
}
|
|
|
|
private static StdCostPriceExchangeDto BuildScrapNoteOrderExchangeMes(mes_product product)
|
|
{
|
|
|
|
var price = new StdCostPriceExchangeDto()
|
|
{
|
|
ItemCode = product.mes_product_part,
|
|
StdCostPrice = product.mes_product_price_std,
|
|
Description = "接口同步",
|
|
};
|
|
return price;
|
|
}
|
|
}
|
|
|