package com.seer.teach.common.cache;

import com.seer.teach.common.cache.dto.DeviceMetricDTO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


import java.util.Map;

@Slf4j
@Service
public class DeviceMetricsCacheService {

    @Resource
    private DeviceMetricsCache deviceMetricsCache;

    /** 上报设备指标 */
    public void reportMetric(String deviceKey, DeviceMetricDTO dto) {
        deviceMetricsCache.put(deviceKey, dto);
    }

    /** 获取最新指标 */
    public DeviceMetricDTO getLatestMetric(String deviceKey) {
        return deviceMetricsCache.get(deviceKey);
    }

    /** 删除设备缓存 */
    public void invalidateMetric(String deviceKey) {
        deviceMetricsCache.invalidate(deviceKey);
    }

    /** 获取全部在线设备 */
    public Map<String, DeviceMetricDTO> getAllOnlineDevices() {
        return deviceMetricsCache.getAllOnline();
    }

}
