From 6498df181883bec38922befdac4e570430e7669a Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Thu, 29 Jan 2026 15:58:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=B9=E5=A4=84=E7=90=86=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=8A=A5=E5=91=8A=E7=AA=97=E5=8F=A3=EF=BC=8C=E6=89=B9?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=89=A7=E8=A1=8C=E7=BB=93=E6=9D=9F=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=B1=87=E6=80=BB=E4=BF=A1=E6=81=AF=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=A2=B0=E6=92=9E=E4=B8=BA0=E6=97=B6=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E4=B8=8A=E4=B8=AA=E6=B5=8B=E8=AF=95=E7=9A=84=E7=A2=B0?= =?UTF-8?q?=E6=92=9E=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GenerateCollisionReportCommand.cs | 18 +++- src/Core/BatchQueueManager.cs | 97 ++++++++++++++++++- .../Collision/ClashDetectiveIntegration.cs | 3 + 3 files changed, 112 insertions(+), 6 deletions(-) diff --git a/src/Commands/GenerateCollisionReportCommand.cs b/src/Commands/GenerateCollisionReportCommand.cs index b61bf53..9d38e78 100644 --- a/src/Commands/GenerateCollisionReportCommand.cs +++ b/src/Commands/GenerateCollisionReportCommand.cs @@ -49,6 +49,11 @@ namespace NavisworksTransport.Commands /// public bool HasHighlighted { get; set; } = false; + /// + /// 是否显示报告窗口(批处理模式设为false,只生成报告不弹窗) + /// + public bool ShowDialog { get; set; } = true; + public PathPlanningResult ValidateParameters() { return PathPlanningResult.Success("参数验证通过"); @@ -317,8 +322,11 @@ namespace NavisworksTransport.Commands UpdateProgress(100, "报告生成完成"); - // 显示报告(UI线程) - ShowReport(result); + // 显示报告(UI线程),根据参数决定是否弹窗 + if (_parameters.ShowDialog) + { + ShowReport(result); + } // 🔥 自动导出HTML报告 try @@ -717,7 +725,8 @@ namespace NavisworksTransport.Commands /// /// 路径ID(用于视角调整),如果为空则使用全局CurrentRoute /// 碰撞结果是否已经被高亮 - public static GenerateCollisionReportCommand CreateComprehensive(string routeId = null, bool hasHighlighted = false) + /// 是否显示报告窗口(批处理模式设为false) + public static GenerateCollisionReportCommand CreateComprehensive(string routeId = null, bool hasHighlighted = false, bool showDialog = true) { // 如果没有传入路径ID,则从全局CurrentRoute获取 if (string.IsNullOrEmpty(routeId)) @@ -741,7 +750,8 @@ namespace NavisworksTransport.Commands Type = CollisionReportParameters.ReportType.Comprehensive, IncludeDetails = true, HasHighlighted = hasHighlighted, - RouteId = routeId + RouteId = routeId, + ShowDialog = showDialog }); } diff --git a/src/Core/BatchQueueManager.cs b/src/Core/BatchQueueManager.cs index 9c67fc2..749190e 100644 --- a/src/Core/BatchQueueManager.cs +++ b/src/Core/BatchQueueManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Threading.Tasks; using Autodesk.Navisworks.Api; using NavisworksTransport.Core.Animation; @@ -115,6 +116,13 @@ namespace NavisworksTransport.Core public async Task ProcessQueueAsync() { Autodesk.Navisworks.Api.Progress progress = null; + + // 统计信息 + DateTime startTime = DateTime.Now; + int totalCount = 0; + int successCount = 0; + int failedCount = 0; + int skippedCount = 0; try { @@ -156,6 +164,7 @@ namespace NavisworksTransport.Core if (progress != null && progress.IsCanceled) { LogManager.Info("[批处理队列] 用户取消操作"); + skippedCount = initialQueueCount - completedCount; break; } @@ -163,6 +172,7 @@ namespace NavisworksTransport.Core if (_shouldStop) { LogManager.Info("[批处理队列] 收到停止执行请求,将在完成当前项后停止"); + skippedCount = initialQueueCount - completedCount; break; } @@ -176,9 +186,10 @@ namespace NavisworksTransport.Core itemId = _queue.Dequeue(); } + totalCount++; + try { - var item = await _database.GetBatchQueueItemAsync(itemId); _currentItem = item; @@ -187,11 +198,17 @@ namespace NavisworksTransport.Core await ExecuteQueueItemAsync(item); ItemCompleted?.Invoke(this, new BatchQueueItemEventArgs { Item = item }); + + // 执行成功 + successCount++; } catch (Exception ex) { LogManager.Error($"队列项执行失败 (Id: {itemId}): {ex.Message}"); + // 执行失败 + failedCount++; + // 更新状态为失败 if (_database != null) { @@ -249,6 +266,81 @@ namespace NavisworksTransport.Core // 重置停止标志 _shouldStop = false; + + // 显示执行汇总信息 + DateTime endTime = DateTime.Now; + TimeSpan duration = endTime - startTime; + ShowBatchSummary(startTime, endTime, duration, totalCount, successCount, failedCount, skippedCount); + } + } + + /// + /// 显示批处理执行汇总信息 + /// + private void ShowBatchSummary(DateTime startTime, DateTime endTime, TimeSpan duration, + int totalCount, int successCount, int failedCount, int skippedCount) + { + try + { + // 计算成功率 + double successRate = totalCount > 0 ? (double)successCount / totalCount * 100 : 0; + + // 格式化执行时长 + string durationText; + if (duration.TotalHours >= 1) + { + durationText = $"{duration.TotalHours:F1}小时"; + } + else if (duration.TotalMinutes >= 1) + { + durationText = $"{duration.TotalMinutes:F1}分钟"; + } + else + { + durationText = $"{duration.TotalSeconds:F1}秒"; + } + + // 构建汇总信息 + var summary = new StringBuilder(); + summary.AppendLine("===== 批处理执行汇总 ====="); + summary.AppendLine(); + summary.AppendLine($"开始时间:{startTime:yyyy-MM-dd HH:mm:ss}"); + summary.AppendLine($"结束时间:{endTime:yyyy-MM-dd HH:mm:ss}"); + summary.AppendLine($"执行时长:{durationText}"); + summary.AppendLine(); + summary.AppendLine($"执行数量:{totalCount} 项"); + summary.AppendLine($"成功数量:{successCount} 项"); + summary.AppendLine($"失败数量:{failedCount} 项"); + if (skippedCount > 0) + { + summary.AppendLine($"跳过数量:{skippedCount} 项"); + } + summary.AppendLine($"成功率:{successRate:F1}%"); + + if (failedCount > 0) + { + summary.AppendLine(); + summary.AppendLine("⚠️ 有任务执行失败,请查看日志了解详情。"); + } + else if (successCount > 0) + { + summary.AppendLine(); + summary.AppendLine("✅ 所有任务执行成功!"); + } + + LogManager.Info($"[批处理队列] 执行汇总 - 总计:{totalCount}, 成功:{successCount}, 失败:{failedCount}, 跳过:{skippedCount}, 耗时:{durationText}"); + + // 在UI线程显示消息框 + System.Windows.Application.Current?.Dispatcher.Invoke(() => + { + System.Windows.MessageBox.Show(summary.ToString(), "批处理执行完成", + System.Windows.MessageBoxButton.OK, + failedCount > 0 ? System.Windows.MessageBoxImage.Warning : System.Windows.MessageBoxImage.Information); + }); + } + catch (Exception ex) + { + LogManager.Error($"[批处理队列] 显示汇总信息失败: {ex.Message}"); } } @@ -454,7 +546,8 @@ namespace NavisworksTransport.Core var reportCommand = Commands.GenerateCollisionReportCommand.CreateComprehensive( routeId: item.RouteId, // 使用任务自己的路径ID - hasHighlighted: false + hasHighlighted: false, + showDialog: false // 批处理模式不弹窗 ); reportCommand.SetTestName(testName); diff --git a/src/Core/Collision/ClashDetectiveIntegration.cs b/src/Core/Collision/ClashDetectiveIntegration.cs index 6431f9b..459113b 100644 --- a/src/Core/Collision/ClashDetectiveIntegration.cs +++ b/src/Core/Collision/ClashDetectiveIntegration.cs @@ -558,6 +558,9 @@ namespace NavisworksTransport { LogManager.Warning("[ClashDetective] 没有有效的碰撞,保存空碰撞记录"); + // 重置碰撞计数器(重要:避免保留上次测试的值) + _clashDetectiveCollisionCount = 0; + // 保存到数据库 SaveClashDetectiveResultToDatabase( routeId,