feat(store): 扩展临时时段配置

This commit is contained in:
2026-01-20 18:41:34 +08:00
parent 3385674490
commit 32f5bbbd43
15 changed files with 7871 additions and 33 deletions

View File

@@ -1,10 +1,11 @@
using MediatR;
using TakeoutSaaS.Application.App.Stores.Dto;
using TakeoutSaaS.Domain.Stores.Enums;
namespace TakeoutSaaS.Application.App.Stores.Commands;
/// <summary>
/// 创建节假日配置命令。
/// 创建临时时段配置命令。
/// </summary>
public sealed record CreateStoreHolidayCommand : IRequest<StoreHolidayDto>
{
@@ -14,14 +15,34 @@ public sealed record CreateStoreHolidayCommand : IRequest<StoreHolidayDto>
public long StoreId { get; init; }
/// <summary>
/// 日期。
/// 开始日期。
/// </summary>
public DateTime Date { get; init; }
/// <summary>
/// 是否闭店
/// 结束日期(可选)
/// </summary>
public bool IsClosed { get; init; } = true;
public DateTime? EndDate { get; init; }
/// <summary>
/// 是否全天。
/// </summary>
public bool IsAllDay { get; init; } = true;
/// <summary>
/// 开始时间IsAllDay=false 时必填)。
/// </summary>
public TimeSpan? StartTime { get; init; }
/// <summary>
/// 结束时间IsAllDay=false 时必填)。
/// </summary>
public TimeSpan? EndTime { get; init; }
/// <summary>
/// 覆盖类型。
/// </summary>
public OverrideType OverrideType { get; init; } = OverrideType.Closed;
/// <summary>
/// 说明。

View File

@@ -1,10 +1,11 @@
using MediatR;
using TakeoutSaaS.Application.App.Stores.Dto;
using TakeoutSaaS.Domain.Stores.Enums;
namespace TakeoutSaaS.Application.App.Stores.Commands;
/// <summary>
/// 更新节假日配置命令。
/// 更新临时时段配置命令。
/// </summary>
public sealed record UpdateStoreHolidayCommand : IRequest<StoreHolidayDto?>
{
@@ -19,14 +20,34 @@ public sealed record UpdateStoreHolidayCommand : IRequest<StoreHolidayDto?>
public long StoreId { get; init; }
/// <summary>
/// 日期。
/// 开始日期。
/// </summary>
public DateTime Date { get; init; }
/// <summary>
/// 是否闭店
/// 结束日期(可选)
/// </summary>
public bool IsClosed { get; init; } = true;
public DateTime? EndDate { get; init; }
/// <summary>
/// 是否全天。
/// </summary>
public bool IsAllDay { get; init; } = true;
/// <summary>
/// 开始时间IsAllDay=false 时必填)。
/// </summary>
public TimeSpan? StartTime { get; init; }
/// <summary>
/// 结束时间IsAllDay=false 时必填)。
/// </summary>
public TimeSpan? EndTime { get; init; }
/// <summary>
/// 覆盖类型。
/// </summary>
public OverrideType OverrideType { get; init; } = OverrideType.Closed;
/// <summary>
/// 说明。

View File

@@ -1,10 +1,11 @@
using System.Text.Json.Serialization;
using TakeoutSaaS.Domain.Stores.Enums;
using TakeoutSaaS.Shared.Abstractions.Serialization;
namespace TakeoutSaaS.Application.App.Stores.Dto;
/// <summary>
/// 门店节假日 DTO。
/// 门店临时时段 DTO。
/// </summary>
public sealed record StoreHolidayDto
{
@@ -27,12 +28,37 @@ public sealed record StoreHolidayDto
public long StoreId { get; init; }
/// <summary>
/// 日期。
/// 开始日期。
/// </summary>
public DateTime Date { get; init; }
/// <summary>
/// 是否闭店
/// 结束日期(可选)
/// </summary>
public DateTime? EndDate { get; init; }
/// <summary>
/// 是否全天。
/// </summary>
public bool IsAllDay { get; init; }
/// <summary>
/// 开始时间。
/// </summary>
public TimeSpan? StartTime { get; init; }
/// <summary>
/// 结束时间。
/// </summary>
public TimeSpan? EndTime { get; init; }
/// <summary>
/// 覆盖类型。
/// </summary>
public OverrideType OverrideType { get; init; }
/// <summary>
/// 是否闭店(兼容)。
/// </summary>
public bool IsClosed { get; init; }

View File

@@ -3,6 +3,7 @@ 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.Enums;
using TakeoutSaaS.Domain.Stores.Repositories;
using TakeoutSaaS.Shared.Abstractions.Constants;
using TakeoutSaaS.Shared.Abstractions.Exceptions;
@@ -39,7 +40,12 @@ public sealed class CreateStoreHolidayCommandHandler(
{
StoreId = request.StoreId,
Date = request.Date,
IsClosed = request.IsClosed,
EndDate = request.EndDate,
IsAllDay = request.IsAllDay,
StartTime = request.StartTime,
EndTime = request.EndTime,
OverrideType = request.OverrideType,
IsClosed = request.OverrideType == OverrideType.Closed,
Reason = request.Reason?.Trim()
};

View File

@@ -3,6 +3,7 @@ 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.Enums;
using TakeoutSaaS.Domain.Stores.Repositories;
using TakeoutSaaS.Shared.Abstractions.Constants;
using TakeoutSaaS.Shared.Abstractions.Exceptions;
@@ -42,7 +43,12 @@ public sealed class UpdateStoreHolidayCommandHandler(
// 3. 更新字段
existing.Date = request.Date;
existing.IsClosed = request.IsClosed;
existing.EndDate = request.EndDate;
existing.IsAllDay = request.IsAllDay;
existing.StartTime = request.StartTime;
existing.EndTime = request.EndTime;
existing.OverrideType = request.OverrideType;
existing.IsClosed = request.OverrideType == OverrideType.Closed;
existing.Reason = request.Reason?.Trim();
// 4. 持久化

View File

@@ -150,6 +150,11 @@ public static class StoreMapping
TenantId = holiday.TenantId,
StoreId = holiday.StoreId,
Date = holiday.Date,
EndDate = holiday.EndDate,
IsAllDay = holiday.IsAllDay,
StartTime = holiday.StartTime,
EndTime = holiday.EndTime,
OverrideType = holiday.OverrideType,
IsClosed = holiday.IsClosed,
Reason = holiday.Reason,
CreatedAt = holiday.CreatedAt

View File

@@ -15,6 +15,27 @@ public sealed class CreateStoreHolidayCommandValidator : AbstractValidator<Creat
{
RuleFor(x => x.StoreId).GreaterThan(0);
RuleFor(x => x.Date).NotEmpty();
RuleFor(x => x.Reason).MaximumLength(256);
RuleFor(x => x.EndDate)
.GreaterThanOrEqualTo(x => x.Date)
.When(x => x.EndDate.HasValue)
.WithMessage("结束日期不能早于开始日期");
RuleFor(x => x.StartTime)
.NotNull()
.When(x => !x.IsAllDay)
.WithMessage("非全天模式下必须填写开始时间");
RuleFor(x => x.EndTime)
.NotNull()
.When(x => !x.IsAllDay)
.WithMessage("非全天模式下必须填写结束时间");
RuleFor(x => x.EndTime)
.GreaterThan(x => x.StartTime)
.When(x => !x.IsAllDay && x.StartTime.HasValue && x.EndTime.HasValue)
.WithMessage("结束时间必须晚于开始时间");
RuleFor(x => x.Reason).MaximumLength(200);
}
}

View File

@@ -16,6 +16,27 @@ public sealed class UpdateStoreHolidayCommandValidator : AbstractValidator<Updat
RuleFor(x => x.HolidayId).GreaterThan(0);
RuleFor(x => x.StoreId).GreaterThan(0);
RuleFor(x => x.Date).NotEmpty();
RuleFor(x => x.Reason).MaximumLength(256);
RuleFor(x => x.EndDate)
.GreaterThanOrEqualTo(x => x.Date)
.When(x => x.EndDate.HasValue)
.WithMessage("结束日期不能早于开始日期");
RuleFor(x => x.StartTime)
.NotNull()
.When(x => !x.IsAllDay)
.WithMessage("非全天模式下必须填写开始时间");
RuleFor(x => x.EndTime)
.NotNull()
.When(x => !x.IsAllDay)
.WithMessage("非全天模式下必须填写结束时间");
RuleFor(x => x.EndTime)
.GreaterThan(x => x.StartTime)
.When(x => !x.IsAllDay && x.StartTime.HasValue && x.EndTime.HasValue)
.WithMessage("结束时间必须晚于开始时间");
RuleFor(x => x.Reason).MaximumLength(200);
}
}