From bc9a169ce3648467136a279d167f72c4fbab9595 Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期六, 05 九月 2026 00:53:48 +0800
Subject: [PATCH] 完成设备发现登记与状态事实

---
 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCollectorServiceImpl.java |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCollectorServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCollectorServiceImpl.java
index 24f941b..c6cf102 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCollectorServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TCollectorServiceImpl.java
@@ -105,6 +105,7 @@
         collector.setChannelCount(candidate.channelCount());
         validateCollector(collector, false);
         collector.setOnlineStatus(OFFLINE);
+        // 测试占用由 t_test_collector_channel + t_test 派生,采集器登记表不写入这些字段。
         collector.setTestStatus(IDLE);
         collector.setCurrentTest(null);
         collector.setCurrentSampleName(null);
@@ -118,7 +119,11 @@
         }
         collector.setDelFlag("0");
         collector.setCreateTime(new Date());
-        return collectorMapper.insertCollector(collector);
+        int rows = collectorMapper.insertCollector(collector);
+        // 登记瞬间同步候选事实,避免正式记录暂时显示为离线且没有最近观测时间。
+        collectorMapper.updateRegisteredObservation(collector.getCollectorCode(),
+                candidate.online() ? "ONLINE" : "OFFLINE");
+        return rows;
     }
 
     /**
@@ -127,6 +132,11 @@
     @Override
     public int updateCollector(TCollector collector)
     {
+        TCollector current = collector == null || collector.getCollectorId() == null ? null
+                : collectorMapper.selectCollectorById(collector.getCollectorId());
+        if (current == null) throw new ServiceException("采集器不存在");
+        if (collector.getCollectorCode() != null && !collector.getCollectorCode().trim().equals(current.getCollectorCode()))
+            throw new ServiceException("设备编码不可修改");
         validateCollector(collector, true);
         validateStatus(collector.getStatus(), "状态");
         if (DISABLED.equals(collector.getStatus()))
@@ -354,6 +364,8 @@
     {
         CollectorCandidate candidate = candidates.get(collector.getCollectorCode());
         collector.setOnlineStatus(candidate != null && candidate.online() ? ONLINE : OFFLINE);
+        // 候选过期只改变当前在线展示,不能抹掉 MySQL 保存的最近观测时间。
+        if (candidate != null) collector.setLastSeenAtUtc(candidate.observedAt());
         return collector;
     }
 }

--
Gitblit v1.7.1