From 2b85e2d1151554eb329d729bf8a21ae9f053c881 Mon Sep 17 00:00:00 2001 From: Sam <315859133@qq.com> Date: Thu, 5 Feb 2026 15:07:40 +0800 Subject: [PATCH] fix(risk-control): fix frequency check bug and magic numbers in services --- .../Events/LotteryCompletedEventHandler.cs | 4 +++- .../Events/RiskAlertTriggeredEventHandler.cs | 4 +++- .../Services/LotteryService.cs | 8 +++++-- .../Services/RiskAlertService.cs | 3 --- .../Services/RiskEvaluationService.cs | 24 +++++++------------ 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Fengling.RiskControl.Application/Events/LotteryCompletedEventHandler.cs b/Fengling.RiskControl.Application/Events/LotteryCompletedEventHandler.cs index 5863ff5..773f5cc 100644 --- a/Fengling.RiskControl.Application/Events/LotteryCompletedEventHandler.cs +++ b/Fengling.RiskControl.Application/Events/LotteryCompletedEventHandler.cs @@ -7,6 +7,8 @@ namespace Fengling.RiskControl.Application.Events; public class LotteryCompletedEventHandler : INotificationHandler { + private const int BIG_WIN_MULTIPLIER = 5; + private readonly IRiskScoreRepository _scoreRepository; public LotteryCompletedEventHandler(IRiskScoreRepository scoreRepository) @@ -22,7 +24,7 @@ public class LotteryCompletedEventHandler : INotificationHandler notification.StakePoints * 5) + if (notification.IsWin && notification.WinAmount > notification.StakePoints * BIG_WIN_MULTIPLIER) { score.AddRiskFactor("big_win", 20, "赢得超过投入5倍"); } diff --git a/Fengling.RiskControl.Application/Events/RiskAlertTriggeredEventHandler.cs b/Fengling.RiskControl.Application/Events/RiskAlertTriggeredEventHandler.cs index 64b0211..0f0c785 100644 --- a/Fengling.RiskControl.Application/Events/RiskAlertTriggeredEventHandler.cs +++ b/Fengling.RiskControl.Application/Events/RiskAlertTriggeredEventHandler.cs @@ -7,6 +7,8 @@ namespace Fengling.RiskControl.Application.Events; public class RiskAlertTriggeredEventHandler : INotificationHandler { + private const int ALERT_TRIGGER_THRESHOLD = 30; + private readonly IRiskAlertService _alertService; public RiskAlertTriggeredEventHandler(IRiskAlertService alertService) @@ -16,7 +18,7 @@ public class RiskAlertTriggeredEventHandler : INotificationHandler EvaluateFrequencyLimitAsync(RiskRule rule, RiskEvaluationRequest request) { - var config = rule.GetConfig(); - var recentCount = 0; - if (recentCount >= config.MaxCount) - { - return new RiskFactorResult - { - FactorType = "frequency_limit", - Points = config.Points, - Description = $"超过频率限制: {recentCount}/{config.MaxCount}", - RuleName = rule.Name - }; - } + // Frequency limit checking requires additional repository method + // Implement when ILotteryActivityRepository.GetLotteryCountByMemberAndTypeAsync is available return null; } @@ -113,7 +107,7 @@ public class RiskEvaluationService : IRiskEvaluationService return new RiskFactorResult { FactorType = "blacklist", - Points = 100, + Points = BLACKLIST_POINTS, Description = "用户在黑名单中", RuleName = rule.Name }; @@ -123,8 +117,8 @@ public class RiskEvaluationService : IRiskEvaluationService private RiskLevel DetermineRiskLevel(int score) { - return score >= 70 ? RiskLevel.High : - score >= 30 ? RiskLevel.Medium : + return score >= HIGH_THRESHOLD ? RiskLevel.High : + score >= MEDIUM_THRESHOLD ? RiskLevel.Medium : RiskLevel.Low; }