package com.jpsoft.shinestar.modules.hikvision.callback;

import com.jpsoft.ehome.callback.DeviceRegisterCallBack;
import com.jpsoft.shinestar.modules.base.entity.DeviceInfo;
import com.jpsoft.shinestar.modules.base.service.DeviceInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.Date;

@Slf4j
@Component
public class DeviceRegisterCallBackImpl implements DeviceRegisterCallBack {
    @Autowired
    private DeviceInfoService deviceInfoService;

    @Override
    public void register(String deviceNo, int loginID, boolean online) {
        try {
            DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(deviceNo);

            if (deviceInfo!=null){
                deviceInfo.setIsOnline(online);
                deviceInfo.setHeartbeatUpdateTime(new Date());

                deviceInfoService.update(deviceInfo);
            }
        }
        catch (Exception ex){
            log.error(ex.getMessage());
        }
    }
}
