feat: Mini 桌码扫码上下文接口

This commit is contained in:
2025-12-04 09:37:05 +08:00
parent 19422df0f1
commit 9220e0ca36
8 changed files with 202 additions and 2 deletions

View File

@@ -0,0 +1,64 @@
using System.Text.Json.Serialization;
using TakeoutSaaS.Domain.Stores.Enums;
using TakeoutSaaS.Shared.Abstractions.Serialization;
namespace TakeoutSaaS.Application.App.Stores.Dto;
/// <summary>
/// 桌码上下文 DTO。
/// </summary>
public sealed record StoreTableContextDto
{
/// <summary>
/// 门店 ID。
/// </summary>
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long StoreId { get; init; }
/// <summary>
/// 门店名称。
/// </summary>
public string StoreName { get; init; } = string.Empty;
/// <summary>
/// 门店公告。
/// </summary>
public string? Announcement { get; init; }
/// <summary>
/// 门店标签。
/// </summary>
public string? Tags { get; init; }
/// <summary>
/// 桌台 ID。
/// </summary>
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long TableId { get; init; }
/// <summary>
/// 桌码。
/// </summary>
public string TableCode { get; init; } = string.Empty;
/// <summary>
/// 区域 ID。
/// </summary>
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
public long? AreaId { get; init; }
/// <summary>
/// 容量。
/// </summary>
public int Capacity { get; init; }
/// <summary>
/// 标签。
/// </summary>
public string? TableTags { get; init; }
/// <summary>
/// 状态。
/// </summary>
public StoreTableStatus Status { get; init; }
}

View File

@@ -0,0 +1,55 @@
using MediatR;
using Microsoft.Extensions.Logging;
using TakeoutSaaS.Application.App.Stores.Dto;
using TakeoutSaaS.Application.App.Stores.Queries;
using TakeoutSaaS.Domain.Stores.Repositories;
using TakeoutSaaS.Shared.Abstractions.Constants;
using TakeoutSaaS.Shared.Abstractions.Exceptions;
using TakeoutSaaS.Shared.Abstractions.Tenancy;
namespace TakeoutSaaS.Application.App.Stores.Handlers;
/// <summary>
/// 桌码上下文查询处理器。
/// </summary>
public sealed class GetStoreTableContextQueryHandler(
IStoreRepository storeRepository,
ITenantProvider tenantProvider,
ILogger<GetStoreTableContextQueryHandler> logger)
: IRequestHandler<GetStoreTableContextQuery, StoreTableContextDto?>
{
/// <inheritdoc />
public async Task<StoreTableContextDto?> Handle(GetStoreTableContextQuery request, CancellationToken cancellationToken)
{
// 1. 查询桌码
var tenantId = tenantProvider.GetCurrentTenantId();
var table = await storeRepository.FindTableByCodeAsync(request.TableCode, tenantId, cancellationToken);
if (table is null)
{
logger.LogWarning("未找到桌码 {TableCode}", request.TableCode);
return null;
}
// 2. 查询门店
var store = await storeRepository.FindByIdAsync(table.StoreId, tenantId, cancellationToken);
if (store is null)
{
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
}
// 3. 组装上下文
return new StoreTableContextDto
{
StoreId = store.Id,
StoreName = store.Name,
Announcement = store.Announcement,
Tags = store.Tags,
TableId = table.Id,
TableCode = table.TableCode,
AreaId = table.AreaId,
Capacity = table.Capacity,
TableTags = table.Tags,
Status = table.Status
};
}
}

View File

@@ -0,0 +1,15 @@
using MediatR;
using TakeoutSaaS.Application.App.Stores.Dto;
namespace TakeoutSaaS.Application.App.Stores.Queries;
/// <summary>
/// 桌码上下文查询。
/// </summary>
public sealed record GetStoreTableContextQuery : IRequest<StoreTableContextDto?>
{
/// <summary>
/// 桌码。
/// </summary>
public string TableCode { get; init; } = string.Empty;
}

View File

@@ -0,0 +1,18 @@
using FluentValidation;
using TakeoutSaaS.Application.App.Stores.Queries;
namespace TakeoutSaaS.Application.App.Stores.Validators;
/// <summary>
/// 桌码上下文查询验证器。
/// </summary>
public sealed class GetStoreTableContextQueryValidator : AbstractValidator<GetStoreTableContextQuery>
{
/// <summary>
/// 初始化验证规则。
/// </summary>
public GetStoreTableContextQueryValidator()
{
RuleFor(x => x.TableCode).NotEmpty().MaximumLength(32);
}
}