package com.neusoft.smart.pos.gateway.task;

import com.neusoft.smart.pos.dto.device.request.DeviceRequest;
import com.neusoft.smart.pos.framework.task.RedisTask;
import com.neusoft.smart.pos.framework.utils.SpringUtils;
import com.neusoft.smart.pos.gateway.service.feignService.RemoteDeviceService;
import com.neusoft.smart.pos.redis.bean.DeviceVersionList;
import lombok.Setter;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Date;

public class UpdateDeviceRequestTimeTask extends RedisTask {
	
	@Setter
	protected String serialno;
	
	@Setter
	private String SignalStrength;
	
	@Setter
	private String IPAddress;
	
	private RedisTemplate redisTemplate = SpringUtils.getBean("redisTemplate", RedisTemplate.class);
	
	private RemoteDeviceService remoteDeviceService = SpringUtils.getBean(RemoteDeviceService.class);
	
	@Override
	public void executeTask() {
		BoundHashOperations<String, String, DeviceVersionList> deviceMap = redisTemplate.boundHashOps("deviceVersionsMap");
		DeviceVersionList versions = deviceMap.get(this.serialno);
		DeviceRequest deviceRequest = new DeviceRequest();
		deviceRequest.setId(versions.getDeviceInfo().getId());
		deviceRequest.setSignalStrength(this.SignalStrength);
		deviceRequest.setIpAddress(this.IPAddress);
		deviceRequest.setLastRequestTime(new Date());
		remoteDeviceService.updateSelective(deviceRequest);
	}
}
