From 6b13e3126beb5d27ccdac7dec0d81caf3cb6538b Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Thu, 6 Aug 2026 18:33:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20F1=20=E6=89=B9=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=9B=9E=E5=86=99=E4=B8=BB=E5=BA=93=E6=A3=80=E6=B5=8B=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=EF=BC=88=E5=8E=86=E5=8F=B2=E8=A1=A8=E6=A0=BC=E7=A2=B0?= =?UTF-8?q?=E6=92=9E=E6=95=B0=200=20=E9=97=AE=E9=A2=98=EF=BC=89+=20?= =?UTF-8?q?=E9=80=9A=E9=81=93=E6=8E=92=E9=99=A4=E8=AF=8A=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题1(历史表格碰撞数 0): - F1 副实例检测结果只更新队列表,主库 CollisionDetectionRecords 未更新(批处理创建快照时 CollisionCount=0)→ 动画检测历史表格显示 0 - 修复:F1 完成后 UpdateCollisionDetectionResult 回写主库记录 (testName=F1副实例检测_{route}_{itemId}) - 配套:测试端点 batch-queue-add 创建检测记录(与 UI 一致); UpdateBatchQueueItemAsync 的 UPDATE 补 DetectionRecordId 列 问题2(通道被碰撞): - 副实例通道缓存正常(3 个可通行 = 用户设置),非通道对象 689 个 - 增加通道诊断日志:副实例检测完成后打印通道对象/碰撞对象/ 碰撞中含通道对比(验证楼板等通道是否被正确排除) - 测试模型验证:碰撞中含通道 0 个(排除正常) 验证:F1 测试 30 秒通过,回写日志确认(Id=534 碰撞 12) --- src/Core/BatchQueueManager.cs | 23 ++++++++ src/Core/PathDatabase.cs | 4 +- .../Services/TestAutomationHttpService.cs | 56 +++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/Core/BatchQueueManager.cs b/src/Core/BatchQueueManager.cs index 002ec97..5d84af1 100644 --- a/src/Core/BatchQueueManager.cs +++ b/src/Core/BatchQueueManager.cs @@ -629,6 +629,29 @@ namespace NavisworksTransport.Core } LogManager.Info($"[F2映射] 完成: {mappedCount}/{detection.CollidedObjectMappings.Count} 个碰撞对象映射到主模型"); + // 🔥 回写主库检测记录:副实例检测结果更新到主 NW 的 CollisionDetectionRecords + // (批处理创建快照时 CollisionCount=0,动画检测历史表格读主库——不回写则显示 0) + if (item.DetectionRecordId.HasValue) + { + try + { + _database.UpdateCollisionDetectionResult( + item.DetectionRecordId.Value, + testName: $"F1副实例检测_{pathRoute.Name}_{item.Id}", + collisionCount: detection.TotalCollisions, + animationCollisionCount: detection.TotalCollisions); + LogManager.Info($"[批处理] 已回写主库检测记录: DetectionRecordId={item.DetectionRecordId}, 碰撞数={detection.TotalCollisions}"); + } + catch (Exception recordEx) + { + LogManager.Warning($"[批处理] 回写检测记录失败: {recordEx.Message}"); + } + } + else + { + LogManager.Warning($"[批处理] F1 任务缺少 DetectionRecordId,无法回写检测记录 (itemId={item.Id})"); + } + // F3:清理副实例临时工作目录(导出模型/临时库/路径文件);副实例刚关闭,文件锁可能未释放,带重试 string workDirectory = Path.Combine(Path.GetTempPath(), "NavisworksTransportBatch", $"item-{item.Id}"); for (int cleanupAttempt = 0; cleanupAttempt < 3; cleanupAttempt++) diff --git a/src/Core/PathDatabase.cs b/src/Core/PathDatabase.cs index 9a66452..6a31c1a 100644 --- a/src/Core/PathDatabase.cs +++ b/src/Core/PathDatabase.cs @@ -3166,7 +3166,8 @@ namespace NavisworksTransport cmd.CommandText = @" UPDATE BatchQueueItems SET Status = @Status, StartTime = @StartTime, EndTime = @EndTime, ErrorMessage = @ErrorMessage, - ClashDetectiveTestName = @ClashDetectiveTestName, CollisionCount = @CollisionCount + ClashDetectiveTestName = @ClashDetectiveTestName, CollisionCount = @CollisionCount, + DetectionRecordId = @DetectionRecordId WHERE Id = @Id"; cmd.Parameters.AddWithValue("@Status", item.Status.ToString()); @@ -3175,6 +3176,7 @@ namespace NavisworksTransport cmd.Parameters.AddWithValue("@ErrorMessage", item.ErrorMessage ?? ""); cmd.Parameters.AddWithValue("@ClashDetectiveTestName", item.ClashDetectiveTestName ?? ""); cmd.Parameters.AddWithValue("@CollisionCount", item.CollisionCount ?? (object)DBNull.Value); + cmd.Parameters.AddWithValue("@DetectionRecordId", item.DetectionRecordId ?? (object)DBNull.Value); cmd.Parameters.AddWithValue("@Id", item.Id); cmd.ExecuteNonQuery(); diff --git a/src/Core/Services/TestAutomationHttpService.cs b/src/Core/Services/TestAutomationHttpService.cs index 147a328..72a8f9b 100644 --- a/src/Core/Services/TestAutomationHttpService.cs +++ b/src/Core/Services/TestAutomationHttpService.cs @@ -1177,6 +1177,40 @@ namespace NavisworksTransport.Core.Services int itemId = await manager.AddQueueItemAsync(item).ConfigureAwait(false); + // 创建检测记录(与 UI“加入批处理”一致):F1 副实例检测结果回写主库检测记录 + // (动画检测历史表格读主库 CollisionDetectionRecords) + int? detectionRecordId = null; + try + { + var pathDatabase = pathManager?.GetPathDatabase(); + if (pathDatabase != null) + { + var record = new NavisworksTransport.CollisionDetectionRecord + { + RouteId = route.Id, + CreatedTime = DateTime.Now, + FrameRate = frameRate, + DurationSeconds = durationSeconds, + IsVirtualObject = isVirtualObject, + AnimatedObjectName = isVirtualObject ? "虚拟物体" : movingObjectName, + DetectAllObjects = true, + Description = $"测试批处理添加于 {DateTime.Now:yyyy-MM-dd HH:mm:ss}", + TestName = $"批处理任务创建_{DateTime.Now:MMdd_HHmmssfff}", + TestTime = DateTime.Now, + CollisionCount = 0, + AnimationCollisionCount = 0 + }; + detectionRecordId = pathDatabase.SaveCollisionDetectionRecord(record); + item.DetectionRecordId = detectionRecordId; + await manager.GetDatabase().UpdateBatchQueueItemAsync(item).ConfigureAwait(false); + LogManager.Info($"[测试HTTP] 批处理项已创建检测记录 (Id={detectionRecordId}, itemId={itemId})"); + } + } + catch (Exception recordEx) + { + LogManager.Warning($"[测试HTTP] 创建批处理检测记录失败: {recordEx.Message}"); + } + // 真实物体:主实例解析名字并写入 MovingObject 引用(BatchQueueItems 表无 MovingObjectName 列, // F1 副实例检测从 ModelItemReferences 读取移动物体名) if (!isVirtualObject) @@ -1578,6 +1612,28 @@ namespace NavisworksTransport.Core.Services PathAnimationManager animationManager = PathAnimationManager.GetInstance(); CollisionReportResult report = animationVm.LastGeneratedReport; + // 🔥 通道排除诊断:打印通道对象 vs 碰撞对象对比(验证楼板等通道是否被正确排除) + try + { + var channelCache = ClashDetectiveIntegration.GetChannelObjectsCache(); + var collidedNames = report?.AllCollisions?.Select(c => c.Item2?.DisplayName) + .Where(n => !string.IsNullOrWhiteSpace(n)) + .Distinct() + .ToList() ?? new List(); + var channelNames = channelCache?.Select(c => c.DisplayName) + .Where(n => !string.IsNullOrWhiteSpace(n)) + .Distinct() + .ToList() ?? new List(); + var channelHit = collidedNames.Intersect(channelNames, StringComparer.OrdinalIgnoreCase).ToList(); + LogManager.Info($"[通道诊断] 通道对象({channelNames.Count})={string.Join(", ", channelNames)}"); + LogManager.Info($"[通道诊断] 碰撞对象({collidedNames.Count})={string.Join(", ", collidedNames)}"); + LogManager.Info($"[通道诊断] 碰撞中含通道: {channelHit.Count} 个 = {string.Join(", ", channelHit)}"); + } + catch (Exception diagEx) + { + LogManager.Warning($"[通道诊断] 输出失败: {diagEx.Message}"); + } + return new { route = setupResult.route,