yeg
2026-08-26 de98fe81cca90dd855e0519f065e77fce56333ef
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;