yeg
2026-09-05 bc9a169ce3648467136a279d167f72c4fbab9595
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/DeviceDiscoveryPersistenceService.java
@@ -65,6 +65,13 @@
        return testMapper == null || testMapper.hasReceivingTestForAdapter(adapterCode) > 0;
    }
    /** 发现失败或返回空拓扑时,清除该适配器下已登记设备的过期运行事实。 */
    public void markUnavailable(String adapterCode)
    {
        detectionCabinetMapper.markRegisteredFactsUnobservable(adapterCode);
        detectionCabinetMapper.markRegisteredCabinetsOffline(adapterCode);
    }
    private AdapterDiscoveryResult discoverNow(DeviceAdapterRegistry registry, DiscoverySource source)
    {
        DiscoveryObservation observation = registry.execute(source.adapterCode(), runtime -> {
@@ -97,6 +104,7 @@
                        observedAt, observedAt.plus(lifetime)))
                .toList();
        candidateStore.recordCabinets(candidates);
        if (detected.isEmpty()) markUnavailable(source.adapterCode());
        synchronizeRegisteredFacts(source, detected, snapshots, observedAt);
        return new AdapterDiscoveryResult(grouped.size(), detected.size(), observedAt);
    }
@@ -132,6 +140,9 @@
            detectionCabinetMapper.updateRegisteredChannelObservation(source.adapterCode(), identity.devtype(),
                    identity.devid(), identity.subdevid(), identity.chlid(), channel.available() ? "ONLINE" : "OFFLINE",
                    workStatus.name(), observedAt, successfulObservation);
            if (channel.available() && !successfulObservation)
                detectionCabinetMapper.touchRegisteredChannelObservation(source.adapterCode(), identity.devtype(),
                        identity.devid(), identity.subdevid(), identity.chlid(), observedAt);
            CabinetKey cabinet = new CabinetKey(identity.devtype(), identity.devid());
            cabinetOnline.merge(cabinet, channel.available(), Boolean::logicalOr);
        }
@@ -141,6 +152,15 @@
                        && channel.identity().devtype() == cabinet.devtype()
                        && channel.identity().devid() == cabinet.devid()
                        && snapshots.containsKey(channel.identity()))));
        cabinetOnline.forEach((cabinet, online) -> {
            boolean successfulSnapshot = online && detected.stream().anyMatch(channel -> channel.available()
                    && channel.identity().devtype() == cabinet.devtype()
                    && channel.identity().devid() == cabinet.devid()
                    && snapshots.containsKey(channel.identity()));
            if (online && !successfulSnapshot)
                detectionCabinetMapper.touchRegisteredCabinetObservation(source.adapterCode(), cabinet.devtype(),
                        cabinet.devid(), observedAt);
        });
    }
    private CabinetCandidate toCandidate(DiscoverySource source, CabinetKey key, List<DetectedChannel> channels,