From 7259e265b9237286996b09da03038ea5a133e1e0 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 05 九月 2026 17:45:07 +0800
Subject: [PATCH] 收敛模拟器为设备事实与实时观测

---
 battery-business/src/main/java/com/battery/business/service/impl/TTestLiveServiceImpl.java |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/battery-business/src/main/java/com/battery/business/service/impl/TTestLiveServiceImpl.java b/battery-business/src/main/java/com/battery/business/service/impl/TTestLiveServiceImpl.java
index 9878255..a089af6 100644
--- a/battery-business/src/main/java/com/battery/business/service/impl/TTestLiveServiceImpl.java
+++ b/battery-business/src/main/java/com/battery/business/service/impl/TTestLiveServiceImpl.java
@@ -52,7 +52,7 @@
             if (battery.getBinding() != null)
                 sources.add(snapshotFor(cabinetSource(battery, cabinets), receiving));
             if (battery.getCollectorId() != null)
-                sources.add(snapshotFor(collectorSource(battery), receiving));
+                sources.add(collectorSource(battery, receiving));
         }
         List<Map<String, Object>> exceptions = new ArrayList<>();
         if (receiving)
@@ -157,11 +157,20 @@
         return value;
     }
 
-    private LiveSource collectorSource(TTestBattery battery)
+    private LiveSource collectorSource(TTestBattery battery, boolean receiving)
     {
         if (adapter == null || mapper == null) return new LiveSource("COLLECTOR", battery.getCollectorId(), battery.getBatteryNo(),
                 "OFFLINE", Map.of());
-        var collector = adapter.latestCollector(mapper.selectCollectorCode(battery.getCollectorId()));
+        String collectorCode = mapper.selectCollectorCode(battery.getCollectorId());
+        // 非接收状态只读设备发现事实,不能先请求测量再隐藏,否则仍会产生新观测。
+        if (!receiving)
+        {
+            boolean online = candidates.findCollector(collectorCode, Instant.now())
+                    .map(DeviceDiscoveryCandidateStore.CollectorCandidate::online).orElse(false);
+            return new LiveSource("COLLECTOR", battery.getCollectorId(), battery.getBatteryNo(),
+                    online ? "ONLINE" : "OFFLINE", Map.of());
+        }
+        var collector = adapter.latestCollector(collectorCode);
         if (collector != null)
         {
             Map<String, Object> value = new LinkedHashMap<>();

--
Gitblit v1.7.1