package com.zksy.radar.utils;/*
package com.zksy.gasTransmitter.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class DeviceOfflineCheckTask {
    private static final Logger logger = LoggerFactory.getLogger(DeviceOfflineCheckTask.class);

    // 用于存储设备编号及其最后一次接收数据的时间
    public static ConcurrentHashMap<String, Date> deviceLastReceiveTimeMap = new ConcurrentHashMap<>();
    @Autowired
    private BaseDevicesService baseDevicesService;

    // 定时检查设备是否离线
    @Scheduled(fixedRate = 24 * 60 * 60 * 1000) // 每24小时执行一次
    public void checkDeviceOffline() {
        Date now = new Date();
        for (Map.Entry<String, Date> entry : deviceLastReceiveTimeMap.entrySet()) {
            long diff = now.getTime() - entry.getValue().getTime();
            // 如果设备在 23 小时内没有接收数据，则认为设备离线
            if (diff > 23 * 60 * 60 * 1000) {
                baseDevicesService.getByDeviceNumberStatus(entry.getKey(), 1, 0);
                logger.info("设备 {} 已离线", entry.getKey());
            }
        }
    }
}*/
