fix: 排班事务兼容ef重试策略
All checks were successful
Build and Deploy TenantApi / build-and-deploy (push) Successful in 42s

This commit is contained in:
2026-02-20 09:17:48 +08:00
parent 9651022261
commit f2142de407

View File

@@ -816,16 +816,44 @@ public sealed class StoreStaffController(
IReadOnlyCollection<StoreStaffWeeklySchedule> nextRows, IReadOnlyCollection<StoreStaffWeeklySchedule> nextRows,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var nextRowPayloads = nextRows
.Select(x => new
{
x.StoreId,
x.StaffId,
x.DayOfWeek,
x.ShiftType,
x.StartTime,
x.EndTime
})
.ToList();
var executionStrategy = dbContext.Database.CreateExecutionStrategy();
await executionStrategy.ExecuteAsync(async () =>
{
dbContext.ChangeTracker.Clear();
await using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken); await using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken);
await deleteQuery.ExecuteDeleteAsync(cancellationToken); await deleteQuery.ExecuteDeleteAsync(cancellationToken);
if (nextRows.Count > 0) if (nextRowPayloads.Count > 0)
{ {
await dbContext.StoreStaffWeeklySchedules.AddRangeAsync(nextRows, cancellationToken); var insertRows = nextRowPayloads.Select(x => new StoreStaffWeeklySchedule
{
StoreId = x.StoreId,
StaffId = x.StaffId,
DayOfWeek = x.DayOfWeek,
ShiftType = x.ShiftType,
StartTime = x.StartTime,
EndTime = x.EndTime
}).ToList();
await dbContext.StoreStaffWeeklySchedules.AddRangeAsync(insertRows, cancellationToken);
await dbContext.SaveChangesAsync(cancellationToken); await dbContext.SaveChangesAsync(cancellationToken);
} }
await transaction.CommitAsync(cancellationToken); await transaction.CommitAsync(cancellationToken);
});
} }
private static List<StaffDayShiftDto> CreateOffWeekShifts() private static List<StaffDayShiftDto> CreateOffWeekShifts()