From de98fe81cca90dd855e0519f065e77fce56333ef Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期三, 26 八月 2026 16:28:30 +0800
Subject: [PATCH] fix(device): address adapter discovery review
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DeviceDiscoveryPersistenceService.java | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DeviceDiscoveryPersistenceService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DeviceDiscoveryPersistenceService.java
index 2989aaa..55f051b 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DeviceDiscoveryPersistenceService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DeviceDiscoveryPersistenceService.java
@@ -9,6 +9,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.device.model.DetectedChannel;
+import com.ruoyi.device.model.ChannelIdentity;
+import com.ruoyi.device.model.RealtimeSnapshot;
import com.ruoyi.system.domain.TDetectionCabinet;
import com.ruoyi.system.domain.TDetectionChannel;
import com.ruoyi.system.domain.TDeviceAdapter;
@@ -27,7 +29,8 @@
/** 在一个事务内 upsert 本轮观测事实;未返回通道保持原记录不变。 */
@Transactional(rollbackFor = Exception.class)
- public AdapterDiscoveryResult persist(TDeviceAdapter adapter, List<DetectedChannel> detected, Instant observedAt)
+ public AdapterDiscoveryResult persist(TDeviceAdapter adapter, List<DetectedChannel> detected,
+ Map<ChannelIdentity, RealtimeSnapshot> snapshots, Instant observedAt)
{
Map<CabinetKey, List<DetectedChannel>> cabinets = detected.stream().collect(
java.util.stream.Collectors.groupingBy(
@@ -38,7 +41,8 @@
{
Long cabinetId = ensureCabinet(adapter, entry.getKey(), entry.getValue(), observedAt);
for (DetectedChannel item : entry.getValue())
- mapper.upsertDetectedChannel(toChannel(adapter.getAdapterId(), cabinetId, item, observedAt));
+ mapper.upsertDetectedChannel(toChannel(adapter.getAdapterId(), cabinetId, item,
+ snapshots.get(item.identity()), observedAt));
}
return new AdapterDiscoveryResult(cabinets.size(), detected.size(), observedAt);
}
@@ -78,7 +82,8 @@
return cabinetId;
}
- private TDetectionChannel toChannel(Long adapterId, Long cabinetId, DetectedChannel detected, Instant observedAt)
+ private TDetectionChannel toChannel(Long adapterId, Long cabinetId, DetectedChannel detected,
+ RealtimeSnapshot snapshot, Instant observedAt)
{
TDetectionChannel channel = new TDetectionChannel();
channel.setAdapterId(adapterId);
@@ -89,7 +94,8 @@
channel.setChlid(detected.identity().chlid());
channel.setDisplayNo(detected.identity().subdevid() + "-" + detected.identity().chlid());
channel.setOnlineStatus(detected.available() ? "ONLINE" : "OFFLINE");
- channel.setWorkStatus("UNKNOWN");
+ channel.setWorkStatus(snapshot == null || snapshot.workStatus() == null
+ ? "UNKNOWN" : snapshot.workStatus().name());
channel.setLastSeenAtUtc(observedAt);
channel.setStatus("0");
return channel;
--
Gitblit v1.7.1