feat: 完成门店子资源管理与文档同步
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Enums;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 创建营业时段命令。
|
||||
/// </summary>
|
||||
public sealed record CreateStoreBusinessHourCommand : IRequest<StoreBusinessHourDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 星期几。
|
||||
/// </summary>
|
||||
public DayOfWeek DayOfWeek { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 时段类型。
|
||||
/// </summary>
|
||||
public BusinessHourType HourType { get; init; } = BusinessHourType.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间。
|
||||
/// </summary>
|
||||
public TimeSpan StartTime { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间。
|
||||
/// </summary>
|
||||
public TimeSpan EndTime { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 容量限制。
|
||||
/// </summary>
|
||||
public int? CapacityLimit { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注。
|
||||
/// </summary>
|
||||
public string? Notes { get; init; }
|
||||
}
|
||||
@@ -98,4 +98,14 @@ public sealed class CreateStoreCommand : IRequest<StoreDto>
|
||||
/// 支持配送。
|
||||
/// </summary>
|
||||
public bool SupportsDelivery { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 支持预约。
|
||||
/// </summary>
|
||||
public bool SupportsReservation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 支持排队叫号。
|
||||
/// </summary>
|
||||
public bool SupportsQueueing { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 创建配送区域命令。
|
||||
/// </summary>
|
||||
public sealed record CreateStoreDeliveryZoneCommand : IRequest<StoreDeliveryZoneDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 区域名称。
|
||||
/// </summary>
|
||||
public string ZoneName { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// GeoJSON。
|
||||
/// </summary>
|
||||
public string PolygonGeoJson { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 起送价。
|
||||
/// </summary>
|
||||
public decimal? MinimumOrderAmount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 配送费。
|
||||
/// </summary>
|
||||
public decimal? DeliveryFee { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 预计分钟。
|
||||
/// </summary>
|
||||
public int? EstimatedMinutes { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序。
|
||||
/// </summary>
|
||||
public int SortOrder { get; init; } = 100;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 创建节假日配置命令。
|
||||
/// </summary>
|
||||
public sealed record CreateStoreHolidayCommand : IRequest<StoreHolidayDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 日期。
|
||||
/// </summary>
|
||||
public DateTime Date { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否闭店。
|
||||
/// </summary>
|
||||
public bool IsClosed { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 说明。
|
||||
/// </summary>
|
||||
public string? Reason { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using MediatR;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 删除营业时段命令。
|
||||
/// </summary>
|
||||
public sealed record DeleteStoreBusinessHourCommand : IRequest<bool>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 营业时段 ID。
|
||||
/// </summary>
|
||||
public long BusinessHourId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using MediatR;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 删除配送区域命令。
|
||||
/// </summary>
|
||||
public sealed record DeleteStoreDeliveryZoneCommand : IRequest<bool>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 配送区域 ID。
|
||||
/// </summary>
|
||||
public long DeliveryZoneId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using MediatR;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 删除节假日配置命令。
|
||||
/// </summary>
|
||||
public sealed record DeleteStoreHolidayCommand : IRequest<bool>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 节假日 ID。
|
||||
/// </summary>
|
||||
public long HolidayId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Enums;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 更新营业时段命令。
|
||||
/// </summary>
|
||||
public sealed record UpdateStoreBusinessHourCommand : IRequest<StoreBusinessHourDto?>
|
||||
{
|
||||
/// <summary>
|
||||
/// 营业时段 ID。
|
||||
/// </summary>
|
||||
public long BusinessHourId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 星期几。
|
||||
/// </summary>
|
||||
public DayOfWeek DayOfWeek { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 时段类型。
|
||||
/// </summary>
|
||||
public BusinessHourType HourType { get; init; } = BusinessHourType.Normal;
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间。
|
||||
/// </summary>
|
||||
public TimeSpan StartTime { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间。
|
||||
/// </summary>
|
||||
public TimeSpan EndTime { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 容量限制。
|
||||
/// </summary>
|
||||
public int? CapacityLimit { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注。
|
||||
/// </summary>
|
||||
public string? Notes { get; init; }
|
||||
}
|
||||
@@ -103,4 +103,14 @@ public sealed record UpdateStoreCommand : IRequest<StoreDto?>
|
||||
/// 支持配送。
|
||||
/// </summary>
|
||||
public bool SupportsDelivery { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 支持预约。
|
||||
/// </summary>
|
||||
public bool SupportsReservation { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支持排队叫号。
|
||||
/// </summary>
|
||||
public bool SupportsQueueing { get; init; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 更新配送区域命令。
|
||||
/// </summary>
|
||||
public sealed record UpdateStoreDeliveryZoneCommand : IRequest<StoreDeliveryZoneDto?>
|
||||
{
|
||||
/// <summary>
|
||||
/// 配送区域 ID。
|
||||
/// </summary>
|
||||
public long DeliveryZoneId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 区域名称。
|
||||
/// </summary>
|
||||
public string ZoneName { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// GeoJSON。
|
||||
/// </summary>
|
||||
public string PolygonGeoJson { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 起送价。
|
||||
/// </summary>
|
||||
public decimal? MinimumOrderAmount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 配送费。
|
||||
/// </summary>
|
||||
public decimal? DeliveryFee { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 预计分钟。
|
||||
/// </summary>
|
||||
public int? EstimatedMinutes { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序。
|
||||
/// </summary>
|
||||
public int SortOrder { get; init; } = 100;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// 更新节假日配置命令。
|
||||
/// </summary>
|
||||
public sealed record UpdateStoreHolidayCommand : IRequest<StoreHolidayDto?>
|
||||
{
|
||||
/// <summary>
|
||||
/// 节假日 ID。
|
||||
/// </summary>
|
||||
public long HolidayId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 日期。
|
||||
/// </summary>
|
||||
public DateTime Date { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否闭店。
|
||||
/// </summary>
|
||||
public bool IsClosed { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 说明。
|
||||
/// </summary>
|
||||
public string? Reason { get; init; }
|
||||
}
|
||||
@@ -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 StoreBusinessHourDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 营业时段 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 租户 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long TenantId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 星期几。
|
||||
/// </summary>
|
||||
public DayOfWeek DayOfWeek { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 时段类型。
|
||||
/// </summary>
|
||||
public BusinessHourType HourType { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始时间。
|
||||
/// </summary>
|
||||
public TimeSpan StartTime { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束时间。
|
||||
/// </summary>
|
||||
public TimeSpan EndTime { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 容量限制。
|
||||
/// </summary>
|
||||
public int? CapacityLimit { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 备注。
|
||||
/// </summary>
|
||||
public string? Notes { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间。
|
||||
/// </summary>
|
||||
public DateTime CreatedAt { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using TakeoutSaaS.Shared.Abstractions.Serialization;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 门店配送区域 DTO。
|
||||
/// </summary>
|
||||
public sealed record StoreDeliveryZoneDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 配送区域 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 租户 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long TenantId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 区域名称。
|
||||
/// </summary>
|
||||
public string ZoneName { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// GeoJSON。
|
||||
/// </summary>
|
||||
public string PolygonGeoJson { get; init; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 起送价。
|
||||
/// </summary>
|
||||
public decimal? MinimumOrderAmount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 配送费。
|
||||
/// </summary>
|
||||
public decimal? DeliveryFee { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 预计分钟。
|
||||
/// </summary>
|
||||
public int? EstimatedMinutes { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 排序。
|
||||
/// </summary>
|
||||
public int SortOrder { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间。
|
||||
/// </summary>
|
||||
public DateTime CreatedAt { get; init; }
|
||||
}
|
||||
@@ -112,6 +112,16 @@ public sealed class StoreDto
|
||||
/// </summary>
|
||||
public bool SupportsDelivery { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支持预约。
|
||||
/// </summary>
|
||||
public bool SupportsReservation { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 支持排队叫号。
|
||||
/// </summary>
|
||||
public bool SupportsQueueing { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间。
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using TakeoutSaaS.Shared.Abstractions.Serialization;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// 门店节假日 DTO。
|
||||
/// </summary>
|
||||
public sealed record StoreHolidayDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 节假日 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 租户 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long TenantId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(SnowflakeIdJsonConverter))]
|
||||
public long StoreId { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 日期。
|
||||
/// </summary>
|
||||
public DateTime Date { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否闭店。
|
||||
/// </summary>
|
||||
public bool IsClosed { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 说明。
|
||||
/// </summary>
|
||||
public string? Reason { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间。
|
||||
/// </summary>
|
||||
public DateTime CreatedAt { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Entities;
|
||||
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 CreateStoreBusinessHourCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<CreateStoreBusinessHourCommandHandler> logger)
|
||||
: IRequestHandler<CreateStoreBusinessHourCommand, StoreBusinessHourDto>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<CreateStoreBusinessHourCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<StoreBusinessHourDto> Handle(CreateStoreBusinessHourCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 校验门店存在
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var store = await _storeRepository.FindByIdAsync(request.StoreId, tenantId, cancellationToken);
|
||||
if (store is null)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
|
||||
}
|
||||
|
||||
// 2. 构建实体
|
||||
var hour = new StoreBusinessHour
|
||||
{
|
||||
StoreId = request.StoreId,
|
||||
DayOfWeek = request.DayOfWeek,
|
||||
HourType = request.HourType,
|
||||
StartTime = request.StartTime,
|
||||
EndTime = request.EndTime,
|
||||
CapacityLimit = request.CapacityLimit,
|
||||
Notes = request.Notes?.Trim()
|
||||
};
|
||||
|
||||
// 3. 持久化
|
||||
await _storeRepository.AddBusinessHoursAsync(new[] { hour }, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("创建营业时段 {BusinessHourId} 对应门店 {StoreId}", hour.Id, request.StoreId);
|
||||
|
||||
// 4. 返回 DTO
|
||||
return StoreMapping.ToDto(hour);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,9 @@ public sealed class CreateStoreCommandHandler(IStoreRepository storeRepository,
|
||||
DeliveryRadiusKm = request.DeliveryRadiusKm,
|
||||
SupportsDineIn = request.SupportsDineIn,
|
||||
SupportsPickup = request.SupportsPickup,
|
||||
SupportsDelivery = request.SupportsDelivery
|
||||
SupportsDelivery = request.SupportsDelivery,
|
||||
SupportsReservation = request.SupportsReservation,
|
||||
SupportsQueueing = request.SupportsQueueing
|
||||
};
|
||||
|
||||
// 2. 持久化
|
||||
@@ -73,6 +75,8 @@ public sealed class CreateStoreCommandHandler(IStoreRepository storeRepository,
|
||||
SupportsDineIn = store.SupportsDineIn,
|
||||
SupportsPickup = store.SupportsPickup,
|
||||
SupportsDelivery = store.SupportsDelivery,
|
||||
SupportsReservation = store.SupportsReservation,
|
||||
SupportsQueueing = store.SupportsQueueing,
|
||||
CreatedAt = store.CreatedAt
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Entities;
|
||||
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 CreateStoreDeliveryZoneCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<CreateStoreDeliveryZoneCommandHandler> logger)
|
||||
: IRequestHandler<CreateStoreDeliveryZoneCommand, StoreDeliveryZoneDto>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<CreateStoreDeliveryZoneCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<StoreDeliveryZoneDto> Handle(CreateStoreDeliveryZoneCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 校验门店存在
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var store = await _storeRepository.FindByIdAsync(request.StoreId, tenantId, cancellationToken);
|
||||
if (store is null)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
|
||||
}
|
||||
|
||||
// 2. 构建实体
|
||||
var zone = new StoreDeliveryZone
|
||||
{
|
||||
StoreId = request.StoreId,
|
||||
ZoneName = request.ZoneName.Trim(),
|
||||
PolygonGeoJson = request.PolygonGeoJson.Trim(),
|
||||
MinimumOrderAmount = request.MinimumOrderAmount,
|
||||
DeliveryFee = request.DeliveryFee,
|
||||
EstimatedMinutes = request.EstimatedMinutes,
|
||||
SortOrder = request.SortOrder
|
||||
};
|
||||
|
||||
// 3. 持久化
|
||||
await _storeRepository.AddDeliveryZonesAsync(new[] { zone }, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("创建配送区域 {DeliveryZoneId} 对应门店 {StoreId}", zone.Id, request.StoreId);
|
||||
|
||||
// 4. 返回 DTO
|
||||
return StoreMapping.ToDto(zone);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Entities;
|
||||
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 CreateStoreHolidayCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<CreateStoreHolidayCommandHandler> logger)
|
||||
: IRequestHandler<CreateStoreHolidayCommand, StoreHolidayDto>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<CreateStoreHolidayCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<StoreHolidayDto> Handle(CreateStoreHolidayCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 校验门店存在
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var store = await _storeRepository.FindByIdAsync(request.StoreId, tenantId, cancellationToken);
|
||||
if (store is null)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.NotFound, "门店不存在");
|
||||
}
|
||||
|
||||
// 2. 构建实体
|
||||
var holiday = new StoreHoliday
|
||||
{
|
||||
StoreId = request.StoreId,
|
||||
Date = request.Date,
|
||||
IsClosed = request.IsClosed,
|
||||
Reason = request.Reason?.Trim()
|
||||
};
|
||||
|
||||
// 3. 持久化
|
||||
await _storeRepository.AddHolidaysAsync(new[] { holiday }, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("创建节假日 {HolidayId} 对应门店 {StoreId}", holiday.Id, request.StoreId);
|
||||
|
||||
// 4. 返回 DTO
|
||||
return StoreMapping.ToDto(holiday);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Domain.Stores.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 删除营业时段处理器。
|
||||
/// </summary>
|
||||
public sealed class DeleteStoreBusinessHourCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<DeleteStoreBusinessHourCommandHandler> logger)
|
||||
: IRequestHandler<DeleteStoreBusinessHourCommand, bool>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<DeleteStoreBusinessHourCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Handle(DeleteStoreBusinessHourCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 读取时段
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var existing = await _storeRepository.FindBusinessHourByIdAsync(request.BusinessHourId, tenantId, cancellationToken);
|
||||
if (existing is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 校验门店归属
|
||||
if (existing.StoreId != request.StoreId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. 删除
|
||||
await _storeRepository.DeleteBusinessHourAsync(request.BusinessHourId, tenantId, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("删除营业时段 {BusinessHourId} 对应门店 {StoreId}", request.BusinessHourId, request.StoreId);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Domain.Stores.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 删除配送区域处理器。
|
||||
/// </summary>
|
||||
public sealed class DeleteStoreDeliveryZoneCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<DeleteStoreDeliveryZoneCommandHandler> logger)
|
||||
: IRequestHandler<DeleteStoreDeliveryZoneCommand, bool>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<DeleteStoreDeliveryZoneCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Handle(DeleteStoreDeliveryZoneCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 读取区域
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var existing = await _storeRepository.FindDeliveryZoneByIdAsync(request.DeliveryZoneId, tenantId, cancellationToken);
|
||||
if (existing is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 校验门店归属
|
||||
if (existing.StoreId != request.StoreId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. 删除
|
||||
await _storeRepository.DeleteDeliveryZoneAsync(request.DeliveryZoneId, tenantId, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("删除配送区域 {DeliveryZoneId} 对应门店 {StoreId}", request.DeliveryZoneId, request.StoreId);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Domain.Stores.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 删除节假日配置处理器。
|
||||
/// </summary>
|
||||
public sealed class DeleteStoreHolidayCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<DeleteStoreHolidayCommandHandler> logger)
|
||||
: IRequestHandler<DeleteStoreHolidayCommand, bool>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<DeleteStoreHolidayCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<bool> Handle(DeleteStoreHolidayCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 读取配置
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var existing = await _storeRepository.FindHolidayByIdAsync(request.HolidayId, tenantId, cancellationToken);
|
||||
if (existing is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. 校验门店归属
|
||||
if (existing.StoreId != request.StoreId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. 删除
|
||||
await _storeRepository.DeleteHolidayAsync(request.HolidayId, tenantId, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("删除节假日 {HolidayId} 对应门店 {StoreId}", request.HolidayId, request.StoreId);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,8 @@ public sealed class GetStoreByIdQueryHandler(
|
||||
SupportsDineIn = store.SupportsDineIn,
|
||||
SupportsPickup = store.SupportsPickup,
|
||||
SupportsDelivery = store.SupportsDelivery,
|
||||
SupportsReservation = store.SupportsReservation,
|
||||
SupportsQueueing = store.SupportsQueueing,
|
||||
CreatedAt = store.CreatedAt
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Linq;
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Application.App.Stores.Queries;
|
||||
using TakeoutSaaS.Domain.Stores.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 营业时段列表查询处理器。
|
||||
/// </summary>
|
||||
public sealed class ListStoreBusinessHoursQueryHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider)
|
||||
: IRequestHandler<ListStoreBusinessHoursQuery, IReadOnlyList<StoreBusinessHourDto>>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<StoreBusinessHourDto>> Handle(ListStoreBusinessHoursQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 查询时段列表
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var hours = await _storeRepository.GetBusinessHoursAsync(request.StoreId, tenantId, cancellationToken);
|
||||
|
||||
// 2. 映射 DTO
|
||||
return hours.Select(StoreMapping.ToDto).ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Linq;
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Application.App.Stores.Queries;
|
||||
using TakeoutSaaS.Domain.Stores.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 配送区域列表查询处理器。
|
||||
/// </summary>
|
||||
public sealed class ListStoreDeliveryZonesQueryHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider)
|
||||
: IRequestHandler<ListStoreDeliveryZonesQuery, IReadOnlyList<StoreDeliveryZoneDto>>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<StoreDeliveryZoneDto>> Handle(ListStoreDeliveryZonesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 查询配送区域
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var zones = await _storeRepository.GetDeliveryZonesAsync(request.StoreId, tenantId, cancellationToken);
|
||||
|
||||
// 2. 映射 DTO
|
||||
return zones.Select(StoreMapping.ToDto).ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System.Linq;
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Application.App.Stores.Queries;
|
||||
using TakeoutSaaS.Domain.Stores.Repositories;
|
||||
using TakeoutSaaS.Shared.Abstractions.Tenancy;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// 门店节假日列表查询处理器。
|
||||
/// </summary>
|
||||
public sealed class ListStoreHolidaysQueryHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider)
|
||||
: IRequestHandler<ListStoreHolidaysQuery, IReadOnlyList<StoreHolidayDto>>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IReadOnlyList<StoreHolidayDto>> Handle(ListStoreHolidaysQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 查询节假日
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var holidays = await _storeRepository.GetHolidaysAsync(request.StoreId, tenantId, cancellationToken);
|
||||
|
||||
// 2. 映射 DTO
|
||||
return holidays.Select(StoreMapping.ToDto).ToList();
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,8 @@ public sealed class SearchStoresQueryHandler(
|
||||
SupportsDineIn = store.SupportsDineIn,
|
||||
SupportsPickup = store.SupportsPickup,
|
||||
SupportsDelivery = store.SupportsDelivery,
|
||||
SupportsReservation = store.SupportsReservation,
|
||||
SupportsQueueing = store.SupportsQueueing,
|
||||
CreatedAt = store.CreatedAt
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Entities;
|
||||
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 UpdateStoreBusinessHourCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<UpdateStoreBusinessHourCommandHandler> logger)
|
||||
: IRequestHandler<UpdateStoreBusinessHourCommand, StoreBusinessHourDto?>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<UpdateStoreBusinessHourCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<StoreBusinessHourDto?> Handle(UpdateStoreBusinessHourCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 读取时段
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var existing = await _storeRepository.FindBusinessHourByIdAsync(request.BusinessHourId, tenantId, cancellationToken);
|
||||
if (existing is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 校验门店归属
|
||||
if (existing.StoreId != request.StoreId)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.ValidationFailed, "营业时段不属于该门店");
|
||||
}
|
||||
|
||||
// 3. 更新字段
|
||||
existing.DayOfWeek = request.DayOfWeek;
|
||||
existing.HourType = request.HourType;
|
||||
existing.StartTime = request.StartTime;
|
||||
existing.EndTime = request.EndTime;
|
||||
existing.CapacityLimit = request.CapacityLimit;
|
||||
existing.Notes = request.Notes?.Trim();
|
||||
|
||||
// 4. 持久化
|
||||
await _storeRepository.UpdateBusinessHourAsync(existing, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("更新营业时段 {BusinessHourId} 对应门店 {StoreId}", existing.Id, existing.StoreId);
|
||||
|
||||
// 5. 返回 DTO
|
||||
return StoreMapping.ToDto(existing);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,8 @@ public sealed class UpdateStoreCommandHandler(
|
||||
existing.SupportsDineIn = request.SupportsDineIn;
|
||||
existing.SupportsPickup = request.SupportsPickup;
|
||||
existing.SupportsDelivery = request.SupportsDelivery;
|
||||
existing.SupportsReservation = request.SupportsReservation;
|
||||
existing.SupportsQueueing = request.SupportsQueueing;
|
||||
|
||||
// 3. 持久化
|
||||
await _storeRepository.UpdateStoreAsync(existing, cancellationToken);
|
||||
@@ -83,6 +85,8 @@ public sealed class UpdateStoreCommandHandler(
|
||||
SupportsDineIn = store.SupportsDineIn,
|
||||
SupportsPickup = store.SupportsPickup,
|
||||
SupportsDelivery = store.SupportsDelivery,
|
||||
SupportsReservation = store.SupportsReservation,
|
||||
SupportsQueueing = store.SupportsQueueing,
|
||||
CreatedAt = store.CreatedAt
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Entities;
|
||||
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 UpdateStoreDeliveryZoneCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<UpdateStoreDeliveryZoneCommandHandler> logger)
|
||||
: IRequestHandler<UpdateStoreDeliveryZoneCommand, StoreDeliveryZoneDto?>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<UpdateStoreDeliveryZoneCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<StoreDeliveryZoneDto?> Handle(UpdateStoreDeliveryZoneCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 读取区域
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var existing = await _storeRepository.FindDeliveryZoneByIdAsync(request.DeliveryZoneId, tenantId, cancellationToken);
|
||||
if (existing is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 校验门店归属
|
||||
if (existing.StoreId != request.StoreId)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.ValidationFailed, "配送区域不属于该门店");
|
||||
}
|
||||
|
||||
// 3. 更新字段
|
||||
existing.ZoneName = request.ZoneName.Trim();
|
||||
existing.PolygonGeoJson = request.PolygonGeoJson.Trim();
|
||||
existing.MinimumOrderAmount = request.MinimumOrderAmount;
|
||||
existing.DeliveryFee = request.DeliveryFee;
|
||||
existing.EstimatedMinutes = request.EstimatedMinutes;
|
||||
existing.SortOrder = request.SortOrder;
|
||||
|
||||
// 4. 持久化
|
||||
await _storeRepository.UpdateDeliveryZoneAsync(existing, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("更新配送区域 {DeliveryZoneId} 对应门店 {StoreId}", existing.Id, existing.StoreId);
|
||||
|
||||
// 5. 返回 DTO
|
||||
return StoreMapping.ToDto(existing);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Entities;
|
||||
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 UpdateStoreHolidayCommandHandler(
|
||||
IStoreRepository storeRepository,
|
||||
ITenantProvider tenantProvider,
|
||||
ILogger<UpdateStoreHolidayCommandHandler> logger)
|
||||
: IRequestHandler<UpdateStoreHolidayCommand, StoreHolidayDto?>
|
||||
{
|
||||
private readonly IStoreRepository _storeRepository = storeRepository;
|
||||
private readonly ITenantProvider _tenantProvider = tenantProvider;
|
||||
private readonly ILogger<UpdateStoreHolidayCommandHandler> _logger = logger;
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<StoreHolidayDto?> Handle(UpdateStoreHolidayCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
// 1. 读取配置
|
||||
var tenantId = _tenantProvider.GetCurrentTenantId();
|
||||
var existing = await _storeRepository.FindHolidayByIdAsync(request.HolidayId, tenantId, cancellationToken);
|
||||
if (existing is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// 2. 校验门店归属
|
||||
if (existing.StoreId != request.StoreId)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.ValidationFailed, "节假日配置不属于该门店");
|
||||
}
|
||||
|
||||
// 3. 更新字段
|
||||
existing.Date = request.Date;
|
||||
existing.IsClosed = request.IsClosed;
|
||||
existing.Reason = request.Reason?.Trim();
|
||||
|
||||
// 4. 持久化
|
||||
await _storeRepository.UpdateHolidayAsync(existing, cancellationToken);
|
||||
await _storeRepository.SaveChangesAsync(cancellationToken);
|
||||
_logger.LogInformation("更新节假日 {HolidayId} 对应门店 {StoreId}", existing.Id, existing.StoreId);
|
||||
|
||||
// 5. 返回 DTO
|
||||
return StoreMapping.ToDto(existing);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// 营业时段列表查询。
|
||||
/// </summary>
|
||||
public sealed record ListStoreBusinessHoursQuery : IRequest<IReadOnlyList<StoreBusinessHourDto>>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// 配送区域列表查询。
|
||||
/// </summary>
|
||||
public sealed record ListStoreDeliveryZonesQuery : IRequest<IReadOnlyList<StoreDeliveryZoneDto>>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using MediatR;
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Queries;
|
||||
|
||||
/// <summary>
|
||||
/// 门店节假日列表查询。
|
||||
/// </summary>
|
||||
public sealed record ListStoreHolidaysQuery : IRequest<IReadOnlyList<StoreHolidayDto>>
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店 ID。
|
||||
/// </summary>
|
||||
public long StoreId { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using TakeoutSaaS.Application.App.Stores.Dto;
|
||||
using TakeoutSaaS.Domain.Stores.Entities;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores;
|
||||
|
||||
/// <summary>
|
||||
/// 门店相关映射助手。
|
||||
/// </summary>
|
||||
public static class StoreMapping
|
||||
{
|
||||
/// <summary>
|
||||
/// 映射营业时段 DTO。
|
||||
/// </summary>
|
||||
/// <param name="hour">营业时段实体。</param>
|
||||
/// <returns>DTO。</returns>
|
||||
public static StoreBusinessHourDto ToDto(StoreBusinessHour hour) => new()
|
||||
{
|
||||
Id = hour.Id,
|
||||
TenantId = hour.TenantId,
|
||||
StoreId = hour.StoreId,
|
||||
DayOfWeek = hour.DayOfWeek,
|
||||
HourType = hour.HourType,
|
||||
StartTime = hour.StartTime,
|
||||
EndTime = hour.EndTime,
|
||||
CapacityLimit = hour.CapacityLimit,
|
||||
Notes = hour.Notes,
|
||||
CreatedAt = hour.CreatedAt
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 映射配送区域 DTO。
|
||||
/// </summary>
|
||||
/// <param name="zone">配送区域实体。</param>
|
||||
/// <returns>DTO。</returns>
|
||||
public static StoreDeliveryZoneDto ToDto(StoreDeliveryZone zone) => new()
|
||||
{
|
||||
Id = zone.Id,
|
||||
TenantId = zone.TenantId,
|
||||
StoreId = zone.StoreId,
|
||||
ZoneName = zone.ZoneName,
|
||||
PolygonGeoJson = zone.PolygonGeoJson,
|
||||
MinimumOrderAmount = zone.MinimumOrderAmount,
|
||||
DeliveryFee = zone.DeliveryFee,
|
||||
EstimatedMinutes = zone.EstimatedMinutes,
|
||||
SortOrder = zone.SortOrder,
|
||||
CreatedAt = zone.CreatedAt
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 映射节假日 DTO。
|
||||
/// </summary>
|
||||
/// <param name="holiday">节假日实体。</param>
|
||||
/// <returns>DTO。</returns>
|
||||
public static StoreHolidayDto ToDto(StoreHoliday holiday) => new()
|
||||
{
|
||||
Id = holiday.Id,
|
||||
TenantId = holiday.TenantId,
|
||||
StoreId = holiday.StoreId,
|
||||
Date = holiday.Date,
|
||||
IsClosed = holiday.IsClosed,
|
||||
Reason = holiday.Reason,
|
||||
CreatedAt = holiday.CreatedAt
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 创建营业时段命令验证器。
|
||||
/// </summary>
|
||||
public sealed class CreateStoreBusinessHourCommandValidator : AbstractValidator<CreateStoreBusinessHourCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public CreateStoreBusinessHourCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.StoreId).GreaterThan(0);
|
||||
RuleFor(x => x.StartTime).LessThan(x => x.EndTime).WithMessage("结束时间必须晚于开始时间");
|
||||
RuleFor(x => x.CapacityLimit).GreaterThanOrEqualTo(0).When(x => x.CapacityLimit.HasValue);
|
||||
RuleFor(x => x.Notes).MaximumLength(256);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 创建配送区域命令验证器。
|
||||
/// </summary>
|
||||
public sealed class CreateStoreDeliveryZoneCommandValidator : AbstractValidator<CreateStoreDeliveryZoneCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public CreateStoreDeliveryZoneCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.StoreId).GreaterThan(0);
|
||||
RuleFor(x => x.ZoneName).NotEmpty().MaximumLength(64);
|
||||
RuleFor(x => x.PolygonGeoJson).NotEmpty();
|
||||
RuleFor(x => x.MinimumOrderAmount).GreaterThanOrEqualTo(0).When(x => x.MinimumOrderAmount.HasValue);
|
||||
RuleFor(x => x.DeliveryFee).GreaterThanOrEqualTo(0).When(x => x.DeliveryFee.HasValue);
|
||||
RuleFor(x => x.EstimatedMinutes).GreaterThan(0).When(x => x.EstimatedMinutes.HasValue);
|
||||
RuleFor(x => x.SortOrder).GreaterThanOrEqualTo(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 创建节假日命令验证器。
|
||||
/// </summary>
|
||||
public sealed class CreateStoreHolidayCommandValidator : AbstractValidator<CreateStoreHolidayCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public CreateStoreHolidayCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.StoreId).GreaterThan(0);
|
||||
RuleFor(x => x.Date).NotEmpty();
|
||||
RuleFor(x => x.Reason).MaximumLength(256);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 更新营业时段命令验证器。
|
||||
/// </summary>
|
||||
public sealed class UpdateStoreBusinessHourCommandValidator : AbstractValidator<UpdateStoreBusinessHourCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public UpdateStoreBusinessHourCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.BusinessHourId).GreaterThan(0);
|
||||
RuleFor(x => x.StoreId).GreaterThan(0);
|
||||
RuleFor(x => x.StartTime).LessThan(x => x.EndTime).WithMessage("结束时间必须晚于开始时间");
|
||||
RuleFor(x => x.CapacityLimit).GreaterThanOrEqualTo(0).When(x => x.CapacityLimit.HasValue);
|
||||
RuleFor(x => x.Notes).MaximumLength(256);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 更新配送区域命令验证器。
|
||||
/// </summary>
|
||||
public sealed class UpdateStoreDeliveryZoneCommandValidator : AbstractValidator<UpdateStoreDeliveryZoneCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public UpdateStoreDeliveryZoneCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.DeliveryZoneId).GreaterThan(0);
|
||||
RuleFor(x => x.StoreId).GreaterThan(0);
|
||||
RuleFor(x => x.ZoneName).NotEmpty().MaximumLength(64);
|
||||
RuleFor(x => x.PolygonGeoJson).NotEmpty();
|
||||
RuleFor(x => x.MinimumOrderAmount).GreaterThanOrEqualTo(0).When(x => x.MinimumOrderAmount.HasValue);
|
||||
RuleFor(x => x.DeliveryFee).GreaterThanOrEqualTo(0).When(x => x.DeliveryFee.HasValue);
|
||||
RuleFor(x => x.EstimatedMinutes).GreaterThan(0).When(x => x.EstimatedMinutes.HasValue);
|
||||
RuleFor(x => x.SortOrder).GreaterThanOrEqualTo(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using FluentValidation;
|
||||
using TakeoutSaaS.Application.App.Stores.Commands;
|
||||
|
||||
namespace TakeoutSaaS.Application.App.Stores.Validators;
|
||||
|
||||
/// <summary>
|
||||
/// 更新节假日命令验证器。
|
||||
/// </summary>
|
||||
public sealed class UpdateStoreHolidayCommandValidator : AbstractValidator<UpdateStoreHolidayCommand>
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化验证规则。
|
||||
/// </summary>
|
||||
public UpdateStoreHolidayCommandValidator()
|
||||
{
|
||||
RuleFor(x => x.HolidayId).GreaterThan(0);
|
||||
RuleFor(x => x.StoreId).GreaterThan(0);
|
||||
RuleFor(x => x.Date).NotEmpty();
|
||||
RuleFor(x => x.Reason).MaximumLength(256);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user