using CMS.Plugin.MesSuite.Abstractions.Events;
|
using CMS.Plugin.MesSuite.Abstractions.Models;
|
using CMS.Plugin.HIAWms.Domain.WmsPlaces;
|
using CMS.Plugin.OrderManagement.Abstractions.Models;
|
using CMS.Plugin.ProcessManagement.Abstractions.Models;
|
using CMS.Plugin.TraceManagement.Abstractions.Models.Traces;
|
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.Logging;
|
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.EventBus.Distributed;
|
using Volo.Abp.Uow;
|
|
namespace CMS.Plugin.HIAWms.EventHandlers
|
{
|
/// <summary>
|
/// 流程事件处理程序
|
/// </summary>
|
public class HIAWmsEventHandler : IDistributedEventHandler<ProcessFlowEto>, ITransientDependency
|
{
|
private readonly ILogger _logger;
|
private readonly IServiceProvider _serviceProvider;
|
|
/// <summary>
|
/// Initializes a new instance of the <see cref="HIAWmsEventHandler"/> class.
|
/// </summary>
|
/// <param name="logger">The logger.</param>
|
/// <param name="serviceProvider">The service provider.</param>
|
public HIAWmsEventHandler(ILogger<HIAWmsEventHandler> logger, IServiceProvider serviceProvider)
|
{
|
this._logger = logger;
|
this._serviceProvider = serviceProvider;
|
}
|
|
/// <summary>
|
/// Handler handles the event by implementing this method.
|
/// </summary>
|
/// <param name="eventData">Event data</param>
|
public async Task HandleEventAsync(ProcessFlowEto eventData)
|
{
|
if (eventData.Activity.Equals("步骤名称"))
|
{
|
_logger.LogInformation($"WmsPlaceEventHandler: Activity={eventData.Activity}");
|
|
var serialNumber = eventData?.FlowItems[FlowItemCollection.SerialNumber]?.ToString();
|
|
// 工艺模型
|
var process = eventData?.FlowItems[FlowItemCollection.ApplicationData] as ProcessModel;
|
|
// 产品模型
|
var product = eventData?.FlowItems[FlowItemCollection.ProductModel] as AssociationProductModel;
|
|
// 追溯模型
|
var trace = eventData?.FlowItems[FlowItemCollection.TraceModel] as TraceModel;
|
|
// 工单模型
|
var order = eventData?.FlowItems[FlowItemCollection.OrderModel] as OrderModel;
|
|
// 业务处理
|
await ProcessAsync();
|
}
|
}
|
|
/// <summary>
|
/// Processes the asynchronous.
|
/// </summary>
|
private async Task ProcessAsync()
|
{
|
using var scope = _serviceProvider.CreateScope();
|
var unitOfWorkManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
|
using var uow = unitOfWorkManager.Begin(requiresNew: true);
|
var wmsplaceRepository = scope.ServiceProvider.GetRequiredService<IWmsPlaceRepository>();
|
var count = await wmsplaceRepository.GetCountAsync();
|
|
// 如果有更新数据库操作,需提交保存
|
// await uow.SaveChangesAsync();
|
|
_logger.LogInformation($"ProcessAsync,Count={count}");
|
}
|
}
|
}
|