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,