feat: Mini 桌码扫码上下文接口
This commit is contained in:
@@ -20,8 +20,8 @@
|
|||||||
- 进展:新增桌台区域/桌码 DTO、命令、查询、验证与处理器,支持批量生成桌码、区域绑定和更新;Admin API 增加桌台区域与桌码 CRUD 及二维码 ZIP 导出端点,使用 QRCoder 生成 SVG 并打包下载;仓储补齐桌台/区域的查找、更新、删除。
|
- 进展:新增桌台区域/桌码 DTO、命令、查询、验证与处理器,支持批量生成桌码、区域绑定和更新;Admin API 增加桌台区域与桌码 CRUD 及二维码 ZIP 导出端点,使用 QRCoder 生成 SVG 并打包下载;仓储补齐桌台/区域的查找、更新、删除。
|
||||||
- [x] 员工排班:创建员工、绑定门店角色、维护 StoreEmployeeShift,可查询未来 7 日排班。
|
- [x] 员工排班:创建员工、绑定门店角色、维护 StoreEmployeeShift,可查询未来 7 日排班。
|
||||||
- 进展:新增门店员工 DTO/命令/查询/验证与处理器,支持员工创建/更新/删除及按门店查询;新增排班 CRUD(默认查询未来 7 天),校验员工归属、时间冲突;Admin API 增加员工与排班控制器及权限种子,仓储补充排班查询/更新/删除。
|
- 进展:新增门店员工 DTO/命令/查询/验证与处理器,支持员工创建/更新/删除及按门店查询;新增排班 CRUD(默认查询未来 7 天),校验员工归属、时间冲突;Admin API 增加员工与排班控制器及权限种子,仓储补充排班查询/更新/删除。
|
||||||
- [ ] 桌码扫码入口:Mini 端解析二维码,GET /api/mini/tables/{code}/context 返回门店、桌台、公告。
|
- [x] 桌码扫码入口:Mini 端解析二维码,GET /api/mini/tables/{code}/context 返回门店、桌台、公告。
|
||||||
- 当前:MiniApi 无桌码相关接口,未实现桌码解析与上下文返回。
|
- 进展:新增桌码上下文查询 DTO/验证/处理器,可按桌码解析返回门店名称/公告/标签及桌台信息;MiniApi 增加 `TablesController` 提供 `/context` 端点,仓储支持按桌码查询。
|
||||||
- [ ] 菜品建模:分类、SPU、SKU、规格/加料组、价格策略、媒资 CRUD + 上下架流程;Mini 端可拉取完整 JSON。
|
- [ ] 菜品建模:分类、SPU、SKU、规格/加料组、价格策略、媒资 CRUD + 上下架流程;Mini 端可拉取完整 JSON。
|
||||||
- 当前:Admin 仅有基础商品 CRUD(Product 级),未覆盖 SKU/规格/加料组、价格策略、媒资与上下架流程,Mini 端也未提供完整商品 JSON 拉取接口。
|
- 当前:Admin 仅有基础商品 CRUD(Product 级),未覆盖 SKU/规格/加料组、价格策略、媒资与上下架流程,Mini 端也未提供完整商品 JSON 拉取接口。
|
||||||
- [ ] 库存体系:SKU 库存、批次、调整、售罄管理,支持预售/档期锁定并在订单中扣减/释放。
|
- [ ] 库存体系:SKU 库存、批次、调整、售罄管理,支持预售/档期锁定并在订单中扣减/释放。
|
||||||
|
|||||||
35
src/Api/TakeoutSaaS.MiniApi/Controllers/TablesController.cs
Normal file
35
src/Api/TakeoutSaaS.MiniApi/Controllers/TablesController.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using MediatR;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||||
|
using TakeoutSaaS.Application.App.Stores.Queries;
|
||||||
|
using TakeoutSaaS.Shared.Abstractions.Constants;
|
||||||
|
using TakeoutSaaS.Shared.Abstractions.Results;
|
||||||
|
using TakeoutSaaS.Shared.Web.Api;
|
||||||
|
|
||||||
|
namespace TakeoutSaaS.MiniApi.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 桌码上下文。
|
||||||
|
/// </summary>
|
||||||
|
[ApiVersion("1.0")]
|
||||||
|
[Authorize]
|
||||||
|
[Route("api/mini/v{version:apiVersion}/tables")]
|
||||||
|
public sealed class TablesController(IMediator mediator) : BaseApiController
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 解析桌码并返回上下文。
|
||||||
|
/// </summary>
|
||||||
|
[HttpGet("{code}/context")]
|
||||||
|
[ProducesResponseType(typeof(ApiResponse<StoreTableContextDto>), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(typeof(ApiResponse<object>), StatusCodes.Status404NotFound)]
|
||||||
|
public async Task<ApiResponse<StoreTableContextDto>> GetContext(string code, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = await mediator.Send(new GetStoreTableContextQuery { TableCode = code }, cancellationToken);
|
||||||
|
return result is null
|
||||||
|
? ApiResponse<StoreTableContextDto>.Error(ErrorCodes.NotFound, "桌码不存在")
|
||||||
|
: ApiResponse<StoreTableContextDto>.Ok(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,6 +71,11 @@ public interface IStoreRepository
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
Task<StoreTable?> FindTableByIdAsync(long tableId, long tenantId, CancellationToken cancellationToken = default);
|
Task<StoreTable?> FindTableByIdAsync(long tableId, long tenantId, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 依据桌码获取桌台。
|
||||||
|
/// </summary>
|
||||||
|
Task<StoreTable?> FindTableByCodeAsync(string tableCode, long tenantId, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取门店员工排班(可选时间范围)。
|
/// 获取门店员工排班(可选时间范围)。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -146,6 +146,14 @@ public sealed class EfStoreRepository(TakeoutAppDbContext context) : IStoreRepos
|
|||||||
.FirstOrDefaultAsync(cancellationToken);
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public Task<StoreTable?> FindTableByCodeAsync(string tableCode, long tenantId, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return context.StoreTables
|
||||||
|
.Where(x => x.TenantId == tenantId && x.TableCode == tableCode)
|
||||||
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<IReadOnlyList<StoreEmployeeShift>> GetShiftsAsync(long storeId, long tenantId, DateTime? from = null, DateTime? to = null, CancellationToken cancellationToken = default)
|
public async Task<IReadOnlyList<StoreEmployeeShift>> GetShiftsAsync(long storeId, long tenantId, DateTime? from = null, DateTime? to = null, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user