12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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<NextStepNotify>
- {
- private readonly IOrderDomainService _orderDomainService;
- private readonly ILogger<NextStepHandler> _logger;
- private readonly IKnowledgeDomainService _knowledgeDomainService;
- private readonly ICapPublisher _capPublisher;
- private readonly IMapper _mapper;
- public NextStepHandler(
- IOrderDomainService orderDomainService,
- IKnowledgeDomainService knowledgeDomainService,
- ICapPublisher capPublisher,
- IMapper mapper,
- ILogger<NextStepHandler> logger)
- {
- _orderDomainService = orderDomainService;
- _knowledgeDomainService = knowledgeDomainService;
- _capPublisher = capPublisher;
- _mapper = mapper;
- _logger = logger;
- }
- /// <summary>Handles a notification</summary>
- /// <param name="notification">The notification</param>
- /// <param name="cancellationToken">Cancellation token</param>
- 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<WorkflowTraceDto>(notification.Trace)
- },
- cancellationToken: cancellationToken);
- break;
- case WorkflowModuleConsts.KnowledgeAdd:
- case WorkflowModuleConsts.KnowledgeUpdate:
- case WorkflowModuleConsts.KnowledgeDelete:
- await _knowledgeDomainService.UpdateWorkAssign(notification.FlowAssignMode, workflow.ExternalId, cancellationToken);
- break;
- }
- }
- }
|