yeg
2026-09-03 6b9019956913fc47499ba185beedf4370bb5354c
修正实时设备连接状态与异常展示
2个文件已修改
33 ■■■■■ 已修改文件
ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestLiveServiceImplTest.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/TTestLiveServiceImplTest.java
@@ -60,6 +60,20 @@
    }
    @Test
    void onlineCabinetWithStoppedWorkStatusShouldRemainOnlineAndNotRaiseSourceAlarm()
    {
        Instant now = Instant.parse("2026-09-02T06:00:00Z");
        TTestLiveServiceImpl service = liveService(test("RECEIVING"), now, true, DeviceWorkStatus.STOPPED);
        LiveState state = service.current(10L);
        var cabinet = state.sources().stream().filter(source -> "CABINET_CHANNEL".equals(source.sourceType()))
                .findFirst().orElseThrow();
        assertEquals("ONLINE", cabinet.deviceStatus());
        assertTrue(state.exceptions().isEmpty());
    }
    @Test
    void pausedShouldNotExposeUnavailableSourceAsAlarm()
    {
        Instant now = Instant.parse("2026-09-02T06:00:00Z");
@@ -98,17 +112,23 @@
    private static TTestLiveServiceImpl liveService(TTest test, Instant now, boolean online)
    {
        return liveService(test, now, online, DeviceWorkStatus.WORKING);
    }
    private static TTestLiveServiceImpl liveService(TTest test, Instant now, boolean online,
            DeviceWorkStatus workStatus)
    {
        DeviceDiscoveryCandidateStore candidates = mock(DeviceDiscoveryCandidateStore.class);
        BtsDevelopmentSimulator simulator = mock(BtsDevelopmentSimulator.class);
        ITTestService tests = mock(ITTestService.class);
        when(tests.selectTestById(10L)).thenReturn(test);
        ChannelIdentity identity = new ChannelIdentity("dev-sim", 1, 1, 0, 1);
        RealtimeSnapshot snapshot = new RealtimeSnapshot(identity, DeviceWorkStatus.WORKING, 1, 1, "cc", null,
        RealtimeSnapshot snapshot = new RealtimeSnapshot(identity, workStatus, 1, 1, "cc", null,
                new BigDecimal("1.200"), new BigDecimal("3.700"), new BigDecimal("2.500"),
                new BigDecimal("9.250"), 12L, 12L, "0", now,
                java.util.Map.of());
        DeviceDiscoveryCandidateStore.ChannelCandidate channel = new DeviceDiscoveryCandidateStore.ChannelCandidate(
                identity, online, DeviceWorkStatus.WORKING, now, snapshot);
                identity, online, workStatus, now, snapshot);
        DeviceDiscoveryCandidateStore.CabinetCandidate cabinet = new DeviceDiscoveryCandidateStore.CabinetCandidate(
                "dev-sim", 1L, "dev-sim", 1, 1, "127.0.0.2", "mac", "cabinet", "vendor", "model",
                List.of(channel), now, now.plusSeconds(60));
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTestLiveServiceImpl.java
@@ -64,8 +64,7 @@
        List<Map<String, Object>> exceptions = new ArrayList<>();
        if (receiving)
            exceptions.addAll(sources.stream().filter(source -> !"COLLECTOR".equals(source.sourceType())
                    && !"ONLINE".equals(source.deviceStatus())
                    && !"WORKING".equals(source.deviceStatus()) && !"PAUSED".equals(source.deviceStatus()))
                    && "OFFLINE".equals(source.deviceStatus()))
                    .map(source -> Map.<String, Object>of("sourceType", source.sourceType(), "sourceId", source.sourceId(),
                            "batteryNo", source.batteryNo(), "status", source.deviceStatus(), "message", "数据来源当前不可观测"))
                    .toList());
@@ -169,9 +168,9 @@
                    && Objects.equals(channel.identity().subdevid(), binding.getSubdevid())
                    && Objects.equals(channel.identity().chlid(), binding.getChlid()))
                return new LiveSource("CABINET_CHANNEL", binding.getChannelId(), battery.getBatteryNo(),
                        channel.online() ? channel.workStatus().name() : "OFFLINE",
                        channel.online() ? "ONLINE" : "OFFLINE",
                        channel.online() ? snapshot(channel) : Map.of());
        return new LiveSource("CABINET_CHANNEL", binding.getChannelId(), battery.getBatteryNo(), "UNKNOWN", Map.of());
        return new LiveSource("CABINET_CHANNEL", binding.getChannelId(), battery.getBatteryNo(), "OFFLINE", Map.of());
    }
    private Map<String, Object> snapshot(ChannelCandidate channel)
@@ -217,7 +216,7 @@
            return new LiveSource("COLLECTOR", (long) collector.collectorId(), battery.getBatteryNo(),
                    collector.online() ? "ONLINE" : "OFFLINE", collector.online() ? value : Map.of());
        }
        return new LiveSource("COLLECTOR", battery.getCollectorId(), battery.getBatteryNo(), "UNKNOWN", Map.of());
        return new LiveSource("COLLECTOR", battery.getCollectorId(), battery.getBatteryNo(), "OFFLINE", Map.of());
    }
    @PreDestroy void shutdown() { scheduler.shutdownNow(); }