⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pms_server.cpp.svn-base

📁 sigmadesign smp8623 gui source code ,bingo
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
/* ------------------------------------------------------------------------- * pms_server.cpp - pms  server functions * Copyright (C) 2008 Dimitar Atanasov <datanasov@deisytechbg.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * ------------------------------------------------------------------------- */#include "common.h"#include "servers.h"inline int get_room_id(mysqlpp::Query& qr, std::string& RoomName){	std::ostringstream room_name_q;	normalize_string(RoomName);	room_name_q << "SELECT RoomID FROM Room WHERE RoomName='" << RoomName<<"'";	mysqlpp::StoreQueryResult room_name_res = qr.store(room_name_q.str().c_str());	int RoomNo = 0;	if(room_name_res.num_rows() > 0)	{		RoomNo = (int)room_name_res[0][0];	}	return RoomNo;}void link_start(std::string&){	ctxt.pmsanswered = 1;	{		std::ostringstream la;		la << "LD|DA"  << get_date << "|TI" << get_time << "|V#1.02|IFVI|";		send_to_pms(la);		sleep(1);	}	send_to_pms("LR|RIDR|FLDATI|");	sleep(1);	send_to_pms("LR|RIDR|FLDATI|");	sleep(1);	send_to_pms("LR|RIDR|FLDATI|");	sleep(1);	send_to_pms("LR|RIKR|FLWSKCRNKTK#G#GNGDDT$2|");	sleep(1);	send_to_pms("LR|RIKD|FLWSKCRNG#|");	sleep(1);	send_to_pms("LR|RIKA|FLASKCWS|");	sleep(1);	if(!ctxt.conf->second_interface)	{		send_to_pms("LR|RIXL|FLRNG#MIMTDATI|");		sleep(1);		send_to_pms("LR|RIXD|FLRNG#MI|");		sleep(1);		send_to_pms("LR|RIXR|FLRNG#|");		sleep(1);		send_to_pms("LR|RIXI|FLRNG#DCBIBDF#FDDATI|");		sleep(1);		send_to_pms("LR|RIXB|FLRNG#BADATI|");		sleep(1);	}	send_to_pms("LR|RIGI|FLRNG#GNGLGSSF|");	sleep(1);	send_to_pms("LR|RIGO|FLRNG#GSSF|");	sleep(1);	send_to_pms("LR|RIGC|FLRNG#GNGLROGS|");	sleep(1);	if(!ctxt.conf->second_interface)	{		send_to_pms("LR|RIPS|FLRNPTTAMAM#DATI|");		sleep(1);		send_to_pms("LR|RIPA|FLRNDATIAS|");		sleep(1);		send_to_pms("LR|RIRE|FLRNRS|");		sleep(1);	}	{		std::ostringstream la;		la << "LA|DA"  << get_date << "|TI" << get_time << "|";		send_to_pms(la);	}}void link_start_2(std::string&){	ctxt.pmsanswered2 = 1;	{		std::ostringstream la;		la << "LD|DA"  << get_date << "|TI" << get_time << "|V#1.02|IFVI|";		send_to_pms(la,ctxt.pmssock2);		sleep(1);	}	send_to_pms("LR|RIXL|FLRNG#MIMTDATI|",ctxt.pmssock2);	sleep(1);	send_to_pms("LR|RIXD|FLRNG#MI|",ctxt.pmssock2);	sleep(1);	send_to_pms("LR|RIXR|FLRNG#|",ctxt.pmssock2);	sleep(1);	send_to_pms("LR|RIXI|FLRNG#DCBIBDF#FDDATI|",ctxt.pmssock2);	sleep(1);	send_to_pms("LR|RIXB|FLRNG#BADATI|",ctxt.pmssock2);	sleep(1);	send_to_pms("LR|RIPS|FLRNPTTAMAM#DATI|",ctxt.pmssock2);	sleep(1);	send_to_pms("LR|RIPA|FLRNDATIAS|",ctxt.pmssock2);	sleep(1);	send_to_pms("LR|RIRE|FLRNRS|",ctxt.pmssock2);	sleep(1);	{		std::ostringstream la;		la << "LA|DA"  << get_date << "|TI" << get_time << "|";		send_to_pms(la,ctxt.pmssock2);	}}void link_alive(std::string&){	std::ostringstream date_time;	date_time << "DA"<< get_date << "|TI"<< get_time << "|";	if(ctxt.pmsanswered == 0)	{		std::ostringstream la;		la << "LA|" << date_time.str();		send_to_pms(la);		std::ostringstream dr;		dr << "DR|" << date_time.str();		send_to_pms(dr);		ctxt.pmsanswered = 2;	} else if(ctxt.pmsanswered == 1)	{		std::ostringstream dr;		dr << "DR|" << date_time.str();		send_to_pms(dr);		ctxt.pmsanswered = 2;	}	//else {	//}}void link_alive_2(std::string&){	std::ostringstream date_time;	date_time << "DA"<< get_date << "|TI"<< get_time << "|";	if(ctxt.pmsanswered2 == 0)	{		std::ostringstream la;		la << "LA|" << date_time.str();		send_to_pms(la,ctxt.pmssock2);		ctxt.pmsanswered2 = 2;	} else if(ctxt.pmsanswered2 == 1)	{		ctxt.pmsanswered2 = 2;	}	//else {	//}}void key_request(std::string& req){	std::string WS = "1";	int KC = 1;	int RNo = 0;	std::string RoomName;	std::string KeyType;	std::string KeyNum ="1";	int GuestNo = 0;	std::string GuestName;	std::string CardData;	int ReqID = 0;	std::string DateTo;	std::string TimeTo;	DECODE_BEGIN(req)		EXTRACT("WS([\\x20-\\x7B\\x7D-\\xFF]+)", WS)		EXTRACT("KC(\\d+)", 				KC)		EXTRACT("RN([\\x20-\\x7B\\x7D-\\xFF]+)", 	RoomName)		EXTRACT("KT(\\w+)", 				KeyType)		EXTRACT("K\\#(\\w+)", 				KeyNum)		EXTRACT("G\\#(\\d+)", 				GuestNo)		EXTRACT("GN([\\x20-\\x7B\\x7D-\\xFF]+)", 	GuestName)		EXTRACT("\\$2(\\w+)", 				CardData)		EXTRACT("GD(\\w+)", 				DateTo)		EXTRACT("DT([\\w\\:]+)", 			TimeTo)	DECODE_END()	BEGIN_DB()		RNo = get_room_id(qr, RoomName);		std::ostringstream pms_answer;		pms_answer.fill('0');		pms_answer << "KA|ASOK|KC"<< std::setw(2)<< KC << "|WS" << WS << "|";		send_to_pms(pms_answer);		if(RNo == 0)		{			END_DB_RETURN();			return;		}		normalize_string(req);		std::ostringstream keycard_req_q;		keycard_req_q << "INSERT INTO KeycardReq (ReqType, KCID, ReqText, ReqDate) VALUES (2, "<<KC<<", '"<< req <<"', '"<<get_date_time<<"')";		DB_EXECUTE(keycard_req_q.str().c_str());		mysqlpp::StoreQueryResult req_id_max = DB_STORE("SELECT MAX(ReqID) FROM KeycardReq WHERE ReqType=2;");		if(req_id_max.num_rows() > 0)		{			ReqID = req_id_max[0][0];		}		std::ostringstream sData;		sData << "KR|RN" << RNo <<"|K#"<< KeyNum << "|G#" << GuestNo <<"|$2"<<CardData<<"|HN"<<GuestName<<"|HT1|R#"<<ReqID;		if(ctxt.conf->using_enddate)		{			if(DateTo != "")				sData << "|GD"<<DateTo<<"|DT"<<TimeTo;		}		bool AS = send_to_mng(sData, KC);		if(!AS)		{			ctxt.add_to_pmsbuffer(sData);		}	END_DB()}void key_delete(std::string& req){	std::string WS;	int KC = 1;	int RNo = 0;	std::string RoomName;	int GuestNo = 0;	int ReqID = 0;	DECODE_BEGIN(req)		EXTRACT("WS([\\x20-\\x7B\\x7D-\\xFF]+)", WS)		EXTRACT("KC(\\d+)", 				KC)		EXTRACT("RN([\\x20-\\x7B\\x7D-\\xFF]+)", 	RoomName)		EXTRACT("G\\#(\\d+)", 				GuestNo)	DECODE_END()	BEGIN_DB()		RNo = get_room_id(qr, RoomName);		std::ostringstream pms_answer;		pms_answer << "KA|ASOK|KC"<< KC << "|WS" << WS << "|";		send_to_pms(pms_answer);		if(KC == 0)		{			END_DB_RETURN()			return;		}		normalize_string(req);		std::ostringstream keycard_req_q;		keycard_req_q << "INSERT INTO KeycardReq (ReqType, KCID, ReqText, ReqDate) VALUES (2, "<<KC<<", '"<< req <<"', '"<<get_date_time<<"')";		DB_EXECUTE(keycard_req_q.str().c_str());		mysqlpp::StoreQueryResult req_id_max = DB_STORE("SELECT MAX(ReqID) FROM KeycardReq WHERE ReqType=2;");		if(req_id_max.num_rows() > 0)		{			ReqID = req_id_max[0][0];		}		else		{			END_DB_RETURN()			return;		}		std::ostringstream key_data_q;		key_data_q << "SELECT hex(KeyID) As KeyN FROM Keycard Where KHRoomID="<<RNo<<" AND GuestNo=" << GuestNo;		mysqlpp::StoreQueryResult key_data_req = DB_STORE(key_data_q.str().c_str());		if(key_data_req.num_rows() > 0)		{			std::vector<int> RCs;			for(uint16 i = 0; i < key_data_req.num_rows(); i ++)			{				std::ostringstream room_q;				room_q << "SELECT RoomID FROM KeycardRoom WHERE KeyID=0x" << key_data_req[i][0].c_str();				mysqlpp::StoreQueryResult room_res = DB_STORE(room_q.str().c_str());				if(room_res.num_rows() > 0)				{					for(uint16 j = 0; j < room_res.num_rows(); j ++)					{						RCs.push_back((int)room_res[j][0]);					}				}				TRANSACTION_BEGIN(*conn);					std::ostringstream keykard_req_q;					keykard_req_q << "INSERT INTO KeycardReq (ReqType, KCID, ReqText, ReqDate, EmpID, ParentReqID) VALUES (1, " << KC << ", '"<<req<<", '"<< get_date_time <<"', 0, "<< ReqID <<")";					DB_EXECUTE(keycard_req_q.str().c_str());					mysqlpp::StoreQueryResult req_max_res = DB_STORE("SELECT MAX(ReqID) FROM KeycardReq WHERE ReqType=1;");					int ReqNo = 0;					if(req_max_res.num_rows() > 0)					{						ReqNo = (int)req_max_res[0][0];					}					{						std::ostringstream del_q;						del_q << "DELETE FROM Keycard WHERE KeyID=0x" << key_data_req[i][0].c_str();						DB_EXECUTE(del_q.str().c_str());					}					{						std::ostringstream del_q;						del_q << "DELETE FROM KeycardRoom WHERE KeyID=0x" << key_data_req[i][0].c_str();						DB_EXECUTE(del_q.str().c_str());					}					{						std::ostringstream del_q;						del_q << "UPDATE KeycardLog SET EndReqID=" << ReqNo <<", End='"<< get_date_time <<"' WHERE KeyID=0x" << key_data_req[i][0].c_str() <<" AND (EndReqID=0)";						logger(INFO, "Update KeycarLog pms dell key %s\n", del_q.str().c_str());						DB_EXECUTE(del_q.str().c_str());					}					{						std::ostringstream del_q;						del_q << "UPDATE KeycardRoomLog SET EndReqID="<<ReqNo<<", End='" << get_date_time << "' WHERE KeyID=0x" << key_data_req[i][0].c_str() <<" AND (EndReqID=0)";						DB_EXECUTE(del_q.str().c_str());					}				TRANSACTION_END();				if(bOK)				{					std::ostringstream blnk;					blnk.fill('0');					//blnk << "BLNK:" << std::hex << std::uppercase << std::setw(16) << key_data_req[i][0].c_str() << "*";					blnk << std::hex << std::uppercase << std::setw(16) << key_data_req[i][0].c_str();					for(uint16 j = 0; j < RCs.size(); j++)					{						std::string ip = get_rc_ip(qr, RCs[j]);						pthread_mutex_lock(&ctxt.rooms[ip]->lock);						ctxt.rooms[ip]->key_map_send[blnk.str()] = true;									//send_to_rc(affected_rcs[i], message);						pthread_mutex_unlock(&ctxt.rooms[ip]->lock);						//send_to_rc(ip, blnk);					}				}			}		}	END_DB()}inline int get_guest_in_room(mysqlpp::Query& qr, int RoomNo){	int GuestNo = 0;	std::ostringstream query;	query << "SELECT GuestNo FROM Room WHERE RoomID=" << RoomNo;	mysqlpp::StoreQueryResult query_res = DB_STORE(query.str().c_str());	if(query_res.num_rows() > 0)		GuestNo = (int) query_res[0][0];	return GuestNo;}inline int guest_to_int(std::string& lang){	if(lang == "EA")		return 0;	else if(lang == "BG")		return 1;	else if(lang == "GE")		return 2;	return 0;}static void init_synch_room_data(int RoomNo, int GuestNo, std::string GuestName, int GuestLang){	pthread_mutex_lock(&ctxt.synh_lock);	bool bSendToRC=0;	//std::cout<<RoomNo<<"    " << ctxt.SF_RoomNo;	if (RoomNo != ctxt.SF_RoomNo)	{		if (ctxt.SF_RoomNo != 0)		{			std::vector<int> TZones;			std::vector<int> TargetT;			std::vector<int> GuestT_EmptyRoom;			std::vector<int> Mode;			BEGIN_DB()				TRANSACTION_BEGIN(*conn)					//std::cout<<"being transaction\n";					{						std::ostringstream del_q;						del_q << "DELETE FROM RoomGuest WHERE RoomID=" << ctxt.SF_RoomNo;						DB_EXECUTE(del_q.str().c_str());					}		//			pthread_mutex_lock(&ctxt.synh_lock);					std::map<int, linked_ptr<synh_room_data_t> >::iterator i = ctxt.synh_data.begin();					for(; i != ctxt.synh_data.end(); i++)					{						std::ostringstream room_quest_q;						room_quest_q << "INSERT INTO RoomGuest (RoomID, GuestNo, GuestName) VALUES("<< ctxt.SF_RoomNo <<" ,"<< i->first <<",'"<<i->second->GuestName<<"')";						DB_EXECUTE(room_quest_q.str().c_str());					}		//			pthread_mutex_unlock(&ctxt.synh_lock);					std::ostringstream guest_no_q;					guest_no_q << "SELECT GuestNo, GuestName FROM Room WHERE RoomID=" << ctxt.SF_RoomNo;					mysqlpp::StoreQueryResult guest_no_res = DB_STORE(guest_no_q.str().c_str());					int bAddTitular = 0;					if(guest_no_res.num_rows() > 0)					{						int GuestNo_T = (int)guest_no_res[0][0];						if(GuestNo_T != 0)						{							std::ostringstream guest_info_q;							guest_info_q << "SELECT GuestNo, GuestName FROM RoomGuest WHERE RoomID=" << ctxt.SF_RoomNo<<" AND GuestNo="<<GuestNo_T;							mysqlpp::StoreQueryResult guest_info_res = DB_STORE(guest_info_q.str().c_str());							if(guest_info_res.num_rows() == 0)							{								bAddTitular = 2;							} else {							}						} else {							bAddTitular = 1;						}					}					if(bAddTitular)					{						std::ostringstream guest_no_titul_q;						guest_no_titul_q << "SELECT GuestNo FROM RoomGuest WHERE RoomID=" << ctxt.SF_RoomNo <<" ORDER BY GuestNo LIMIT 1";						mysqlpp::StoreQueryResult guest_no_titul_res = DB_STORE(guest_no_titul_q.str().c_str());						if(guest_no_titul_res.num_rows() > 0)						{							int GuestNo_New = (int) guest_no_titul_res[0][0];							std::ostringstream update_room_q;				//			pthread_mutex_lock(&ctxt.synh_lock);							update_room_q << "UPDATE Room SET GuestNo=" << GuestNo_New <<", GuestName='"<< ctxt.synh_data[GuestNo_New]->GuestName <<"', LangID=" << ctxt.synh_data[GuestNo_New]->GuestLang << ",  LastChange='" << get_date_time << "', WakeUp='0000-00-00 00:00:01' WHERE RoomID=" << ctxt.SF_RoomNo;				//			pthread_mutex_unlock(&ctxt.synh_lock);							DB_EXECUTE(update_room_q.str().c_str());						}						std::ostringstream room_zone_q;						room_zone_q << "UPDATE RoomTZone SET TargetT=DefaultGuestT WHERE RoomID=" << ctxt.SF_RoomNo;						DB_EXECUTE(room_zone_q.str().c_str());						std::ostringstream temp_q;						temp_q << "SELECT TZoneID, DefaultGuestT,DefaultGuestT_EmptyRoom,Mode FROM RoomTZone WHERE RoomID=" << ctxt.SF_RoomNo;						mysqlpp::StoreQueryResult temp_res = DB_STORE(temp_q.str().c_str());						for(uint16 i = 0; i < temp_res.num_rows(); i++)						{							TZones.push_back(temp_res[i][0]);							TargetT.push_back(temp_res[i][1]);							GuestT_EmptyRoom.push_back(temp_res[i][2]);							Mode.push_back(temp_res[i][3]);						}						bSendToRC = true;					}					//std::cout<<"end transaction\n";				TRANSACTION_END()				if(bOK)				{					if(bSendToRC && ctxt.conf->using_rc)					{						int Season = get_season(qr);						for(uint16 i = 0; i < TZones.size(); i++)						{							std::ostringstream clmt;							clmt.fill('0');							clmt << "CLMT:" << std::setw(2) << TZones[i] - 1 << Season << std::setw(2) << TargetT[i] << std::setw(2) << GuestT_EmptyRoom[i] << Mode[i] << "*";							std::string ip = get_rc_ip(qr, ctxt.SF_RoomNo);							send_to_rc(ip, clmt);						}					}				}				else				{					std::ostringstream msg;					msg << "Неуспешна заявка за настаняване на гост в стая "<<RoomNo;					write_event(4, msg);					ctxt.SF_RoomNo = RoomNo;				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -