Browse Source

撤回 版本 解决事务问题

feature/x1-web-request
hyh 2 days ago
parent
commit
ce39595a90
  1. 5
      et --hard d9ef1cb
  2. 19
      src/X1.Application/BackendServiceManager/DeviceManagementService.cs
  3. 3
      tatus

5
et --hard d9ef1cb

@ -0,0 +1,5 @@
6de45ae (HEAD -> feature/x1-web-request, origin/feature/x1-web-request) 修复GetDeviceRuntimesAsync类型不匹配问题,使用DeviceRuntimeDto简化类型转换
43135fb 简化GetRuntimesByDeviceCodesAsync方法,只返回需要的四个字段
d9ef1cb 修复Swagger schemaId冲突:提取共享的BatchOperationSummary类
18dbe0d 修复前端StopDevices功能:添加批量停止设备支持、状态管理和UI优化
d8d02f9 feat: 添加运行时状态数组参数支持从前端传入过滤条件

19
src/X1.Application/BackendServiceManager/DeviceManagementService.cs

@ -148,9 +148,10 @@ namespace X1.Application.BackendServiceManager
var repository = serviceProvider.GetRequiredService<IProtocolLogRepository>();
var unitOfWork = serviceProvider.GetRequiredService<IUnitOfWork>();
// 使用事务处理
using var transaction = await unitOfWork.BeginTransactionAsync(IsolationLevel.ReadCommitted, cancellationToken);
try
{
// 使用事务处理
await unitOfWork.ExecuteTransactionAsync(async () =>
{
// 批量插入到数据库
await repository.AddRangeAsync(validLogs, cancellationToken);
@ -158,23 +159,19 @@ namespace X1.Application.BackendServiceManager
// 保存更改
await unitOfWork.SaveChangesAsync(cancellationToken);
// 提交事务
await unitOfWork.CommitTransactionAsync(transaction, cancellationToken);
_logger.LogDebug("协议日志批量插入数据库成功,数量:{Count}", validLogs.Count());
}, IsolationLevel.ReadCommitted, cancellationToken);
}
catch (OperationCanceledException)
{
_logger.LogInformation("协议日志处理被取消");
await unitOfWork.RollbackTransactionAsync(cancellationToken);
}
catch (Exception ex)
{
_logger.LogError(ex, "批量插入协议日志到数据库失败,数量:{Count}", validLogs.Count());
await unitOfWork.RollbackTransactionAsync(cancellationToken);
// 如果批量插入失败,尝试逐个插入
await ProcessProtocolLogsIndividually(validLogs, cancellationToken);
//await ProcessProtocolLogsIndividually(validLogs, cancellationToken);
}
}, cancellationToken);
@ -253,9 +250,10 @@ namespace X1.Application.BackendServiceManager
}
var batch = logs.Skip(i).Take(batchSize);
using var transaction = await unitOfWork.BeginTransactionAsync(IsolationLevel.ReadCommitted, cancellationToken);
try
{
await unitOfWork.ExecuteTransactionAsync(async () =>
{
foreach (var log in batch)
{
@ -273,14 +271,13 @@ namespace X1.Application.BackendServiceManager
// 保存当前批次的更改
await unitOfWork.SaveChangesAsync(cancellationToken);
await unitOfWork.CommitTransactionAsync(transaction, cancellationToken);
}, IsolationLevel.ReadCommitted, cancellationToken);
_logger.LogDebug("批次处理完成,成功:{SuccessCount},失败:{ErrorCount},批次大小:{BatchSize}",
successCount, errorCount, batch.Count());
}
catch (Exception ex)
{
await unitOfWork.RollbackTransactionAsync(cancellationToken);
_logger.LogError(ex, "批次处理失败,批次索引:{BatchIndex}", i / batchSize);
errorCount += batch.Count();
}

3
tatus

@ -0,0 +1,3 @@
43135fb (HEAD -> feature/x1-web-request) 简化GetRuntimesByDeviceCodesAsync方法,只返回需要的四个字段
d9ef1cb 修复Swagger schemaId冲突:提取共享的BatchOperationSummary类
18dbe0d 修复前端StopDevices功能:添加批量停止设备支持、状态管理和UI优化
Loading…
Cancel
Save