package net.vtstar.zhongtong.avi.mqtt.handle;

import lombok.extern.slf4j.Slf4j;
import net.vtstar.scada.base.mqtt.utils.MqttConstants;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class RfidMessageHandler extends AbstractTesterMessageHandler {

	@Resource(name = "redisTemplate")
	private ListOperations listOperations;
	@Resource(name = "redisTemplate")
	private ValueOperations valueOperations;

	public RfidMessageHandler() {
		super("translation", "data/all");
	}

	@Override
	public void handleMessage(Message<?> message) throws MessagingException {
		String payload = (String) message.getPayload();
		System.out.println(payload);
		MessageHeaders headers = message.getHeaders();
		String equipmentNumber = headers.get(MqttConstants.MSG_HEADER_KEY_EQUIPMENTNUMBER, String.class);
		/*try {
			ChipCheckData data = new ChipCheckData();
			data.setEquipCode(equipmentNumber);
			data.setFangzuyi(new BigDecimal(payload).setScale(3, RoundingMode.HALF_UP));
			data.setBeginTime(new Date());

			log.info("方阻仪：" + data.getFangzuyi());

			BaseKey baseKey = new BaseKey(ChipEquipType.FANGZUYI.getValue(), equipmentNumber);
			listOperations.rightPush(baseKey.listKey(), data);

			valueOperations.set(baseKey.lastKey(), data);
		} catch (Exception e) {
			log.error("handleMessage error:", e);
		}*/
	}
}
