From 8e13d5a26f6cb6f981b31799e43330f40c791192 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期四, 03 九月 2026 23:39:01 +0800
Subject: [PATCH] 停止后隐藏实时预警并补充完成态测试

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java    |    3 ++-
 ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestLiveServiceImplTest.java |   38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestLiveServiceImplTest.java b/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestLiveServiceImplTest.java
index 5dfef99..17874e3 100644
--- a/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestLiveServiceImplTest.java
+++ b/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestLiveServiceImplTest.java
@@ -6,6 +6,8 @@
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.io.IOException;
@@ -25,6 +27,8 @@
 import com.ruoyi.system.domain.TTest;
 import com.ruoyi.system.domain.TTestBattery;
 import com.ruoyi.system.domain.TTestChannelBinding;
+import com.ruoyi.system.domain.TTestWarningException;
+import com.ruoyi.system.mapper.TTestMapper;
 import com.ruoyi.system.service.ITTestService;
 import com.ruoyi.system.service.ITestLiveService.LiveState;
 
@@ -85,6 +89,28 @@
         assertTrue(state.exceptions().isEmpty());
     }
 
+    @Test
+    void completedTestShouldNotExposeOpenWarningInLiveAlarm()
+    {
+        Instant now = Instant.parse("2026-09-02T06:00:00Z");
+        TTestMapper mapper = mock(TTestMapper.class);
+        TTestWarningException warning = new TTestWarningException();
+        warning.setExceptionId(1L);
+        warning.setSourceType("COLLECTOR");
+        warning.setMetricCode("TEMPERATURE");
+        warning.setAbnormalValue(new BigDecimal("25.3"));
+        warning.setUnit("℃");
+        warning.setExceptionStatus("OPEN");
+        when(mapper.selectWarningExceptions(10L, "OPEN")).thenReturn(List.of(warning));
+
+        TTestLiveServiceImpl service = liveService(test("ENDED"), now, true, DeviceWorkStatus.STOPPED, mapper);
+
+        LiveState state = service.current(10L);
+
+        assertTrue(state.exceptions().isEmpty());
+        verify(mapper, never()).selectWarningExceptions(10L, "OPEN");
+    }
+
     private static TTest test(String receptionStatus)
     {
         TTest test = new TTest();
@@ -118,6 +144,12 @@
     private static TTestLiveServiceImpl liveService(TTest test, Instant now, boolean online,
             DeviceWorkStatus workStatus)
     {
+        return liveService(test, now, online, workStatus, null);
+    }
+
+    private static TTestLiveServiceImpl liveService(TTest test, Instant now, boolean online,
+            DeviceWorkStatus workStatus, TTestMapper mapper)
+    {
         DeviceDiscoveryCandidateStore candidates = mock(DeviceDiscoveryCandidateStore.class);
         BtsDevelopmentSimulator simulator = mock(BtsDevelopmentSimulator.class);
         ITTestService tests = mock(ITTestService.class);
@@ -137,7 +169,7 @@
         var plan = new BtsDevelopmentSimulator.BtsTestSnapshot(1, 1, 1, List.of());
         when(simulator.btsTest(anyInt(), anyInt())).thenReturn(plan);
         when(simulator.btsTest(anyInt(), anyInt(), anyInt())).thenReturn(plan);
-        return new CurrentLiveService(tests, candidates, simulator);
+        return new CurrentLiveService(tests, candidates, simulator, mapper);
     }
 
     @Test
@@ -205,9 +237,9 @@
     private static final class CurrentLiveService extends TTestLiveServiceImpl
     {
         private CurrentLiveService(ITTestService tests, DeviceDiscoveryCandidateStore candidates,
-                BtsDevelopmentSimulator simulator)
+                BtsDevelopmentSimulator simulator, TTestMapper mapper)
         {
-            super(tests, candidates, simulator);
+            super(tests, candidates, simulator, mapper);
         }
     }
 
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 50401a0..6345a50 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
@@ -68,7 +68,8 @@
                     .map(source -> Map.<String, Object>of("sourceType", source.sourceType(), "sourceId", source.sourceId(),
                             "batteryNo", source.batteryNo(), "status", source.deviceStatus(), "message", "数据来源当前不可观测"))
                     .toList());
-        if (mapper != null) {
+        // 完成或暂停后只保留历史异常事实,实时控制台不再展示开放预警。
+        if (receiving && mapper != null) {
             mapper.selectWarningExceptions(testId, "OPEN").forEach(item -> exceptions.add(Map.of(
                     "exceptionId", item.getExceptionId(), "sourceType", item.getSourceType(),
                     "metricCode", item.getMetricCode(), "value", item.getAbnormalValue(), "unit", item.getUnit(),

--
Gitblit v1.7.1