22 changed files with 558 additions and 42 deletions
@ -0,0 +1,39 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.CallMtl; |
|||
public class CallMtl : Entity |
|||
{ |
|||
/// <summary>
|
|||
/// 序号
|
|||
/// </summary>
|
|||
[Key] |
|||
public string mesout_callmtl_id { get; set; } |
|||
/// <summary>
|
|||
/// 物料
|
|||
/// </summary>
|
|||
public string mesout_callmtl_erpno { get; set; } |
|||
/// <summary>
|
|||
/// 库位
|
|||
/// </summary>
|
|||
public string mesout_callmtl_loc { get; set; } |
|||
/// <summary>
|
|||
/// 数量
|
|||
/// </summary>
|
|||
public decimal mesout_callmtl_num { get; set; } |
|||
/// <summary>
|
|||
/// 时间
|
|||
/// </summary>
|
|||
public string mesout_callmtl_wt { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 是否读取(0,1)
|
|||
/// </summary>
|
|||
public long Yl1 { get; set; } |
|||
|
|||
public override object[] GetKeys() |
|||
{ |
|||
return new object[] { mesout_callmtl_id }; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,44 @@ |
|||
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.CallMtl; |
|||
public class CallMtlManager : DomainService, ICallMtlManager |
|||
{ |
|||
private readonly ICallMtlRepository _repository; |
|||
|
|||
public CallMtlManager(ICallMtlRepository repository) |
|||
{ |
|||
_repository = repository; |
|||
} |
|||
public virtual async Task<List<CallMtl>> GetToBeProcessedListAsync() |
|||
{ |
|||
var plans = await _repository.GetListAsync(p => p.Yl1 == 0).ConfigureAwait(false); |
|||
return plans; |
|||
} |
|||
public virtual async Task UpdateProcesseErrordListAsync(List<CallMtl> entities) |
|||
{ |
|||
var ids = entities.Select(p => p.mesout_callmtl_id); |
|||
var plans = await _repository.GetListAsync(p => ids.Contains(p.mesout_callmtl_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<CallMtl> entities) |
|||
{ |
|||
var ids = entities.Select(p => p.mesout_callmtl_id); |
|||
var plans = await _repository.GetListAsync(p => ids.Contains(p.mesout_callmtl_id)).ConfigureAwait(false); |
|||
plans.ForEach(p => |
|||
{ |
|||
p.Yl1 = 1; |
|||
|
|||
// p.WmsDate = Clock.Now;
|
|||
}); |
|||
await _repository.UpdateManyAsync(plans).ConfigureAwait(false); |
|||
} |
|||
} |
@ -0,0 +1,10 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.CallMtl; |
|||
public interface ICallMtlManager |
|||
{ |
|||
Task<List<CallMtl>> GetToBeProcessedListAsync(); |
|||
Task UpdateProcessedListAsync(List<CallMtl> entities); |
|||
Task UpdateProcesseErrordListAsync(List<CallMtl> entities); |
|||
} |
@ -0,0 +1,7 @@ |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.CallMtl; |
|||
public interface ICallMtlRepository : IRepository<CallMtl> |
|||
{ |
|||
|
|||
} |
@ -0,0 +1,27 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore.Modeling; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.CallMtl; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.EntityFrameworkCore.Fawtyg.Mes; |
|||
public static class CallMtlDbContextModelCreatingExtensions |
|||
{ |
|||
public static void ConfigureCallMtl(this ModelBuilder builder, MesModelBuilderConfigurationOptions options) |
|||
{ |
|||
builder.Entity<CallMtl>(b => |
|||
{ |
|||
//Configure table & schema Name
|
|||
b.ToTable(options.TablePrefix + "mesout_callmtl", options.Schema); |
|||
//Configure ABP properties
|
|||
b.ConfigureByConvention(); |
|||
|
|||
//Properties
|
|||
b.Property(q => q.mesout_callmtl_id).HasMaxLength(20); |
|||
b.Property(q => q.mesout_callmtl_erpno).HasMaxLength(20); |
|||
b.Property(q => q.mesout_callmtl_loc).HasMaxLength(10); |
|||
b.Property(q => q.mesout_callmtl_num).HasPrecision(10, 2); |
|||
b.Property(q => q.mesout_callmtl_wt).HasMaxLength(20); |
|||
b.Property(q => q.Yl1); |
|||
}); |
|||
|
|||
} |
|||
} |
@ -0,0 +1,12 @@ |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.CallMtl; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.EntityFrameworkCore.Fawtyg.Mes; |
|||
public class CallMtlEfCoreRepository : EfCoreRepository<MesDbContext, CallMtl>, ICallMtlRepository |
|||
{ |
|||
public CallMtlEfCoreRepository(IDbContextProvider<MesDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
} |
|||
} |
@ -0,0 +1,101 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
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.InjectionIssueRequest; |
|||
using Win_in.Sfs.Wms.Store.Application.Contracts; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Incoming; |
|||
public class CallMtlConverter : IIncomingConverter |
|||
{ |
|||
private readonly IIncomingFromExternalManager _incomingFromExternalManager; |
|||
private readonly IIncomingToWmsManager _incomingToWmsManager; |
|||
private readonly IObjectMapper _objectMapper; |
|||
private readonly IItemBasicAppService _itemBasicAppService; |
|||
private readonly ILocationAppService _locationAppService; |
|||
private readonly ILogger<CallMtlConverter> _logger; |
|||
|
|||
public CallMtlConverter( |
|||
IIncomingToWmsManager incomingToWmsManager |
|||
, IObjectMapper objectMapper |
|||
, IItemBasicAppService itemBasicAppService |
|||
, ILogger<CallMtlConverter> 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 CallMtls"); |
|||
return; |
|||
} |
|||
|
|||
//按Number合并InjectionIssue单据
|
|||
var transferNoteList = await BuildIncomingToWmsOfInjectionIssueAsync(incomingFromExternalList).ConfigureAwait(false); |
|||
await _incomingToWmsManager.CreateManyAsync(transferNoteList).ConfigureAwait(false); |
|||
//归档
|
|||
await _incomingFromExternalManager.ArchiveManyAsync(incomingFromExternalList).ConfigureAwait(false); |
|||
} |
|||
|
|||
private async Task<List<IncomingToWms>> BuildIncomingToWmsOfInjectionIssueAsync(List<IncomingFromExternal> incomingDataList) |
|||
{ |
|||
var incomingToWmsList = new List<IncomingToWms>(); |
|||
foreach (var incomingData in incomingDataList) |
|||
{ |
|||
var incomingToWms = new IncomingToWms() |
|||
{ |
|||
DataType = incomingData.DataType, |
|||
DataAction = incomingData.DataAction, |
|||
SourceSystem = incomingData.SourceSystem, |
|||
DataIdentityCode = incomingData.SourceDataGroupCode, |
|||
}; |
|||
incomingToWms.SetEffectiveDate(incomingData.EffectiveDate); |
|||
var exchangeInjectionIssue = JsonSerializer.Deserialize<InjectionIssueRequestExchangeDto>(incomingData.DestinationDataContent); |
|||
var wmsInjectionIssueDetail = _objectMapper.Map<InjectionIssueRequestDetailExchangeDto, InjectionIssueRequestDetailInput>(exchangeInjectionIssue.Detail); |
|||
var wmsInjectionIssue = _objectMapper.Map<InjectionIssueRequestExchangeDto, InjectionIssueRequestEditInput>(exchangeInjectionIssue); |
|||
wmsInjectionIssue.Details = new List<InjectionIssueRequestDetailInput>(); |
|||
var item = await _itemBasicAppService.GetByCodeAsync(wmsInjectionIssueDetail.ItemCode).ConfigureAwait(false); |
|||
try |
|||
{ |
|||
|
|||
if (item != null) |
|||
{ |
|||
wmsInjectionIssueDetail.ItemName = item.Name; |
|||
wmsInjectionIssueDetail.ItemDesc1 = !string.IsNullOrEmpty(item.Desc1) ? item.Desc1 : ""; |
|||
wmsInjectionIssueDetail.ItemDesc2 = !string.IsNullOrEmpty(item.Desc2) ? item.Desc2 : ""; |
|||
wmsInjectionIssueDetail.Uom = !string.IsNullOrEmpty(item.BasicUom) ? item.BasicUom : ""; |
|||
wmsInjectionIssueDetail.StdPackQty = item.StdPackQty; |
|||
} |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
wmsInjectionIssueDetail.ItemName = ""; |
|||
wmsInjectionIssueDetail.ItemDesc1 = ""; |
|||
wmsInjectionIssueDetail.ItemDesc2 = ""; |
|||
wmsInjectionIssueDetail.Uom = ""; |
|||
} |
|||
|
|||
wmsInjectionIssue.Details.Add(wmsInjectionIssueDetail); |
|||
|
|||
incomingToWms.DataContent = JsonSerializer.Serialize(wmsInjectionIssue); |
|||
incomingToWmsList.Add(incomingToWms); |
|||
} |
|||
return incomingToWmsList; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,121 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Logging; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain.Shared; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain; |
|||
using System.Text.Json; |
|||
using Win_in.Sfs.Basedata.Application.Contracts; |
|||
using Win_in.Sfs.Shared.Domain.Shared; |
|||
using Win_in.Sfs.Wms.DataExchange.Domain.Fawtyg.CallMtl; |
|||
using Win_in.Sfs.Wms.DataExchange.WMS.InjectionIssueRequest; |
|||
using Win_in.Sfs.Shared.Domain.Shared.Enums.Store; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.Fawtyg.MesAgent.Incoming; |
|||
public class CallMtlReader : IReader |
|||
{ |
|||
private readonly ICallMtlManager _CallMtlManager; |
|||
private readonly IIncomingFromExternalManager _incomingFromExternalManager; |
|||
private readonly ILogger<CallMtlReader> _logger; |
|||
private readonly ILocationAppService _locationAppService; |
|||
|
|||
public CallMtlReader( |
|||
ICallMtlManager pillTaskManager |
|||
, IIncomingFromExternalManager incomingFromExternalManager |
|||
, ILogger<CallMtlReader> logger |
|||
, ILocationAppService locationAppService |
|||
) |
|||
{ |
|||
_CallMtlManager = pillTaskManager; |
|||
_incomingFromExternalManager = incomingFromExternalManager; |
|||
_logger = logger; |
|||
_locationAppService = locationAppService; |
|||
} |
|||
|
|||
public virtual async Task<List<IncomingFromExternal>> ReadAsync() |
|||
|
|||
{ |
|||
//从MES读取待处理CallMtl
|
|||
var toBeProcessedPillTasks = await _CallMtlManager.GetToBeProcessedListAsync().ConfigureAwait(false); |
|||
if (!toBeProcessedPillTasks.Any()) |
|||
{ |
|||
_logger.LogInformation("no CallMtls"); |
|||
return new List<IncomingFromExternal>(); |
|||
} |
|||
//CallMtl逐一转换为MaterialRequest
|
|||
var holdLocation = await _locationAppService.GetFirstByTypeAsync(EnumLocationType.HOLD).ConfigureAwait(false); |
|||
var incomingDataList = BuildIncomingFromExternalFromPillTaskAsync(toBeProcessedPillTasks, holdLocation == null ? "" : holdLocation.Code); |
|||
await _incomingFromExternalManager.CreateManyAsync(incomingDataList).ConfigureAwait(false); |
|||
//更新MES数据状态
|
|||
await _CallMtlManager.UpdateProcessedListAsync(toBeProcessedPillTasks).ConfigureAwait(false); |
|||
|
|||
return incomingDataList; |
|||
} |
|||
|
|||
private static List<IncomingFromExternal> BuildIncomingFromExternalFromPillTaskAsync(List<CallMtl> toBeProcessedCallMtls, string holdLocationCode) |
|||
{ |
|||
var incomingDataList = new List<IncomingFromExternal>(); |
|||
foreach (var CallMtl in toBeProcessedCallMtls) |
|||
{ |
|||
var incomingData = BuildIncomingFromExternal(CallMtl); |
|||
|
|||
incomingData.SetEffectiveDate(DateTime.Now); |
|||
incomingData.SetSuccess(); |
|||
try |
|||
{ |
|||
var MaterialRequest = BuildMesNoteCreateInput(CallMtl, holdLocationCode); |
|||
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(CallMtl CallMtl) |
|||
{ |
|||
var incomingData = new IncomingFromExternal() |
|||
{ |
|||
DataType = EnumIncomingDataType.CallMtl.ToString(), |
|||
DataAction = EnumExchangeDataAction.Add, |
|||
SourceSystem = EnumSystemType.MES.ToString(), |
|||
SourceDataId = CallMtl.mesout_callmtl_id.ToString(), |
|||
SourceDataGroupCode = CallMtl.mesout_callmtl_id, |
|||
SourceDataDetailCode = CallMtl.mesout_callmtl_erpno, |
|||
SourceDataContent = JsonSerializer.Serialize(CallMtl), |
|||
WriteTime = DateTime.Now, |
|||
Writer = nameof(MesIncomingBackgroundWorker), |
|||
|
|||
DestinationSystem = EnumSystemType.WMS.ToString(), |
|||
}; |
|||
return incomingData; |
|||
} |
|||
|
|||
private static InjectionIssueRequestExchangeDto BuildMesNoteCreateInput(CallMtl CallMtl, string holdLocationCode) |
|||
{ |
|||
var request = new InjectionIssueRequestExchangeDto() |
|||
{ |
|||
IssueRequestType = EnumIssueRequestType.Mes, |
|||
Worker = "MesZDJL", |
|||
ActiveDate = DateTime.TryParse(CallMtl.mesout_callmtl_wt, out DateTime dateTime) ? dateTime : DateTime.Now |
|||
}; |
|||
var detail = new InjectionIssueRequestDetailExchangeDto() |
|||
{ |
|||
ItemCode = CallMtl.mesout_callmtl_erpno, |
|||
Qty = CallMtl.mesout_callmtl_num, |
|||
BoxQty = CallMtl.mesout_callmtl_num, |
|||
ToLocationCode = CallMtl.mesout_callmtl_loc, |
|||
RecommendType = EnumRecommendType.RAW, |
|||
}; |
|||
request.Detail = detail; |
|||
return request; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Win_in.Sfs.Shared.Domain.Shared; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.WMS.InjectionIssueRequest; |
|||
public class InjectionIssueRequestDetailExchangeDto |
|||
{ |
|||
/// <summary>
|
|||
/// 目标ERP储位
|
|||
/// </summary>
|
|||
[Display(Name = "目标储位")] |
|||
public string ToLocationCode { get; set; } |
|||
/// <summary>
|
|||
/// 数量
|
|||
/// </summary>
|
|||
[Display(Name = "数量")] |
|||
public decimal Qty { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 需求箱数量
|
|||
/// </summary>
|
|||
[Display(Name = "需求箱数量")] |
|||
public decimal BoxQty { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 物品代码
|
|||
/// </summary>
|
|||
[Display(Name = "物品代码")] |
|||
public string ItemCode { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 推荐类型
|
|||
/// </summary>
|
|||
public EnumRecommendType RecommendType { get; set; } |
|||
} |
@ -0,0 +1,36 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Win_in.Sfs.Shared.Domain; |
|||
using Win_in.Sfs.Shared.Domain.Shared; |
|||
using Win_in.Sfs.Shared.Domain.Shared.Enums.Store; |
|||
using Win_in.Sfs.Wms.DataExchange.WMS.MesNote; |
|||
using Win_in.Sfs.Wms.DataExchange.WMS.PurchaseOrder; |
|||
|
|||
namespace Win_in.Sfs.Wms.DataExchange.WMS.InjectionIssueRequest; |
|||
public class InjectionIssueRequestExchangeDto |
|||
{ |
|||
/// <summary>
|
|||
/// 叫料类型
|
|||
/// </summary>
|
|||
[Display(Name = "叫料类型")] |
|||
public EnumIssueRequestType IssueRequestType { get; set; } |
|||
/// <summary>
|
|||
/// 操作员
|
|||
/// </summary>
|
|||
[Display(Name = "操作员")] |
|||
[StringLength(SfsEfCorePropertyConst.CodeLength, ErrorMessage = "{0}最多输入{1}个字符")] |
|||
public string Worker { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 生效日期
|
|||
/// </summary>
|
|||
[Display(Name = "生效日期")] |
|||
public DateTime ActiveDate { get; set; } = DateTime.Now.Date; |
|||
|
|||
/// <summary>
|
|||
/// 明细
|
|||
/// </summary>
|
|||
[Display(Name = "明细")] |
|||
public InjectionIssueRequestDetailExchangeDto Detail { get; set; } = new(); |
|||
} |
Loading…
Reference in new issue