#include "FromWebAPI.h" #include "GlobalVariable.h" #include "commonDefine.h" #include #include FromWebAPI::FromWebAPI() { m_logger = spdlog::get("FromWebAPI"); if(m_logger == nullptr) { fmt::print("FromWebAPI: Logger FromWebAPI not found\n"); return; } } FromWebAPI::~FromWebAPI() { } /* 获取数据库中的对比项信息 */ bool FromWebAPI::getCompareItemInfo(QList& listItems) { /* 先获取对比项信息 */ nJson json0; json0["opName"] = "ACAS_GetCompareItem"; QString strCmd1 = QString::fromStdString(json0.dump()); QString strRet1; int ret = m_httpApi->DBDoInterface(enDBOperatorType::EDBOT_Select, strCmd1, strRet1); if(ret != 0) { SPDLOG_LOGGER_ERROR(m_logger, "获取对比项信息失败,错误码: {}, 错误信息: {}", ret, m_httpApi->DoGetLastError(&ret).toStdString()); return false; } /* 再获取对比项的通道信息 */ nJson json1; json1["opName"] = "ACAS_GetCompareItemRoad"; QString strCmd2 = QString::fromStdString(json1.dump()); QString strRet2; ret = m_httpApi->DBDoInterface(enDBOperatorType::EDBOT_Select, strCmd2, strRet2); if(ret != 0) { SPDLOG_LOGGER_ERROR(m_logger, "获取对比项通道信息失败,错误码: {}, 错误信息: {}", ret, m_httpApi->DoGetLastError(&ret).toStdString()); return false; } /*---------------------------------- 解析对比项信息 ------------------------------*/ try { nJson jsonRet; /* 将json的key全部转换成小写 */ if(!convertJsonKeyToLower(nJson::parse(strRet1.toStdString()), jsonRet)) { SPDLOG_LOGGER_ERROR(m_logger, "转换JSON键名为小写失败"); return false; } int code = jsonRet["code"].get(); if(code != 0) { SPDLOG_LOGGER_ERROR(m_logger, "获取对比项信息失败,错误码: {}, 错误信息: {}", code, jsonRet["message"].get()); return false; } nJson jsonResult = jsonRet["result"]; for(const auto& item : jsonResult) { CompareItemInfo_t compareItem; compareItem.nID = item["itemid"].get(); compareItem.strName = QString::fromStdString(item["itemname"].get()); compareItem.isEnable = item["itemenable"].get(); compareItem.paramMute.isEnable = item["silentenable"].get(); compareItem.paramMute.nLen = item["silentduration"].get(); compareItem.paramMute.threshold.nThreshold = item["silentthreshold"].get(); compareItem.paramMute.nSensibility = item["silentsensibility"].get(); compareItem.paramOverload.isEnable = item["overloadenable"].get(); compareItem.paramOverload.nLen = item["overloadduration"].get(); compareItem.paramOverload.threshold.nThreshold = item["overloadthreshold"].get(); compareItem.paramOverload.nSensibility = item["overloadsensibility"].get(); compareItem.paramPhase.isEnable = item["phaseenable"].get(); compareItem.paramPhase.nLen = item["phaseduration"].get(); compareItem.paramPhase.threshold.dThreshold = item["phasethreshold"].get(); compareItem.paramPhase.nSensibility = item["phasesensibility"].get(); listItems.append(compareItem); } }nJsonCatch /*---------------------------------- 解析对比项录音通道信息 ------------------------------*/ try { /* 将json的key全部转换成小写 */ nJson jsonRet; if(!convertJsonKeyToLower(nJson::parse(strRet1.toStdString()), jsonRet)) { SPDLOG_LOGGER_ERROR(m_logger, "转换JSON键名为小写失败"); return false; } int code = jsonRet["code"].get(); if(code != 0) { SPDLOG_LOGGER_ERROR(m_logger, "获取对比项通道信息失败,错误码: {}, 错误信息: {}", code, jsonRet["message"].get()); return false; } nJson jsonResult = jsonRet["result"]; /* 使用迭代器获取对比项信息 */ auto it = listItems.begin(); for(const auto& item : jsonResult) { CompareItemRoadInfo_t roadInfo; int itemID = item["itemid"].get(); roadInfo.nCompareRoadNum = item["roadnum"].get(); roadInfo.strCompareRoadName = QString::fromStdString(item["roadname"].get()); roadInfo.isEnableRecord = item["roadrecordenable"].get(); roadInfo.scRoadInfo.nSoundCardNum = item["soundcardnum"].get(); roadInfo.scRoadInfo.strSoundCardID = QString::fromStdString(item["soundcardid"].get()); roadInfo.scRoadInfo.strSoundCardName = QString::fromStdString(item["soundcardname"].get()); roadInfo.scRoadInfo.roadInfo.nRoadNum = item["soundcardroadnum"].get(); roadInfo.scRoadInfo.roadInfo.nChannelID = item["chnannelid"].get(); roadInfo.scRoadInfo.roadInfo.strChannelName = QString::fromStdString(item["channelname"].get()); /* 如果这个通道是当前迭代器的,就直接插入,如果不是则重新寻找 */ if(it->nID == itemID) { it->listRoads.append(roadInfo); }else { for(it = listItems.begin(); it != listItems.end(); ++it) { if(it->nID == itemID) { it->listRoads.append(roadInfo); break; } } } } }nJsonCatch return true; } /* 添加对比项信息 */ bool FromWebAPI::insertCompareItem(const QList& listItems) { /*---------------------------------- 插入对比项信息 ------------------------------*/ try { int key = 1; nJson jsonArray = nJson::array(); for(const auto& item : listItems) { nJson json0; json0["opName"] = "ACAS_InsertCompareItem"; json0["Key"] = key++; nJson jsonItem; jsonItem["itemID"] = item.nID; jsonItem["itemName"] = item.strName.toStdString(); jsonItem["itemEnable"] = item.isEnable; jsonItem["roadCount"] = item.listRoads.size(); jsonItem["silentEnable"] = item.paramMute.isEnable; jsonItem["silentDuration"] = item.paramMute.nLen; jsonItem["silentThreshold"] = item.paramMute.threshold.nThreshold; jsonItem["silentSensibility"] = item.paramMute.nSensibility; jsonItem["overloadEnable"] = item.paramOverload.isEnable; jsonItem["overloadDuration"] = item.paramOverload.nLen; jsonItem["overloadThreshold"] = item.paramOverload.threshold.nThreshold; jsonItem["overloadSensibility"] = item.paramOverload.nSensibility; jsonItem["phaseEnable"] = item.paramPhase.isEnable; jsonItem["phaseDuration"] = item.paramPhase.nLen; jsonItem["phaseThreshold"] = item.paramPhase.threshold.dThreshold; jsonItem["phaseSensibility"] = item.paramPhase.nSensibility; json0["paramList"] = jsonItem; jsonArray.push_back(json0); } QString strSend = QString::fromStdString(jsonArray.dump()); QString strRet; int ret = m_httpApi->DBDoInterface(enDBOperatorType::EDBOT_BatchTransAction, strSend, strRet); if(ret != 0) { SPDLOG_LOGGER_ERROR(m_logger, "添加对比项信息失败,错误码: {}, 错误信息: {}", ret, m_httpApi->DoGetLastError(&ret).toStdString()); return false; } }nJsonCatch try { int Key = 1; nJson jsonArray = nJson::array(); for(const auto& item : listItems) { for(const auto& road : item.listRoads) { nJson json1; json1["opName"] = "ACAS_InsertCompareItemRoad"; json1["Key"] = Key++; nJson jsonRoad; jsonRoad["itemID"] = item.nID; jsonRoad["roadNum"] = road.nCompareRoadNum; jsonRoad["roadName"] = road.strCompareRoadName.toStdString(); jsonRoad["roadRecordEnable"] = road.isEnableRecord; jsonRoad["soundCardNum"] = road.scRoadInfo.nSoundCardNum; jsonRoad["soundCardID"] = road.scRoadInfo.strSoundCardID.toStdString(); jsonRoad["soundCardName"] = road.scRoadInfo.strSoundCardName.toStdString(); jsonRoad["soundCardRoadNum"] = road.scRoadInfo.roadInfo.nRoadNum; jsonRoad["channelID"] = road.scRoadInfo.roadInfo.nChannelID; jsonRoad["channelName"] = road.scRoadInfo.roadInfo.strChannelName.toStdString(); json1["paramList"] = jsonRoad; jsonArray.push_back(json1); } } QString strSend = QString::fromStdString(jsonArray.dump()); QString strRet; int ret = m_httpApi->DBDoInterface(enDBOperatorType::EDBOT_BatchTransAction, strSend, strRet); if(ret != 0) { SPDLOG_LOGGER_ERROR(m_logger, "添加对比项通道信息失败,错误码: {}, 错误信息: {}", ret, m_httpApi->DoGetLastError(&ret).toStdString()); return false; } }nJsonCatch return true; } /* 修改对比项信息 */ bool FromWebAPI::updateCompareItem(const QList& listItems) { return true; } /* 删除对比项信息 */ bool FromWebAPI::deleteCompareItem(QList listIDs) { return true; }