fix: 修复bug - 在可用性检查中支持忽略剩余令牌校验,避免负数用量包被错误过滤
- 将 PremiumPackageAggregateRoot.IsAvailable 增加参数 isVerifyRemainingToken=true,保持默认行为不变,允许按需跳过对 RemainingTokens 的校验。 - 在 UsageStatisticsService 中计算可用包时改为使用 p.IsAvailable(false),仅过滤过期或禁用的包,但不再因 RemainingTokens 为负而将包排除,从而保证统计(如 TotalTokens/RemainingTokens 汇总)包含负数用量的包,修正统计错误。 修改文件: - Yi.Framework.AiHub.Domain/Entities/PremiumPackageAggregateRoot.cs - Yi.Framework.AiHub.Application/Services/UsageStatisticsService.cs
This commit is contained in:
@@ -125,9 +125,9 @@ public class UsageStatisticsService : ApplicationService, IUsageStatisticsServic
|
||||
|
||||
if (premiumPackages.Any())
|
||||
{
|
||||
// 过滤掉已过期的包
|
||||
// 过滤掉已过期、禁用的包,不过滤用量负数的包
|
||||
var validPackages = premiumPackages
|
||||
.Where(p => p.IsAvailable())
|
||||
.Where(p => p.IsAvailable(false))
|
||||
.ToList();
|
||||
|
||||
result.PremiumTotalTokens = validPackages.Sum(x => x.TotalTokens);
|
||||
|
||||
@@ -86,14 +86,14 @@ public class PremiumPackageAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
/// 检查是否可用
|
||||
/// </summary>
|
||||
/// <returns>是否可用</returns>
|
||||
public bool IsAvailable()
|
||||
public bool IsAvailable(bool isVerifyRemainingToken=true)
|
||||
{
|
||||
if (!IsActive)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (RemainingTokens <= 0)
|
||||
if (isVerifyRemainingToken&&RemainingTokens <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user