From bd921b8e2db78be2178803c018f1a6f63a02525f Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 05 九月 2026 19:39:53 +0800
Subject: [PATCH] 按当前设备状态展示控制台离线提醒

---
 ruoyi-admin/src/test/java/com/battery/business/service/impl/TTestLiveServiceImplTest.java |   38 ++++++++++++++++++++++++++++++++++++--
 1 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/ruoyi-admin/src/test/java/com/battery/business/service/impl/TTestLiveServiceImplTest.java b/ruoyi-admin/src/test/java/com/battery/business/service/impl/TTestLiveServiceImplTest.java
index 1944295..efbae8e 100644
--- a/ruoyi-admin/src/test/java/com/battery/business/service/impl/TTestLiveServiceImplTest.java
+++ b/ruoyi-admin/src/test/java/com/battery/business/service/impl/TTestLiveServiceImplTest.java
@@ -38,7 +38,7 @@
 class TTestLiveServiceImplTest
 {
     @Test
-    void persistedOfflineWarningWithoutMeasurementReplacesLiveHintAndSurvivesRefresh()
+    void offlineHintIsIndependentOfHistoricalHandlingStatusAndSurvivesRefresh()
     {
         TTest test = test("RECEIVING");
         var mapper = mock(TTestMapper.class);
@@ -55,13 +55,42 @@
         for (int attempt = 0; attempt < 2; attempt++) {
             var alarms = service.current(10L).exceptions();
             assertEquals(1, alarms.size());
-            assertEquals(21L, alarms.get(0).get("exceptionId"));
+            assertFalse(alarms.get(0).containsKey("exceptionId"));
             assertEquals("DEVICE_OFFLINE", alarms.get(0).get("exceptionType"));
+            assertFalse(alarms.get(0).get("message").toString().contains("处理"));
         }
+        warning.setExceptionStatus("CLOSED");
+        when(mapper.selectWarningExceptions(10L, "OPEN")).thenReturn(List.of());
+        assertEquals(1, service.current(10L).exceptions().size());
         test.setReceptionStatus("PAUSED");
         assertTrue(service.current(10L).exceptions().isEmpty());
         test.setReceptionStatus("ENDED");
         assertTrue(service.current(10L).exceptions().isEmpty());
+    }
+
+    @Test
+    void recoveredSourcesHideOfflineHintsEvenWhenHistoryRemainsOpen()
+    {
+        TTest test = test("RECEIVING");
+        test.getBatteries().get(0).setCollectorId(7L);
+        var mapper = mock(TTestMapper.class);
+        var warnings = List.of("CABINET_CHANNEL", "COLLECTOR").stream().map(sourceType -> {
+            var warning = new TTestWarningException();
+            warning.setExceptionType("DEVICE_OFFLINE");
+            warning.setSourceType(sourceType);
+            warning.setSourceIdentity("COLLECTOR".equals(sourceType) ? "7" : "dev-sim:1:1:0:1");
+            warning.setExceptionStatus("OPEN");
+            return warning;
+        }).toList();
+        when(mapper.selectWarningExceptions(10L, "OPEN")).thenReturn(warnings);
+
+        for (boolean online : List.of(false, true, true, false)) {
+            var service = liveService(test, Instant.now(), online, DeviceWorkStatus.WORKING, mapper);
+            var state = service.current(10L);
+            assertTrue(state.sources().stream().allMatch(source -> (online ? "ONLINE" : "OFFLINE").equals(source.deviceStatus())));
+            assertEquals(online ? 0 : 2, state.exceptions().size());
+            assertTrue(warnings.stream().allMatch(warning -> "OPEN".equals(warning.getExceptionStatus())));
+        }
     }
 
     @Test
@@ -245,6 +274,11 @@
                 new DeviceDiscoveryCandidateStore.CandidateSnapshot(List.of(cabinet), List.of()));
         var plan = new TestDataObservationAdapter.TestPlan(1, 1, 1, List.of());
         when(simulator.testPlan(any(ChannelIdentity.class))).thenReturn(plan);
+        if (mapper != null && test.getBatteries().get(0).getCollectorId() != null) {
+            when(mapper.selectCollectorCode(7L)).thenReturn("collector-7");
+            when(simulator.latestCollector("collector-7")).thenReturn(
+                    new TestDataObservationAdapter.CollectorRealtime("collector-7", online, 1000, List.of(), null));
+        }
 
         return new CurrentLiveService(tests, candidates, simulator, mapper);
     }

--
Gitblit v1.7.1