diff --git a/et --hard d9ef1cb b/et --hard d9ef1cb new file mode 100644 index 0000000..4ae3cd0 --- /dev/null +++ b/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: 添加运行时状态数组参数支持从前端传入过滤条件 diff --git a/src/X1.Application/BackendServiceManager/DeviceManagementService.cs b/src/X1.Application/BackendServiceManager/DeviceManagementService.cs index 6e13e2d..cd060a1 100644 --- a/src/X1.Application/BackendServiceManager/DeviceManagementService.cs +++ b/src/X1.Application/BackendServiceManager/DeviceManagementService.cs @@ -148,33 +148,30 @@ namespace X1.Application.BackendServiceManager var repository = serviceProvider.GetRequiredService(); var unitOfWork = serviceProvider.GetRequiredService(); - // 使用事务处理 - using var transaction = await unitOfWork.BeginTransactionAsync(IsolationLevel.ReadCommitted, cancellationToken); try { - // 批量插入到数据库 - await repository.AddRangeAsync(validLogs, cancellationToken); - - // 保存更改 - await unitOfWork.SaveChangesAsync(cancellationToken); - - // 提交事务 - await unitOfWork.CommitTransactionAsync(transaction, cancellationToken); - - _logger.LogDebug("协议日志批量插入数据库成功,数量:{Count}", validLogs.Count()); + // 使用事务处理 + await unitOfWork.ExecuteTransactionAsync(async () => + { + // 批量插入到数据库 + await repository.AddRangeAsync(validLogs, cancellationToken); + + // 保存更改 + await unitOfWork.SaveChangesAsync(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,34 +250,34 @@ namespace X1.Application.BackendServiceManager } var batch = logs.Skip(i).Take(batchSize); - using var transaction = await unitOfWork.BeginTransactionAsync(IsolationLevel.ReadCommitted, cancellationToken); try { - foreach (var log in batch) + await unitOfWork.ExecuteTransactionAsync(async () => { - try + foreach (var log in batch) { - await repository.AddAsync(log, cancellationToken); - successCount++; + try + { + await repository.AddAsync(log, cancellationToken); + successCount++; + } + catch (Exception ex) + { + errorCount++; + _logger.LogError(ex, "插入单个协议日志失败,ID:{LogId},设备:{DeviceCode}", log.Id, log.DeviceCode); + } } - catch (Exception ex) - { - errorCount++; - _logger.LogError(ex, "插入单个协议日志失败,ID:{LogId},设备:{DeviceCode}", log.Id, log.DeviceCode); - } - } - // 保存当前批次的更改 - await unitOfWork.SaveChangesAsync(cancellationToken); - await unitOfWork.CommitTransactionAsync(transaction, cancellationToken); + // 保存当前批次的更改 + await unitOfWork.SaveChangesAsync(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(); } diff --git a/tatus b/tatus new file mode 100644 index 0000000..35a940a --- /dev/null +++ b/tatus @@ -0,0 +1,3 @@ +43135fb (HEAD -> feature/x1-web-request) 简化GetRuntimesByDeviceCodesAsync方法,只返回需要的四个字段 +d9ef1cb 修复Swagger schemaId冲突:提取共享的BatchOperationSummary类 +18dbe0d 修复前端StopDevices功能:添加批量停止设备支持、状态管理和UI优化