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,
CancellationToken cancellationToken)
{
await using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken);
await deleteQuery.ExecuteDeleteAsync(cancellationToken);
var nextRowPayloads = nextRows
.Select(x => new
{
x.StoreId,
x.StaffId,
x.DayOfWeek,
x.ShiftType,
x.StartTime,
x.EndTime
})
.ToList();
if (nextRows.Count > 0)
var executionStrategy = dbContext.Database.CreateExecutionStrategy();
await executionStrategy.ExecuteAsync(async () =>
{
await dbContext.StoreStaffWeeklySchedules.AddRangeAsync(nextRows, cancellationToken);
await dbContext.SaveChangesAsync(cancellationToken);
}
dbContext.ChangeTracker.Clear();
await transaction.CommitAsync(cancellationToken);
await using var transaction = await dbContext.Database.BeginTransactionAsync(cancellationToken);
await deleteQuery.ExecuteDeleteAsync(cancellationToken);
if (nextRowPayloads.Count > 0)
{
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 transaction.CommitAsync(cancellationToken);
});
}
private static List<StaffDayShiftDto> CreateOffWeekShifts()