using Fengling.RiskControl.Domain.Aggregates.RiskScores; using Fengling.RiskControl.Domain.Events; using Fengling.RiskControl.Domain.Repositories; using MediatR; namespace Fengling.RiskControl.Application.Events; public class LotteryCompletedEventHandler : INotificationHandler { private const int BIG_WIN_MULTIPLIER = 5; private readonly IRiskScoreRepository _scoreRepository; public LotteryCompletedEventHandler(IRiskScoreRepository scoreRepository) { _scoreRepository = scoreRepository; } public async Task Handle(LotteryCompletedEvent notification, CancellationToken cancellationToken) { var score = RiskScore.Create( notification.MemberId, "lottery_result", notification.ActivityId.ToString(), expiresAt: DateTime.UtcNow.AddDays(1)); if (notification.IsWin && notification.WinAmount > notification.StakePoints * BIG_WIN_MULTIPLIER) { score.AddRiskFactor("big_win", 20, "赢得超过投入5倍"); } await _scoreRepository.AddAsync(score); } }