From 1de35281a699b8d2ca90777f63c7e032c3c9dc3d Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期一, 12 十月 2026 13:34:34 +0800
Subject: [PATCH] 对接第 6 台新威上位机(7.6 客户端,走库路线),并修两处对接中暴露的问题

---
 ruoyi-admin/src/test/java/com/battery/business/service/impl/TDetectionCabinetServiceImplTest.java |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/ruoyi-admin/src/test/java/com/battery/business/service/impl/TDetectionCabinetServiceImplTest.java b/ruoyi-admin/src/test/java/com/battery/business/service/impl/TDetectionCabinetServiceImplTest.java
index 26d0218..77ff911 100644
--- a/ruoyi-admin/src/test/java/com/battery/business/service/impl/TDetectionCabinetServiceImplTest.java
+++ b/ruoyi-admin/src/test/java/com/battery/business/service/impl/TDetectionCabinetServiceImplTest.java
@@ -94,7 +94,7 @@
         assertEquals(new BigDecimal("120.50"), savedCabinet.getCapacity());
         assertEquals("OFFLINE", savedCabinet.getOnlineStatus());
         assertEquals("0", savedCabinet.getStatus());
-        assertNull(savedCabinet.getCurrentTest());
+        assertTrue(savedCabinet.getRelatedTests().isEmpty());
     }
 
     /**
@@ -134,10 +134,10 @@
     }
 
     /**
-     * 验证检测柜主列表从通道事实派生旧页面展示字段,不读取数据库不存在的列。
+     * 验证检测柜主列表保留操作校验所需派生状态,不读取数据库不存在的列。
      */
     @Test
-    void detectionCabinetListSqlShouldDeriveLegacyPresentationFields() throws IOException
+    void detectionCabinetListSqlShouldDeriveOperationStateWithoutCurrentTest() throws IOException
     {
         try (InputStream input = getClass().getResourceAsStream(
                 "/mapper/battery/TDetectionCabinetMapper.xml"))
@@ -150,7 +150,7 @@
             assertFalse(selectSql.contains("online_status, test_status"));
             assertFalse(selectSql.contains("current_test, status"));
             assertTrue(selectSql.contains("as test_status"));
-            assertTrue(selectSql.contains("as current_test"));
+            assertFalse(selectSql.contains("current_test"));
             String activeTestSql = sqlFragment(mapperXml, "activeCabinetTestExists");
             assertTrue(activeTestSql.contains("t_test_channel_binding"));
             assertTrue(activeTestSql.contains("t_detection_channel"));
@@ -193,6 +193,26 @@
         return mapperXml.substring(start, end);
     }
 
+    /**
+     * 通道显示号:来源自己报了叫法就用它(操作员拿它跟厂商软件对上),没报就回退到身份里的「单元-通道」。
+     * 显示号只是展示,不参与通道身份。
+     */
+    @Test
+    void channelDisplayNoPrefersTheSourceOwnLabelAndFallsBackToTheIdentity()
+    {
+        ChannelCandidate declared = new ChannelCandidate(new ChannelIdentity("j22", 0, 0, 1, 26), true,
+                DeviceWorkStatus.UNKNOWN, java.time.Instant.now(), null, null, "27");
+        assertEquals("27", TDetectionCabinetServiceImpl.channelDisplayNo(declared));
+
+        ChannelCandidate blank = new ChannelCandidate(new ChannelIdentity("j22", 0, 0, 1, 26), true,
+                DeviceWorkStatus.UNKNOWN, java.time.Instant.now(), null, null, "   ");
+        assertEquals("1-26", TDetectionCabinetServiceImpl.channelDisplayNo(blank));
+
+        ChannelCandidate absent = new ChannelCandidate(new ChannelIdentity("neware76", 21, 3, 1, 4), true,
+                DeviceWorkStatus.UNKNOWN, java.time.Instant.now());
+        assertEquals("1-4", TDetectionCabinetServiceImpl.channelDisplayNo(absent));
+    }
+
     private CabinetCandidate candidate(String deviceCode, boolean online, DeviceWorkStatus workStatus)
     {
         java.time.Instant observedAt = java.time.Instant.now();
@@ -206,7 +226,7 @@
     }
 
     /**
-     * 验证设备选择列表读取 Redis 候选,并保持原前端字段和状态文本。
+     * 验证设备选择列表读取候选的设备事实,不推断系统测试关系。
      */
     @Test
     void selectDiscoveredCabinetListShouldMapPersistedCabinetFacts()
@@ -220,12 +240,30 @@
         assertEquals("192.168.1.10", devices.get(0).getIp());
         assertEquals("AA:BB:CC:DD:EE:FF", devices.get(0).getMac());
         assertEquals("在线", devices.get(0).getOnlineStatus());
-        assertEquals("测试中", devices.get(0).getTestStatus());
-        assertEquals("待确认", devices.get(0).getCurrentTest());
+        var fields = new com.fasterxml.jackson.databind.ObjectMapper().valueToTree(devices.get(0));
+        assertFalse(fields.has("testStatus"));
+        assertFalse(fields.has("currentTest"));
         assertEquals("一号模拟柜", devices.get(0).getName());
         assertEquals("开发模拟器", devices.get(0).getManufacturer());
         assertEquals("BTS Virtual Cabinet", devices.get(0).getModel());
         assertEquals(8, devices.get(0).getChannelCount());
+    }
+
+    @Test
+    void offlineCabinetRemainsDiscoverableAndCanBeRegistered()
+    {
+        var store = new InMemoryDeviceDiscoveryCandidateStore();
+        store.recordCabinets(List.of(candidate("CABINET-001", false, DeviceWorkStatus.UNOBSERVABLE)));
+        var service = new TDetectionCabinetServiceImpl(detectionCabinetMapper, store);
+        when(detectionCabinetMapper.selectRegisteredCabinetCodes()).thenReturn(List.of());
+        var devices = service.selectDiscoveredCabinetList();
+        assertEquals(1, devices.size());
+        assertEquals("离线", devices.get(0).getOnlineStatus());
+        when(detectionCabinetMapper.insertDetectionCabinet(any(TDetectionCabinet.class))).thenReturn(1);
+        assertEquals(1, service.insertDetectionCabinet(detectionCabinet));
+        assertEquals("OFFLINE", detectionCabinet.getOnlineStatus());
+        when(detectionCabinetMapper.selectRegisteredCabinetCodes()).thenReturn(List.of("CABINET-001"));
+        assertEquals(0, service.selectDiscoveredCabinetList().size());
     }
 
     /**
@@ -255,7 +293,7 @@
         ServiceException exception = assertThrows(ServiceException.class,
                 () -> detectionCabinetService.insertDetectionCabinet(detectionCabinet));
 
-        assertEquals("请先选择在线的发现候选设备", exception.getMessage());
+        assertEquals("请先选择有效的发现候选设备", exception.getMessage());
         verify(detectionCabinetMapper, never()).insertDetectionCabinet(any());
     }
 

--
Gitblit v1.7.1