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.
 
 
 
 
 
 

143 lines
7.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Volo.Abp.ObjectMapping;
using Win_in.Sfs.Auth.Application.Contracts;
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.ItemTransformNote;
using Win_in.Sfs.Wms.Store.Application.Contracts;
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Outgoing;
public class ItemTransformNoteConverter : IOutgoingConverter
{
private readonly IOutgoingFromWmsManager _outgoingFromWmsManager;
private readonly IOutgoingToExternalManager _outgoingToExternalManager;
private readonly ISupplierAsnAppService _supplierAsnAppService;
private readonly IDepartmentAppService _departmentAppService;
private readonly IObjectMapper _objectMapper;
private readonly ILocationAppService _locationAppService;
public ItemTransformNoteConverter(
IOutgoingFromWmsManager outgoingFromWmsManager
, IOutgoingToExternalManager outgoingToExternalManager
, ISupplierAsnAppService supplierAsnAppService
, IDepartmentAppService departmentAppService
, IObjectMapper objectMapper
, ILocationAppService locationAppService
)
{
_outgoingFromWmsManager = outgoingFromWmsManager;
_outgoingToExternalManager = outgoingToExternalManager;
_supplierAsnAppService = supplierAsnAppService;
_departmentAppService = departmentAppService;
_objectMapper = objectMapper;
_locationAppService = locationAppService;
}
public virtual async Task<List<OutgoingToExternal>> ConvertAsync()
{
var outgoingToExternalList = new List<OutgoingToExternal>();
var outgoingFromWmsList = await _outgoingFromWmsManager.GetToBeProcessedListAsync(EnumOutgoingDataType.Item_Transform, EnumSystemType.ERP).ConfigureAwait(false);
foreach (var outgoingFromWms in outgoingFromWmsList)
{
var wmsCountAdjust = JsonSerializer.Deserialize<ItemTransformNoteDTO>(outgoingFromWms.DataContent);
if (Enum.Parse<EnumTransSubType>(wmsCountAdjust.Type) == EnumTransSubType.Item_Transform)
{
string tyrpNumber = outgoingFromWms.TyrpNumber;
var department = await _departmentAppService.GetByUsernameAsync(wmsCountAdjust.Worker).ConfigureAwait(false);
var departmentCode = department == null ? "" : department.Code;
var details = wmsCountAdjust.Details.GroupBy(r => new { r.ItemCode, r.ToItemCode, r.LocationErpCode, r.ToLocationCode }).Select(p => new ItemTransformNoteDetailExchangeDto { ToQty = p.Sum(itm => itm.ToQty), FromQty = p.Sum(itm => itm.FromQty), ItemCode = p.Key.ItemCode, ToItemCode = p.Key.ToItemCode, LocationErpCode = p.Key.LocationErpCode, ReasonCode = String.Join("、", p.Select(x => x.ReasonCode).ToArray()) });
foreach (var detail in details)
{
List<ItemTransformNoteDetailExchangeDto> ItemTransform = new List<ItemTransformNoteDetailExchangeDto>();
ItemTransformNoteDetailExchangeDto ItemTrans = new ItemTransformNoteDetailExchangeDto();
ItemTrans.ItemCode = detail.ItemCode;
ItemTrans.LocationErpCode = detail.LocationErpCode;
ItemTrans.FromQty = detail.FromQty - detail.FromQty - detail.FromQty;
ItemTrans.ReasonCode = detail.ReasonCode;
ItemTransform.Add(ItemTrans);
ItemTransformNoteDetailExchangeDto ItemTranss = new ItemTransformNoteDetailExchangeDto();
ItemTranss.ItemCode = detail.ToItemCode;
ItemTranss.LocationErpCode = detail.LocationErpCode;
ItemTranss.FromQty = detail.ToQty;
ItemTranss.ReasonCode = detail.ReasonCode;
ItemTransform.Add(ItemTranss);
foreach (var Item in ItemTransform)
{
var outgoingToExternal = new OutgoingToExternal()
{
DataType = outgoingFromWms.DataType,
DataAction = outgoingFromWms.DataAction,
SerialNumber= tyrpNumber,
SourceSystem = EnumSystemType.WMS.ToString(),
SourceDataId = wmsCountAdjust.Number,
SourceDataGroupCode = wmsCountAdjust.Number,
SourceDataDetailCode = Item.ItemCode,
Writer = nameof(TyrpOutgoingBackgroundWorker),
DestinationSystem = EnumSystemType.ERP.ToString(),
DestinationDataId = "",
};
outgoingToExternal.SetEffectiveDate(outgoingFromWms.EffectiveDate);
var exchangeIssue = await BuildPurchaseReceiptExchangeDtoAsync(wmsCountAdjust, Item).ConfigureAwait(false);
outgoingToExternal.SourceDataContent = JsonSerializer.Serialize(exchangeIssue);
var arrive = BuildIssue(exchangeIssue, departmentCode);
outgoingToExternal.DestinationDataContent = JsonSerializer.Serialize(arrive);
outgoingToExternalList.Add(outgoingToExternal);
}
}
}
}
await _outgoingToExternalManager.CreateManyAsync(outgoingToExternalList).ConfigureAwait(false); ;
//将outgoingFromWms数据归档
await _outgoingFromWmsManager.ArchiveManyAsync(outgoingFromWmsList).ConfigureAwait(false); ;
return outgoingToExternalList;
//插入到中间表OutgoingToExternal
}
private CountAdjust BuildIssue(ItemTransformNoteExchangeDto exchangeCountAdjust, string departmentCode)
{
var detail = exchangeCountAdjust.Detail;
// _locationAppService.GetListByCodesAndTypesAsync
var counta = new CountAdjust()
{
mesout_asd_refc = "MES",
mesout_asd_dt_w = DateTime.Now.ToString("yyyyMMdd HH:mm:ss"),
mesout_asd_type = "4003",
mesout_asd_part = detail.ItemCode,
//mesout_asd_date = exchangeCountAdjust.ActiveDate.ToString("yyyyMMdd"),
mesout_asd_date = DateTime.Now.ToString("yyyyMMdd"),
mesout_asd_loc = detail.LocationErpCode,
mesout_asd_code = detail.ReasonCode,
mesout_asd_qty = detail.FromQty,
mesout_asd_user = "WMS",
mesout_asd_k = string.Empty,
mesout_asd_stat = "Y"
};
return counta;
}
private async Task<ItemTransformNoteExchangeDto> BuildPurchaseReceiptExchangeDtoAsync(
ItemTransformNoteDTO wmsCountAdjust, ItemTransformNoteDetailExchangeDto wmsCountAdjustDetail)
{
var exchangeCountAdjust = _objectMapper.Map<ItemTransformNoteDTO, ItemTransformNoteExchangeDto>(wmsCountAdjust);
exchangeCountAdjust.Detail = wmsCountAdjustDetail;
return exchangeCountAdjust;
}
}