StartWorkflowHandler.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Text.Encodings.Web;
  2. using System.Text.Json;
  3. using System.Text.Unicode;
  4. using Hotline.CallCenter.Tels;
  5. using Hotline.FlowEngine.Notifications;
  6. using Hotline.FlowEngine.WfModules;
  7. using Hotline.KnowledgeBase;
  8. using Hotline.Orders;
  9. using MediatR;
  10. using Microsoft.Extensions.Logging;
  11. namespace Hotline.Application.Handlers.FlowEngine
  12. {
  13. public class StartWorkflowHandler : INotificationHandler<StartWorkflowNotify>
  14. {
  15. private readonly IOrderDomainService _orderDomainService;
  16. private readonly IKnowledgeDomainService _knowledgeDomainService;
  17. private readonly ITelDomainService _telDomainService;
  18. private readonly ILogger<StartWorkflowHandler> _logger;
  19. public StartWorkflowHandler(
  20. IOrderDomainService orderDomainService,
  21. IKnowledgeDomainService knowledgeDomainService,
  22. ITelDomainService telDomainService,
  23. ILogger<StartWorkflowHandler> logger)
  24. {
  25. _orderDomainService = orderDomainService;
  26. _knowledgeDomainService = knowledgeDomainService;
  27. _telDomainService = telDomainService;
  28. _logger = logger;
  29. }
  30. /// <summary>Handles a notification</summary>
  31. /// <param name="notification">The notification</param>
  32. /// <param name="cancellationToken">Cancellation token</param>
  33. public async Task Handle(StartWorkflowNotify notification, CancellationToken cancellationToken)
  34. {
  35. //基础拉丁字母和中日韩统一表意文字的基础Unicode 块(U+4E00-U+9FCC)。 基本涵盖了除使用西里尔字母以外所有西方国家的文字和亚洲中日韩越的文字
  36. _logger.LogInformation(
  37. $"收到{nameof(StartWorkflowNotify)}, notification: {JsonSerializer.Serialize(notification, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs) })}");
  38. var workflow = notification.Workflow;
  39. var data = notification.Dto;
  40. switch (workflow.ModuleCode)
  41. {
  42. case WorkflowModuleConsts.OrderManage:
  43. await _orderDomainService.ManageFlowStartAsync(notification.FlowAssignMode,
  44. notification.IsCountersignStart, workflow.ExternalId, workflow.Id,
  45. workflow.ActualHandleStepTime, workflow.ActualHandleStepName, workflow.ExpiredTime, cancellationToken);
  46. break;
  47. case WorkflowModuleConsts.KnowledgeAdd:
  48. case WorkflowModuleConsts.KnowledgeUpdate:
  49. case WorkflowModuleConsts.KnowledgeDelete:
  50. await _knowledgeDomainService.UpdateWorkFlowId(notification.FlowAssignMode, workflow.ExternalId, workflow.Id, cancellationToken);
  51. break;
  52. case WorkflowModuleConsts.TelRestApply:
  53. await _telDomainService.TelRestFlowStartAsync(notification.FlowAssignMode, workflow.ExternalId, workflow.Id, cancellationToken);
  54. break;
  55. }
  56. }
  57. }
  58. }