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

@@ -20,30 +20,30 @@ public sealed class RegisterTenantCommandHandler(
ILogger<RegisterTenantCommandHandler> logger)
: IRequestHandler<RegisterTenantCommand, TenantDto>
{
private readonly ITenantRepository _tenantRepository = tenantRepository;
private readonly IIdGenerator _idGenerator = idGenerator;
private readonly ILogger<RegisterTenantCommandHandler> _logger = logger;
/// <inheritdoc />
public async Task<TenantDto> Handle(RegisterTenantCommand request, CancellationToken cancellationToken)
{
// 1. 校验订阅时长
if (request.DurationMonths <= 0)
{
throw new BusinessException(ErrorCodes.BadRequest, "订阅时长必须大于 0");
}
if (await _tenantRepository.ExistsByCodeAsync(request.Code, cancellationToken))
// 2. 检查租户编码唯一性
if (await tenantRepository.ExistsByCodeAsync(request.Code, cancellationToken))
{
throw new BusinessException(ErrorCodes.Conflict, $"租户编码 {request.Code} 已存在");
}
// 3. 计算生效时间
var now = DateTime.UtcNow;
var effectiveFrom = request.EffectiveFrom ?? now;
var effectiveTo = effectiveFrom.AddMonths(request.DurationMonths);
// 4. 构建租户实体
var tenant = new Tenant
{
Id = _idGenerator.NextId(),
Id = idGenerator.NextId(),
Code = request.Code.Trim(),
Name = request.Name,
ShortName = request.ShortName,
@@ -56,9 +56,10 @@ public sealed class RegisterTenantCommandHandler(
EffectiveTo = effectiveTo
};
// 5. 构建订阅实体
var subscription = new TenantSubscription
{
Id = _idGenerator.NextId(),
Id = idGenerator.NextId(),
TenantId = tenant.Id,
TenantPackageId = request.TenantPackageId,
EffectiveFrom = effectiveFrom,
@@ -69,9 +70,10 @@ public sealed class RegisterTenantCommandHandler(
Notes = "Init subscription"
};
await _tenantRepository.AddTenantAsync(tenant, cancellationToken);
await _tenantRepository.AddSubscriptionAsync(subscription, cancellationToken);
await _tenantRepository.AddAuditLogAsync(new TenantAuditLog
// 6. 持久化租户、订阅和审计日志
await tenantRepository.AddTenantAsync(tenant, cancellationToken);
await tenantRepository.AddSubscriptionAsync(subscription, cancellationToken);
await tenantRepository.AddAuditLogAsync(new TenantAuditLog
{
TenantId = tenant.Id,
Action = TenantAuditAction.RegistrationSubmitted,
@@ -79,10 +81,12 @@ public sealed class RegisterTenantCommandHandler(
Description = $"提交套餐 {request.TenantPackageId},时长 {request.DurationMonths} 月"
}, cancellationToken);
await _tenantRepository.SaveChangesAsync(cancellationToken);
await tenantRepository.SaveChangesAsync(cancellationToken);
_logger.LogInformation("已注册租户 {TenantCode}", tenant.Code);
// 7. 记录日志
logger.LogInformation("已注册租户 {TenantCode}", tenant.Code);
// 8. 返回 DTO
return TenantMapping.ToDto(tenant, subscription, null);
}
}