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

import com.neusoft.smart.pos.dto.device.request.DeviceRequest;
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.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;

@Slf4j
public class DevicePostRequestTask extends AbstractDevicePostRequestTask {
	
	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);
		this.updateStatusAndCreateHistory(versions);
		//更新设备<IP、信号>版本号
		DeviceRequest deviceRequest = new DeviceRequest();
		deviceRequest.setId(versions.getDeviceInfo().getId());
		deviceRequest.setCurVersion(this.version);
		remoteDeviceService.updateSelective(deviceRequest);
		log.info("执行了更新pos任务1次");
	}
}
