package com.xy.consumer.redis;

import com.xy.annotation.RedisTimeout;
import com.xy.service.DeviceNetRecordServiceImpl;
import com.xy.service.RedisTimeoutMessage;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * redis设备离线订阅
 */
@Slf4j
@Service
@AllArgsConstructor
@RedisTimeout("device:offline")
public class DeviceOfflineConsumer implements RedisTimeoutMessage {

    private DeviceNetRecordServiceImpl deviceNetRecordService;

    @Override
    public void message(String key) {
        long deviceId = Long.parseLong(key.split(":")[2]);
        log.info("设备：{} 离线已超时", deviceId);
        if(deviceId>0L){
            // 推送离线超时消息
            deviceNetRecordService.deviceOfflineTimeOutPushMsg(deviceId);
        }
    }
}
