using MediatR; using TakeoutSaaS.Application.App.Merchants.Dto; using TakeoutSaaS.Application.App.Merchants.Queries; using TakeoutSaaS.Domain.Merchants.Repositories; using TakeoutSaaS.Shared.Abstractions.Constants; using TakeoutSaaS.Shared.Abstractions.Exceptions; using TakeoutSaaS.Shared.Abstractions.Tenancy; namespace TakeoutSaaS.Application.App.Merchants.Handlers; /// /// 查询合同列表。 /// public sealed class GetMerchantContractsQueryHandler( IMerchantRepository merchantRepository, ITenantProvider tenantProvider) : IRequestHandler> { public async Task> Handle(GetMerchantContractsQuery request, CancellationToken cancellationToken) { // 1. 获取租户上下文并校验商户存在 var tenantId = tenantProvider.GetCurrentTenantId(); _ = await merchantRepository.FindByIdAsync(request.MerchantId, tenantId, cancellationToken) ?? throw new BusinessException(ErrorCodes.NotFound, "商户不存在"); // 2. 查询合同列表 var contracts = await merchantRepository.GetContractsAsync(request.MerchantId, tenantId, cancellationToken); return MerchantMapping.ToContractDtos(contracts); } }