package com.ruoyi.web.controller.task;

import cn.hutool.core.util.NumberUtil;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.RedisUtils;
import com.ruoyi.zhdd.service.IDhService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 大华相关定时任务
 * @Author: huangcheng
 * @Date: 2022/1/20
 * @Version V1.0
 */
@Component("dhTask")
public class DhTask {

    @Autowired
    private IDhService dhService;

    /**
     * 大华token保活处理
     */
    public void keepalive() {
        long ttl = RedisUtils.getTtl(Constants.CACHE_DH_TOKEN);
        if (NumberUtil.compare(ttl, 0) == 1 && NumberUtil.compare(ttl, 20) == -1) {
            // 保活token
            dhService.tokenKeepalive(RedisUtils.getCacheObject(Constants.CACHE_DH_TOKEN));
        }
    }
}
