QiaoJiaSystem/DataManagerServer/CMakeLists.txt
@@ -111,7 +111,7 @@ ../LocalDBTool/SqliteFaceEncap.cpp ../../../BasicPlatForm/basic/db/sqlite/sqliteEncapsulation.cpp ../../../BasicPlatForm/basic/db/sqlite/sqliteEncapsulation.h ) vss/dao/BaseDao.cpp) target_link_libraries(DataWebServer glog QiaoJiaSystem/DataManagerServer/vss/controller/VssLocalSettingTblController.h
@@ -17,47 +17,52 @@ */ class VssLocalSettingTblController : public VssBaseController { private: /** 本地国标配置构造函数 */ VssLocalSettingTblController() {} /** 本地国标配置构造函数 */ VssLocalSettingTblController() {} public: /** 本地国标配置单例模式 */ static VssLocalSettingTblController* instance() { /** 本地国标配置单例模式 */ static VssLocalSettingTblController *instance() { static VssLocalSettingTblController instance; return &instance; } public: /** 注册{label}http服务 */ void registerHttpServices(HttpSrvRetRecieve& _HttpSrvRetRecieve) { _HttpSrvRetRecieve.setInfo("^/addVssLocalSettingTbl$", "POST", std::bind(&VssLocalSettingTblController::addVssLocalSettingTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/delVssLocalSettingTbl$", "POST", std::bind(&VssLocalSettingTblController::delVssLocalSettingTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/updateVssLocalSettingTbl$", "POST", std::bind(&VssLocalSettingTblController::updateVssLocalSettingTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/findVssLocalSettingTbl$", "POST", std::bind(&VssLocalSettingTblController::findVssLocalSettingTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/findVssLocalSettingTblList$", "POST", std::bind(&VssLocalSettingTblController::findVssLocalSettingTblList, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); public: /** 注册{label}http服务 */ void registerHttpServices(HttpSrvRetRecieve &_HttpSrvRetRecieve) { _HttpSrvRetRecieve.setInfo("^/addVssLocalSettingTbl$", "POST", std::bind(&VssLocalSettingTblController::addVssLocalSettingTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/delVssLocalSettingTbl$", "POST", std::bind(&VssLocalSettingTblController::delVssLocalSettingTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/updateVssLocalSettingTbl$", "POST", std::bind(&VssLocalSettingTblController::updateVssLocalSettingTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/findVssLocalSettingTbl$", "POST", std::bind(&VssLocalSettingTblController::findVssLocalSettingTbl, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); _HttpSrvRetRecieve.setInfo("^/findVssLocalSettingTblList$", "POST", std::bind(&VssLocalSettingTblController::findVssLocalSettingTblList, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); } public: /** 添加本地国标配置 */ /** 添加本地国标配置 */ std::string addVssLocalSettingTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { DBG("ip:" << ip << "; port:" << port); DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; @@ -65,43 +70,43 @@ responseJsonValue["success"] = "false"; if (requestJsonReader.parse(content, requestJsonValue)) { VssLocalSettingTblBuilder vssLocalSettingTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addID(std::stoi(iDJsonValue.asString())); } Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; if (serverIpJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerIp(serverIpJsonValue.asString()); } Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; if (serverPortJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerPort(serverPortJsonValue.asString()); } Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; if (serverIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerId(serverIdJsonValue.asString()); } Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; if (userAuthIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUserAuthId(userAuthIdJsonValue.asString()); } Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; if (passwordJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addPassword(passwordJsonValue.asString()); } Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUpdateTime(updateTimeJsonValue.asString()); } auto keyValuesToAdd = vssLocalSettingTblBuilder.buildVssLocalSettingTblMap(); if (keyValuesToAdd.size() > 0) { auto keyValuesToAdd = vssLocalSettingTblBuilder.buildVssLocalSettingTblMap(); if (keyValuesToAdd.size() > 0) { responseJsonValue = VssLocalSettingTblSqliteDao::instance()->addVssLocalSettingTbl(keyValuesToAdd); } } @@ -110,16 +115,18 @@ /** 删除本地国标配置 */ std::string delVssLocalSettingTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { DBG("ip:" << ip << "; port:" << port); DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; responseJsonValue["message"] = "删除失败!"; responseJsonValue["success"] = "false"; if (requestJsonReader.parse(content, requestJsonValue)) { Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { string iDValue = iDJsonValue.asString(); responseJsonValue = VssLocalSettingTblSqliteDao::instance()->deleteByColumn("ID", iDValue); Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { string iDValue = iDJsonValue.asString(); responseJsonValue = VssLocalSettingTblSqliteDao::instance()->deleteByColumn("ID", iDValue); } } @@ -128,6 +135,8 @@ /** 更新本地国标配置 */ std::string updateVssLocalSettingTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { DBG("ip:" << ip << "; port:" << port); DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; @@ -136,43 +145,44 @@ if (requestJsonReader.parse(content, requestJsonValue)) { VssLocalSettingTblBuilder vssLocalSettingTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addID(std::stoi(iDJsonValue.asString())); } Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; if (serverIpJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerIp(serverIpJsonValue.asString()); } Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; if (serverPortJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerPort(serverPortJsonValue.asString()); } Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; if (serverIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerId(serverIdJsonValue.asString()); } Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; if (userAuthIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUserAuthId(userAuthIdJsonValue.asString()); } Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; if (passwordJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addPassword(passwordJsonValue.asString()); } Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUpdateTime(updateTimeJsonValue.asString()); } if (iDJsonValue.type() != Json::ValueType::nullValue) { string iDValue = iDJsonValue.asString(); responseJsonValue = VssLocalSettingTblSqliteDao::instance()->updateVssLocalSettingTbl(vssLocalSettingTblBuilder.buildVssLocalSettingTblMap(), "ID", iDValue); if (iDJsonValue.type() != Json::ValueType::nullValue) { string iDValue = iDJsonValue.asString(); responseJsonValue = VssLocalSettingTblSqliteDao::instance()->updateVssLocalSettingTbl( vssLocalSettingTblBuilder.buildVssLocalSettingTblMap(), "ID", iDValue); } } return responseJsonValue.toStyledString(); @@ -180,6 +190,8 @@ /** 查找单个本地国标配置 */ std::string findVssLocalSettingTbl(std::string ip, unsigned int port, std::string content, PResponse &response) { DBG("ip:" << ip << "; port:" << port); DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; @@ -188,49 +200,53 @@ if (requestJsonReader.parse(content, requestJsonValue)) { VssLocalSettingTblBuilder vssLocalSettingTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addID(std::stoi(iDJsonValue.asString())); } Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; if (serverIpJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerIp(serverIpJsonValue.asString()); } Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; if (serverPortJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerPort(serverPortJsonValue.asString()); } Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; if (serverIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerId(serverIdJsonValue.asString()); } Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; if (userAuthIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUserAuthId(userAuthIdJsonValue.asString()); } Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; if (passwordJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addPassword(passwordJsonValue.asString()); } Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUpdateTime(updateTimeJsonValue.asString()); } responseJsonValue["message"] = "查询成功!"; responseJsonValue["success"] = "true"; responseJsonValue = VssLocalSettingTblSqliteDao::instance()->findVssLocalSettingTblList(vssLocalSettingTblBuilder.buildVssLocalSettingTblMap()); responseJsonValue["message"] = "查询成功!"; responseJsonValue["success"] = "true"; responseJsonValue = VssLocalSettingTblSqliteDao::instance()->findVssLocalSettingTblList( vssLocalSettingTblBuilder.buildVssLocalSettingTblMap()); } return responseJsonValue.toStyledString(); } /** 查找本地国标配置列表 */ std::string findVssLocalSettingTblList(std::string ip, unsigned int port, std::string content, PResponse &response) { std::string findVssLocalSettingTblList(std::string ip, unsigned int port, std::string content, PResponse &response) { DBG("ip:" << ip << "; port:" << port); DBG("content: " << content); Json::Reader requestJsonReader; Json::Value requestJsonValue; Json::Value responseJsonValue; @@ -239,52 +255,49 @@ if (content == "" || requestJsonReader.parse(content, requestJsonValue)) { VssLocalSettingTblBuilder vssLocalSettingTblBuilder; Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; Json::Value iDJsonValue = requestJsonValue[VssLocalSettingTbl_ID]; if (iDJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addID(std::stoi(iDJsonValue.asString())); } Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; Json::Value serverIpJsonValue = requestJsonValue[VssLocalSettingTbl_ServerIp]; if (serverIpJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerIp(serverIpJsonValue.asString()); } Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; Json::Value serverPortJsonValue = requestJsonValue[VssLocalSettingTbl_ServerPort]; if (serverPortJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerPort(serverPortJsonValue.asString()); } Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; Json::Value serverIdJsonValue = requestJsonValue[VssLocalSettingTbl_ServerId]; if (serverIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addServerId(serverIdJsonValue.asString()); } Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; Json::Value userAuthIdJsonValue = requestJsonValue[VssLocalSettingTbl_UserAuthId]; if (userAuthIdJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUserAuthId(userAuthIdJsonValue.asString()); } Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; Json::Value passwordJsonValue = requestJsonValue[VssLocalSettingTbl_Password]; if (passwordJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addPassword(passwordJsonValue.asString()); } Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; Json::Value updateTimeJsonValue = requestJsonValue[VssLocalSettingTbl_UpdateTime]; if (updateTimeJsonValue.type() != Json::ValueType::nullValue) { vssLocalSettingTblBuilder.addUpdateTime(updateTimeJsonValue.asString()); } responseJsonValue["message"] = "查询成功!"; responseJsonValue["success"] = "true"; responseJsonValue = VssLocalSettingTblSqliteDao::instance()->findVssLocalSettingTblList(vssLocalSettingTblBuilder.buildVssLocalSettingTblMap()); responseJsonValue["message"] = "查询成功!"; responseJsonValue["success"] = "true"; responseJsonValue = VssLocalSettingTblSqliteDao::instance()->findVssLocalSettingTblList( vssLocalSettingTblBuilder.buildVssLocalSettingTblMap()); } return responseJsonValue.toStyledString(); } }; #endif //VSSLOCALSETTINGTBL_CONTROLLER_H QiaoJiaSystem/DataManagerServer/vss/dao/BaseDao.cpp
New file @@ -0,0 +1,3 @@ #include "BaseDao.h" mysqlpp::Connection* BaseDao::conn = nullptr; QMutex BaseDao::m_mutexVisit; QiaoJiaSystem/DataManagerServer/vss/dao/BaseDao.h
@@ -8,11 +8,15 @@ #include <iostream> #include <mysql++.h> #include <AppConfig.h> #include <QtCore/QMutex> using namespace std; static mysqlpp::Connection* conn; class BaseDao { public: static QMutex m_mutexVisit; private: static mysqlpp::Connection* conn; public: static mysqlpp::SimpleResult add(std::map<std::string, std::string>& columns, string tableName) { initConnection(); @@ -126,20 +130,20 @@ return updateSql; } static void doConnect() { // if (conn->connect( // appConfig.getStringProperty("database").c_str(), // appConfig.getStringProperty("db_host").c_str(), // appConfig.getStringProperty("db_user").c_str(), // appConfig.getStringProperty("db_password").c_str(), // appConfig.getIntProperty("db_port") // )) { if (conn->connect( "EGEyesForVSS", "127.0.0.1", "root", "123456", 3306 appConfig.getStringProperty("database").c_str(), appConfig.getStringProperty("db_host").c_str(), appConfig.getStringProperty("db_user").c_str(), appConfig.getStringProperty("db_password").c_str(), appConfig.getIntProperty("db_port") )) { // if (conn->connect( // "EGEyesForVSS", // "192.168.1.148", // "root", // "123456", // 3306 // )) { cout << "connect success" << endl; } else { cout << "connect failed" << endl; QiaoJiaSystem/DataManagerServer/vss/dao/BaseSqliteDao.cpp
New file @@ -0,0 +1,7 @@ #include "BaseSqliteDao.h" LDBTool* BaseSqliteDao::lDBTool = nullptr; QSqlDatabase* BaseSqliteDao::m_db = nullptr; QSqlTableModel *BaseSqliteDao::m_pModel = nullptr; QMutex* BaseSqliteDao::m_mutexVisit = nullptr; ErlangTool::ErlangDbTool *BaseSqliteDao::erlangDbTool = nullptr; QiaoJiaSystem/DataManagerServer/vss/dao/VssChannelTblDao.h
@@ -23,6 +23,7 @@ /** 添加创建二级设备表 keyValuesToAdd 需要添加的列名和列值对map*/ mysqlpp::SimpleResult addVssChannelTbl(std::map<std::string, std::string>& keyValuesToAdd) { QMutexLocker mutexLocker(&m_mutexVisit); return add(keyValuesToAdd, VSSChannelTbl_TABLE_NAME); } @@ -35,12 +36,14 @@ /** 删除创建二级设备表 whereColumnNameValues 列名和列值对条件 */ bool deleteVssChannelTbl(std::map<std::string, std::string>& whereKeyValues) { QMutexLocker mutexLocker(&m_mutexVisit); return del(VSSChannelTbl_TABLE_NAME, whereKeyValues); } /** 更新创建二级设备表 keyValuesToUpdate 需要更新的列名和列值对; whereKeyValues 列名和列值条件 */ bool updateVssChannelTbl(std::map<std::string, std::string>& keyValuesToUpdate, bool updateVssChannelTbl(std::map<std::string, std::string>& keyValuesToUpdate, std::map<std::string, std::string>& whereKeyValues) { QMutexLocker mutexLocker(&m_mutexVisit); return update(keyValuesToUpdate, VSSChannelTbl_TABLE_NAME, whereKeyValues); } @@ -55,6 +58,7 @@ /** 查询创建二级设备表列表 querySql 要查询的sql语句 */ vector<VssChannelTbl> findVssChannelTblList(string querySql) { QMutexLocker mutexLocker(&m_mutexVisit); vector<VssChannelTbl> vssChannelTblVec; vector<map<string, string>> rowDatList = findList(querySql); vssChannelTblVec.reserve(rowDatList.size()); @@ -81,6 +85,7 @@ /** 执行sql语句 */ bool execute(string sql) { QMutexLocker mutexLocker(&m_mutexVisit); return exec(move(sql)); } QiaoJiaSystem/DataManagerServer/vss/dao/VssDevTblDao.h
@@ -23,6 +23,7 @@ /** 添加创建一级设备表 keyValuesToAdd 需要添加的列名和列值对map*/ mysqlpp::SimpleResult addVssDevTbl(std::map<std::string, std::string>& keyValuesToAdd) { QMutexLocker mutexLocker(&m_mutexVisit); return add(keyValuesToAdd, VSSDevTbl_TABLE_NAME); } @@ -35,12 +36,14 @@ /** 删除创建一级设备表 whereColumnNameValues 列名和列值对条件 */ bool deleteVssDevTbl(std::map<std::string, std::string>& whereKeyValues) { QMutexLocker mutexLocker(&m_mutexVisit); return del(VSSDevTbl_TABLE_NAME, whereKeyValues); } /** 更新创建一级设备表 keyValuesToUpdate 需要更新的列名和列值对; whereKeyValues 列名和列值条件 */ bool updateVssDevTbl(std::map<std::string, std::string>& keyValuesToUpdate, std::map<std::string, std::string>& whereKeyValues) { QMutexLocker mutexLocker(&m_mutexVisit); return update(keyValuesToUpdate, VSSDevTbl_TABLE_NAME, whereKeyValues); } @@ -55,6 +58,7 @@ /** 查询创建一级设备表列表 querySql 要查询的sql语句 */ vector<VssDevTbl> findVssDevTblList(string querySql) { QMutexLocker mutexLocker(&m_mutexVisit); vector<VssDevTbl> vssDevTblVec; vector<map<string, string>> rowDatList = findList(querySql); vssDevTblVec.reserve(rowDatList.size()); @@ -76,11 +80,13 @@ /** 查询map列表 querySql 要查询的sql语句 */ vector<map<string, string>> findMapList(string querySql) { QMutexLocker mutexLocker(&m_mutexVisit); return findList(querySql); } /** 执行sql语句 */ bool execute(string sql) { QMutexLocker mutexLocker(&m_mutexVisit); return exec(move(sql)); } QiaoJiaSystem/GB28181DecoderModel/FFmpegDecoderJPG.cpp
@@ -44,7 +44,6 @@ } BASICGB28181::FFmpegDecoderJPG::~FFmpegDecoderJPG() { while (m_rtpQueue.count_queue()) { m_rtpQueue.popNotWait(); } @@ -65,10 +64,20 @@ info->buffLen = datalen; info->camIdx = camIdx; memcpy(info->buff, data, datalen); { // FILE *fp11 = NULL; // if (!fp11) { // fp11 = fopen(camIdx.c_str(), "a+"); // } // fwrite(data, sizeof(char), datalen, fp11); // fclose(fp11); } #ifdef TestCode DBG(" m_rtpQueue.push before "); #endif m_rtpQueue.push(info); m_rtpQueue. push(info); #ifdef TestCode DBG(" m_rtpQueue.push after "); #endif @@ -193,7 +202,7 @@ p_this->frame_number++; int err6 = avcodec_send_packet(ctx, &pkt); av_packet_unref(&pkt); // av_packet_unref(&pkt); int err7 = avcodec_receive_frame(ctx, frame); if ((err7 == AVERROR(EAGAIN)) || (err5 < 0) || (err6 < 0)) { ERR(" error << err7:" << err7 << " err5: " << err5 << " err6: " << err6); @@ -446,6 +455,7 @@ m_frameIndex++; m_packetsVec.push_back({m_frameIndex, newPacket}); if (newPacket.flags & AV_PKT_FLAG_KEY) { DBG("newPacket.flags & AV_PKT_FLAG_KEY "); m_last_I_FrameId = m_frameIndex; } } @@ -466,27 +476,27 @@ */ m_pOutVideo_stream = avformat_new_stream(m_pOutFmtCtx, NULL); { // AVCodecContext *c; // c = m_pOutVideo_stream->codec; // c->bit_rate = 400000; // c->codec_id = video_st->codec->codec_id; // c->codec_type = video_st->codec->codec_type; // c->time_base.num = video_st->time_base.num; // c->time_base.den = video_st->time_base.den; // fprintf(stderr, "time_base.num = %d time_base.den = %d\n", c->time_base.num, c->time_base.den); // c->width = video_st->codec->width; // c->height = video_st->codec->height; // c->pix_fmt = video_st->codec->pix_fmt; // printf("%d %d %d", c->width, c->height, c->pix_fmt); // c->flags = video_st->codec->flags; // c->flags |= CODEC_FLAG_GLOBAL_HEADER; // c->me_range = video_st->codec->me_range; // c->max_qdiff = video_st->codec->max_qdiff; // // c->qmin = video_st->codec->qmin; // c->qmax = video_st->codec->qmax; // // c->qcompress = video_st->codec->qcompress; AVCodecContext *c; c = m_pOutVideo_stream->codec; c->bit_rate = 400000; c->codec_id = video_st->codec->codec_id; c->codec_type = video_st->codec->codec_type; c->time_base.num = video_st->time_base.num; c->time_base.den = video_st->time_base.den; fprintf(stderr, "time_base.num = %d time_base.den = %d\n", c->time_base.num, c->time_base.den); c->width = video_st->codec->width; c->height = video_st->codec->height; c->pix_fmt = video_st->codec->pix_fmt; printf("%d %d %d", c->width, c->height, c->pix_fmt); c->flags = video_st->codec->flags; c->flags |= CODEC_FLAG_GLOBAL_HEADER; c->me_range = video_st->codec->me_range; c->max_qdiff = video_st->codec->max_qdiff; c->qmin = video_st->codec->qmin; c->qmax = video_st->codec->qmax; c->qcompress = video_st->codec->qcompress; } ret = avio_open(&m_pOutFmtCtx->pb, filename, AVIO_FLAG_WRITE); if (ret < 0) { @@ -494,7 +504,7 @@ return -1; } avformat_write_header(m_pOutFmtCtx, NULL); DBG(" avformat_write_header " << avformat_write_header(m_pOutFmtCtx, NULL)); m_bstartWrite = true; m_bFirstKeyFrame = true; QiaoJiaSystem/VideoAnalysFromHC/main.cpp
@@ -84,7 +84,7 @@ int arg1 = atoi(argv[1]); int gindx = abs(arg1) % 2; int GB28181_Enable = arg1 < 0 ? gindx : -1; int GB28181_Enable = arg1 < 0 ? 1 : -1; DBG(gindx); appPref.setIntData("GB28181_Enable", GB28181_Enable); QiaoJiaSystem/VideoToImageMulth/CMakeLists.txt
@@ -97,12 +97,14 @@ ) add_executable(${PROJECT_NAME} ./pushStream/PushStreamAppPipeController.cpp ../GB28181DecoderModel/FFmpegDecoderJPG.cpp ../GB28181DecoderModel/GB28181Server.cpp ../GB28181DecoderModel/VideoCaptureElementWithRtp.cpp ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp # ../../../BasicPlatForm/basic/pipe_element/ffmpeg/VideoChangeScore.cpp ../../../BasicPlatForm/basic/util/BASE64/Base64.cpp # ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp # ../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp ../VideoServer/QiaoJia/DB/LDBTool.cpp ./rpc/RtspAnalysServer.cpp RtspCaptureElement.cpp QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.cpp
@@ -165,9 +165,12 @@ m_imgRedisCRwLock.unlock(); //VideoCaptureElementWithRtp(std::string &chanPubID, int fps, int streamTransType, int gpuIdx = -1) m_controllers_videoCapElem[index] = new BASICGB28181::VideoCaptureElementWithRtp( const_cast<string &>(index), 25, 0, 0, this); // m_controllers_videoCapElem[index] = new BASICGB28181::VideoCaptureElementWithRtp( // const_cast<string &>(index), // 25, 0, 0, this); m_controllers_videoCapElem[index] = new PushStreamAppPipeController(const_cast<string &>(index), 25, 0, 0, this); m_controllers_videoCapElem[index]->SetVideoMinMaxSeconds(lst_dev.n_cut_min_duration, lst_dev.n_cut_max_duration); m_controllers_videoCapElem[index]->start(); @@ -310,7 +313,7 @@ auto pCaptureElem = m_controllers_videoCapElem.find(nameSt.m_camId); if (pCaptureElem != m_controllers_videoCapElem.end()) { //#todo ~~~~~~!!!!!!! 这里有bug 需要放开调试 // pCaptureElem->second->SaveVideo(name); pCaptureElem->second->SaveVideo(name); } else { ERR("Can not Find CamId " << nameSt.m_camId); } QiaoJiaSystem/VideoToImageMulth/RtspAnalysManager.h
@@ -9,7 +9,8 @@ #include <map> #include "RtspCaptureElement.h" #include "RtspImageRedis.h" #include "../GB28181DecoderModel/VideoCaptureElementWithRtp.h" //#include "../GB28181DecoderModel/VideoCaptureElementWithRtp.h" #include "pushStream/PushStreamAppPipeController.h" //#include <VideoCaptureElementWithRtp.h> #include <QiaoJia/DB/LDBTool.h> #include <basic/util/app/AppPreference.hpp> @@ -63,7 +64,8 @@ std::map<std::string, RtspCaptureElement *> m_controllers; //保存CamID和VideoCaptureElementWithRtp的映射关系 std::map<std::string, BASICGB28181::VideoCaptureElementWithRtp *> m_controllers_videoCapElem; // std::map<std::string, BASICGB28181::VideoCaptureElementWithRtp *> m_controllers_videoCapElem; std::map<std::string, PushStreamAppPipeController *> m_controllers_videoCapElem; //保存CamID和RtspImageRedisElement的映射关系 std::map<std::string, RtspImageRedisElement *> m_imgRedisControllers; QiaoJiaSystem/VideoToImageMulth/RtspCaptureElement.cpp
@@ -2,12 +2,13 @@ #include <basic/debug/Debug.h> #include <opencv2/opencv.hpp> #include <basic/timer_counter/Clocktimer.h> #include <basic/pipe_element/ffmpeg/cap_ffmpeg_impl.hpp> #include <thread> #include <basic/util/app/AppPreference.hpp> #include <QString> #include <QDateTime> #include "RtspAnalysManager.h" //#include <basic/pipe_element/ffmpeg/cap_ffmpeg_impl.hpp> #include "../../../BasicPlatForm/basic/pipe_element/ffmpeg/FfmpegElement.cpp" RtspCaptureElement::RtspCaptureElement(const std::string &path, const std::string &camId, int fps, int reopenTime, int gpuIndex, RtspAnalysManager *manager) : QiaoJiaSystem/VideoToImageMulth/main.cpp
@@ -62,11 +62,17 @@ if (argc < 4) { assert("t_value.size()"); } { // std::string rtmpAddr = appConfig.getStringProperty("srsAddr"); // std::string publish_basepath = rtmpAddr + "" ; // appPref.setStringData("publish.basepath", publish_basepath); appPref.setIntData("pulish.width", 640); appPref.setIntData("pulish.height", 360); } int arg1 = atoi(argv[1]); int gindx = abs(arg1) % 2; int GB28181_Enable = arg1 < 0 ? gindx : -1; int GB28181_Enable = arg1 < 0 ? 1 : 0; DBG(gindx); appPref.setIntData("GB28181_Enable", GB28181_Enable); QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.cpp
New file @@ -0,0 +1,50 @@ #include "PushStreamAppPipeController.h" #include <basic/util/app/AppPreference.hpp> #include <basic/util/app/AppUtil.h> //#include <sstream> #include <algorithm> #include <basic/util/app/AppConfig.h> PushStreamAppPipeController::PushStreamAppPipeController(std::string &chanPubID, int fps, int streamTransType, int gpuIdx, RtspAnalysManager *manager) : videoCaptureElement(chanPubID, fps, streamTransType, gpuIdx, manager), index(chanPubID), videoPublishElement(nullptr) { string path = appConfig.getStringProperty("srsAddr") + "cam" + chanPubID + ".flv"; cv::Size size_(appPref.getIntData("pulish.width"), appPref.getIntData("pulish.height")); int gupIdx = appPref.getLongData("gpu.index"); videoPublishElement = new ffmpeg::VideoPublishElement(path, size_, "flv", 25, gupIdx); if (appPref.getIntData("pulish.width") < 0 || appPref.getIntData("pulish.height") < 0) { ERR("pulish.width: " << appPref.getIntData("pulish.width") << " Height: " << appPref.getIntData("pulish.height")); } videoCaptureElement.registerConnector([&] { //if(!videoPublishElement.isBusy()){ videoPublishElement->setImage(videoCaptureElement.getImage()); //videoPublishElement.submit(); //} }); registerElement(videoCaptureElement); registerElement(*videoPublishElement); // videoCaptureElement.setOutPutInterval(3); } std::string PushStreamAppPipeController::getRtmp() { std::string ret = videoPublishElement->getPath(); size_t pos = ret.find(".flv"); ret = ret.substr(0, pos); INFO(ret); return ret; } void PushStreamAppPipeController::SaveVideo(const std::string &strImageName) { videoCaptureElement.SaveVideo(strImageName); } void PushStreamAppPipeController::SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds) { videoCaptureElement.SetVideoMinMaxSeconds(minSeconds, maxSeconds); } QiaoJiaSystem/VideoToImageMulth/pushStream/PushStreamAppPipeController.h
New file @@ -0,0 +1,29 @@ #ifndef PUSHSTREAMAPPPIPECONTROLLER_H #define PUSHSTREAMAPPPIPECONTROLLER_H #include <basic/pipe/PipeController.h> #include <basic/pipe_element/ffmpeg/FfmpegElement.h> #include <jsoncpp/json/json.h> #include "../GB28181DecoderModel/VideoCaptureElementWithRtp.h" class PushStreamAppPipeController : public PipeController { public: PushStreamAppPipeController(std::string &chanPubID, int fps, int streamTransType, int gpuIdx, RtspAnalysManager *manager); std::string getRtmp(); void SaveVideo(const std::string &strImageName); //设置保存视频的最小和最大长度,单位是秒,实际的运行情况有一些差距,需要完善 void SetVideoMinMaxSeconds(const int minSeconds, const int maxSeconds); private: BASICGB28181::VideoCaptureElementWithRtp videoCaptureElement; ffmpeg::VideoPublishElement* videoPublishElement; std::string index; }; #endif // PUSHSTREAMAPPPIPECONTROLLER_H QiaoJiaSystem/YoloServer/YoloDetectClientTest.cpp
@@ -75,12 +75,11 @@ appPref.setIntData("yolo.port", 10003); // rpcClient(appPref.getStringData("yolo.proxy"), appPref.getStringData("yolo.ip"), appPref.getLongData("yolo.port"),"tcp"), Controllor *_Controllor = new Controllor(1, "/home/bsk/210235C23NF187000045$2019-02-28-23-07-30_209850_210049.mp4"); Controllor *_Controllor = new Controllor(1, "/home/pans/work/qiaojia/cut/44120000001325000005/201903/06/2019030617/44120000001325000005$2019-03-06-17-51-53_4747_4946.mp4"); _Controllor->start(); getchar(); YoloRpcElement m_YoloRpcElement("YoloRpc");