#include "FromWebAPI.h" FromEQM::FromEQM() { } FromEQM::~FromEQM() { if(m_httpApi != nullptr) { delete m_httpApi; m_httpApi = nullptr; } } /* 初始化WebApi */ bool FromEQM::initWebApi(const QString& url, const QString& serverIP, const QString& serID) { if(m_httpApi == nullptr) { m_httpApi = new lhhttpapi; } if(!m_httpApi->Load()) { SPDLOG_ERROR("Load WebApi failed"); return false; } int ret = 0; auto pHttp = m_httpApi->DBInit(url.toStdString().c_str(), true); // 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; char serverList[8192] = {0}; ret = m_httpApi->DBGetServerList(serverList, 8192-1); if(ret < 0) { SPDLOG_ERROR("Get server list failed:{}, error info:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString()); // return false; } // SPDLOG_LOGGER_TRACE(m_logger,"Server list:{}",serverList.toStdString()); SPDLOG_DEBUG("WebAPI Sucess!"); /* 登录,第二个参数是限制的服务 */ ret = m_httpApi->DBLogin(serverIP, serID, "SPSC", m_userToken, true, pHttp); if(ret < 0) { SPDLOG_ERROR("WebAPI Login failed:{}, error info:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString()); return false; } SPDLOG_INFO("WebAPI Login sucess!"); return true; } bool FromEQM::test() { if(m_httpApi == nullptr) { SPDLOG_ERROR("WebAPI is nullptr"); return false; } nJson json0 = nJson::array(); nJson jsonData1; jsonData1["opName"] = "SPSC_test"; jsonData1["Key"] = 1; nJson jsonParam1; jsonParam1["pkid"] = 2807; jsonData1["paramList"] = jsonParam1; json0.push_back(jsonData1); nJson jsonData2; jsonData2["opName"] = "SPSC_test"; // jsonData2["Key"] = 2; nJson jsonParam2; jsonParam2["pkid"] = 2808; jsonData2["paramList"] = jsonParam2; json0.push_back(jsonData2); SPDLOG_INFO("json: {}", jsonData2.dump(4)); QString strCmd = QString::fromStdString(jsonData2.dump()); QString strRet; auto ret = m_httpApi->DBDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet, true); if(ret != 0) { SPDLOG_ERROR("DBDoInterface failed: {}, error info: {}", ret, m_httpApi->DoGetLastError(&ret).toStdString()); return false; } SPDLOG_INFO("DBDoInterface sucess: {}", nJson::parse(strRet.toStdString()).dump(4)); return true; } bool FromEQM::test2() { nJson json0; json0["opName"] = "SPSC_GetOnWorkInfoByTime"; nJson jsonData; jsonData["startTime"] = "2024-10-01 00:00:00"; jsonData["endTime"] = "2024-10-02 23:59:59"; json0["paramList"] = jsonData; SPDLOG_INFO("strCmd: {}", json0.dump(4)); QString strCmd = QString::fromStdString(json0.dump()); QString strRet; int ret = m_httpApi->DBDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet, true); if(ret != 0) { SPDLOG_ERROR("DBDoInterface failed: {}, error info: {}", ret, m_httpApi->DoGetLastError(&ret).toStdString()); return false; } SPDLOG_INFO("DBDoInterface sucess: {}", nJson::parse(strRet.toStdString()).dump(4)); return true; }