#ifndef VSSDOMAINUNITTBL_CONTROLLER_H #define VSSDOMAINUNITTBL_CONTROLLER_H #include #include #include "vss/dao/VssDomainUnitTblDao.h" #include "vss/model/VssDomainUnitTblBuilder.h" #include "vss/model/VssDomainUnitTbl.h" #include "VssBaseController.h" #include using namespace std; /** * 创建一级设备表 */ class VssDomainUnitTblController : public VssBaseController { private: /** 创建一级设备表构造函数 */ VssDomainUnitTblController() {} public: /** 创建一级设备表单例模式 */ static VssDomainUnitTblController* instance() { static VssDomainUnitTblController instance; return &instance; } public: /** 注册{label}http服务 */ void registerHttpServices(HttpSrvRetRecieve& _HttpSrvRetRecieve) { _HttpSrvRetRecieve.setInfo("^/addVssDomainUnitTbl$", "POST", std::bind(&VssDomainUnitTblController::addVssDomainUnitTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/delVssDomainUnitTbl$", "POST", std::bind(&VssDomainUnitTblController::delVssDomainUnitTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/updateVssDomainUnitTbl$", "POST", std::bind(&VssDomainUnitTblController::updateVssDomainUnitTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/findVssDomainUnitTbl$", "POST", std::bind(&VssDomainUnitTblController::findVssDomainUnitTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/findVssDomainUnitTblList$", "POST", std::bind(&VssDomainUnitTblController::findVssDomainUnitTblList, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); } public: /** 添加创建一级设备表 */ std::string addVssDomainUnitTbl(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)) { VssDomainUnitTblBuilder vssDomainUnitTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addID(std::stoi((iDJsonValue.asString()))); } Json::Value devPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DevPubID]; if (devPubIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDevPubID((devPubIDJsonValue.asString())); } Json::Value domainPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DomainPubID]; if (domainPubIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDomainPubID((domainPubIDJsonValue.asString())); } Json::Value nameJsonValue = requestJsonValue[VssDomainUnitTbl_Name]; if (nameJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addName((nameJsonValue.asString())); } Json::Value businessGroupIDJsonValue = requestJsonValue[VssDomainUnitTbl_BusinessGroupID]; if (businessGroupIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addBusinessGroupID((businessGroupIDJsonValue.asString())); } Json::Value parentIdJsonValue = requestJsonValue[VssDomainUnitTbl_ParentId]; if (parentIdJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addParentId((parentIdJsonValue.asString())); } Json::Value domainTypeJsonValue = requestJsonValue[VssDomainUnitTbl_DomainType]; if (domainTypeJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDomainType(std::stoi((domainTypeJsonValue.asString()))); } Json::Value updateTimeJsonValue = requestJsonValue[VssDomainUnitTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addUpdateTime((updateTimeJsonValue.asString())); } auto keyValuesToAdd = vssDomainUnitTblBuilder.buildVssDomainUnitTblMap(); if (keyValuesToAdd.size() > 0) { mysqlpp::SimpleResult addVssDomainUnitTblResult = VssDomainUnitTblDao::instance()->addVssDomainUnitTbl(keyValuesToAdd); if (addVssDomainUnitTblResult.rows() > 0) { responseJsonValue["success"] = "true"; responseJsonValue["message"] = "添加成功!"; } } } return responseJsonValue.toStyledString(); } /** 删除创建一级设备表 */ std::string delVssDomainUnitTbl(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[VssDomainUnitTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { string iDValue = iDJsonValue.asString(); if (iDValue.size() > 0 && VssDomainUnitTblDao::instance()->deleteByColumn("ID", iDValue)) { responseJsonValue["success"] = "true"; responseJsonValue["message"] = "删除成功!"; } } } return responseJsonValue.toStyledString(); } /** 更新创建一级设备表 */ std::string updateVssDomainUnitTbl(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)) { VssDomainUnitTblBuilder vssDomainUnitTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addID(std::stoi((iDJsonValue.asString()))); } Json::Value devPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DevPubID]; if (devPubIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDevPubID((devPubIDJsonValue.asString())); } Json::Value domainPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DomainPubID]; if (domainPubIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDomainPubID((domainPubIDJsonValue.asString())); } Json::Value nameJsonValue = requestJsonValue[VssDomainUnitTbl_Name]; if (nameJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addName((nameJsonValue.asString())); } Json::Value businessGroupIDJsonValue = requestJsonValue[VssDomainUnitTbl_BusinessGroupID]; if (businessGroupIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addBusinessGroupID((businessGroupIDJsonValue.asString())); } Json::Value parentIdJsonValue = requestJsonValue[VssDomainUnitTbl_ParentId]; if (parentIdJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addParentId((parentIdJsonValue.asString())); } Json::Value domainTypeJsonValue = requestJsonValue[VssDomainUnitTbl_DomainType]; if (domainTypeJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDomainType(std::stoi((domainTypeJsonValue.asString()))); } Json::Value updateTimeJsonValue = requestJsonValue[VssDomainUnitTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addUpdateTime((updateTimeJsonValue.asString())); } if (iDJsonValue.type() != Json::ValueType::nullValue) { string iDValue = iDJsonValue.asString(); if (iDValue.size() > 0 && VssDomainUnitTblDao::instance()->updateVssDomainUnitTbl(vssDomainUnitTblBuilder.buildVssDomainUnitTblMap(), "ID", iDValue)) { responseJsonValue["success"] = "true"; responseJsonValue["message"] = "更新成功!"; } } } return responseJsonValue.toStyledString(); } /** 查找单个创建一级设备表 */ std::string findVssDomainUnitTbl(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)) { VssDomainUnitTblBuilder vssDomainUnitTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addID(std::stoi((iDJsonValue.asString()))); } Json::Value devPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DevPubID]; if (devPubIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDevPubID((devPubIDJsonValue.asString())); } Json::Value domainPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DomainPubID]; if (domainPubIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDomainPubID((domainPubIDJsonValue.asString())); } Json::Value nameJsonValue = requestJsonValue[VssDomainUnitTbl_Name]; if (nameJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addName((nameJsonValue.asString())); } Json::Value businessGroupIDJsonValue = requestJsonValue[VssDomainUnitTbl_BusinessGroupID]; if (businessGroupIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addBusinessGroupID((businessGroupIDJsonValue.asString())); } Json::Value parentIdJsonValue = requestJsonValue[VssDomainUnitTbl_ParentId]; if (parentIdJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addParentId((parentIdJsonValue.asString())); } Json::Value domainTypeJsonValue = requestJsonValue[VssDomainUnitTbl_DomainType]; if (domainTypeJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDomainType(std::stoi((domainTypeJsonValue.asString()))); } Json::Value updateTimeJsonValue = requestJsonValue[VssDomainUnitTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addUpdateTime((updateTimeJsonValue.asString())); } responseJsonValue["message"] = "查询成功!"; responseJsonValue["success"] = "true"; responseJsonValue["data"] = VssDomainUnitTblDao::instance()->findJsonArray(string("select * from ") + VSSDomainUnitTbl_TABLE_NAME + " where 1 = 1 limit 1", vssDomainUnitTblBuilder.buildVssDomainUnitTblMap()); } return responseJsonValue.toStyledString(); } /** 查找创建一级设备表列表 */ std::string findVssDomainUnitTblList(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)) { VssDomainUnitTblBuilder vssDomainUnitTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssDomainUnitTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addID(std::stoi((iDJsonValue.asString()))); } Json::Value devPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DevPubID]; if (devPubIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDevPubID((devPubIDJsonValue.asString())); } Json::Value domainPubIDJsonValue = requestJsonValue[VssDomainUnitTbl_DomainPubID]; if (domainPubIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDomainPubID((domainPubIDJsonValue.asString())); } Json::Value nameJsonValue = requestJsonValue[VssDomainUnitTbl_Name]; if (nameJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addName((nameJsonValue.asString())); } Json::Value businessGroupIDJsonValue = requestJsonValue[VssDomainUnitTbl_BusinessGroupID]; if (businessGroupIDJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addBusinessGroupID((businessGroupIDJsonValue.asString())); } Json::Value parentIdJsonValue = requestJsonValue[VssDomainUnitTbl_ParentId]; if (parentIdJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addParentId((parentIdJsonValue.asString())); } Json::Value domainTypeJsonValue = requestJsonValue[VssDomainUnitTbl_DomainType]; if (domainTypeJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addDomainType(std::stoi((domainTypeJsonValue.asString()))); } Json::Value updateTimeJsonValue = requestJsonValue[VssDomainUnitTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssDomainUnitTblBuilder.addUpdateTime((updateTimeJsonValue.asString())); } responseJsonValue["message"] = "查询成功!"; responseJsonValue["success"] = "true"; responseJsonValue["data"] = VssDomainUnitTblDao::instance()->findJsonArray(string("select * from ") + VSSDomainUnitTbl_TABLE_NAME + " where 1 = 1", vssDomainUnitTblBuilder.buildVssDomainUnitTblMap()); } return responseJsonValue.toStyledString(); } }; #endif //VSSDOMAINUNITTBL_CONTROLLER_H