From 56cddf53e7e71afad29885d7fcf773a222b95f6c Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期日, 30 八月 2026 19:38:18 +0800
Subject: [PATCH] 修复采集器断线区间重复关闭

---
 ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/CollectorDisconnectRecoveryServiceImplTest.java |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/CollectorDisconnectRecoveryServiceImplTest.java b/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/CollectorDisconnectRecoveryServiceImplTest.java
index dd11996..1c2c636 100644
--- a/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/CollectorDisconnectRecoveryServiceImplTest.java
+++ b/ruoyi-admin/src/test/java/com/ruoyi/system/service/impl/CollectorDisconnectRecoveryServiceImplTest.java
@@ -56,6 +56,34 @@
         verify(mapper, never()).insertCollectorExceptionInterval(any());
     }
 
+    @Test
+    void allowsAnotherDisconnectCycleAfterPreviousIntervalWasClosed()
+    {
+        TTestCollectorSource source = source(10L, 20L, 8L, "COL-1", "S-01");
+        TTestCollectorExceptionInterval first = openInterval(99L);
+        TTestCollectorExceptionInterval second = openInterval(100L);
+        when(mapper.selectReceivingCollectorSources()).thenReturn(List.of(source));
+        when(mapper.selectOpenCollectorException(10L, 20L, 8L, "S-01"))
+                .thenReturn(null, first, null, second);
+
+        service.reconcile(Set.of(), Instant.parse("2026-08-30T09:00:00Z"));
+        service.reconcile(Set.of("COL-1"), Instant.parse("2026-08-30T09:01:00Z"));
+        service.reconcile(Set.of(), Instant.parse("2026-08-30T09:02:00Z"));
+        service.reconcile(Set.of("COL-1"), Instant.parse("2026-08-30T09:03:00Z"));
+
+        verify(mapper, org.mockito.Mockito.times(2)).insertCollectorExceptionInterval(any());
+        verify(mapper).closeCollectorExceptionInterval(eq(99L), any(), any());
+        verify(mapper).closeCollectorExceptionInterval(eq(100L), any(), any());
+    }
+
+    private TTestCollectorExceptionInterval openInterval(Long intervalId)
+    {
+        TTestCollectorExceptionInterval interval = new TTestCollectorExceptionInterval();
+        interval.setIntervalId(intervalId);
+        interval.setIntervalStatus("OPEN");
+        return interval;
+    }
+
     private TTestCollectorSource source(Long testId, Long relationId, Long collectorId,
             String collectorCode, String channelCode)
     {

--
Gitblit v1.7.1