using Admin.NET.Plugin.ApprovalFlow.Service; using Microsoft.Extensions.Logging; namespace Admin.NET.Plugin.AiDOP.Service.S8; /// /// N-1:当 ApprovalFlow 引擎调用 S8 BizHandler(EXCEPTION_ESCALATION / EXCEPTION_CLOSURE)失败时, /// 写入 ado_s8_notification_log(channel = s8-invoke-handler-failed),让"不可见失败"变可见。 /// 不做反查、不做去重、不做补偿;上抛仍由 ApprovalFlow 引擎完成。 /// public class S8FlowHandlerFailureNotifier : IFlowHandlerFailureNotifier, ITransient { public const string AlertChannel = "s8-invoke-handler-failed"; private static readonly HashSet S8BizTypes = new(StringComparer.Ordinal) { "EXCEPTION_ESCALATION", "EXCEPTION_CLOSURE", }; private readonly S8NotificationService _notificationService; private readonly ILogger _logger; public S8FlowHandlerFailureNotifier( S8NotificationService notificationService, ILogger logger) { _notificationService = notificationService; _logger = logger; } public async Task NotifyAsync(string bizType, long instanceId, Exception exception, CancellationToken cancellationToken = default) { if (!S8BizTypes.Contains(bizType)) return; var payload = new { type = "FLOW_HANDLER_FAILED", message = "S8 审批流回调 Handler 抛异常,已被引擎上抛;请人工核对业务单与审批实例状态", bizType, instanceId, errorType = exception.GetType().FullName, errorMessage = exception.Message, detectedAt = DateTime.Now }; await _notificationService.SendAsync(0, 0, null, AlertChannel, payload); _logger.LogWarning( "S8 FlowHandler 失败已落告警: BizType={BizType}, InstanceId={InstanceId}, ErrorType={ErrorType}, ErrorMessage={ErrorMessage}", bizType, instanceId, exception.GetType().FullName, exception.Message); } }