using DotNetCore.CAP; using Hotline.Application.FlowEngine; using Hotline.FlowEngine.Notifications; using Hotline.FlowEngine.Workflows; using Hotline.KnowledgeBase; using Hotline.Orders; using Hotline.Settings; using Hotline.Share.Dtos.FlowEngine; using Hotline.Share.Dtos.Order; using Hotline.Share.Enums.Order; using Hotline.Share.Mq; using MapsterMapper; using MediatR; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using XF.Domain.Entities; using XF.Domain.Exceptions; namespace Hotline.Application.Handlers.FlowEngine; public class NextStepHandler : INotificationHandler { private readonly IOrderDomainService _orderDomainService; private readonly ILogger _logger; private readonly IKnowledgeDomainService _knowledgeDomainService; private readonly ICapPublisher _capPublisher; private readonly IMapper _mapper; public NextStepHandler( IOrderDomainService orderDomainService, IKnowledgeDomainService knowledgeDomainService, ICapPublisher capPublisher, IMapper mapper, ILogger logger) { _orderDomainService = orderDomainService; _knowledgeDomainService = knowledgeDomainService; _capPublisher = capPublisher; _mapper = mapper; _logger = logger; } /// Handles a notification /// The notification /// Cancellation token public async Task Handle(NextStepNotify notification, CancellationToken cancellationToken) { _logger.LogInformation($"收到{nameof(NextStepNotify)}, notification: {JsonConvert.SerializeObject(notification)}"); var workflow = notification.Workflow; var data = notification.Dto; //var assignMode = await _workflowApplication.GetFlowAssignModeAsync(notification.StepDefine, // data.NextHandlers.Select(d => d.Id).ToList(), cancellationToken); switch (workflow.ModuleCode) { case WorkflowModuleConsts.OrderManage: var orderDto = await _orderDomainService.ManageFlowNextAsync( notification.FlowAssignMode, notification.IsCountersignStart, notification.IsCountersignEnd, workflow.ExternalId, workflow.CurrentStepTime, workflow.CurrentStepName, workflow.ExpiredTime, workflow.ProcessType, cancellationToken); await _capPublisher.PublishAsync(EventNames.HotlineOrderFlow, new OrderFlowDto { Order = orderDto, WorkflowTrace = _mapper.Map(notification.Trace) }, cancellationToken: cancellationToken); break; case WorkflowModuleConsts.KnowledgeAdd: case WorkflowModuleConsts.KnowledgeUpdate: case WorkflowModuleConsts.KnowledgeDelete: await _knowledgeDomainService.UpdateWorkAssign(notification.FlowAssignMode, workflow.ExternalId, cancellationToken); break; } } }