|
|
|
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.Auth.Users;
|
|
|
|
using Win_in.Sfs.Shared.Domain.Shared.Enums.Store;
|
|
|
|
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.UnplannedReceiptNote;
|
|
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Outgoing;
|
|
|
|
|
|
|
|
public class UnplannedReceiptNoteConverter : IOutgoingConverter
|
|
|
|
{
|
|
|
|
//private readonly string billtype = "4014";
|
|
|
|
private readonly IOutgoingFromWmsManager _outgoingFromWmsManager;
|
|
|
|
private readonly IOutgoingToExternalManager _outgoingToExternalManager;
|
|
|
|
private readonly IDepartmentAppService _departmentAppService;
|
|
|
|
private readonly IObjectMapper _objectMapper;
|
|
|
|
private readonly ISfsUserAppService _sfsUserAppService;
|
|
|
|
private readonly IUnplannedReceiptRequestAppService _unplannedReceiptRequestAppService;
|
|
|
|
public UnplannedReceiptNoteConverter(
|
|
|
|
IOutgoingFromWmsManager outgoingFromWmsManager
|
|
|
|
, IOutgoingToExternalManager outgoingToExternalManager
|
|
|
|
, IDepartmentAppService departmentAppService
|
|
|
|
, IObjectMapper objectMapper
|
|
|
|
, ISfsUserAppService sfsUserAppService
|
|
|
|
,
|
|
|
|
IUnplannedReceiptRequestAppService unplannedReceiptRequestAppService )
|
|
|
|
{
|
|
|
|
_outgoingFromWmsManager = outgoingFromWmsManager;
|
|
|
|
_outgoingToExternalManager = outgoingToExternalManager;
|
|
|
|
_departmentAppService = departmentAppService;
|
|
|
|
_objectMapper = objectMapper;
|
|
|
|
_sfsUserAppService = sfsUserAppService;
|
|
|
|
_unplannedReceiptRequestAppService = unplannedReceiptRequestAppService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 转换数据
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual async Task<List<OutgoingToExternal>> ConvertAsync()
|
|
|
|
{
|
|
|
|
var outgoingToExternalList = new List<OutgoingToExternal>();
|
|
|
|
//获取要同步得数据
|
|
|
|
var outgoingFromWmsList = await _outgoingFromWmsManager.GetToBeProcessedListAsync(EnumOutgoingDataType.UnplannedReceipt, EnumSystemType.ERP).ConfigureAwait(false);
|
|
|
|
foreach (var outgoingFromWms in outgoingFromWmsList)
|
|
|
|
{
|
|
|
|
string tyrpNumber = outgoingFromWms.TyrpNumber;
|
|
|
|
#region 主表
|
|
|
|
var wmsReceipt = JsonSerializer.Deserialize<UnplannedReceiptNoteDTO>(outgoingFromWms.DataContent);
|
|
|
|
var exchangeReceipt = _objectMapper.Map<UnplannedReceiptNoteDTO, UnplannedReceiptNoteExchangeDto>(wmsReceipt);
|
|
|
|
var department = await _departmentAppService.GetByUsernameAsync(exchangeReceipt.Worker).ConfigureAwait(false);
|
|
|
|
var departmentCode = department == null ? "" : department.Code;
|
|
|
|
var requset = await _unplannedReceiptRequestAppService.GetByNumberAsync(exchangeReceipt.UnplannedReceiptRequestNumber).ConfigureAwait(false);
|
|
|
|
//if (Guid.TryParse(exchangeReceipt.CreatorId.ToString(), out Guid guid))
|
|
|
|
//{
|
|
|
|
// var username = await _sfsUserAppService.GetUserNameById(guid).ConfigureAwait(false);
|
|
|
|
// if (!string.IsNullOrEmpty(username))
|
|
|
|
// {
|
|
|
|
// exchangeReceipt.Worker = username;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
var purchaseOrder = BuildDataInterface(exchangeReceipt, tyrpNumber, departmentCode, requset?.Worker);
|
|
|
|
var outgoingToExternal = new OutgoingToExternal()
|
|
|
|
{
|
|
|
|
DataType = EnumOutgoingDataType.UnplannedReceipt.ToString(),
|
|
|
|
TableType = EnumExchangeTableType.MainTable,
|
|
|
|
DataAction = outgoingFromWms.DataAction,
|
|
|
|
SerialNumber=tyrpNumber,
|
|
|
|
SourceSystem = EnumSystemType.WMS.ToString(),
|
|
|
|
SourceDataId = wmsReceipt.Id.ToString(),
|
|
|
|
SourceDataGroupCode = wmsReceipt.Number,
|
|
|
|
SourceDataDetailCode = wmsReceipt.Number,
|
|
|
|
Writer = nameof(TyrpOutgoingBackgroundWorker),
|
|
|
|
DestinationSystem = EnumSystemType.ERP.ToString(),
|
|
|
|
DestinationDataId = "",
|
|
|
|
};
|
|
|
|
outgoingToExternal.SetEffectiveDate(outgoingFromWms.EffectiveDate);
|
|
|
|
outgoingToExternal.SourceDataContent = JsonSerializer.Serialize(exchangeReceipt);
|
|
|
|
outgoingToExternal.DestinationDataContent = JsonSerializer.Serialize(purchaseOrder);
|
|
|
|
outgoingToExternalList.Add(outgoingToExternal);
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 明细
|
|
|
|
var WipDetails = wmsReceipt.Details.GroupBy(r => new { r.Number, r.ItemCode, r.LocationErpCode,r.ProjCapacityCode,r.CaseCode }).Select(p => new UnplannedReceiptNoteDetailExchangeDto { Qty = p.Sum(itm => itm.Qty), Number = p.Key.Number, ItemCode = p.Key.ItemCode, LocationErpCode = p.Key.LocationErpCode,ProjCapacityCode=p.Key.ProjCapacityCode,CaseCode=p.Key.CaseCode });
|
|
|
|
|
|
|
|
foreach (var detail in WipDetails)
|
|
|
|
{
|
|
|
|
var outgoingDetailToExternal = new OutgoingToExternal()
|
|
|
|
{
|
|
|
|
DataType = EnumOutgoingDataType.UnplannedReceipt.ToString(),
|
|
|
|
TableType = EnumExchangeTableType.DetailTable,
|
|
|
|
DataAction = outgoingFromWms.DataAction,
|
|
|
|
SerialNumber = tyrpNumber,
|
|
|
|
SourceSystem = EnumSystemType.WMS.ToString(),
|
|
|
|
SourceDataId = detail.Number.ToString(),
|
|
|
|
SourceDataGroupCode = wmsReceipt.Number,
|
|
|
|
SourceDataDetailCode = detail.ItemCode,
|
|
|
|
Writer = nameof(TyrpOutgoingBackgroundWorker),
|
|
|
|
DestinationSystem = EnumSystemType.ERP.ToString(),
|
|
|
|
DestinationDataId = "",
|
|
|
|
};
|
|
|
|
outgoingDetailToExternal.SetEffectiveDate(outgoingFromWms.EffectiveDate);
|
|
|
|
outgoingDetailToExternal.SourceDataContent = JsonSerializer.Serialize(detail);
|
|
|
|
var purchaseOrderDetail = BuildDataInterfaceDetail(tyrpNumber, detail);
|
|
|
|
outgoingDetailToExternal.DestinationDataContent = JsonSerializer.Serialize(purchaseOrderDetail);
|
|
|
|
outgoingToExternalList.Add(outgoingDetailToExternal);
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
//插入到中间表OutgoingToExternal
|
|
|
|
await _outgoingToExternalManager.CreateManyAsync(outgoingToExternalList).ConfigureAwait(false);
|
|
|
|
//将outgoingFromWms数据归档
|
|
|
|
await _outgoingFromWmsManager.ArchiveManyAsync(outgoingFromWmsList).ConfigureAwait(false);
|
|
|
|
|
|
|
|
return outgoingToExternalList;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 构建主表
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="exchangeOrder"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private Wmsoutm BuildDataInterface(UnplannedReceiptNoteExchangeDto exchangeOrder, string tyrpNumber,string departmentCode,string worker)
|
|
|
|
{
|
|
|
|
string billtype = "4014";
|
|
|
|
if (exchangeOrder.UnplannedReceiptType == EnumUnplannedReceiptType.Wip)
|
|
|
|
{
|
|
|
|
billtype = "4036";
|
|
|
|
}
|
|
|
|
var ret = new Wmsoutm()
|
|
|
|
{
|
|
|
|
wmsoutm_nbr = tyrpNumber,
|
|
|
|
wmsoutm_type = billtype,
|
|
|
|
wmsoutm_dt_w = DateTime.Now.ToString("yyyyMMdd HH:mm:ss"),
|
|
|
|
wmsoutm_stat = "Y",
|
|
|
|
wmsoutm_tyrp_dt = "",
|
|
|
|
wmsoutm_user = worker.Length>=6? worker.Substring(worker.Length-6) : worker,
|
|
|
|
wmsoutm_dept = departmentCode,//根据Worker从UserDepartment中获取
|
|
|
|
//wmsoutm_date = exchangeOrder.ActiveDate.ToString("yyyyMMdd"),
|
|
|
|
wmsoutm_date = DateTime.Now.ToString("yyyyMMdd"),
|
|
|
|
wmsoutm_cust = "",
|
|
|
|
wmsoutm_shm_nbr = "",
|
|
|
|
wmsoutm_cust_loc = "",
|
|
|
|
wmsoutm_stock_stat = "",
|
|
|
|
wmsoutm_open_part = "",
|
|
|
|
wmsoutm_open_loc = "",
|
|
|
|
wmsoutm_open_hours = 0,
|
|
|
|
wmsoutm_tyrp_k = "",
|
|
|
|
wmsoutm_id = 0,//明细中最大scmsend_id
|
|
|
|
wmsoutm_open_qty = 0,
|
|
|
|
};
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 构建明细
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="exchangeOrder"></param>
|
|
|
|
/// <param name="exchangeDetailOrder"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
private Wmsoutd BuildDataInterfaceDetail(string tyrpNumber, UnplannedReceiptNoteDetailExchangeDto exchangeDetailOrder)
|
|
|
|
{
|
|
|
|
var ret = new Wmsoutd()
|
|
|
|
{
|
|
|
|
wmsoutd_nbr = tyrpNumber,
|
|
|
|
wmsoutd_part = exchangeDetailOrder.ItemCode,
|
|
|
|
wmsoutd_loc = exchangeDetailOrder.LocationErpCode ?? "",
|
|
|
|
wmsoutd_qty = exchangeDetailOrder.Qty,
|
|
|
|
wmsoutd_bcm_code = string.IsNullOrEmpty(exchangeDetailOrder.ProjCapacityCode) ? "" : exchangeDetailOrder.ProjCapacityCode,//项目代码
|
|
|
|
wmsoutd_projt_id = string.IsNullOrEmpty(exchangeDetailOrder.CaseCode) ? "" : exchangeDetailOrder.CaseCode,//专案代码
|
|
|
|
};
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|