


#include <stdio.h>
#include <string>

#include "json/writer.h"
#include "json/reader.h"
#include "json/value.h"

#include "KK_CcuConfig.h"
#include "LSC_Logger.h"
#include "KK_Util.h"
#include "MQ_CCU_Adapter.h"


KK_CcuConfig* KK_CcuConfig::ms_pInstance = NULL;

KK_CcuConfig* KK_CcuConfig::GetInstance() {
	if (ms_pInstance == NULL) {
		ms_pInstance = new KK_CcuConfig();
	}
	return ms_pInstance;
}


KK_CcuConfig::KK_CcuConfig(): db("hj", "hj", "127.0.0.1", "5432", "hjhome"){

}

int KK_CcuConfig::Open(){
	try {
		db.OpenConnection();
	} catch (exception& e) {
		LOGW("%s.\n",e.what());
		return -1;
	}
	return 0;
}

//这个好像未用到
string KK_CcuConfig::getCentralAcGwMac(string NodeId){
	string CentralAcGwMac  = "";
	DBRES result = NULL;
	string sql = "SELECT mac from all_node_config where id = '"+NodeId+"';";
	try {
		db.StartTransaction();
		 result = db.ExecuteQuery(sql);
		db.CommitTransaction();

		if (result->size() == 1) {
			CentralAcGwMac =  result->at(0)->find("mac")->second;
		} else {
			LOGW("query table all_gw_config get error result size:%d.\n",result->size());
		}
		EH_DB::ReleaseResultSet(result);
	} catch (exception& e) {
		LOGW("%s.\n",e.what());
		EH_DB::ReleaseResultSet(result);
	}
	return CentralAcGwMac;
}

