|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text.Json;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
|
using DocumentFormat.OpenXml.Presentation;
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
using Nito.AsyncEx;
|
|
|
|
using Volo.Abp.Identity;
|
|
|
|
using Volo.Abp.ObjectMapping;
|
|
|
|
using Volo.Abp.Users;
|
|
|
|
using Win_in.Sfs.Auth.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.UnplannedIssueNote;
|
|
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
|
|
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.TyrpAgent.Outgoing;
|
|
|
|
|
|
|
|
public class UnplannedIssueNoteConverter : IOutgoingConverter
|
|
|
|
{
|
|
|
|
private readonly string billtype = "4013";
|
|
|
|
private readonly IOutgoingFromWmsManager _outgoingFromWmsManager;
|
|
|
|
private readonly IOutgoingToExternalManager _outgoingToExternalManager;
|
|
|
|
private readonly IDepartmentAppService _departmentAppService;
|
|
|
|
private readonly IObjectMapper _objectMapper;
|
|
|
|
private readonly IIdentityUserAppService identityUserAppService;
|
|
|
|
|
|
|
|
public UnplannedIssueNoteConverter(
|
|
|
|
IOutgoingFromWmsManager outgoingFromWmsManager
|
|
|
|
, IOutgoingToExternalManager outgoingToExternalManager
|
|
|
|
, IDepartmentAppService departmentAppService
|
|
|
|
, IObjectMapper objectMapper
|
|
|
|
,
|
|
|
|
IIdentityUserAppService identityUserAppService)
|
|
|
|
{
|
|
|
|
_outgoingFromWmsManager = outgoingFromWmsManager;
|
|
|
|
_outgoingToExternalManager = outgoingToExternalManager;
|
|
|
|
_departmentAppService = departmentAppService;
|
|
|
|
_objectMapper = objectMapper;
|
|
|
|
this.identityUserAppService = identityUserAppService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 转换数据
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
public virtual async Task<List<OutgoingToExternal>> ConvertAsync()
|
|
|
|
{
|
|
|
|
var outgoingToExternalList = new List<OutgoingToExternal>();
|
|
|
|
//获取要同步得数据
|
|
|
|
var outgoingFromWmsList = await _outgoingFromWmsManager.GetToBeProcessedListAsync(EnumOutgoingDataType.UnplannedIssue, EnumSystemType.ERP).ConfigureAwait(false);
|
|
|
|
foreach (var outgoingFromWms in outgoingFromWmsList)
|
|
|
|
{
|
|
|
|
#region 主表
|
|
|
|
var wmsReceipt = JsonSerializer.Deserialize<UnplannedIssueNoteDTO>(outgoingFromWms.DataContent);
|
|
|
|
var exchangeReceipt = _objectMapper.Map<UnplannedIssueNoteDTO, UnplannedIssueNoteExchangeDto>(wmsReceipt);
|
|
|
|
var department = await _departmentAppService.GetByUsernameAsync(exchangeReceipt.Worker).ConfigureAwait(false);
|
|
|
|
var departmentCode = department == null ? "" : department.Code;
|
|
|
|
if (Guid.TryParse(exchangeReceipt.CreatorId.ToString(), out Guid guid))
|
|
|
|
{
|
|
|
|
var user = await identityUserAppService.GetAsync(guid).ConfigureAwait(false);
|
|
|
|
if(user != null)
|
|
|
|
{
|
|
|
|
exchangeReceipt.Worker = user.UserName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var purchaseOrder = BuildDataInterface(exchangeReceipt);
|
|
|
|
var outgoingToExternal = new OutgoingToExternal()
|
|
|
|
{
|
|
|
|
DataType = EnumOutgoingDataType.UnplannedIssue.ToString(),
|
|
|
|
TableType = EnumExchangeTableType.MainTable,
|
|
|
|
DataAction = outgoingFromWms.DataAction,
|
|
|
|
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 明细
|
|
|
|
foreach (var detail in wmsReceipt.Details)
|
|
|
|
{
|
|
|
|
var outgoingDetailToExternal = new OutgoingToExternal()
|
|
|
|
{
|
|
|
|
DataType = EnumOutgoingDataType.UnplannedIssue.ToString(),
|
|
|
|
TableType = EnumExchangeTableType.DetailTable,
|
|
|
|
DataAction = outgoingFromWms.DataAction,
|
|
|
|
SourceSystem = EnumSystemType.WMS.ToString(),
|
|
|
|
SourceDataId = detail.Id.ToString(),
|
|
|
|
SourceDataGroupCode = wmsReceipt.Number,
|
|
|
|
SourceDataDetailCode = detail.ItemCode,
|
|
|
|
Writer = nameof(TyrpOutgoingBackgroundWorker),
|
|
|
|
DestinationSystem = EnumSystemType.ERP.ToString(),
|
|
|
|
DestinationDataId = "",
|
|
|
|
};
|
|
|
|
outgoingDetailToExternal.SetEffectiveDate(outgoingFromWms.EffectiveDate);
|
|
|
|
var exchangeReceiptDetail = _objectMapper.Map<UnplannedIssueNoteDetailDTO, UnplannedIssueNoteDetailExchangeDto>(detail);
|
|
|
|
outgoingDetailToExternal.SourceDataContent = JsonSerializer.Serialize(exchangeReceiptDetail);
|
|
|
|
var purchaseOrderDetail = BuildDataInterfaceDetail(exchangeReceipt, exchangeReceiptDetail);
|
|
|
|
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(UnplannedIssueNoteExchangeDto exchangeOrder)
|
|
|
|
{
|
|
|
|
var ret = new Wmsoutm()
|
|
|
|
{
|
|
|
|
wmsoutm_nbr = exchangeOrder.Number,
|
|
|
|
wmsoutm_type = billtype,
|
|
|
|
wmsoutm_dt_w = DateTime.Now.ToString("yyyyMMdd HH:mm:ss"),
|
|
|
|
wmsoutm_stat = "Y",
|
|
|
|
wmsoutm_tyrp_dt = "",
|
|
|
|
wmsoutm_user = exchangeOrder.Worker.Length >= 6 ? exchangeOrder.Worker.Substring(0, 6) : exchangeOrder.Worker,
|
|
|
|
wmsoutm_dept = "",//根据Worker从UserDepartment中获取
|
|
|
|
wmsoutm_date = exchangeOrder.ActiveDate.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(UnplannedIssueNoteExchangeDto exchangeOrder, UnplannedIssueNoteDetailExchangeDto exchangeDetailOrder)
|
|
|
|
{
|
|
|
|
var ret = new Wmsoutd()
|
|
|
|
{
|
|
|
|
wmsoutd_nbr = exchangeOrder.Number,
|
|
|
|
wmsoutd_part = exchangeDetailOrder.ItemCode,
|
|
|
|
wmsoutd_loc = exchangeDetailOrder.LocationErpCode ?? "",
|
|
|
|
wmsoutd_qty = exchangeDetailOrder.Qty,
|
|
|
|
wmsoutd_bcm_code = "",//有问题
|
|
|
|
wmsoutd_projt_id = "",//有问题
|
|
|
|
};
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|