| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #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;
- }
|