NextStepHandler.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using DotNetCore.CAP;
  2. using Hotline.Application.FlowEngine;
  3. using Hotline.FlowEngine.Notifications;
  4. using Hotline.FlowEngine.Workflows;
  5. using Hotline.KnowledgeBase;
  6. using Hotline.Orders;
  7. using Hotline.Settings;
  8. using Hotline.Share.Dtos.FlowEngine;
  9. using Hotline.Share.Dtos.Order;
  10. using Hotline.Share.Enums.Order;
  11. using Hotline.Share.Mq;
  12. using MapsterMapper;
  13. using MediatR;
  14. using Microsoft.Extensions.Logging;
  15. using Newtonsoft.Json;
  16. using XF.Domain.Entities;
  17. using XF.Domain.Exceptions;
  18. namespace Hotline.Application.Handlers.FlowEngine;
  19. public class NextStepHandler : INotificationHandler<NextStepNotify>
  20. {
  21. private readonly IOrderDomainService _orderDomainService;
  22. private readonly ILogger<NextStepHandler> _logger;
  23. private readonly IKnowledgeDomainService _knowledgeDomainService;
  24. private readonly ICapPublisher _capPublisher;
  25. private readonly IMapper _mapper;
  26. public NextStepHandler(
  27. IOrderDomainService orderDomainService,
  28. IKnowledgeDomainService knowledgeDomainService,
  29. ICapPublisher capPublisher,
  30. IMapper mapper,
  31. ILogger<NextStepHandler> logger)
  32. {
  33. _orderDomainService = orderDomainService;
  34. _knowledgeDomainService = knowledgeDomainService;
  35. _capPublisher = capPublisher;
  36. _mapper = mapper;
  37. _logger = logger;
  38. }
  39. /// <summary>Handles a notification</summary>
  40. /// <param name="notification">The notification</param>
  41. /// <param name="cancellationToken">Cancellation token</param>
  42. public async Task Handle(NextStepNotify notification, CancellationToken cancellationToken)
  43. {
  44. _logger.LogInformation($"收到{nameof(NextStepNotify)}, notification: {JsonConvert.SerializeObject(notification)}");
  45. var workflow = notification.Workflow;
  46. var data = notification.Dto;
  47. //var assignMode = await _workflowApplication.GetFlowAssignModeAsync(notification.StepDefine,
  48. // data.NextHandlers.Select(d => d.Id).ToList(), cancellationToken);
  49. switch (workflow.ModuleCode)
  50. {
  51. case WorkflowModuleConsts.OrderManage:
  52. var orderDto = await _orderDomainService.ManageFlowNextAsync(
  53. notification.FlowAssignMode, notification.IsCountersignStart, notification.IsCountersignEnd,
  54. workflow.ExternalId, workflow.CurrentStepTime, workflow.CurrentStepName, workflow.ExpiredTime, workflow.ProcessType,
  55. cancellationToken);
  56. await _capPublisher.PublishAsync(EventNames.HotlineOrderFlow, new OrderFlowDto
  57. {
  58. Order = orderDto,
  59. WorkflowTrace = _mapper.Map<WorkflowTraceDto>(notification.Trace)
  60. },
  61. cancellationToken: cancellationToken);
  62. break;
  63. case WorkflowModuleConsts.KnowledgeAdd:
  64. case WorkflowModuleConsts.KnowledgeUpdate:
  65. case WorkflowModuleConsts.KnowledgeDelete:
  66. await _knowledgeDomainService.UpdateWorkAssign(notification.FlowAssignMode, workflow.ExternalId, cancellationToken);
  67. break;
  68. }
  69. }
  70. }