From 1522564d7ddf949131641f220766a25d8d981751 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期日, 30 八月 2026 16:07:20 +0800
Subject: [PATCH] 收敛测试暂停继续与停止生命周期

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java
index b38b100..02f04cf 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java
@@ -11,6 +11,8 @@
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 import jakarta.annotation.PreDestroy;
 import org.springframework.stereotype.Service;
 import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
@@ -33,6 +35,7 @@
     private final DeviceDiscoveryCandidateStore candidates;
     private final BtsDevelopmentSimulator simulator;
     private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
+    private final ConcurrentMap<String, LiveSource> lastSources = new ConcurrentHashMap<>();
 
     public TTestLiveServiceImpl(ITTestService tests, DeviceDiscoveryCandidateStore candidates,
             BtsDevelopmentSimulator simulator)
@@ -43,10 +46,14 @@
         TTest test = tests.selectTestById(testId);
         List<CabinetCandidate> cabinets = candidates.snapshot(Instant.now()).cabinets();
         List<LiveSource> sources = new ArrayList<>();
+        boolean freezeSnapshots = "PAUSED".equals(test.getReceptionStatus())
+                || "ENDED".equals(test.getReceptionStatus());
         for (TTestBattery battery : test.getBatteries() == null ? List.<TTestBattery>of() : test.getBatteries())
         {
-            if (battery.getBinding() != null) sources.add(cabinetSource(battery, cabinets));
-            if (battery.getCollectorId() != null) sources.add(collectorSource(battery));
+            if (battery.getBinding() != null)
+                sources.add(snapshotFor(testId, cabinetSource(battery, cabinets), freezeSnapshots));
+            if (battery.getCollectorId() != null)
+                sources.add(snapshotFor(testId, collectorSource(battery), freezeSnapshots));
         }
         List<Map<String, Object>> exceptions = sources.stream().filter(source -> !"ONLINE".equals(source.deviceStatus())
                 && !"WORKING".equals(source.deviceStatus()) && !"PAUSED".equals(source.deviceStatus()))
@@ -56,6 +63,14 @@
         return new LiveState(testId, test.getTestStatus(), test.getReceptionStatus(), Instant.now(), sources, exceptions);
     }
 
+    private LiveSource snapshotFor(Long testId, LiveSource fresh, boolean freeze)
+    {
+        String key = testId + ":" + fresh.sourceType() + ":" + fresh.sourceId() + ":" + fresh.batteryNo();
+        if (freeze) return lastSources.getOrDefault(key, fresh);
+        lastSources.put(key, fresh);
+        return fresh;
+    }
+
     @Override public SseEmitter stream(Long testId)
     {
         SseEmitter emitter = new SseEmitter(0L);

--
Gitblit v1.7.1