chore: add documentation comments and stylecop rules
This commit is contained in:
@@ -17,31 +17,32 @@ public sealed class ReviewTenantCommandHandler(
|
||||
ICurrentUserAccessor currentUserAccessor)
|
||||
: IRequestHandler<ReviewTenantCommand, TenantDto>
|
||||
{
|
||||
private readonly ITenantRepository _tenantRepository = tenantRepository;
|
||||
private readonly ICurrentUserAccessor _currentUserAccessor = currentUserAccessor;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<TenantDto> Handle(ReviewTenantCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var tenant = await _tenantRepository.FindByIdAsync(request.TenantId, cancellationToken)
|
||||
// 1. 获取租户与认证资料
|
||||
var tenant = await tenantRepository.FindByIdAsync(request.TenantId, cancellationToken)
|
||||
?? throw new BusinessException(ErrorCodes.NotFound, "租户不存在");
|
||||
|
||||
var verification = await _tenantRepository.GetVerificationProfileAsync(request.TenantId, cancellationToken)
|
||||
var verification = await tenantRepository.GetVerificationProfileAsync(request.TenantId, cancellationToken)
|
||||
?? throw new BusinessException(ErrorCodes.BadRequest, "请先提交实名认证资料");
|
||||
|
||||
var subscription = await _tenantRepository.GetActiveSubscriptionAsync(request.TenantId, cancellationToken);
|
||||
var subscription = await tenantRepository.GetActiveSubscriptionAsync(request.TenantId, cancellationToken);
|
||||
|
||||
var actorName = _currentUserAccessor.IsAuthenticated
|
||||
? $"user:{_currentUserAccessor.UserId}"
|
||||
// 2. 记录审核人
|
||||
var actorName = currentUserAccessor.IsAuthenticated
|
||||
? $"user:{currentUserAccessor.UserId}"
|
||||
: "system";
|
||||
|
||||
// 3. 写入审核信息
|
||||
verification.ReviewedAt = DateTime.UtcNow;
|
||||
verification.ReviewedBy = _currentUserAccessor.UserId == 0 ? null : _currentUserAccessor.UserId;
|
||||
verification.ReviewedBy = currentUserAccessor.UserId == 0 ? null : currentUserAccessor.UserId;
|
||||
verification.ReviewedByName = actorName;
|
||||
verification.ReviewRemarks = request.Reason;
|
||||
|
||||
var previousStatus = tenant.Status;
|
||||
|
||||
// 4. 更新租户与订阅状态
|
||||
if (request.Approve)
|
||||
{
|
||||
verification.Status = TenantVerificationStatus.Approved;
|
||||
@@ -61,26 +62,29 @@ public sealed class ReviewTenantCommandHandler(
|
||||
}
|
||||
}
|
||||
|
||||
await _tenantRepository.UpdateTenantAsync(tenant, cancellationToken);
|
||||
await _tenantRepository.UpsertVerificationProfileAsync(verification, cancellationToken);
|
||||
// 5. 持久化租户与认证资料
|
||||
await tenantRepository.UpdateTenantAsync(tenant, cancellationToken);
|
||||
await tenantRepository.UpsertVerificationProfileAsync(verification, cancellationToken);
|
||||
if (subscription != null)
|
||||
{
|
||||
await _tenantRepository.UpdateSubscriptionAsync(subscription, cancellationToken);
|
||||
await tenantRepository.UpdateSubscriptionAsync(subscription, cancellationToken);
|
||||
}
|
||||
|
||||
await _tenantRepository.AddAuditLogAsync(new Domain.Tenants.Entities.TenantAuditLog
|
||||
// 6. 记录审核日志
|
||||
await tenantRepository.AddAuditLogAsync(new Domain.Tenants.Entities.TenantAuditLog
|
||||
{
|
||||
TenantId = tenant.Id,
|
||||
Action = request.Approve ? TenantAuditAction.VerificationApproved : TenantAuditAction.VerificationRejected,
|
||||
Title = request.Approve ? "审核通过" : "审核驳回",
|
||||
Description = request.Reason,
|
||||
OperatorId = _currentUserAccessor.UserId == 0 ? null : _currentUserAccessor.UserId,
|
||||
OperatorId = currentUserAccessor.UserId == 0 ? null : currentUserAccessor.UserId,
|
||||
OperatorName = actorName,
|
||||
PreviousStatus = previousStatus,
|
||||
CurrentStatus = tenant.Status
|
||||
}, cancellationToken);
|
||||
|
||||
await _tenantRepository.SaveChangesAsync(cancellationToken);
|
||||
// 7. 保存并返回 DTO
|
||||
await tenantRepository.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return TenantMapping.ToDto(tenant, subscription, verification);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user