QThreadHttpServer.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. #include "QThreadHttpServer.h"
  2. #include "DataManager.h"
  3. #include "TaskMNG.h"
  4. #include "ElectricityVOC.h"
  5. #ifdef Q_OS_WIN
  6. #pragma execution_character_set("utf-8")
  7. #endif
  8. #define NetFrom 0;
  9. #define TrainingID DataManager::instance().pRunThread->m_nTrainID;
  10. static int nHttpNumber = 0;
  11. void* QThreadHttpServer::pFunWnd = nullptr;
  12. //UserLoginCallBack QThreadHttpServer::pFunCtrl = nullptr;
  13. QThreadHttpServer::QThreadHttpServer(QObject* parent)
  14. : QThread(parent)
  15. {
  16. m_strServerIP = "10.2.2.95";
  17. m_nServerPost = 18080;
  18. svr = nullptr;
  19. }
  20. QThreadHttpServer::~QThreadHttpServer()
  21. {
  22. StopThread();
  23. }
  24. void QThreadHttpServer::InitHttpServer()
  25. {
  26. if (!svr)
  27. {
  28. svr = new Server();
  29. }
  30. if (!svr)
  31. {
  32. return;
  33. }
  34. if (!svr->is_valid()) {
  35. printf(" server has an error...\n");
  36. return;
  37. }
  38. /*
  39. svr->Get(".*", [](const httplib::Request& req, httplib::Response& res) {
  40. // 注意:这只是一个简单示例,在实际应用中可能需要更精细的路由匹配
  41. std::cout << "[Global Logger] " << req.method << " " << req.path << " from " << req.remote_addr << std::endl;
  42. // 注意:这个处理器会捕获所有GET请求,你需要确保它不会干扰其他特定路由
  43. // 更佳实践是为重要的特定路由分别记录,或者使用Server的`set_logger`方法(如果httplib版本支持)
  44. });*/
  45. svr->Post("/", [=](const Request& /*req*/, Response& res) {
  46. res.set_redirect("/hi");
  47. });
  48. svr->Post("/ServerCtrl/Run", [](const Request& req, Response& res)
  49. {//课程运行标记
  50. nHttpNumber = 0;
  51. Json::Value pJsonData;
  52. Json::Reader pReadJson;
  53. std::string jsonData = "{\"code\": 200, \"msg\": \"\", \"data\": \"\"}";
  54. if (pReadJson.parse(req.body, pJsonData))
  55. {
  56. SetSystemRun(pJsonData);
  57. }
  58. else
  59. {
  60. jsonData = "{\"code\": -1, \"msg\": \"Json Read Error\", \"data\": \"\"}";
  61. }
  62. res.status = 200;
  63. res.set_content(jsonData, "application/json");
  64. AddLogJson(req.body,jsonData, "/ServerCtrl/Run",true);
  65. });
  66. svr->Post("/ServerCtrl/Stop", [](const Request& req, Response& res)
  67. {//课程运行标记
  68. nHttpNumber=0;
  69. SetSystemStop();
  70. std::string jsonData = "{\"code\": 200, \"msg\": \"\", \"data\": \"\"}";
  71. res.status = 200;
  72. res.set_content(jsonData, "application/json");
  73. AddLogJson(req.body,jsonData,"/ServerCtrl/Stop", true);
  74. });
  75. svr->Post("/ServerCtrl/RunStatus", [](const Request& req, Response& res)
  76. {//课程运行标记
  77. QString strData = "";
  78. std::string jsonData;
  79. auto taskStatus = TaskMNG::instance()->getTaskStatus();
  80. int nTaskStatus = taskStatus;
  81. switch (taskStatus)
  82. {
  83. case TaskMNG::Status_Null:
  84. {
  85. strData = G2U("结课/未初始化");
  86. }
  87. break;
  88. case TaskMNG::Status_Init:
  89. {
  90. strData = G2U("课程初始成功,正在开课");
  91. }
  92. break;
  93. case TaskMNG::Status_Run:
  94. {
  95. strData = G2U("课程开课成功");
  96. }
  97. break;
  98. case TaskMNG::Status_Pass:
  99. {
  100. strData = G2U("课程暂停");
  101. }
  102. break;
  103. case TaskMNG::Status_Stop:
  104. {
  105. strData = G2U("课程已结束,正在释放资源");
  106. }
  107. break;
  108. case TaskMNG::Status_Error:
  109. {
  110. strData = QString::fromStdString(TaskMNG::instance()->getTaskText());
  111. }
  112. break;
  113. default:
  114. break;
  115. }
  116. //double pData = nHttpNumber / 5.0 * 100.0;
  117. QString qstrRet = QString("{\"code\": 200, \"msg\": \"\", \"data\": { \"RunStatus\" :\"%1\",\"StatusText\" :\"%2\"} }").arg(nTaskStatus).arg(strData);
  118. jsonData = qstrRet.toStdString();
  119. //std::string jsonData = "{\"code\": 200, \"msg\": \"\", \"data\": \"\"}";
  120. res.status = 200;
  121. res.set_content(jsonData, "application/json");
  122. AddLogJson(req.body,jsonData, "/ServerCtrl/RunStatus", true);
  123. });
  124. svr->Post("/ServerCtrl/AllEqpmtList", [](const Request& req, Response& res)
  125. {//
  126. Json::Value pJsonData;
  127. SendAllEqpmtData(pJsonData);
  128. Json::FastWriter pJsonW;
  129. std::string jsonData = pJsonW.write(pJsonData);
  130. res.status = 200;
  131. res.set_content(jsonData, "application/json");
  132. AddLogJson(req.body,jsonData, "/ServerCtrl/AllEqpmtList", true);
  133. });
  134. svr->Post("/ServerCtrl/SetEqpmtOper", [](const Request& req, Response& res)
  135. {//
  136. Json::Value pJsonData;
  137. Json::Reader pReadJson;
  138. std::string jsonData = "{\"code\": 200, \"msg\": \"\", \"data\": \"\"}";
  139. if (pReadJson.parse(req.body, pJsonData))
  140. {
  141. SetEqpmtData(pJsonData);
  142. }
  143. else
  144. {
  145. jsonData = "{\"code\": -1, \"msg\": \"Json Read Error\", \"data\": \"\"}";
  146. }
  147. res.status = 200;
  148. res.set_content(jsonData, "application/json");
  149. AddLogJson(req.body, jsonData, "/ServerCtrl/SetEqpmtOper", true);
  150. });
  151. svr->Post("/ServerCtrl/SetEqpmtFault", [](const Request& req, Response& res)
  152. {//
  153. Json::Value pJsonData;
  154. Json::Reader pReadJson;
  155. std::string jsonData = "{\"code\": 200, \"msg\": \"\", \"data\": \"\"}";
  156. if (pReadJson.parse(req.body, pJsonData))
  157. {
  158. SetEqpmtFault(pJsonData);
  159. }
  160. else
  161. {
  162. jsonData = "{\"code\": -1, \"msg\": \"Json Read Error\", \"data\": \"\"}";
  163. }
  164. res.status = 200;
  165. res.set_content(jsonData, "application/json");
  166. AddLogJson(req.body, jsonData, "/ServerCtrl/SetEqpmtFault", true);
  167. });
  168. //子系统状态查询
  169. svr->Post("/ServerCtrl/SubSysStatus", [](const Request& req, Response& res)
  170. {//
  171. Json::Value pJsonData;
  172. SendAllSystemData(pJsonData);
  173. Json::FastWriter pJsonW;
  174. std::string jsonData = pJsonW.write(pJsonData);
  175. res.status = 200;
  176. res.set_content(jsonData, "application/json");
  177. AddLogJson(req.body, jsonData, "/ServerCtrl/SubSysStatus", true);
  178. });
  179. //子系统状态查询
  180. svr->Post("/ServerCtrl/SystemCtrl", [](const Request& req, Response& res)
  181. {//
  182. std::string jsonData = "{\"code\": 200, \"msg\": \"\", \"data\": \"\"}";
  183. res.status = 200;
  184. res.set_content(jsonData, "application/json");
  185. AddLogJson(req.body, jsonData, "/ServerCtrl/SystemCtrl", true);
  186. });
  187. svr->Get("/course/stop", [](const Request& req, Response& res)
  188. {//课程运行标记
  189. nHttpNumber=0;
  190. std::string jsonData = "{\"code\": 200, \"msg\": \"\", \"data\": \"\"}";
  191. res.status = 200;
  192. res.set_content(jsonData, "application/json");
  193. AddLogJson(req.body, jsonData, "/course/stop", true);
  194. });
  195. svr->Post("/ServerCtrl/GetEqpmtFault", [](const Request& req, Response& res)
  196. {//
  197. Json::Value pJsonData;
  198. Json::Reader pReadJson;
  199. Json::Value pJsonRes;
  200. Json::FastWriter pJsonW;
  201. std::string jsonData;// = "{\"code\": 200, \"msg\": \"\", \"data\": \"\"}";
  202. if (!req.body.empty())
  203. {
  204. if (pReadJson.parse(req.body, pJsonData))
  205. {
  206. std::string strEqpmt = pJsonData.get("EqpmtID", "").asString();
  207. GetEqpmtFault(strEqpmt, pJsonRes);
  208. }
  209. }
  210. else
  211. {
  212. GetEqpmtFault("", pJsonRes);
  213. }
  214. res.status = 200;
  215. jsonData=pJsonW.write(pJsonRes);
  216. res.set_content(jsonData, "application/json");
  217. AddLogJson(req.body, jsonData, "/ServerCtrl/GetEqpmtFault", true);
  218. });
  219. svr->set_error_handler([](const Request& /*req*/, Response& res) {
  220. const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
  221. char buf[BUFSIZ];
  222. snprintf(buf, sizeof(buf), fmt, res.status);
  223. res.set_content(buf, "text/html");
  224. });
  225. }
  226. void QThreadHttpServer::run()
  227. {
  228. if (!svr)
  229. {
  230. return;
  231. }
  232. std::string strIp = m_strServerIP.toStdString();
  233. svr->listen(strIp, m_nServerPost);
  234. delete svr;
  235. svr = nullptr;
  236. }
  237. std::string QThreadHttpServer::logData(const Request& req, const Response& res)
  238. {
  239. /*
  240. std::string s;
  241. char buf[BUFSIZ];
  242. s += "================================\n";
  243. snprintf(buf, sizeof(buf), "%s %s %s", req.method.c_str(),
  244. req.version.c_str(), req.path.c_str());
  245. s += buf;
  246. std::string query;
  247. for (auto it = req.params.begin(); it != req.params.end(); ++it) {
  248. const auto& x = *it;
  249. snprintf(buf, sizeof(buf), "%c%s=%s",
  250. (it == req.params.begin()) ? '?' : '&', x.first.c_str(),
  251. x.second.c_str());
  252. query += buf;
  253. }
  254. snprintf(buf, sizeof(buf), "%s\n", query.c_str());
  255. s += buf;
  256. //s += dump_headers(req.headers);
  257. s += "--------------------------------\n";
  258. snprintf(buf, sizeof(buf), "%d %s\n", res.status, res.version.c_str());
  259. s += buf;
  260. //s += dump_headers(res.headers);
  261. s += "\n";
  262. if (!res.body.empty()) { s += res.body; }
  263. s += "\n";
  264. return s;*/
  265. return"";
  266. }
  267. void QThreadHttpServer::StopThread()
  268. {
  269. if (svr&&svr->is_running())
  270. {
  271. svr->stop();
  272. }
  273. }
  274. void QThreadHttpServer::setIPPost(QString strIp, int nServerPost)
  275. {
  276. m_strServerIP = strIp;
  277. m_nServerPost = nServerPost;
  278. }
  279. void QThreadHttpServer::InitLink(const Request& req, Response& res)
  280. {//接受初始化消息
  281. std::string query;
  282. QString strSN = "", strPushOptionsFlag = "";
  283. for (auto it = req.params.begin(); it != req.params.end(); ++it)
  284. {
  285. if ("SN" == it->first)
  286. {
  287. strSN = QString::fromStdString(it->second);
  288. }
  289. else if ("PushOptionsFlag" == it->first)
  290. {
  291. strPushOptionsFlag = QString::fromStdString(it->second);
  292. }
  293. }
  294. if (strSN.isEmpty() || strPushOptionsFlag.isEmpty())
  295. {
  296. return;
  297. }
  298. QString strOption = initOptions(strSN, strPushOptionsFlag);
  299. std::string strSend = strOption.toStdString();
  300. res.headers;
  301. res.set_content(strSend, "text/plain");
  302. }
  303. QString QThreadHttpServer::initOptions(QString strSN, QString PushOptionsFlag)
  304. {//组装返回命令
  305. QString devOptions = "";
  306. devOptions.append("GET OPTION FROM: " + strSN);
  307. // + "\nStamp=" + devInfo.devInfoJson.getString("Stamp")
  308. devOptions.append("\nATTLOGStamp=0");
  309. devOptions.append("\nOPERLOGStamp=0");
  310. devOptions.append("\nBIODATAStamp=0");
  311. devOptions.append("\nATTPHOTOStamp=0");
  312. devOptions.append("\nErrorDelay=10");//断网重连
  313. devOptions.append("\nDelay=5");//心跳间隔
  314. devOptions.append("\nTimeZone=8");//时区
  315. devOptions.append("\nRealtime=1");//实时上传
  316. devOptions.append("\nServerVer=3.0.1");//这个必须填写
  317. devOptions.append("\nPushProtVer=2.4.1");
  318. // 1 考勤记录
  319. // 2 操作日志
  320. // 3 考勤照片
  321. // 4 登记新指纹
  322. // 5 登记新用户
  323. // 6 指纹图片
  324. // 7 修改用户信息
  325. // 8 修改指纹
  326. // 9 新登记人脸
  327. // 10 用户照片
  328. // 11 工作号码
  329. // 12 比对照片
  330. // devOptions.append("\nTransFlag=111111111111");// 1-12二进制位 分别代表以上含义
  331. devOptions.append("\nTransFlag=100000000001");// 1-12二进制位 分别代表以上含义
  332. if (!PushOptionsFlag.isEmpty() && PushOptionsFlag=="1")
  333. {
  334. // 支持参数单独获取的才要把需要获取的参数回传给设备 modifeid by max 20170926
  335. devOptions.append("\nPushOptions=RegDeviceType,FingerFunOn,FaceFunOn,FPVersion,FaceVersion,NetworkType,HardwareId3,HardwareId5,HardwareId56,LicenseStatus3,LicenseStatus5,LicenseStatus56");
  336. }
  337. devOptions.append("\n");
  338. return devOptions;
  339. }
  340. void QThreadHttpServer::RtData(const Request& req, Response& res)
  341. {
  342. logData(req, res);
  343. std::string strSN="";
  344. auto iterSN = req.params.find("SN");
  345. if (iterSN == req.params.end())
  346. {
  347. strSN = iterSN->second;
  348. }
  349. auto iterTable = req.params.find("table");
  350. if (iterTable==req.params.end())
  351. {
  352. return;
  353. }
  354. if (iterTable->second == "ATTLOG")
  355. {
  356. std::string dataArray = req.body; //数据转为数组
  357. int num = dataArray.length();
  358. // if (pFunCtrl)
  359. // {
  360. // pFunCtrl(pFunWnd, strSN, dataArray);
  361. // }
  362. }
  363. }
  364. void QThreadHttpServer::AddLogJson(std::string strRequest, std::string strResponse, std::string nAPIID, bool bStatus,bool ServerData)
  365. {
  366. std::string strShow = "", strRetrun = "";
  367. // strShow = UTF8_to_string(strRequest);
  368. // strRetrun = strResponse;
  369. if (!DataManager::JsonToStyled(strRequest, strShow))
  370. {
  371. strShow = DataManager::UTF8_to_string(strRequest);
  372. }
  373. else
  374. {
  375. strShow = DataManager::UTF8_to_string(strShow);
  376. }
  377. if (!DataManager::JsonToStyled(strResponse, strRetrun))
  378. {
  379. strRetrun = strResponse;
  380. }
  381. LogJson pData(strShow, strRetrun, nAPIID, bStatus,ServerData);
  382. DataManager::instance().AddHttpLog(pData);
  383. }
  384. void QThreadHttpServer::SendAllEqpmtData(Json::Value& pJson)
  385. {
  386. ElectricityVOC* pElcVoc = (ElectricityVOC*)TaskMNG::instance()->pGetEleVOC();
  387. if (!pElcVoc)
  388. {
  389. return;
  390. }
  391. ELEEQPMTMAP* pEqpmtList= pElcVoc->getElectricEqpmtMap();
  392. if (!pEqpmtList)
  393. {
  394. return;
  395. }
  396. //Json::Value pJson;
  397. pJson["code"] = 200;
  398. QString strSize = QString("Eqpmt Size=%1").arg(pEqpmtList->size());
  399. pJson["msg"] = strSize.toStdString();
  400. for (auto iters =pEqpmtList->begin();iters!=pEqpmtList->end();iters++)
  401. {
  402. Json::Value pEqpmtJson;
  403. pEqpmtJson["EqpmtStrID"]= iters->second->GetEqpmentID();
  404. pEqpmtJson["LineID"] = pElcVoc->m_nRunLineID;
  405. pEqpmtJson["EqpmtStdName"] = iters->second->GetEqpmentName();
  406. pEqpmtJson["EqpmtTypeID"] = iters->second->GetBaseType();
  407. pEqpmtJson["CMDType"] = 0;
  408. pEqpmtJson["EqpmtStatus"] = iters->second->GetStatus();
  409. pEqpmtJson["CtrlType"] = 1;
  410. pEqpmtJson["OpeMark"] = 0;
  411. pEqpmtJson["fValue"] = 0.0;
  412. pEqpmtJson["nValueType"] = 0;
  413. pEqpmtJson["IsReset"] = 0;
  414. pJson["data"].append(pEqpmtJson);
  415. }
  416. }
  417. void QThreadHttpServer::SetEqpmtData(Json::Value& InJson)
  418. {
  419. int nValueType = InJson.get("CMDType", 0).asInt();
  420. string strEqpmtID = InJson.get("EqpmtStrID", "").asString();
  421. OCCCOMMAND occcommand;
  422. if (nValueType==0)//设备状态更新
  423. {
  424. OCCCOMMAND opercommand;
  425. DHEQPMTOPER oper;
  426. strcpy(oper.EqpmtStrID, strEqpmtID.c_str());
  427. int nEqpmtCtrlType = InJson.get("CtrlType", 1).asInt();
  428. int nEqpmtStatus = InJson.get("EqpmtStatus", 0).asInt();
  429. switch (nEqpmtCtrlType)
  430. {
  431. case 1:
  432. case 0:
  433. {
  434. oper.CtrlType = CTRLTYPE_STATUS;
  435. oper.EqpmtStatus = nEqpmtStatus;
  436. }
  437. break;
  438. case 2:
  439. {
  440. oper.CtrlType = CTRLTYPE_CARD;
  441. if (nEqpmtStatus==0)
  442. {
  443. oper.EqpmtStatus = ELC_EQPMTCARDSTATUS_NORMAL;//正常
  444. }
  445. else if(nEqpmtStatus == 1)
  446. {
  447. oper.EqpmtStatus = ELC_EQPMTCARDSTATUS_EARTH;//就地
  448. }
  449. else
  450. {
  451. return;
  452. }
  453. }
  454. break;
  455. default:
  456. return;
  457. break;
  458. }
  459. oper.OpeMark = OperClient_Tech;
  460. occcommand.DesNetID = NetFrom;
  461. occcommand.TrainningID = TrainingID;
  462. occcommand.DesSysType = OCC_SYS_DD_SVR;
  463. occcommand.ScrSysType = OCC_SYS_SERVER_TH;
  464. occcommand.setPacketValue(&oper, OCCCOMMAND::eUpdateOper);
  465. }
  466. else if (nValueType==1) // 值更新
  467. {
  468. EQPMTTELEMTRYVALUE oper;
  469. strcpy(oper.EqpmtStrID, strEqpmtID.c_str());
  470. oper.nType = InJson.get("nValueType", 1).asInt();
  471. oper.fValue = InJson.get("fValue", 1).asFloat();
  472. oper.IsReset = InJson.get("IsReset", 1).asInt();
  473. occcommand.DesNetID = NetFrom;
  474. occcommand.TrainningID = TrainingID;
  475. occcommand.DesSysType = OCC_SYS_DD_SVR;
  476. occcommand.ScrSysType = OCC_SYS_SERVER_TH;
  477. occcommand.setPacketValue(&oper, OCCCOMMAND::eUpdateEqpmtTelemeteryValue);
  478. }
  479. TaskMNG::instance()->NetComand_Receive(occcommand);
  480. }
  481. void QThreadHttpServer::SetEqpmtFault(Json::Value& InJson)
  482. {
  483. string strEqpmtID = InJson.get("EqpmtStrID", "").asString();
  484. int status = InJson.get("EventType", "").asInt();
  485. int nFaultID= InJson.get("EventId", "").asInt();
  486. ELCACCIDENT acci;
  487. acci.Eqpmtid = 0;
  488. strcpy(acci.EqpmtStrID, strEqpmtID.c_str());
  489. if (status == 1) //故障发生
  490. {
  491. acci.EventType = POWER_ERORR_OCCAR;
  492. ElectricityVOC* pElcVoc = (ElectricityVOC*)TaskMNG::instance()->pGetEleVOC();
  493. if (!pElcVoc)
  494. {
  495. return;
  496. }
  497. ELEEQPMTMAP* pEqpmtList = pElcVoc->getElectricEqpmtMap();
  498. if (pEqpmtList)
  499. {
  500. auto iterEqpmt = pEqpmtList->find(strEqpmtID);
  501. if (iterEqpmt!= pEqpmtList->end())
  502. {
  503. DataManager::instance().addEqpmFault(strEqpmtID, iterEqpmt->second->GetBaseType(), nFaultID);
  504. }
  505. else
  506. {
  507. DataManager::instance().addEqpmFault(strEqpmtID, 0, nFaultID);
  508. }
  509. }
  510. }
  511. if (status == 2) //恢复故障
  512. {
  513. acci.EventType = POWER_ERORR_REVERT;
  514. DataManager::instance().DeleteEqpmtFault(strEqpmtID, nFaultID);
  515. }
  516. acci.ClientType = OperClient_Tech;
  517. acci.parm = nFaultID;
  518. OCCCOMMAND occcommand;
  519. occcommand.DesNetID = NetFrom;
  520. occcommand.TrainningID = TrainingID;
  521. occcommand.DesSysType = OCC_SYS_DD_SVR;
  522. occcommand.ScrSysType = OCC_SYS_SERVER_TH;
  523. occcommand.setPacketValue(&acci, OCCCOMMAND::eUpdateAccident);
  524. TaskMNG::instance()->m_pRecvList.push(occcommand);
  525. }
  526. void QThreadHttpServer::SendAllSystemData(Json::Value& pJson)
  527. {
  528. QMap<int, SystemData> mapSysStatus = DataManager::instance().m_mapSystemStatus;
  529. if (mapSysStatus.isEmpty())
  530. {
  531. return;
  532. }
  533. //Json::Value pJson;
  534. pJson["code"] = 200;
  535. QString strSize = QString("System Size=%1").arg(mapSysStatus.size());
  536. pJson["msg"] = strSize.toStdString();
  537. for (auto iters = mapSysStatus.begin(); iters != mapSysStatus.end(); iters++)
  538. {
  539. Json::Value pEqpmtJson;
  540. pEqpmtJson["SysID"] = iters.key();
  541. pEqpmtJson["SysType"] = iters->nSysType;
  542. pEqpmtJson["SysTypeName"] = iters->strSysType.toStdString();
  543. pEqpmtJson["SysName"] = iters->strSysName.toStdString();
  544. pEqpmtJson["SysStatus"] = iters->nStatus;
  545. pJson["data"].append(pEqpmtJson);
  546. }
  547. }
  548. void QThreadHttpServer::SetSystemRun(Json::Value& pJson)
  549. {
  550. int nCourseId = pJson.get("CourseID", 0).asInt();
  551. int nRunID = pJson.get("CourseRunID", 0).asInt();
  552. int nLineID = pJson.get("LineID", 0).asInt();
  553. if (nLineID==0)
  554. {
  555. nLineID = pJson.get("LineNo", 0).asInt();
  556. }
  557. string subParam1 = pJson.get("subParam1", "").asString();
  558. string subParam2 = pJson.get("subParam2", "").asString();
  559. DataManager::instance().pRunThread->SetRunData(nCourseId, OCC_SYS_DD_SVR, nRunID, nLineID);
  560. DataManager::instance().pRunThread->SetCMDType(TaskRunThread::server_Run);
  561. DataManager::instance().pRunThread->start();
  562. }
  563. void QThreadHttpServer::SetSystemStop()
  564. {
  565. DataManager::instance().pRunThread->SetCMDType(TaskRunThread::server_Stop);
  566. DataManager::instance().pRunThread->start();
  567. }
  568. void QThreadHttpServer::GetEqpmtFault(std::string strEqpmt, Json::Value& pJson)
  569. {
  570. QMap<std::string, QList<EqpmtFault>> m_Eqpmt=DataManager::instance().m_mapEqpmtFault;
  571. int nEqpmtSize = 0;
  572. if (strEqpmt.empty())//如果是空的返回全部数据
  573. {
  574. Json::Value pEqpmtArray;
  575. for (auto iters = m_Eqpmt.begin();iters !=m_Eqpmt.end();iters++)
  576. {
  577. if (iters.value().isEmpty())
  578. {
  579. continue;
  580. }
  581. Json::Value pEqpmt;
  582. Json::Value pEqpmtFaultData;
  583. for (auto iter =iters.value().begin();iter!=iters.value().end();iter++)
  584. {
  585. Json::Value fileData;
  586. fileData["FaultID"] = iter->nFaultID;
  587. fileData["FaultTime"] = iter->FaultTime.toString("yyyy-MM-dd hh:mm:ss").toStdString();
  588. pEqpmtFaultData.append(fileData);
  589. }
  590. pEqpmt["EqpmtID"] = iters.key();
  591. pEqpmt["EqpmtFault"] = pEqpmtFaultData;
  592. nEqpmtSize++;
  593. pEqpmtArray.append(pEqpmt);
  594. }
  595. pJson["data"] = pEqpmtArray;
  596. }
  597. else//如果存在则返回固定值
  598. {
  599. Json::Value pEqpmtArray;
  600. Json::Value pEqpmt;
  601. Json::Value pEqpmtFaultData;
  602. auto iters = m_Eqpmt.find(strEqpmt);
  603. if (iters!=m_Eqpmt.end() )
  604. {
  605. if (!iters.value().isEmpty())
  606. {
  607. for (auto iter = iters.value().begin(); iter != iters.value().end(); iter++)
  608. {
  609. Json::Value fileData;
  610. fileData["FaultID"] = iter->nFaultID;
  611. fileData["FaultTime"] = iter->FaultTime.toString("yyyy-MM-dd hh:mm:ss").toStdString();
  612. pEqpmtFaultData.append(fileData);
  613. }
  614. }
  615. pEqpmt["EqpmtID"] = iters.key();
  616. pEqpmt["EqpmtFault"] = pEqpmtFaultData;
  617. nEqpmtSize++;
  618. pEqpmtArray.append(pEqpmt);
  619. }
  620. else
  621. {
  622. pEqpmt["EqpmtID"] = iters.key();
  623. pEqpmt["EqpmtFault"] = pEqpmtFaultData;
  624. }
  625. pJson["data"] = pEqpmtArray;
  626. }
  627. pJson["code"] = 200;
  628. QString strSize = QString("Eqpmt Size=%1").arg(nEqpmtSize);
  629. pJson["msg"] = strSize.toStdString();
  630. }