fix(store-hours): reject overlapping holiday date ranges
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 42s
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 42s
This commit is contained in:
@@ -164,6 +164,22 @@ public sealed class StoreHoursController(
|
||||
}
|
||||
|
||||
var holidayId = StoreApiHelpers.ParseSnowflakeOrNull(holidayInput.Id);
|
||||
|
||||
// 同一门店的特殊日期范围不允许重叠(编辑时排除自身)。
|
||||
var hasOverlap = await dbContext.StoreHolidays
|
||||
.AsNoTracking()
|
||||
.AnyAsync(
|
||||
x => x.TenantId == tenantId
|
||||
&& x.StoreId == parsedStoreId
|
||||
&& (!holidayId.HasValue || x.Id != holidayId.Value)
|
||||
&& x.Date <= endDate
|
||||
&& (x.EndDate ?? x.Date) >= startDate,
|
||||
cancellationToken);
|
||||
if (hasOverlap)
|
||||
{
|
||||
throw new BusinessException(ErrorCodes.ValidationFailed, "日期范围与已有节假日/特殊日期冲突,请勿重复设置");
|
||||
}
|
||||
|
||||
var entity = holidayId.HasValue
|
||||
? await dbContext.StoreHolidays.FirstOrDefaultAsync(
|
||||
x => x.Id == holidayId.Value && x.TenantId == tenantId && x.StoreId == parsedStoreId,
|
||||
|
||||
Reference in New Issue
Block a user