35 changed files with 723 additions and 49 deletions
@ -0,0 +1,11 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Services; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Qtyrfe; |
|||
public interface IQtyrfeManager : IDomainService |
|||
{ |
|||
Task<List<Qtyrfe>> GetToBeProcessedListAsync(); |
|||
Task UpdateProcessedListAsync(List<Qtyrfe> entities); |
|||
Task UpdateProcesseErrordListAsync(List<Qtyrfe> entities); |
|||
} |
@ -0,0 +1,7 @@ |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Qtyrfe; |
|||
public interface IQtyrfeRepository : IRepository<Qtyrfe> |
|||
{ |
|||
|
|||
} |
@ -0,0 +1,50 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Qtyrfe; |
|||
public class Qtyrfe : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// 序号
|
|||
/// </summary>
|
|||
[Key] |
|||
public string mesout_qtyrfe_id { get; set; } |
|||
/// <summary>
|
|||
/// 物料
|
|||
/// </summary>
|
|||
public string mesout_qtyrfe_part { get; set; } |
|||
/// <summary>
|
|||
/// 调出储位
|
|||
/// </summary>
|
|||
public string mesout_qtyrfe_loc_from { get; set; } |
|||
/// <summary>
|
|||
/// 调入储位
|
|||
/// </summary>
|
|||
public string mesout_qtyrfe_loc_to { get; set; } |
|||
/// <summary>
|
|||
/// 数量
|
|||
/// </summary>
|
|||
public decimal mesout_qtyrfe_num { get; set; } |
|||
/// <summary>
|
|||
/// 调拨用户
|
|||
/// </summary>
|
|||
public string mesout_qtyrfe_user { get; set; } |
|||
/// <summary>
|
|||
/// 写入时间
|
|||
/// </summary>
|
|||
public string mesout_qtyrfe_wt { get; set; } |
|||
/// <summary>
|
|||
/// 类型(1为质量补)
|
|||
/// </summary>
|
|||
public string mesout_qtyrfe_type { get; set; } |
|||
|
|||
public override object[] GetKeys() |
|||
{ |
|||
return new object[] { mesout_qtyrfe_id }; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 是否读取(0,1)
|
|||
/// </summary>
|
|||
public long Yl1 { get; set; } |
|||
} |
@ -0,0 +1,45 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Services; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Qtyrfe; |
|||
public class QtyrfeManager : DomainService, IQtyrfeManager |
|||
{ |
|||
private readonly IQtyrfeRepository _repository; |
|||
|
|||
public QtyrfeManager(IQtyrfeRepository repository) |
|||
{ |
|||
_repository = repository; |
|||
} |
|||
public virtual async Task<List<Qtyrfe>> GetToBeProcessedListAsync() |
|||
{ |
|||
var plans = await _repository.GetListAsync(p => p.Yl1 == 0).ConfigureAwait(false); |
|||
return plans; |
|||
|
|||
} |
|||
public virtual async Task UpdateProcesseErrordListAsync(List<Qtyrfe> entities) |
|||
{ |
|||
var ids = entities.Select(p => p.mesout_qtyrfe_id); |
|||
var plans = await _repository.GetListAsync(p => ids.Contains(p.mesout_qtyrfe_id)).ConfigureAwait(false); |
|||
plans.ForEach(p => |
|||
{ |
|||
p.Yl1 = 2; |
|||
// p.WmsDate = Clock.Now;
|
|||
}); |
|||
await _repository.UpdateManyAsync(plans).ConfigureAwait(false); |
|||
} |
|||
public virtual async Task UpdateProcessedListAsync(List<Qtyrfe> entities) |
|||
{ |
|||
var ids = entities.Select(p => p.mesout_qtyrfe_id); |
|||
var plans = await _repository.GetListAsync(p => ids.Contains(p.mesout_qtyrfe_id)).ConfigureAwait(false); |
|||
plans.ForEach(p => |
|||
{ |
|||
p.Yl1 = 1; |
|||
|
|||
// p.WmsDate = Clock.Now;
|
|||
}); |
|||
await _repository.UpdateManyAsync(plans).ConfigureAwait(false); |
|||
} |
|||
} |
@ -0,0 +1,30 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore.Modeling; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Qtyrfe; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.EntityFrameworkCore.Fawtyg.Mes; |
|||
public static class QtyrfeDbContextModelCreatingExtensions |
|||
{ |
|||
public static void ConfigureQtyrfe(this ModelBuilder builder, MesModelBuilderConfigurationOptions options) |
|||
{ |
|||
builder.Entity<Qtyrfe>(b => |
|||
{ |
|||
//Configure table & schema Name
|
|||
b.ToTable(options.TablePrefix + "mesout_qtyrfe", options.Schema); |
|||
//Configure ABP properties
|
|||
b.ConfigureByConvention(); |
|||
|
|||
//Properties
|
|||
b.Property(q => q.mesout_qtyrfe_id).HasMaxLength(20); |
|||
b.Property(q => q.mesout_qtyrfe_part).HasMaxLength(20); |
|||
b.Property(q => q.mesout_qtyrfe_loc_from).HasMaxLength(10); |
|||
b.Property(q => q.mesout_qtyrfe_loc_to).HasMaxLength(10); |
|||
b.Property(q => q.mesout_qtyrfe_num).HasPrecision(10, 2); |
|||
b.Property(q => q.mesout_qtyrfe_user).HasMaxLength(20); |
|||
b.Property(q => q.mesout_qtyrfe_wt).HasMaxLength(20); |
|||
b.Property(q => q.mesout_qtyrfe_type).HasMaxLength(2); |
|||
b.Property(q => q.Yl1); |
|||
}); |
|||
|
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Qtyrfe; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.EntityFrameworkCore.Fawtyg.Mes; |
|||
|
|||
public class QtyrfeEfCoreRepository : EfCoreRepository<MesDbContext, Qtyrfe>, IQtyrfeRepository |
|||
{ |
|||
public QtyrfeEfCoreRepository(IDbContextProvider<MesDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
} |
@ -0,0 +1,140 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text.Json; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Logging; |
|||
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.WMS.TransferNote; |
|||
using Win_in.Sfs.Wms.Store.Application.Contracts; |
|||
using Volo.Abp.ObjectMapping; |
|||
using Win_in.Sfs.Wms.Store.Domain; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Incoming; |
|||
public class QtyrfeConverter : IIncomingConverter |
|||
{ |
|||
private readonly IIncomingFromExternalManager _incomingFromExternalManager; |
|||
private readonly IIncomingToWmsManager _incomingToWmsManager; |
|||
private readonly IObjectMapper _objectMapper; |
|||
private readonly IItemBasicAppService _itemBasicAppService; |
|||
private readonly ILocationAppService _locationAppService; |
|||
private readonly ILogger<QtyrfeConverter> _logger; |
|||
|
|||
public QtyrfeConverter( |
|||
IIncomingToWmsManager incomingToWmsManager |
|||
, IObjectMapper objectMapper |
|||
, IItemBasicAppService itemBasicAppService |
|||
, ILogger<QtyrfeConverter> logger, |
|||
ILocationAppService locationAppService, |
|||
IIncomingFromExternalManager incomingFromExternalManager) |
|||
{ |
|||
_incomingToWmsManager = incomingToWmsManager; |
|||
_objectMapper = objectMapper; |
|||
_itemBasicAppService = itemBasicAppService; |
|||
_logger = logger; |
|||
_locationAppService = locationAppService; |
|||
_incomingFromExternalManager = incomingFromExternalManager; |
|||
} |
|||
|
|||
public virtual async Task ConvertAsync(List<IncomingFromExternal> incomingFromExternalList) |
|||
{ |
|||
if (!incomingFromExternalList.Any()) |
|||
{ |
|||
_logger.LogInformation("no Qtyrfes"); |
|||
return; |
|||
} |
|||
|
|||
//按Number合并TransferNote单据
|
|||
var transferNoteList = await BuildIncomingToWmsOfTransferNoteAsync(incomingFromExternalList).ConfigureAwait(false); |
|||
await _incomingToWmsManager.CreateManyAsync(transferNoteList).ConfigureAwait(false); |
|||
//归档
|
|||
await _incomingFromExternalManager.ArchiveManyAsync(incomingFromExternalList).ConfigureAwait(false); |
|||
} |
|||
|
|||
private async Task<List<IncomingToWms>> BuildIncomingToWmsOfTransferNoteAsync(List<IncomingFromExternal> incomingDataList) |
|||
{ |
|||
var incomingToWmsList = new List<IncomingToWms>(); |
|||
var groups = incomingDataList.GroupBy(p => p.SourceDataGroupCode); |
|||
foreach (var group in groups) |
|||
{ |
|||
var first = group.First(); |
|||
var incomingToWms = new IncomingToWms() |
|||
{ |
|||
DataType = first.DataType, |
|||
DataAction = first.DataAction, |
|||
SourceSystem = first.SourceSystem, |
|||
DataIdentityCode = first.SourceDataGroupCode, |
|||
}; |
|||
incomingToWms.SetEffectiveDate(first.EffectiveDate); |
|||
var exchangeTransferNote = JsonSerializer.Deserialize<TransferNoteExchangeDto>(first.DestinationDataContent); |
|||
var wmsTransferNote = _objectMapper.Map<TransferNoteExchangeDto, TransferNoteEditInput>(exchangeTransferNote); |
|||
wmsTransferNote.Type = EnumTransSubType.Transfer_Area.ToString();//客户储位调拨
|
|||
wmsTransferNote.Details = new List<TransferNoteDetailInput>(); |
|||
foreach (var incomingFromExternal in group.ToList()) |
|||
{ |
|||
var transferNote = JsonSerializer.Deserialize<TransferNoteExchangeDto>(incomingFromExternal.DestinationDataContent); |
|||
var wmsTransferNoteDetail = _objectMapper.Map<TransferNoteDetailExchangeDto, TransferNoteDetailInput>(transferNote.Detail); |
|||
var item = await _itemBasicAppService.GetByCodeAsync(wmsTransferNoteDetail.ItemCode).ConfigureAwait(false); |
|||
var tolocation=await _locationAppService.GetByCodeAsync(wmsTransferNoteDetail.ToLocationErpCode).ConfigureAwait(false); |
|||
var fromlocation = await _locationAppService.GetByCodeAsync(wmsTransferNoteDetail.FromLocationErpCode).ConfigureAwait(false); |
|||
try |
|||
{ |
|||
wmsTransferNoteDetail.FromPackingCode = ""; |
|||
wmsTransferNoteDetail.ToPackingCode = ""; |
|||
wmsTransferNoteDetail.FromLot = ""; |
|||
wmsTransferNoteDetail.ToLot = ""; |
|||
wmsTransferNoteDetail.FromStatus = EnumInventoryStatus.OK; |
|||
wmsTransferNoteDetail.ToStatus = EnumInventoryStatus.OK; |
|||
if (transferNote.Remark.Contains("质量补移库"))//质量补
|
|||
{ |
|||
wmsTransferNoteDetail.FromPackingCode = "RFE"; //质量补排序批次
|
|||
wmsTransferNoteDetail.FromLot = "RFE";//质量补箱标签
|
|||
wmsTransferNoteDetail.ToPackingCode = "RFE"; //质量补排序批次
|
|||
wmsTransferNoteDetail.ToLot = "RFE";//质量补箱标签
|
|||
} |
|||
if (item != null) |
|||
{ |
|||
wmsTransferNoteDetail.ItemName = item.Name; |
|||
wmsTransferNoteDetail.ItemDesc1 = !string.IsNullOrEmpty(item.Desc1) ? item.Desc1 : ""; |
|||
wmsTransferNoteDetail.ItemDesc2 = !string.IsNullOrEmpty(item.Desc2) ? item.Desc2 : ""; |
|||
wmsTransferNoteDetail.Uom = !string.IsNullOrEmpty(item.BasicUom) ? item.BasicUom : ""; |
|||
wmsTransferNoteDetail.StdPackQty = item.StdPackQty; |
|||
} |
|||
if (tolocation != null) |
|||
{ |
|||
wmsTransferNoteDetail.ToLocationCode = tolocation.Code; |
|||
wmsTransferNoteDetail.ToLocationArea = tolocation.AreaCode; |
|||
wmsTransferNoteDetail.ToLocationGroup = tolocation.LocationGroupCode; |
|||
wmsTransferNoteDetail.ToWarehouseCode = tolocation.WarehouseCode; |
|||
if (tolocation.Type== EnumLocationType.CUST) |
|||
{ |
|||
wmsTransferNote.Type = EnumTransSubType.Transfer_Customer.ToString();//客户储位调拨
|
|||
} |
|||
} |
|||
if (fromlocation!=null) |
|||
{ |
|||
wmsTransferNoteDetail.FromLocationCode = fromlocation.Code; |
|||
wmsTransferNoteDetail.FromLocationArea = fromlocation.AreaCode; |
|||
wmsTransferNoteDetail.FromLocationGroup = fromlocation.LocationGroupCode; |
|||
wmsTransferNoteDetail.FromWarehouseCode = fromlocation.WarehouseCode; |
|||
} |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
wmsTransferNoteDetail.ItemName = ""; |
|||
wmsTransferNoteDetail.ItemDesc1 = ""; |
|||
wmsTransferNoteDetail.ItemDesc2 = ""; |
|||
wmsTransferNoteDetail.Uom = ""; |
|||
} |
|||
|
|||
wmsTransferNote.Details.Add(wmsTransferNoteDetail); |
|||
} |
|||
incomingToWms.DataContent = JsonSerializer.Serialize(wmsTransferNote); |
|||
incomingToWmsList.Add(incomingToWms); |
|||
} |
|||
return incomingToWmsList; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,117 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text.Json; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Logging; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Qtyrfe; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain.Shared; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain; |
|||
using Win_in.Sfs.Wms.DataExchange.WMS.MaterialRequest; |
|||
using Win_in.Sfs.Wms.DataExchange.WMS.TransferNote; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Incoming; |
|||
public class QtyrfeReader : IReader |
|||
{ |
|||
private readonly IQtyrfeManager _QtyrfeManager; |
|||
private readonly IIncomingFromExternalManager _incomingFromExternalManager; |
|||
private readonly ILogger<QtyrfeReader> _logger; |
|||
|
|||
public QtyrfeReader( |
|||
IQtyrfeManager pillTaskManager |
|||
, IIncomingFromExternalManager incomingFromExternalManager |
|||
, ILogger<QtyrfeReader> logger |
|||
) |
|||
{ |
|||
_QtyrfeManager = pillTaskManager; |
|||
_incomingFromExternalManager = incomingFromExternalManager; |
|||
_logger = logger; |
|||
} |
|||
|
|||
public virtual async Task<List<IncomingFromExternal>> ReadAsync() |
|||
|
|||
{ |
|||
//从MES读取待处理Qtyrfe
|
|||
var toBeProcessedPillTasks = await _QtyrfeManager.GetToBeProcessedListAsync().ConfigureAwait(false); |
|||
if (!toBeProcessedPillTasks.Any()) |
|||
{ |
|||
_logger.LogInformation("no Qtyrfes"); |
|||
return new List<IncomingFromExternal>(); |
|||
} |
|||
//Qtyrfe逐一转换为MaterialRequest
|
|||
var incomingDataList = BuildIncomingFromExternalFromPillTaskAsync(toBeProcessedPillTasks); |
|||
await _incomingFromExternalManager.CreateManyAsync(incomingDataList).ConfigureAwait(false); |
|||
//更新MES数据状态
|
|||
await _QtyrfeManager.UpdateProcessedListAsync(toBeProcessedPillTasks).ConfigureAwait(false); |
|||
|
|||
return incomingDataList; |
|||
} |
|||
|
|||
private static List<IncomingFromExternal> BuildIncomingFromExternalFromPillTaskAsync(List<Qtyrfe> toBeProcessedQtyrfes) |
|||
{ |
|||
var incomingDataList = new List<IncomingFromExternal>(); |
|||
foreach (var Qtyrfe in toBeProcessedQtyrfes) |
|||
{ |
|||
var incomingData = BuildIncomingFromExternal(Qtyrfe); |
|||
|
|||
incomingData.SetEffectiveDate(DateTime.Now); |
|||
incomingData.SetSuccess(); |
|||
try |
|||
{ |
|||
var MaterialRequest = BuildTransferNoteCreateInput(Qtyrfe); |
|||
incomingData.DestinationDataContent = JsonSerializer.Serialize(MaterialRequest); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
incomingData.SetError(EnumExchangeDataErrorCode.Exception, ex.Message, ex.ToString()); |
|||
} |
|||
|
|||
incomingDataList.Add(incomingData); |
|||
|
|||
} |
|||
|
|||
return incomingDataList; |
|||
} |
|||
|
|||
private static IncomingFromExternal BuildIncomingFromExternal(Qtyrfe Qtyrfe) |
|||
{ |
|||
var incomingData = new IncomingFromExternal() |
|||
{ |
|||
DataType = EnumIncomingDataType.TransferNote.ToString(), |
|||
DataAction = EnumExchangeDataAction.Add, |
|||
SourceSystem = EnumSystemType.MES.ToString(), |
|||
SourceDataId = Qtyrfe.mesout_qtyrfe_id.ToString(), |
|||
SourceDataGroupCode = Qtyrfe.mesout_qtyrfe_id, |
|||
SourceDataDetailCode = Qtyrfe.mesout_qtyrfe_part, |
|||
SourceDataContent = JsonSerializer.Serialize(Qtyrfe), |
|||
WriteTime = DateTime.Now, |
|||
Writer = nameof(MesIncomingBackgroundWorker), |
|||
|
|||
DestinationSystem = EnumSystemType.WMS.ToString(), |
|||
}; |
|||
return incomingData; |
|||
} |
|||
|
|||
private static TransferNoteExchangeDto BuildTransferNoteCreateInput(Qtyrfe Qtyrfe) |
|||
{ |
|||
var transferNote = new TransferNoteExchangeDto() |
|||
{ |
|||
Worker = Qtyrfe.mesout_qtyrfe_user, |
|||
Remark = "" |
|||
}; |
|||
if (Qtyrfe.mesout_qtyrfe_type == "1") |
|||
{ |
|||
transferNote.Remark = "质量补移库"; |
|||
} |
|||
var transferNoteDetail = new TransferNoteDetailExchangeDto() |
|||
{ |
|||
ItemCode = Qtyrfe.mesout_qtyrfe_part, |
|||
Qty =Qtyrfe.mesout_qtyrfe_num, |
|||
ToLocationErpCode = Qtyrfe.mesout_qtyrfe_loc_to, |
|||
FromLocationErpCode = Qtyrfe.mesout_qtyrfe_loc_from, |
|||
}; |
|||
transferNote.Detail = transferNoteDetail; |
|||
return transferNote; |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue