package com.neusoft.smart.pos.utils;

import com.neusoft.smart.pos.framework.utils.SpringUtils;
import com.neusoft.smart.pos.redis.bean.DeviceInfo;
import com.neusoft.smart.pos.redis.bean.DeviceVersionList;
import lombok.val;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * POS设备使用Redis工具类
 */
public class PosDeviceRedisUtils {
	private static final String REDIS_TEMPLATE = "redisTemplate";
	private static final String DEVICE_VERSIONS_MAP_WITH_SN = "deviceVersionsMapWithSn";

	public static RedisTemplate getRedisTemplate() {
		return SpringUtils.getBean(REDIS_TEMPLATE,RedisTemplate.class);
	}

	/**
	 * 根据POS及SN编号查询设备信息
	 * @param serialNo
	 * @return
	 */
	public static DeviceInfo getDeviceInfoBySerialNo(String serialNo) {
		BoundHashOperations<String, String, DeviceVersionList> deviceHashWithSn = getRedisTemplate().boundHashOps(DEVICE_VERSIONS_MAP_WITH_SN);
		val deviceVersionList = deviceHashWithSn.get(serialNo);
		if(null == deviceVersionList){
			return null;
		}
		return 	deviceVersionList.getDeviceInfo();
	}
}
