#ifndef VSSUPPERSVRTBL_CONTROLLER_H #define VSSUPPERSVRTBL_CONTROLLER_H #include #include #include "vss/dao/VssUpperSvrTblDao.h" #include "vss/model/VssUpperSvrTblBuilder.h" #include "vss/model/VssUpperSvrTbl.h" #include "VssBaseController.h" #include using namespace std; /** * 创建上级平台服务器表 */ class VssUpperSvrTblController : public VssBaseController { private: /** 创建上级平台服务器表构造函数 */ VssUpperSvrTblController() {} public: /** 创建上级平台服务器表单例模式 */ static VssUpperSvrTblController* instance() { static VssUpperSvrTblController instance; return &instance; } public: /** 注册{label}http服务 */ void registerHttpServices(HttpSrvRetRecieve& _HttpSrvRetRecieve) { _HttpSrvRetRecieve.setInfo("^/addVssUpperSvrTbl$", "POST", std::bind(&VssUpperSvrTblController::addVssUpperSvrTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/delVssUpperSvrTbl$", "POST", std::bind(&VssUpperSvrTblController::delVssUpperSvrTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/updateVssUpperSvrTbl$", "POST", std::bind(&VssUpperSvrTblController::updateVssUpperSvrTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/findVssUpperSvrTbl$", "POST", std::bind(&VssUpperSvrTblController::findVssUpperSvrTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/findVssUpperSvrTblList$", "POST", std::bind(&VssUpperSvrTblController::findVssUpperSvrTblList, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); } public: /** 添加创建上级平台服务器表 */ std::string addVssUpperSvrTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; responseJsonValue["message"] = "添加失败!"; responseJsonValue["success"] = "false"; if (requestJsonReader.parse(content, requestJsonValue)) { VssUpperSvrTblBuilder vssUpperSvrTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssUpperSvrTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addID(std::stoi((iDJsonValue.asString()))); } Json::Value nameJsonValue = requestJsonValue[VssUpperSvrTbl_Name]; if (nameJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addName((nameJsonValue.asString())); } Json::Value publicIDJsonValue = requestJsonValue[VssUpperSvrTbl_PublicID]; if (publicIDJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPublicID((publicIDJsonValue.asString())); } Json::Value authUsernameJsonValue = requestJsonValue[VssUpperSvrTbl_AuthUsername]; if (authUsernameJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAuthUsername((authUsernameJsonValue.asString())); } Json::Value authPasswdJsonValue = requestJsonValue[VssUpperSvrTbl_AuthPasswd]; if (authPasswdJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAuthPasswd((authPasswdJsonValue.asString())); } Json::Value domainJsonValue = requestJsonValue[VssUpperSvrTbl_Domain]; if (domainJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addDomain((domainJsonValue.asString())); } Json::Value iPJsonValue = requestJsonValue[VssUpperSvrTbl_IP]; if (iPJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIP((iPJsonValue.asString())); } Json::Value portJsonValue = requestJsonValue[VssUpperSvrTbl_Port]; if (portJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPort(std::stoi((portJsonValue.asString()))); } Json::Value registerTimeJsonValue = requestJsonValue[VssUpperSvrTbl_RegisterTime]; if (registerTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addRegisterTime(std::stoi((registerTimeJsonValue.asString()))); } Json::Value keepAliveTimeJsonValue = requestJsonValue[VssUpperSvrTbl_KeepAliveTime]; if (keepAliveTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addKeepAliveTime(std::stoi((keepAliveTimeJsonValue.asString()))); } Json::Value aliveJsonValue = requestJsonValue[VssUpperSvrTbl_Alive]; if (aliveJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAlive(std::stoi((aliveJsonValue.asString()))); } Json::Value isSyncTimeJsonValue = requestJsonValue[VssUpperSvrTbl_IsSyncTime]; if (isSyncTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIsSyncTime(std::stoi((isSyncTimeJsonValue.asString()))); } Json::Value pushProtocolJsonValue = requestJsonValue[VssUpperSvrTbl_PushProtocol]; if (pushProtocolJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPushProtocol(std::stoi((pushProtocolJsonValue.asString()))); } Json::Value platformInfoJsonValue = requestJsonValue[VssUpperSvrTbl_PlatformInfo]; if (platformInfoJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPlatformInfo(std::stoi((platformInfoJsonValue.asString()))); } Json::Value isEnableJsonValue = requestJsonValue[VssUpperSvrTbl_IsEnable]; if (isEnableJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIsEnable(std::stoi((isEnableJsonValue.asString()))); } Json::Value updateTimeJsonValue = requestJsonValue[VssUpperSvrTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addUpdateTime((updateTimeJsonValue.asString())); } auto keyValuesToAdd = vssUpperSvrTblBuilder.buildVssUpperSvrTblMap(); if (keyValuesToAdd.size() > 0) { mysqlpp::SimpleResult addVssUpperSvrTblResult = VssUpperSvrTblDao::instance()->addVssUpperSvrTbl(keyValuesToAdd); if (addVssUpperSvrTblResult.rows() > 0) { responseJsonValue["success"] = "true"; responseJsonValue["message"] = "添加成功!"; } } } return responseJsonValue.toStyledString(); } /** 删除创建上级平台服务器表 */ std::string delVssUpperSvrTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; responseJsonValue["message"] = "删除失败!"; responseJsonValue["success"] = "false"; if (requestJsonReader.parse(content, requestJsonValue)) { Json::Value iDJsonValue = requestJsonValue[VssUpperSvrTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { string iDValue = iDJsonValue.asString(); if (iDValue.size() > 0 && VssUpperSvrTblDao::instance()->deleteByColumn("ID", iDValue)) { responseJsonValue["success"] = "true"; responseJsonValue["message"] = "删除成功!"; } } } return responseJsonValue.toStyledString(); } /** 更新创建上级平台服务器表 */ std::string updateVssUpperSvrTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; responseJsonValue["message"] = "更新失败!"; responseJsonValue["success"] = "false"; if (requestJsonReader.parse(content, requestJsonValue)) { VssUpperSvrTblBuilder vssUpperSvrTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssUpperSvrTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addID(std::stoi((iDJsonValue.asString()))); } Json::Value nameJsonValue = requestJsonValue[VssUpperSvrTbl_Name]; if (nameJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addName((nameJsonValue.asString())); } Json::Value publicIDJsonValue = requestJsonValue[VssUpperSvrTbl_PublicID]; if (publicIDJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPublicID((publicIDJsonValue.asString())); } Json::Value authUsernameJsonValue = requestJsonValue[VssUpperSvrTbl_AuthUsername]; if (authUsernameJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAuthUsername((authUsernameJsonValue.asString())); } Json::Value authPasswdJsonValue = requestJsonValue[VssUpperSvrTbl_AuthPasswd]; if (authPasswdJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAuthPasswd((authPasswdJsonValue.asString())); } Json::Value domainJsonValue = requestJsonValue[VssUpperSvrTbl_Domain]; if (domainJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addDomain((domainJsonValue.asString())); } Json::Value iPJsonValue = requestJsonValue[VssUpperSvrTbl_IP]; if (iPJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIP((iPJsonValue.asString())); } Json::Value portJsonValue = requestJsonValue[VssUpperSvrTbl_Port]; if (portJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPort(std::stoi((portJsonValue.asString()))); } Json::Value registerTimeJsonValue = requestJsonValue[VssUpperSvrTbl_RegisterTime]; if (registerTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addRegisterTime(std::stoi((registerTimeJsonValue.asString()))); } Json::Value keepAliveTimeJsonValue = requestJsonValue[VssUpperSvrTbl_KeepAliveTime]; if (keepAliveTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addKeepAliveTime(std::stoi((keepAliveTimeJsonValue.asString()))); } Json::Value aliveJsonValue = requestJsonValue[VssUpperSvrTbl_Alive]; if (aliveJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAlive(std::stoi((aliveJsonValue.asString()))); } Json::Value isSyncTimeJsonValue = requestJsonValue[VssUpperSvrTbl_IsSyncTime]; if (isSyncTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIsSyncTime(std::stoi((isSyncTimeJsonValue.asString()))); } Json::Value pushProtocolJsonValue = requestJsonValue[VssUpperSvrTbl_PushProtocol]; if (pushProtocolJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPushProtocol(std::stoi((pushProtocolJsonValue.asString()))); } Json::Value platformInfoJsonValue = requestJsonValue[VssUpperSvrTbl_PlatformInfo]; if (platformInfoJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPlatformInfo(std::stoi((platformInfoJsonValue.asString()))); } Json::Value isEnableJsonValue = requestJsonValue[VssUpperSvrTbl_IsEnable]; if (isEnableJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIsEnable(std::stoi((isEnableJsonValue.asString()))); } Json::Value updateTimeJsonValue = requestJsonValue[VssUpperSvrTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addUpdateTime((updateTimeJsonValue.asString())); } if (iDJsonValue.type() != Json::ValueType::nullValue) { string iDValue = iDJsonValue.asString(); if (iDValue.size() > 0 && VssUpperSvrTblDao::instance()->updateVssUpperSvrTbl(vssUpperSvrTblBuilder.buildVssUpperSvrTblMap(), "ID", iDValue)) { responseJsonValue["success"] = "true"; responseJsonValue["message"] = "更新成功!"; } } } return responseJsonValue.toStyledString(); } /** 查找单个创建上级平台服务器表 */ std::string findVssUpperSvrTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; responseJsonValue["message"] = "查询失败!"; responseJsonValue["success"] = "false"; if (requestJsonReader.parse(content, requestJsonValue)) { VssUpperSvrTblBuilder vssUpperSvrTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssUpperSvrTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addID(std::stoi((iDJsonValue.asString()))); } Json::Value nameJsonValue = requestJsonValue[VssUpperSvrTbl_Name]; if (nameJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addName((nameJsonValue.asString())); } Json::Value publicIDJsonValue = requestJsonValue[VssUpperSvrTbl_PublicID]; if (publicIDJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPublicID((publicIDJsonValue.asString())); } Json::Value authUsernameJsonValue = requestJsonValue[VssUpperSvrTbl_AuthUsername]; if (authUsernameJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAuthUsername((authUsernameJsonValue.asString())); } Json::Value authPasswdJsonValue = requestJsonValue[VssUpperSvrTbl_AuthPasswd]; if (authPasswdJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAuthPasswd((authPasswdJsonValue.asString())); } Json::Value domainJsonValue = requestJsonValue[VssUpperSvrTbl_Domain]; if (domainJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addDomain((domainJsonValue.asString())); } Json::Value iPJsonValue = requestJsonValue[VssUpperSvrTbl_IP]; if (iPJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIP((iPJsonValue.asString())); } Json::Value portJsonValue = requestJsonValue[VssUpperSvrTbl_Port]; if (portJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPort(std::stoi((portJsonValue.asString()))); } Json::Value registerTimeJsonValue = requestJsonValue[VssUpperSvrTbl_RegisterTime]; if (registerTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addRegisterTime(std::stoi((registerTimeJsonValue.asString()))); } Json::Value keepAliveTimeJsonValue = requestJsonValue[VssUpperSvrTbl_KeepAliveTime]; if (keepAliveTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addKeepAliveTime(std::stoi((keepAliveTimeJsonValue.asString()))); } Json::Value aliveJsonValue = requestJsonValue[VssUpperSvrTbl_Alive]; if (aliveJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAlive(std::stoi((aliveJsonValue.asString()))); } Json::Value isSyncTimeJsonValue = requestJsonValue[VssUpperSvrTbl_IsSyncTime]; if (isSyncTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIsSyncTime(std::stoi((isSyncTimeJsonValue.asString()))); } Json::Value pushProtocolJsonValue = requestJsonValue[VssUpperSvrTbl_PushProtocol]; if (pushProtocolJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPushProtocol(std::stoi((pushProtocolJsonValue.asString()))); } Json::Value platformInfoJsonValue = requestJsonValue[VssUpperSvrTbl_PlatformInfo]; if (platformInfoJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPlatformInfo(std::stoi((platformInfoJsonValue.asString()))); } Json::Value isEnableJsonValue = requestJsonValue[VssUpperSvrTbl_IsEnable]; if (isEnableJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIsEnable(std::stoi((isEnableJsonValue.asString()))); } Json::Value updateTimeJsonValue = requestJsonValue[VssUpperSvrTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addUpdateTime((updateTimeJsonValue.asString())); } responseJsonValue["message"] = "查询成功!"; responseJsonValue["success"] = "true"; responseJsonValue["data"] = VssUpperSvrTblDao::instance()->findJsonArray(string("select * from ") + VSSUpperSvrTbl_TABLE_NAME + " where 1 = 1 limit 1"); } return responseJsonValue.toStyledString(); } /** 查找创建上级平台服务器表列表 */ std::string findVssUpperSvrTblList(std::string ip, unsigned int port, std::string content, PResponse &response) { Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; responseJsonValue["message"] = "查询失败!"; responseJsonValue["success"] = "false"; if (content == "" || requestJsonReader.parse(content, requestJsonValue)) { VssUpperSvrTblBuilder vssUpperSvrTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssUpperSvrTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addID(std::stoi((iDJsonValue.asString()))); } Json::Value nameJsonValue = requestJsonValue[VssUpperSvrTbl_Name]; if (nameJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addName((nameJsonValue.asString())); } Json::Value publicIDJsonValue = requestJsonValue[VssUpperSvrTbl_PublicID]; if (publicIDJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPublicID((publicIDJsonValue.asString())); } Json::Value authUsernameJsonValue = requestJsonValue[VssUpperSvrTbl_AuthUsername]; if (authUsernameJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAuthUsername((authUsernameJsonValue.asString())); } Json::Value authPasswdJsonValue = requestJsonValue[VssUpperSvrTbl_AuthPasswd]; if (authPasswdJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAuthPasswd((authPasswdJsonValue.asString())); } Json::Value domainJsonValue = requestJsonValue[VssUpperSvrTbl_Domain]; if (domainJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addDomain((domainJsonValue.asString())); } Json::Value iPJsonValue = requestJsonValue[VssUpperSvrTbl_IP]; if (iPJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIP((iPJsonValue.asString())); } Json::Value portJsonValue = requestJsonValue[VssUpperSvrTbl_Port]; if (portJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPort(std::stoi((portJsonValue.asString()))); } Json::Value registerTimeJsonValue = requestJsonValue[VssUpperSvrTbl_RegisterTime]; if (registerTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addRegisterTime(std::stoi((registerTimeJsonValue.asString()))); } Json::Value keepAliveTimeJsonValue = requestJsonValue[VssUpperSvrTbl_KeepAliveTime]; if (keepAliveTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addKeepAliveTime(std::stoi((keepAliveTimeJsonValue.asString()))); } Json::Value aliveJsonValue = requestJsonValue[VssUpperSvrTbl_Alive]; if (aliveJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addAlive(std::stoi((aliveJsonValue.asString()))); } Json::Value isSyncTimeJsonValue = requestJsonValue[VssUpperSvrTbl_IsSyncTime]; if (isSyncTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIsSyncTime(std::stoi((isSyncTimeJsonValue.asString()))); } Json::Value pushProtocolJsonValue = requestJsonValue[VssUpperSvrTbl_PushProtocol]; if (pushProtocolJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPushProtocol(std::stoi((pushProtocolJsonValue.asString()))); } Json::Value platformInfoJsonValue = requestJsonValue[VssUpperSvrTbl_PlatformInfo]; if (platformInfoJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addPlatformInfo(std::stoi((platformInfoJsonValue.asString()))); } Json::Value isEnableJsonValue = requestJsonValue[VssUpperSvrTbl_IsEnable]; if (isEnableJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addIsEnable(std::stoi((isEnableJsonValue.asString()))); } Json::Value updateTimeJsonValue = requestJsonValue[VssUpperSvrTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssUpperSvrTblBuilder.addUpdateTime((updateTimeJsonValue.asString())); } responseJsonValue["message"] = "查询成功!"; responseJsonValue["success"] = "true"; responseJsonValue["data"] = VssUpperSvrTblDao::instance()->findJsonArray(string("select * from ") + VSSUpperSvrTbl_TABLE_NAME + " where 1 = 1"); } return responseJsonValue.toStyledString(); } }; #endif //VSSUPPERSVRTBL_CONTROLLER_H