package com.ho.common.tools.util;

import com.alibaba.fastjson.JSONObject;
import com.ho.common.tools.constant.CommonConstant;
import com.ho.common.tools.constant.RedisKeyConstant;
import com.ho.common.tools.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class UpdateHeartbeatUtils {

    @Autowired
    RedisService redisService;

    /**
     * 更新心跳
     * @param sn
     */
    public void updateHeartbeat(String sn){
        Date updateTime = new Date();
        //检测到有心跳
        JSONObject heartbeat = new JSONObject();
        heartbeat.put(CommonConstant.UPDATE_TIME, updateTime);
        redisService.hmset(RedisKeyConstant.HEARTBEAT + sn, heartbeat);
    }
}
