12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022 |
- #include "ToEQMDataBase.h"
- #include <QJsonDocument>
- #include <QJsonObject>
- #include <QVector>
- #include <QString>
- ToEQMDataBase::ToEQMDataBase()
- {
- m_logger = spdlog::get("ToEQMDataBase");
- if(m_logger == nullptr)
- {
- SPDLOG_ERROR("ToEQMDataBase logger is nullptr");
- return;
- }
- }
- ToEQMDataBase::~ToEQMDataBase()
- {
- if(m_httpApi != nullptr)
- {
- delete m_httpApi;
- m_httpApi = nullptr;
- }
- }
- /* 初始化WebApi */
- bool ToEQMDataBase::initWebApi(const QString& url, const QString& serverIP, const QString& serID)
- {
- if(m_httpApi == nullptr)
- {
- m_httpApi = new lhhttpapi;
- }
- int ret = 0;
- ret = m_httpApi->DBQInit(url);
- if(ret < 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"Init WebApi failed:{}, error Info:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- // SPDLOG_LOGGER_TRACE(m_logger,"初始化WebApi成功!");
- QString serverList;
- ret = m_httpApi->DBQGetServerList(serverList);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"Get server list failed:{}, error info:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- SPDLOG_LOGGER_TRACE(m_logger,"Server list:{}",serverList.toStdString());
- SPDLOG_LOGGER_DEBUG(m_logger,"WebAPI Sucess!");
- /* 登录,第二个参数是限制的服务 */
- ret = m_httpApi->DBQLogin(serverIP, serID, "SPSS", m_userToken);
- if(ret < 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"Login failed:{}, error info:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- SPDLOG_LOGGER_TRACE(m_logger,"Login sucess!");
- return true;
- }
- /**
- * @brief 写入算法信息,写入tAction表
- *
- * @param vecInfo 要写入的表格数据
- * @param vecNowInfo 现有的表格数据,主要是为了重复利用已经删除的自增主键而传入的
- * @return true
- * @return false
- */
- bool ToEQMDataBase::writeAlgorithmInfo(std::vector<AlgorithmInfo>& vecInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- /* 取出可用的自增主键,从0开始计算 */
- // std::list<int> listPKID;
- // int nPKID = 0;
- // for(const auto& it : vecNowInfo)
- // {
- // while(it.ActionTaskID == nPKID)
- // {
- // if(it.PKID != nPKID)
- // {
- // listPKID.push_back(nPKID);
- // break;
- // }
- // nPKID ++;
- // }
- // }
- /* 循环写入数据 */
- for(const auto& it : vecInfo)
- {
- QString retStr;
- /* 操作名称,现在一次性将设备位置和线条信息都下载下来 */
- nJson json0;
- json0["opName"] = "SPSS_InsertToAction";
- nJson json1;
- json1["actionID"] = it.ActionID; /* 算法ID */
- json1["actionName"] = it.ActionName; /* 算法名称 */
- json1["actionTaskID"] = it.ActionTaskID; /* 算法类型 */
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- int ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, retStr);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"写入tAction失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"写入一条算法 {} 到 tAction成功!", it.ActionID);
- }
- return true;
- }
- /* 删除算法信息 */
- bool ToEQMDataBase::deleteAlgorithmInfo(std::vector<AlgorithmInfo>& vecDeleteInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- for(const auto& it : vecDeleteInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_DeleteFromAction";
- nJson json1;
- json1["actionID"] = it.ActionID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- int ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Delete, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"删除tAction失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"从tAction 删除算法 {} 成功!", it.ActionID);
- }
- return true;
- }
- /* 获取tAction数据 */
- bool ToEQMDataBase::getAlgorithmInfo(std::vector<AlgorithmInfo>& vecInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger, "WebAPI is nullptr");
- return false;
- }
- /* 清空内容 */
- vecInfo.clear();
- nJson json0;
- json0["opName"] = "SPSS_SelectFromAction";
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"获取tAction失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- /* 解析获取到的JSON数据 */
- // SPDLOG_LOGGER_DEBUG(m_logger,"\n{}",strRet.toStdString());
- try {
- nJson json1 = nJson::parse(strRet.toStdString());
- int retCode = json1["code"].get<int>();
- if(retCode != 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"获取tAction失败");
- return false;
- }
- nJson result = json1["result"];
- for(auto& it : result)
- {
- AlgorithmInfo info;
- info.ActionID = it["actionId"].is_null() ? "" : it["actionId"].get<std::string>();
- info.ActionName = it["actionName"].get<std::string>();
- info.ActionTaskID = it["actionTaskid"].get<int>();
- // SPDLOG_LOGGER_DEBUG(m_logger,"ActionID:{}, ActionName:{}, ActionTaskID:{}",info.ActionID,info.ActionName,info.ActionTaskID);
- vecInfo.push_back(info);
- }
- } catch (const nJson::parse_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析tAction数据失败:{}",e.what());
- return false;
- }
- return true;
- }
- /* 插入设备信息 */
- bool ToEQMDataBase::insertDeviceInfo(std::vector<DeviceInfo>& vecInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- if(vecInfo.empty())
- {
- return false;
- }
- bool isSuccess = true;
- for(const auto& it : vecInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_InsertToCamerInfo";
- nJson json1;
- /* 这里不知道是不是“?”运算符的等级是不是不够,不加括号会报错 */
- json1["camerID"] = it.DeviceID;
- json1["camerName"] = it.DeviceName;
- json1["camerIP"] = it.DeviceIP;
- json1["camerPort"] = it.DevicePort;
- json1["camerUser"] = it.UserAccount;
- json1["camerPwd"] = it.UserPassword;
- json1["camerType"] = it.DeviceType;
- json1["camerSerial"] = it.DeviceSerial;
- json1["camerChannel"] = nullptr;
- json1["camerUrl"] = nullptr;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"插入设备信息失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- isSuccess = false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"插入ID {} 信息到 CamerInfo 成功!", it.DeviceID);
- }
- /* 插入信息到tActionCamer表 */
- for(const auto& it0 : vecInfo)
- {
- for(const auto& it1 : it0.vecAlgorithmInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_InsertToActionCamer";
- nJson json1;
- json1["actionID"] = it1.ActionID;
- json1["camerID"] = it0.DeviceID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"插入设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- isSuccess = false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"插入DeviceID {} 和 ActionID {} 到 ActionCamer 成功!", it0.DeviceID, it1.ActionID);
- }
- }
- return isSuccess;
- }
- /* 更新设备信息 */
- bool ToEQMDataBase::updateDeviceInfo(std::vector<DeviceInfo>& vecUpdateInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- if(vecUpdateInfo.empty())
- {
- return false;
- }
- bool isSuccess = true;
- for(const auto& it : vecUpdateInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_UpdateToCamerInfo";
- nJson json1;
- json1["camerID"] = it.DeviceID;
- json1["camerName"] = it.DeviceName;
- json1["camerIP"] = it.DeviceIP;
- json1["camerPort"] = it.DevicePort;
- json1["camerUser"] = it.UserAccount;
- json1["camerPwd"] = it.UserPassword;
- json1["camerType"] = it.DeviceType;
- json1["camerSerial"] = it.DeviceSerial;
- json1["camerChannel"] = nullptr;
- json1["camerUrl"] = nullptr;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Update, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"更新设备信息失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- isSuccess = false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"更新ID {} 信息到 CamerInfo 成功!", it.DeviceID);
- }
- return isSuccess;
- }
- /* 删除设备信息 */
- bool ToEQMDataBase::deleteDeviceInfo(std::vector<DeviceInfo>& vecDeleteInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- if(vecDeleteInfo.empty())
- {
- return false;
- }
- bool isSuccess = true;
- for(const auto& it : vecDeleteInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_DeleteFromCamerInfo";
- nJson json1;
- json1["camerID"] = it.DeviceID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Delete, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"删除设备信息失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- isSuccess = false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"删除数据 {} 到 CamerInfo 成功!", it.DeviceID);
- }
- return isSuccess;
- }
- /* 从EQM获取CamerInfo信息 */
- bool ToEQMDataBase::getDeviceInfo(std::vector<DeviceInfo>& vecInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- vecInfo.clear();
- nJson json0;
- json0["opName"] = "SPSS_SelectFromCamerInfo";
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"获取CamerInfo失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- /* 解析信息 */
- try {
- nJson json1 = nJson::parse(strRet.toStdString());
- int retCode = json1["code"].get<int>();
- if(retCode != 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"获取CamerInfo失败");
- return false;
- }
- nJson result = json1["result"];
- if(result.empty())
- {
- return false;
- }
- for(const auto& it : result)
- {
- // SPDLOG_LOGGER_DEBUG(m_logger,"camerID:{}",it["camerId"].get<int>());
- DeviceInfo info;
- info.DeviceID = it["camerId"].get<int>();
- info.DeviceName = it["camerName"].is_null() ? "" : it["camerName"].get<std::string>();
- info.DeviceIP = it["camerIp"].is_null() ? "" : it["camerIp"].get<std::string>();
- info.DevicePort = it["camerPort"].is_null() ? 0 : it["camerPort"].get<int>();
- info.UserAccount = it["camerUsr"].is_null() ? "" : it["camerUsr"].get<std::string>();
- info.UserPassword = it["camerPwd"].is_null() ? "" : it["camerPwd"].get<std::string>();
- info.DeviceType = it["camerType"].is_null() ? "" : it["camerType"].get<std::string>();
- info.DeviceSerial = it["camerSerial"].is_null() ? "" : it["camerSerial"].get<std::string>();
-
- vecInfo.push_back(info);
- }
- }
- catch (const nJson::parse_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析CamerInfo数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- catch (const nJson::type_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析CamerInfo数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- return true;
- }
- /* 插入设备和算法关联信息 */
- bool ToEQMDataBase::insertDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- /* 插入信息到tActionCamer表 */
- bool isSuccess = true;
- for(const auto& it0 : vecInfo)
- {
- for(const auto& it1 : it0.vecAlgorithmInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_InsertToActionCamer";
- nJson json1;
- json1["actionID"] = it1.ActionID;
- json1["camerID"] = it0.DeviceID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"插入设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- isSuccess = false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"插入DeviceID {} 和 ActionID {} 到 ActionCamer 成功!", it0.DeviceID, it1.ActionID);
- }
- }
- return true;
- }
- /* 更新设备和算法关联表 */
- bool ToEQMDataBase::updateDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- /* 更新之前先删除相关的信息 */
- for(const auto& it : vecInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_DeleteFromActionCamer";
- nJson json1;
- json1["camerID"] = it.DeviceID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Delete, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"删除设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- // return false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"从 ActionCamer 删除DeviceID {} 成功!", it.DeviceID);
- }
- /* 插入信息到tActionCamer表 */
- bool isSuccess = true;
- for(const auto& it0 : vecInfo)
- {
- for(const auto& it1 : it0.vecAlgorithmInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_InsertToActionCamer";
- nJson json1;
- json1["actionID"] = it1.ActionID;
- json1["camerID"] = it0.DeviceID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"插入设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- isSuccess = false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"插入DeviceID {} ActionID {} 到 ActionCamer 成功!", it0.DeviceID, it1.ActionID);
- }
- }
- return isSuccess;
- }
- /* 删除设备和算法关联表 */
- bool ToEQMDataBase::deleteDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- bool isSuccess = true;
- /* 更新之前先删除相关的信息 */
- for(const auto& it : vecInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_DeleteFromActionCamer";
- nJson json1;
- json1["camerID"] = it.DeviceID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Delete, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"删除设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- // return false;
- isSuccess = false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"从 ActionCamer 删除DeviceID {} 成功!", it.DeviceID);
- }
- return isSuccess;
- }
- /* 删除设备和算法关联表 */
- bool ToEQMDataBase::deleteDeviceAlgorithmInfo(std::list<int>& vecID)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- bool isSuccess = true;
- /* 更新之前先删除相关的信息 */
- for(const auto& it : vecID)
- {
- nJson json0;
- json0["opName"] = "SPSS_DeleteFromActionCamer";
- nJson json1;
- json1["camerID"] = it;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Delete, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"删除设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- // return false;
- isSuccess = false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"从 ActionCamer 删除DeviceID {} 成功!", it);
- }
- return isSuccess;
- }
- /* 获取设备和算法信息关联表,需要先从EQM数据库中获取到设备信息 */
- bool ToEQMDataBase::getDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo, std::list<int>& listDevIDDelete)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- if(vecInfo.empty())
- {
- SPDLOG_LOGGER_WARN(m_logger,"Device info is empty");
- return false;
- }
- listDevIDDelete.clear();
- nJson json0;
- json0["opName"] = "SPSS_SelectFromActionCamer";
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"获取ActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- /* 设备和算法关联信息容器 */
- std::vector<DeviceAlgorithmInfo> vecNewInfo;
- /* 解析信息 */
- try {
- nJson json1 = nJson::parse(strRet.toStdString());
- int retCode = json1["code"].get<int>();
- if(retCode != 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"获取ActionCamer失败");
- return false;
- }
- nJson result = json1["result"];
- if(result.empty())
- {
- return false;
- }
- /* 取出所有的设备算法信息 */
-
- for(const auto& it : result)
- {
- DeviceAlgorithmInfo info;
- info.DeviceID = it["camerId"].get<int>();
- info.ActionID = it["actionId"].is_null() ? "" : it["actionId"].get<std::string>();
- info.ActionName = it["actionName"].is_null() ? "" : it["actionName"].get<std::string>();
- info.ActionTaskID = it["actionTaskid"].is_null() ? 0 : it["actionTaskid"].get<int>();
- vecNewInfo.push_back(info);
- }
- }
- catch (const nJson::parse_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析ActionCamer数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- catch (const nJson::type_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析ActionCamer数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- /* 根据缓存中的设备ID取出关联的算法 */
- for(auto& it0 : vecInfo)
- {
- for(auto& it1 : vecNewInfo)
- {
- /* 对比设备ID */
- if(it0.DeviceID == it1.DeviceID)
- {
- AlgorithmInfo info;
- info.ActionID = it1.ActionID;
- info.ActionName = it1.ActionName;
- info.ActionTaskID = it1.ActionTaskID;
- it0.vecAlgorithmInfo.push_back(info);
- }
- }
- }
- /* 取出关联表中已经消失的设备ID,在本轮循环中删除 */
- for(const auto& it : vecNewInfo)
- {
- bool isExist = false;
- for(const auto& it0 : vecInfo)
- {
- if(it.DeviceID == it0.DeviceID)
- {
- isExist = true;
- break;
- }
- }
- if(!isExist)
- {
- /* 检查是否重复,一个ID只需要记录一次 */
- if(std::find(listDevIDDelete.begin(), listDevIDDelete.end(), it.DeviceID) == listDevIDDelete.end())
- {
- listDevIDDelete.push_back(it.DeviceID);
- }
- }
- }
- return true;
- }
- /* 获取设备和算法关联信息,包括频率信息,房间信息,重载版,只获取关联关系 */
- bool ToEQMDataBase::getActionInfo(ListActionInfo& listInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- listInfo.clear();
- nJson json0;
- json0["opName"] = "SPSS_SelectFromActionInfo";
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"获取ActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- /* 解析信息 */
- try
- {
- nJson json1 = nJson::parse(strRet.toStdString());
- int retCode = json1["code"].get<int>();
- if(retCode != 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"获取ActionCamer失败");
- return false;
- }
- nJson result = json1["result"];
- if(result.empty())
- {
- return false;
- }
- /* 取出所有的设备算法信息 */
- for(const auto& it : result)
- {
- ActionInfo info;
- info.CameraID = it["camerId"].is_null() ? -1 : it["camerId"].get<int>();
- info.ActionID = it["actionId"].is_null() ? "" : it["actionId"].get<std::string>();
- info.RoomID = it["roomId"].is_null() ? -1 : it["roomId"].get<int>();
- info.ChannelID = it["chnid"].is_null() ? -1 : it["chnid"].get<int>();
- info.RoomType = it["rtype"].is_null() ? -1 : it["rtype"].get<int>();
- info.strRoomName = it["rname"].is_null() ? "" : it["rname"].get<std::string>();
- listInfo.insertActionInfo(&info);
- }
- }
- catch (const nJson::parse_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析ActionCamer数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- catch (const nJson::type_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析ActionCamer数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- return true;
- }
- /* 获取摄像机和房间关联信息 */
- bool ToEQMDataBase::getRoomCameraInfo(std::list<RoomCameraInfo>& vecInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- vecInfo.clear();
- nJson json0;
- json0["opName"] = "SPSS_SelectRoomCamer";
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"获取RoomCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- try
- {
- nJson json1 = nJson::parse(strRet.toStdString());
- int retCode = json1["code"].get<int>();
- if(retCode != 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"获取RoomCamer失败");
- return false;
- }
- nJson result = json1["result"];
- if(result.empty())
- {
- return false;
- }
- for(const auto& it : result)
- {
- auto roomID = it["roomId"].get<int>();
- auto cameraID = it["camerId"].is_null() ? -1 : it["camerId"].get<int>();
- /* 先检查RoomID是否已经在列表中了 */
- bool isExist = false;
- for(auto& it0 : vecInfo)
- {
- if(it0.RoomID == roomID)
- {
- it0.listCameraID.push_back(cameraID);
- isExist = true;
- break;
- }
- }
- /* 没有找到RoomID,创建一个新的 */
- if(!isExist)
- {
- RoomCameraInfo info;
- info.RoomID = roomID;
- info.listCameraID.push_back(cameraID);
- }
- }
- }
- catch (const nJson::parse_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析ActionCamer数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- catch (const nJson::type_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析ActionCamer数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- return true;
- }
- /* 写入报警信息 */
- bool ToEQMDataBase::insertAlarmInfo(const AlarmInfo& alarmInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- nJson json0;
- json0["opName"] = "SPSS_InsertToAlarmInfo";
- nJson json1;
- json1["AlarmID"] = alarmInfo.AlarmID;
- json1["StartTime"] = alarmInfo.StartTime;
- json1["CreateTime"] = alarmInfo.EventTime;
- json1["EndTime"] = alarmInfo.EndTime;
- json1["bBox"] = alarmInfo.BboxList;
- json1["PicUrl"] = alarmInfo.PicUrl;
- json1["AppID"] = alarmInfo.AppID;
- json1["ActionID"] = alarmInfo.ActionID;
- json1["ActionDes"] = alarmInfo.ActionDes;
- json1["CamerID"] = alarmInfo.DeviceID;
- json1["RoomID"] = alarmInfo.RoomID;
- json1["chnID"] = alarmInfo.ChannelID;
- json1["Stat"] = alarmInfo.State;
- json0["FaceIDList"] = alarmInfo.FaceIDList;
- json0["FaceNameList"] = alarmInfo.FaceNameList;
- json0["OnWork"] = alarmInfo.OnWork;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_WARN(m_logger,"插入报警信息失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"插入报警信息成功!");
- return true;
- }
- /* 更新报警结束时间 */
- bool ToEQMDataBase::updateAlarmEndTime(const AlarmInfo& alarmInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- nJson json0;
- json0["opName"] = "SPSS_UpdateAlarmEndTime";
- nJson json1;
- json1["EndTime"] = alarmInfo.EndTime;
- json1["ChannelID"] = alarmInfo.ChannelID;
- json1["RoomID"] = alarmInfo.RoomID;
- json1["CamerID"] = alarmInfo.DeviceID;
- json1["ActionID"] = alarmInfo.ActionID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- int ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Update, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_WARN(m_logger,"更新报警结束时间失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- return true;
- }
- /* 获取报警规则表 */
- bool ToEQMDataBase::getAlarmRuleInfo(std::vector<AlarmRuleInfo>& vecInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_SelectFromAlarmRule";
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"获取AlarmRule失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- try
- {
- nJson json1 = nJson::parse(strRet.toStdString());
- int retCode = json1["code"].get<int>();
- if(retCode != 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"获取tAlarmRule失败");
- return false;
- }
- nJson result = json1["result"];
- if(result.empty())
- {
- return false;
- }
- for(const auto& it : result)
- {
- AlarmRuleInfo info;
- info.RuleName = it["ruleName"].get<std::string>();
- info.LiveMinEnable = it["liveMinEnable"].get<bool>();
- info.LiveMaxEnable = it["liveMaxEnable"].get<bool>();
- info.DicMinEnable = it["dicMinEnable"].get<bool>();
- info.DicMaxEnable = it["dicMaxEnable"].get<bool>();
- info.LiveDicMinEnable = it["liveDicMinEnable"].get<bool>();
- info.LiveDicMaxEnable = it["liveDicMaxEnable"].get<bool>();
- info.LiveMin = it["liveMin"].get<int>();
- info.LiveMax = it["liveMax"].get<int>();
- info.DicMin = it["dicMin"].get<int>();
- info.DicMax = it["dicMax"].get<int>();
- info.LiveDicMin = it["liveDicMin"].get<int>();
- info.LiveDicMax = it["liveDicMax"].get<int>();
- vecInfo.push_back(info);
- }
- }
- catch (const nJson::parse_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析AlarmRule数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- catch(const nJson::type_error& e)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"解析AlarmRule数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- return true;
- }
- /* 获取报警时段,也同时获取报警的应用信息 */
- bool ToEQMDataBase::getAlarmAppInfo(std::list<AppAndTimeInfo>& listInfo)
- {
- nJson json0;
- json0["opName"] = "SPSS_SelectPeriod";
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_DEBUG(m_logger,"获取AlarmApp失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- try
- {
- nJson json1 = nJson::parse(strRet.toStdString());
- int retCode = json1["code"].get<int>();
- if(retCode != 0)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"获取tAlarmApp失败");
- return false;
- }
- nJson result = json1["result"];
- if(result.empty())
- {
- return false;
- }
- listInfo.clear();
- for(const auto& it : result)
- {
- AppAndTimeInfo info;
- info.ChannelID = it["chnId"].get<int>();
- info.AppType = it["appType"].get<int>();
- QString strStart = QString::fromStdString(it["startTime"].get<std::string>());
- QString strEnd = QString::fromStdString(it["endTime"].get<std::string>());
- info.StartTime = QDateTime::fromString(strStart, "yyyy-MM-ss hh:mm:ss");
- info.EndTime = QDateTime::fromString(strEnd, "yyyy-MM-ss hh:mm:ss");
- listInfo.push_back(info);
- }
- }
- catch (const nJson::parse_error& e) {
- SPDLOG_LOGGER_ERROR(m_logger,"解析AlarmApp数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- catch(const nJson::type_error& e)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"解析AlarmApp数据失败:{}, 错误ID:{}",e.what(), e.id);
- return false;
- }
- return true;
- }
- /* 写入在岗信息 */
- bool ToEQMDataBase::insertOnWorkInfo(const RoomFaceInfo& onWorkInfo)
- {
- if(m_httpApi == nullptr)
- {
- SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
- return false;
- }
- nJson json0;
- json0["opName"] = "SPSS_InsertToOnWork";
- nJson json1;
- json1["nChID"] = onWorkInfo.ChannelID;
- json1["RoomID"] = onWorkInfo.RoomID;
- json1["FaceID"] = onWorkInfo.FaceID;
- json1["StartTime"] = onWorkInfo.StartTime;
- json1["EndTime"] = onWorkInfo.EndTime;
-
- json1["CamerID"] = onWorkInfo.DeviceID;
- json1["ActionID"] = onWorkInfo.ActionID;
- json0["paramList"] = json1;
- QString strCmd = QString::fromStdString(json0.dump());
- QString strRet;
- auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
- if(ret < 0)
- {
- SPDLOG_LOGGER_WARN(m_logger,"插入在岗信息失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
- return false;
- }
- SPDLOG_LOGGER_DEBUG(m_logger,"插入在岗信息成功!");
- return true;
- }
|