package com.ffii.towngas.config;

import org.springframework.stereotype.Component;

import com.ffii.core.support.JdbcDao;
import com.ffii.towngas.pojo.MqttRawData;

@Component
public class MqttDataWriter {

  private static JdbcDao jdbcDao;
  private static final String INSERT_SQL = "INSERT INTO mqtt_source_data (topic, qos, payload, customerId, facilityId, equipmentType, equipmentId, gasRating, pilot, `timestamp`) VALUES(:topic, :qos, :payload, :customerId, :facilityId, :equipmentType, :equipmentId, :gasRating, :pilot, :timestamp);";

  public MqttDataWriter(JdbcDao jdbcDao) {
    this.jdbcDao = jdbcDao;
  }

  public static Integer insertMqttRawData(MqttRawData mqttRawData) {
    try {
      return jdbcDao.executeUpdate(INSERT_SQL, mqttRawData.toMap());
    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }

  }

}
