批处理不显示报告窗口,批处理执行结束显示汇总信息,修复碰撞为0时使用上个测试的碰撞数

This commit is contained in:
tian 2026-01-29 15:58:30 +08:00
parent c3cbaaf6e0
commit 6498df1818
3 changed files with 112 additions and 6 deletions

View File

@ -49,6 +49,11 @@ namespace NavisworksTransport.Commands
/// </summary>
public bool HasHighlighted { get; set; } = false;
/// <summary>
/// 是否显示报告窗口批处理模式设为false只生成报告不弹窗
/// </summary>
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
/// </summary>
/// <param name="routeId">路径ID用于视角调整如果为空则使用全局CurrentRoute</param>
/// <param name="hasHighlighted">碰撞结果是否已经被高亮</param>
public static GenerateCollisionReportCommand CreateComprehensive(string routeId = null, bool hasHighlighted = false)
/// <param name="showDialog">是否显示报告窗口批处理模式设为false</param>
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
});
}

View File

@ -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);
}
}
/// <summary>
/// 显示批处理执行汇总信息
/// </summary>
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);

View File

@ -558,6 +558,9 @@ namespace NavisworksTransport
{
LogManager.Warning("[ClashDetective] 没有有效的碰撞,保存空碰撞记录");
// 重置碰撞计数器(重要:避免保留上次测试的值)
_clashDetectiveCollisionCount = 0;
// 保存到数据库
SaveClashDetectiveResultToDatabase(
routeId,