fengling-risk-control/Fengling.RiskControl.Application/Events/RiskAlertTriggeredEventHandler.cs

37 lines
1.1 KiB
C#

using Fengling.RiskControl.Application.Services;
using Fengling.RiskControl.Domain.Aggregates.RiskAlerts;
using Fengling.RiskControl.Domain.Events;
using MediatR;
namespace Fengling.RiskControl.Application.Events;
public class RiskAlertTriggeredEventHandler : INotificationHandler<RiskAlertTriggeredEvent>
{
private readonly IRiskAlertService _alertService;
public RiskAlertTriggeredEventHandler(IRiskAlertService alertService)
{
_alertService = alertService;
}
public async Task Handle(RiskAlertTriggeredEvent notification, CancellationToken cancellationToken)
{
if (notification.RiskScore < 30)
return;
var priority = notification.RiskScore switch
{
>= 80 => RiskAlertPriority.Critical,
>= 60 => RiskAlertPriority.High,
>= 40 => RiskAlertPriority.Medium,
_ => RiskAlertPriority.Low
};
await _alertService.CreateAlertAsync(
notification.MemberId,
notification.AlertType,
notification.Reason,
priority);
}
}