fix: 排班事务兼容ef重试策略
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user