chore: add documentation comments and stylecop rules

This commit is contained in:
2025-12-04 11:25:01 +08:00
parent 17d143a351
commit 8e4c2b0e45
142 changed files with 1309 additions and 439 deletions

View File

@@ -24,18 +24,20 @@ public sealed class CheckTenantQuotaCommandHandler(
/// <inheritdoc />
public async Task<QuotaCheckResultDto> Handle(CheckTenantQuotaCommand request, CancellationToken cancellationToken)
{
// 1. 校验请求参数
if (request.Delta <= 0)
{
throw new BusinessException(ErrorCodes.BadRequest, "配额消耗量必须大于 0");
}
// 2. 校验租户上下文
var currentTenantId = tenantProvider.GetCurrentTenantId();
if (currentTenantId == 0 || currentTenantId != request.TenantId)
{
throw new BusinessException(ErrorCodes.Forbidden, "租户上下文不匹配,请在请求头 X-Tenant-Id 指定目标租户");
}
// 1. 获取租户与当前订阅
// 3. 获取租户与当前订阅
_ = await tenantRepository.FindByIdAsync(request.TenantId, cancellationToken)
?? throw new BusinessException(ErrorCodes.NotFound, "租户不存在");
@@ -50,7 +52,7 @@ public sealed class CheckTenantQuotaCommandHandler(
var limit = ResolveLimit(package, request.QuotaType);
// 2. 加载配额使用记录并计算
// 4. 加载配额使用记录并计算
var usage = await quotaUsageRepository.FindAsync(request.TenantId, request.QuotaType, cancellationToken)
?? new TenantQuotaUsage
{
@@ -69,12 +71,14 @@ public sealed class CheckTenantQuotaCommandHandler(
throw new BusinessException(ErrorCodes.Conflict, $"{request.QuotaType} 配额不足");
}
// 5. 更新使用并保存
usage.LimitValue = limit ?? usage.LimitValue;
usage.UsedValue = usedAfter;
usage.ResetCycle ??= ResolveResetCycle(request.QuotaType);
await PersistUsageAsync(usage, quotaUsageRepository, cancellationToken);
// 6. 返回结果
return new QuotaCheckResultDto
{
QuotaType = request.QuotaType,