20 changed files with 395 additions and 37 deletions
@ -0,0 +1,56 @@ |
|||||
|
using Volo.Abp.Domain.Entities; |
||||
|
|
||||
|
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Mes; |
||||
|
public class Backflu : Entity |
||||
|
{ |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// MES写入时间
|
||||
|
/// </summary>
|
||||
|
public string scmout_dt_w { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 单据类型
|
||||
|
/// </summary>
|
||||
|
public string scmout_type { get; set; } |
||||
|
/// <summary>
|
||||
|
/// TYRP单号
|
||||
|
/// </summary>
|
||||
|
public string scmout_nbr { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 料号
|
||||
|
/// </summary>
|
||||
|
public string scmout_part { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 追加码/预定交货日/序号/储位
|
||||
|
/// </summary>
|
||||
|
public string scmout_no { get; set; } |
||||
|
/// <summary>
|
||||
|
/// TYRP异动储位
|
||||
|
/// </summary>
|
||||
|
public string scmout_loc { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 库存交易年月
|
||||
|
/// </summary>
|
||||
|
public string scmout_ym { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 库存交易日
|
||||
|
/// </summary>
|
||||
|
public string scmout_date { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 数量
|
||||
|
/// </summary>
|
||||
|
public decimal scmout_qty { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 调入储位
|
||||
|
/// </summary>
|
||||
|
public string scmout_in_loc { get; set; } |
||||
|
/// <summary>
|
||||
|
/// 有效码
|
||||
|
/// </summary>
|
||||
|
public string scmout_stat { get; set; } |
||||
|
|
||||
|
public override object[] GetKeys() |
||||
|
{ |
||||
|
return new object[] { scmout_type + scmout_nbr + scmout_part + scmout_no }; |
||||
|
} |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
|
||||
|
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Mes; |
||||
|
public class BackfluManager : DomainService, IBackfluManager |
||||
|
{ |
||||
|
private readonly IBackfluLinq2DbRepository _repository; |
||||
|
public BackfluManager(IBackfluLinq2DbRepository repository) |
||||
|
{ |
||||
|
_repository = repository; |
||||
|
} |
||||
|
|
||||
|
public async Task<List<scmout>> GetToBeProcessedListAsync() |
||||
|
{ |
||||
|
var Backflu = await _repository.GetListAsync().ConfigureAwait(false); |
||||
|
|
||||
|
return Backflu.ToList(); |
||||
|
} |
||||
|
public virtual async Task UpdateProcessedListAsync(List<scmout> entities) |
||||
|
{ |
||||
|
foreach (var entitie in entities) |
||||
|
{ |
||||
|
entitie.scmout_stat = "N"; |
||||
|
await _repository.UpdateAsync(entitie).ConfigureAwait(false); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
|
||||
|
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Mes; |
||||
|
public interface IBackfluManager : IDomainService |
||||
|
{ |
||||
|
Task<List<Backflu>> GetToBeProcessedListAsync(); |
||||
|
Task UpdateProcessedListAsync(List<Backflu> entities); |
||||
|
} |
@ -0,0 +1,7 @@ |
|||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
|
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Mes; |
||||
|
public interface IBackfluRepository : IRepository<Backflu> |
||||
|
{ |
||||
|
|
||||
|
} |
@ -0,0 +1,31 @@ |
|||||
|
|
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore.Modeling; |
||||
|
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Mes; |
||||
|
|
||||
|
namespace Win_in.Sfs.Wms.DataExchange.EntityFrameworkCore.Fawtyg.Mes; |
||||
|
public static class BackfluDbContextModelCreatingExtensions |
||||
|
{ |
||||
|
public static void ConfigureBackflu(this ModelBuilder builder, MesModelBuilderConfigurationOptions options) |
||||
|
{ |
||||
|
builder.Entity<Backflu>(b => |
||||
|
{ |
||||
|
//Configure table & schema Name
|
||||
|
b.ToTable(options.TablePrefix + "scmout", options.Schema); |
||||
|
//Configure ABP properties
|
||||
|
b.ConfigureByConvention(); |
||||
|
b.Property(q => q.scmout_dt_w).HasMaxLength(20); |
||||
|
b.Property(q => q.scmout_type).HasMaxLength(6); |
||||
|
b.Property(q => q.scmout_nbr).HasMaxLength(12); |
||||
|
b.Property(q => q.scmout_part).HasMaxLength(20); |
||||
|
b.Property(q => q.scmout_no).HasMaxLength(10); |
||||
|
b.Property(q => q.scmout_loc).HasMaxLength(10); |
||||
|
b.Property(q => q.scmout_ym).HasMaxLength(6); |
||||
|
b.Property(q => q.scmout_date).HasMaxLength(8); |
||||
|
b.Property(q => q.scmout_qty).HasPrecision(10, 2); |
||||
|
b.Property(q => q.scmout_in_loc).HasMaxLength(10); |
||||
|
b.Property(q => q.scmout_stat).HasMaxLength(1); |
||||
|
}); |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Mes; |
||||
|
|
||||
|
namespace Win_in.Sfs.Wms.DataExchange.EntityFrameworkCore.Fawtyg.Mes; |
||||
|
public class BackfluEfCoreRepository : EfCoreRepository<MesDbContext, Backflu>, IBackfluRepository |
||||
|
{ |
||||
|
public BackfluEfCoreRepository(IDbContextProvider<MesDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
} |
@ -0,0 +1,83 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text.Json; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Volo.Abp.ObjectMapping; |
||||
|
using Win_in.Sfs.Basedata.Application.Contracts; |
||||
|
using Win_in.Sfs.Wms.DataExchange.Domain; |
||||
|
using Win_in.Sfs.Wms.DataExchange.WMS.BackFlushNote; |
||||
|
using Win_in.Sfs.Wms.Store.Application.Contracts; |
||||
|
|
||||
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Incoming; |
||||
|
|
||||
|
public class BackFluConverter : IIncomingConverter |
||||
|
{ |
||||
|
private readonly IIncomingFromExternalManager _incomingFromExternalManager; |
||||
|
private readonly IIncomingToWmsManager _incomingToWmsManager; |
||||
|
private readonly IItemBasicAppService _itemBasicAppService; |
||||
|
private readonly IObjectMapper _objectMapper; |
||||
|
private readonly ILogger<BackFluConverter> _logger; |
||||
|
public BackFluConverter( |
||||
|
IIncomingToWmsManager incomingToWmsManager, |
||||
|
IItemBasicAppService itemBasicAppService, |
||||
|
IObjectMapper objectMapper, |
||||
|
ILogger<BackFluConverter> logger |
||||
|
, |
||||
|
IIncomingFromExternalManager incomingFromExternalManager |
||||
|
|
||||
|
) |
||||
|
{ |
||||
|
_incomingToWmsManager = incomingToWmsManager; |
||||
|
_itemBasicAppService = itemBasicAppService; |
||||
|
_objectMapper = objectMapper; |
||||
|
_logger = logger; |
||||
|
_incomingFromExternalManager = incomingFromExternalManager; |
||||
|
} |
||||
|
public virtual async Task ConvertAsync(List<IncomingFromExternal> incomingFromExternalList) |
||||
|
{ |
||||
|
if (!incomingFromExternalList.Any()) |
||||
|
{ |
||||
|
_logger.LogInformation("no backflus"); |
||||
|
return; |
||||
|
} |
||||
|
var incomingToWmsDataList = await BuildIncomingToWmsOfPurchaseOrderAsync(incomingFromExternalList).ConfigureAwait(false); |
||||
|
await _incomingToWmsManager.CreateManyAsync(incomingToWmsDataList).ConfigureAwait(false); |
||||
|
//归档
|
||||
|
await _incomingFromExternalManager.ArchiveBulkAsync(incomingFromExternalList).ConfigureAwait(false); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
private async Task<List<IncomingToWms>> BuildIncomingToWmsOfPurchaseOrderAsync(List<IncomingFromExternal> incomingDataList) |
||||
|
{ |
||||
|
await Task.CompletedTask.ConfigureAwait(false); |
||||
|
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 exchangeBack = JsonSerializer.Deserialize<BackFlushNoteExchangeDto>(first.DestinationDataContent); |
||||
|
var wmsBack = _objectMapper.Map<BackFlushNoteExchangeDto, BackFlushNoteEditInput>(exchangeBack); |
||||
|
wmsBack.Details = new List<BackFlushNoteDetailInput>(); |
||||
|
foreach (var incomingFromExternal in group.ToList()) |
||||
|
{ |
||||
|
var back = JsonSerializer.Deserialize<BackFlushNoteExchangeDto>(incomingFromExternal.DestinationDataContent); |
||||
|
var wmsBackDetail = _objectMapper.Map<BackFlushNoteDetailExchangeDto, BackFlushNoteDetailInput>(back.Detail); |
||||
|
|
||||
|
wmsBack.Details.Add(wmsBackDetail); |
||||
|
} |
||||
|
incomingToWms.DataContent = JsonSerializer.Serialize(wmsBack); |
||||
|
incomingToWmsList.Add(incomingToWms); |
||||
|
} |
||||
|
return incomingToWmsList; |
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,112 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text.Json; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Win_in.Sfs.Wms.DataExchange.Domain; |
||||
|
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.Mes; |
||||
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared; |
||||
|
|
||||
|
using Win_in.Sfs.Wms.DataExchange.WMS.BackFlushNote; |
||||
|
|
||||
|
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Incoming; |
||||
|
|
||||
|
public class BackFluReader : IReader |
||||
|
{ |
||||
|
private readonly IBackfluManager _ibackfluManager; |
||||
|
private readonly IIncomingFromExternalManager _incomingFromExternalManager; |
||||
|
private readonly ILogger<BackFluReader> _logger; |
||||
|
private readonly IConfiguration _configuration; |
||||
|
public BackFluReader( |
||||
|
IBackfluManager ibackfuManager |
||||
|
, IIncomingFromExternalManager incomingFromExternalManager |
||||
|
, ILogger<BackFluReader> logger |
||||
|
, IConfiguration configuration |
||||
|
) |
||||
|
{ |
||||
|
_ibackfluManager = ibackfuManager; |
||||
|
_incomingFromExternalManager = incomingFromExternalManager; |
||||
|
_logger = logger; |
||||
|
_configuration = configuration; |
||||
|
} |
||||
|
public virtual async Task<List<IncomingFromExternal>> ReadAsync() |
||||
|
{ |
||||
|
//从Tyrp读取待处理bom
|
||||
|
var BackFull = await _ibackfluManager.GetToBeProcessedListAsync().ConfigureAwait(false); |
||||
|
var toBeProcessedBack = BackFull.Where(p => p.scmout_stat == "Y").ToList(); |
||||
|
if (!toBeProcessedBack.Any()) |
||||
|
{ |
||||
|
_logger.LogInformation("no backflus"); |
||||
|
return new List<IncomingFromExternal>(); |
||||
|
} |
||||
|
//bom逐一转换为bomNote
|
||||
|
var incomingDataList = BuildIncomingFromExternalFromBomAsync(toBeProcessedBack); |
||||
|
await _incomingFromExternalManager.CreateManyAsync(incomingDataList).ConfigureAwait(false); |
||||
|
await _ibackfluManager.UpdateProcessedListAsync(toBeProcessedBack).ConfigureAwait(false); |
||||
|
return incomingDataList; |
||||
|
} |
||||
|
private List<IncomingFromExternal> BuildIncomingFromExternalFromBomAsync(List<Backflu> toBeProcessedIssue) |
||||
|
{ |
||||
|
var incomingDataList = new List<IncomingFromExternal>(); |
||||
|
foreach (var backflu in toBeProcessedIssue) |
||||
|
{ |
||||
|
var incomingData = BuildIncomingFromExternal(backflu); |
||||
|
|
||||
|
incomingData.SetEffectiveDate(DateTime.Now); |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
var bm = BuildScrapNoteOrderExchangeMes(backflu); |
||||
|
incomingData.DestinationDataContent = JsonSerializer.Serialize(backflu); |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
incomingData.SetError(EnumExchangeDataErrorCode.Exception, ex.Message, ex.ToString()); |
||||
|
} |
||||
|
|
||||
|
incomingDataList.Add(incomingData); |
||||
|
|
||||
|
} |
||||
|
return incomingDataList; |
||||
|
} |
||||
|
private IncomingFromExternal BuildIncomingFromExternal(Backflu backflu) |
||||
|
{ |
||||
|
var incomingData = new IncomingFromExternal() |
||||
|
{ |
||||
|
DataType = EnumIncomingDataType.BackFlush.ToString(), |
||||
|
DataAction = EnumExchangeDataAction.Add, |
||||
|
SourceSystem = EnumSystemType.ERP.ToString(), |
||||
|
SourceDataId = backflu.scmout_type, |
||||
|
SourceDataGroupCode = backflu.scmout_nbr, |
||||
|
SourceDataDetailCode = backflu.scmout_part, |
||||
|
SourceDataContent = JsonSerializer.Serialize(backflu), |
||||
|
WriteTime = DateTime.Now, |
||||
|
Writer = nameof(MesIncomingBackgroundWorker), |
||||
|
DestinationSystem = EnumSystemType.ERP.ToString(), |
||||
|
}; |
||||
|
return incomingData; |
||||
|
} |
||||
|
|
||||
|
private static BackFlushNoteExchangeDto BuildScrapNoteOrderExchangeMes(Backflu backflu) |
||||
|
{ |
||||
|
|
||||
|
var back = new BackFlushNoteExchangeDto() |
||||
|
{ |
||||
|
|
||||
|
ActiveDate = Convert.ToDateTime(backflu.scmout_dt_w.Substring(0, 4) + "-" + backflu.scmout_dt_w.Substring(4, 2) + "-" + backflu.scmout_dt_w.Substring(6, 2)), |
||||
|
ItemCode = backflu.scmout_part, |
||||
|
Number = backflu.scmout_nbr |
||||
|
}; |
||||
|
var bakcdetail = new BackFlushNoteDetailExchangeDto() |
||||
|
{ |
||||
|
Number = backflu.scmout_nbr, |
||||
|
ItemCode = backflu.scmout_part, |
||||
|
Qty = backflu.scmout_qty, |
||||
|
LocationErpCode = backflu.scmout_loc |
||||
|
}; |
||||
|
back.Detail = bakcdetail; |
||||
|
return back; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue