using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Unicode; using Hotline.CallCenter.Tels; using Hotline.FlowEngine.Notifications; using Hotline.FlowEngine.WfModules; using Hotline.KnowledgeBase; using Hotline.Orders; using MediatR; using Microsoft.Extensions.Logging; namespace Hotline.Application.Handlers.FlowEngine { public class StartWorkflowHandler : INotificationHandler { private readonly IOrderDomainService _orderDomainService; private readonly IKnowledgeDomainService _knowledgeDomainService; private readonly ITelDomainService _telDomainService; private readonly ILogger _logger; public StartWorkflowHandler( IOrderDomainService orderDomainService, IKnowledgeDomainService knowledgeDomainService, ITelDomainService telDomainService, ILogger logger) { _orderDomainService = orderDomainService; _knowledgeDomainService = knowledgeDomainService; _telDomainService = telDomainService; _logger = logger; } /// Handles a notification /// The notification /// Cancellation token public async Task Handle(StartWorkflowNotify notification, CancellationToken cancellationToken) { //基础拉丁字母和中日韩统一表意文字的基础Unicode 块(U+4E00-U+9FCC)。 基本涵盖了除使用西里尔字母以外所有西方国家的文字和亚洲中日韩越的文字 _logger.LogInformation( $"收到{nameof(StartWorkflowNotify)}, notification: {JsonSerializer.Serialize(notification, new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs) })}"); var workflow = notification.Workflow; var data = notification.Dto; switch (workflow.ModuleCode) { case WorkflowModuleConsts.OrderManage: await _orderDomainService.ManageFlowStartAsync(notification.FlowAssignMode, notification.IsCountersignStart, workflow.ExternalId, workflow.Id, workflow.ActualHandleStepTime, workflow.ActualHandleStepName, workflow.ExpiredTime, cancellationToken); break; case WorkflowModuleConsts.KnowledgeAdd: case WorkflowModuleConsts.KnowledgeUpdate: case WorkflowModuleConsts.KnowledgeDelete: await _knowledgeDomainService.UpdateWorkFlowId(notification.FlowAssignMode, workflow.ExternalId, workflow.Id, cancellationToken); break; case WorkflowModuleConsts.TelRestApply: await _telDomainService.TelRestFlowStartAsync(notification.FlowAssignMode, workflow.ExternalId, workflow.Id, cancellationToken); break; } } } }