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.
155 lines
6.2 KiB
155 lines
6.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Logging;
|
|
using Volo.Abp.Guids;
|
|
using Volo.Abp.ObjectMapping;
|
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
|
using Win_in.Sfs.Shared.Domain.Shared;
|
|
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.ItemBasic;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Incoming;
|
|
|
|
public class ItemBasicReader : IReader
|
|
{
|
|
|
|
private readonly IProductManager _productManager;
|
|
private readonly IIncomingFromExternalManager _incomingFromExternalManager;
|
|
private readonly ILogger<ItemBasicReader> _logger;
|
|
private readonly IGuidGenerator _guidGenerator;
|
|
private readonly IItemBasicAppService _itemBasicAppService;
|
|
private readonly IObjectMapper _objectMapper;
|
|
public ItemBasicReader(
|
|
IProductManager productManager
|
|
, IIncomingFromExternalManager incomingFromExternalManager,
|
|
IGuidGenerator guidGenerator
|
|
, ILogger<ItemBasicReader> logger
|
|
, IItemBasicAppService itemBasicAppService
|
|
, IObjectMapper objectMapper
|
|
)
|
|
{
|
|
_guidGenerator = guidGenerator;
|
|
_productManager = productManager;
|
|
_incomingFromExternalManager = incomingFromExternalManager;
|
|
_logger = logger;
|
|
_itemBasicAppService = itemBasicAppService;
|
|
_objectMapper = objectMapper;
|
|
}
|
|
|
|
public virtual async Task<List<IncomingFromExternal>> ReadAsync()
|
|
{
|
|
//从ERP读取待处理part
|
|
var toBeProcessedParts = await _productManager.GetToBeProcessedListAsync().ConfigureAwait(false);
|
|
//获取wmsBom数据
|
|
SfsBaseDataRequestInputBase input = new SfsBaseDataRequestInputBase();
|
|
var wmsItemBasics = await _itemBasicAppService.GetAllListByFilterAsync(input).ConfigureAwait(false);
|
|
var wmsToItemBasicExchangeDtos = _objectMapper.Map<List<ItemBasicDTO>, List<ItemBasicExchangeDto>>(wmsItemBasics);
|
|
|
|
List<ItemBasicExchangeDto> eosToItemBasicExchangeDtos = new List<ItemBasicExchangeDto>();
|
|
foreach (var toBeProcessedPart in toBeProcessedParts)
|
|
{
|
|
var itemBasic = BuildItemBasicToExchangeDto(toBeProcessedPart);
|
|
eosToItemBasicExchangeDtos.Add(itemBasic);
|
|
}
|
|
//和wms和eos数据进行比较,获取需要处理得数据
|
|
var updateDatas = eosToItemBasicExchangeDtos.Except(wmsToItemBasicExchangeDtos).ToList();
|
|
|
|
if (!updateDatas.Any())
|
|
{
|
|
_logger.LogInformation("No ItemBasics");
|
|
return new List<IncomingFromExternal>();
|
|
}
|
|
|
|
List<IncomingFromExternal> incomingDataList = new List<IncomingFromExternal>();
|
|
foreach (var data in updateDatas)
|
|
{
|
|
var item = toBeProcessedParts.FirstOrDefault(r => r.mes_product_part == data.Code);
|
|
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);
|
|
|
|
}
|
|
await _incomingFromExternalManager.CreateBulkAsync(incomingDataList).ConfigureAwait(false);
|
|
//更新erp数据状态
|
|
// await _productManager.UpdateProcessedListAsync(toBeProcessedPillTasks);
|
|
return incomingDataList;
|
|
}
|
|
private IncomingFromExternal BuildIncomingFromExternal(mes_product product)
|
|
{
|
|
var incomingData = new IncomingFromExternal()
|
|
{
|
|
DataType = EnumIncomingDataType.Item.ToString(),
|
|
DataAction = EnumExchangeDataAction.Add,
|
|
SourceSystem = EnumSystemType.ERP.ToString(),
|
|
SourceDataId = product.mes_product_part_ser.ToString(),
|
|
SourceDataGroupCode = product.mes_product_part_ser,
|
|
SourceDataDetailCode = product.mes_product_part_ser,
|
|
SourceDataContent = JsonSerializer.Serialize(product),
|
|
WriteTime = DateTime.Now,
|
|
Writer = nameof(TyrpIncomingBackgroundWorker),
|
|
DestinationSystem = EnumSystemType.WMS.ToString(),
|
|
};
|
|
return incomingData;
|
|
}
|
|
|
|
private static ItemBasicExchangeDto BuildItemBasicToExchangeDto(mes_product product)
|
|
{
|
|
string type = "";
|
|
switch (product.mes_product_code)
|
|
{
|
|
case "10C01":
|
|
type = "成品";
|
|
break;
|
|
case "10C02":
|
|
type = "成品";
|
|
break;
|
|
case "10C03":
|
|
type = "物料";
|
|
break;
|
|
case "10C04":
|
|
type = "半成品";
|
|
break;
|
|
default:
|
|
type = "无";
|
|
break;
|
|
}
|
|
|
|
var itemBasicRequest = new ItemBasicExchangeDto()
|
|
{
|
|
Code = product.mes_product_part,
|
|
Name = product.mes_product_part_ser,
|
|
Desc1 = product.mes_product_desc,
|
|
//Desc2=product.mes_product_fih_factory,//目前没有这个字段
|
|
Status = product.mes_product_active == "Y" ? EnumItemStatus.Active : EnumItemStatus.Disable,
|
|
|
|
#region 制造类别
|
|
//其中100404 托外-不带原料 、 10405 托外-带原料、10407客户提供料件没有对应字段
|
|
CanMake = product.mes_product_mfg == "10401" ? true : false, //10401 自制
|
|
CanBuy = product.mes_product_mfg == "10403" ? true : false, //10403 采购
|
|
CanOutsourcing = product.mes_product_mfg == "10402" ? true : false,//10402 外包
|
|
IsRecycled = product.mes_product_mfg == "10406" ? true : false, //10406 回收
|
|
#endregion
|
|
|
|
Type = type,//10C01成品、10C02原料、10C03物料、10C04半成品
|
|
Configuration = product.mes_product_spec,
|
|
BasicUom = product.mes_product_unit,
|
|
AbcClass = "",
|
|
};
|
|
return itemBasicRequest;
|
|
}
|
|
}
|
|
|