fix(risk-control): fix null safety and magic numbers in aggregates

This commit is contained in:
Sam 2026-02-05 14:49:19 +08:00
parent 0721965af4
commit 22d0427df9
2 changed files with 7 additions and 4 deletions

View File

@ -53,8 +53,8 @@ public class RiskRule : Entity<long>, IAggregateRoot
UpdatedAt = DateTime.UtcNow;
}
public T GetConfig<T>() where T : class
public T? GetConfig<T>() where T : class
{
return System.Text.Json.JsonSerializer.Deserialize<T>(ConfigJson)!;
return System.Text.Json.JsonSerializer.Deserialize<T>(ConfigJson);
}
}

View File

@ -43,11 +43,14 @@ public class RiskScore : Entity<long>, IAggregateRoot
RiskLevel = RiskLevel.Low;
}
private static readonly int HIGH_THRESHOLD = 70;
private static readonly int MEDIUM_THRESHOLD = 30;
private void RecalculateScore()
{
TotalScore = _factors.Sum(f => f.Points);
RiskLevel = TotalScore >= 70 ? RiskLevel.High :
TotalScore >= 30 ? RiskLevel.Medium :
RiskLevel = TotalScore >= HIGH_THRESHOLD ? RiskLevel.High :
TotalScore >= MEDIUM_THRESHOLD ? RiskLevel.Medium :
RiskLevel.Low;
}