MonitorObject.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. #include "stdafx.h"
  2. #include "MonitorObject.h"
  3. #include <sstream>
  4. #include <ODBC/DBConnectPool.h>
  5. #include <Simplelog.h>
  6. #include <assert.h>
  7. #include "Device.h"
  8. #include <ZlDataDefine.h>
  9. #include <AppService.h>
  10. #include <gbk2utf8.h>
  11. using namespace std;
  12. CMonitorObject::CMonitorObject()
  13. {
  14. }
  15. CMonitorObject::~CMonitorObject()
  16. {
  17. check = 0x00;
  18. for (auto& it : m_lstMo)
  19. {
  20. delete it;
  21. it = nullptr;
  22. }
  23. m_lstMo.clear();
  24. }
  25. CMonitorObjectMng::CMonitorObjectMng()
  26. {
  27. }
  28. CMonitorObjectMng::~CMonitorObjectMng()
  29. {
  30. if (m_treeroot) delete m_treeroot;
  31. m_treeroot = nullptr;
  32. m_mapImeiIdxMoMp.clear();
  33. m_mapMoMpImeiIdx.clear();
  34. }
  35. BOOL CMonitorObjectMng::LoadMoMap()
  36. {
  37. char mo[50];
  38. char mp[50];
  39. char imei[50];
  40. char name1[20];
  41. char name2[20];
  42. char name3[20];
  43. char direct1[20];
  44. char direct2[20];
  45. short idx;
  46. int zzj_no = 0;
  47. int epos = 0;
  48. uint8_t binstall_1 = 0;
  49. uint8_t binstall_2 = 0;
  50. uint8_t binstall_3 = 0;
  51. CString sql = "SELECT mo,mp,ISNULL(IMEI, ''),ISNULL(idx, 0),ISNULL(zl_1_loca, ''),ISNULL(zl_2_loca, ''), '转换阻力曲线',ISNULL(direct1, ''),ISNULL(direct2, ''),zzjno,epos,install_1,install_2,install_3 FROM rm_map";
  52. COdbcStatement stmt;
  53. if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
  54. {
  55. ASSERT(FALSE);
  56. CSimpleLog::Error("执行语句失败" + sql);
  57. return FALSE;
  58. }
  59. int nCol = 1;
  60. stmt.BindCharCol(nCol++, mo, sizeof(mo));
  61. stmt.BindCharCol(nCol++, mp, sizeof(mp));
  62. stmt.BindCharCol(nCol++, imei, sizeof(imei));
  63. stmt.BindSmallIntCol(nCol++, &idx);
  64. stmt.BindCharCol(nCol++, name1, sizeof(name1));
  65. stmt.BindCharCol(nCol++, name2, sizeof(name2));
  66. stmt.BindCharCol(nCol++, name3, sizeof(name3));
  67. stmt.BindCharCol(nCol++, direct1, sizeof(direct1));
  68. stmt.BindCharCol(nCol++, direct2, sizeof(direct2));
  69. stmt.BindIntCol(nCol++, &zzj_no);
  70. stmt.BindIntCol(nCol++, &epos);
  71. stmt.BindTinyIntCol(nCol++, &binstall_1);
  72. stmt.BindTinyIntCol(nCol++, &binstall_2);
  73. stmt.BindTinyIntCol(nCol++, &binstall_3);
  74. stringstream smomp;
  75. stringstream simei;
  76. while (true)
  77. {
  78. memset(imei, 0, sizeof(imei));
  79. if (stmt.FetchNext() != 0)
  80. {
  81. break;
  82. }
  83. if (name1[0x00] != 0)
  84. sprintf_s(name1, 20, "%s%s", name1, "测力曲线");
  85. if (name2[0x00] != 0)
  86. sprintf_s(name2, 20, "%s%s", name2, "测力曲线");
  87. for (int i = 0x00; i < 16; i++) if (imei[i] == 0x20) imei[i] = 0x00; //0x20 代表空格
  88. smomp.str("");
  89. simei.str("");
  90. smomp << mo << '.' << mp;
  91. if (imei[0x00] != 0x00) simei << imei << '.' << idx;
  92. string momp = smomp.str();
  93. //m_mapMoMpZZJNO[momp] = zzj_no;
  94. //m_mapMoMpZZJEPOS[momp][0] = (DAOCHA_POSITION)epos;
  95. m_mapMoMpImeiIdx[momp] = simei.str();
  96. if (imei[0x00] != 0x00) m_mapImeiIdxMoMp[simei.str()] = smomp.str();
  97. {
  98. auto& it = m_mapMoMpInfo[momp];
  99. if (it == nullptr) it = new ST_MOMP_INFO;
  100. it->binstall_1 = binstall_1;
  101. it->binstall_2 = binstall_2;
  102. it->binstall_3 = binstall_3;
  103. it->name1 = name1;
  104. it->name1utf = ANSItoUTF8(name1);
  105. it->name2 = name2;
  106. it->name2utf = ANSItoUTF8(name2);
  107. it->name3 = name3;
  108. it->name3utf = ANSItoUTF8(name3);
  109. it->out_name = direct1;
  110. it->in_name = direct2;
  111. it->imei = imei;
  112. it->idx = idx;
  113. it->zzjno = zzj_no;
  114. it->mo = mo;
  115. it->mp = mp;
  116. it->mapPos[time(0)] = (DAOCHA_POSITION)epos;;
  117. if (!it->imei.empty())
  118. it->pDeivce = CDeviceMng::Instance()->Insert(imei);
  119. }
  120. /*
  121. {
  122. auto& it = m_mapMoMpName[momp];
  123. if (it.size() == 0)
  124. {
  125. it.emplace_back(name1);
  126. it.emplace_back(name2);
  127. it.emplace_back(name3);
  128. it.emplace_back(direct1); //伸出
  129. it.emplace_back(direct2); //缩进
  130. }
  131. else if (it.size() == 3)
  132. {
  133. it[0] = name1;
  134. it[1] = name2;
  135. it[2] = name3;
  136. it.emplace_back(direct1);
  137. it.emplace_back(direct2);
  138. }
  139. else if (it.size() == 5)
  140. {
  141. it[0] = name1;
  142. it[1] = name2;
  143. it[2] = name3;
  144. it[3] = direct1;
  145. it[4] = direct2;
  146. }
  147. else
  148. {
  149. it.clear();
  150. it.emplace_back(name1);
  151. it.emplace_back(name2);
  152. it.emplace_back(name3);
  153. it.emplace_back(direct1);
  154. it.emplace_back(direct2);
  155. }
  156. }
  157. {
  158. auto& it = m_mapMoMpDirect[momp];
  159. if (it.size() == 0)
  160. {
  161. it.push_back(direct1);
  162. it.push_back(direct2);
  163. }
  164. else if (it.size() == 2)
  165. {
  166. it[0] = direct1;
  167. it[1] = direct2;
  168. }
  169. else
  170. {
  171. it.clear();
  172. it.push_back(direct1);
  173. it.push_back(direct2);
  174. }
  175. }
  176. */
  177. }
  178. return m_mapMoMpInfo.size() + 1;
  179. }
  180. void CMonitorObjectMng::GetChild(std::list<CMonitorObject*>& lst, CMonitorObject* parent)
  181. {
  182. for (auto it = lst.begin(); it != lst.end(); ++it)
  183. {
  184. auto p = *it;
  185. if (p == nullptr) continue;
  186. if (p->id.compare(p->up) == 0)
  187. continue;
  188. if (p->up.compare(parent->id) == 0)
  189. {
  190. if (p->type.compare("mo") == 0)
  191. {
  192. for (auto& ik : m_mapMoMpImeiIdx)
  193. {
  194. //int ii = ik.first.find('.');
  195. //int jj = ik.first.find(p->id);
  196. string strName = p->id + '.';
  197. if (ik.first.find(strName) != -1)
  198. {
  199. auto pObject = new CMonitorObject;
  200. pObject->id = ik.first;
  201. pObject->name = p->name + "." + ik.first.substr(ik.first.find('.') + 1);
  202. pObject->type = "mo.mp";
  203. pObject->up = parent->id;
  204. pObject->parent = parent;
  205. pObject->eqpno = m_mapMoMpInfo[pObject->id]->zzjno;
  206. parent->m_lstMo.push_back(pObject);
  207. }
  208. }
  209. }
  210. else
  211. {
  212. p->parent = parent;
  213. parent->m_lstMo.push_back(p);
  214. *it = nullptr;
  215. GetChild(lst, p);
  216. }
  217. }
  218. }
  219. }
  220. bool CMonitorObjectMng::GetStationNameByMomP(CMonitorObject* pInfo, const std::string& momp, std::string& station, std::string& momp_name)
  221. {
  222. if (pInfo == nullptr) return false;
  223. if (pInfo->type.compare("mo.mp") == 0 && pInfo->id.compare(momp) == 0)
  224. {
  225. station = pInfo->up;
  226. momp_name = pInfo->name;
  227. return true;
  228. }
  229. for (const auto& it : pInfo->m_lstMo)
  230. {
  231. if (GetStationNameByMomP(it, momp, station, momp_name))
  232. return true;
  233. }
  234. return false;
  235. }
  236. void CMonitorObjectMng::Clear()
  237. {
  238. if (m_treeroot) delete m_treeroot;
  239. m_treeroot = nullptr;
  240. m_mapImeiIdxMoMp.clear();
  241. m_mapMoMpImeiIdx.clear();
  242. for (auto& it : m_mapMoMpInfo)
  243. delete it.second;
  244. m_mapMoMpInfo.clear();
  245. }
  246. BOOL CMonitorObjectMng::LoadMonitorTree()
  247. {
  248. Clear();
  249. if (!LoadMoMap()) return FALSE;
  250. char id[100];
  251. char type[50];
  252. char up[100];
  253. char name[100];
  254. CString sql = "SELECT [id],[type],[up],[name] FROM [rm_mo]";
  255. COdbcStatement stmt;
  256. if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
  257. {
  258. CSimpleLog::Error("执行语句失败" + sql);
  259. return FALSE;
  260. }
  261. int nCol = 1;
  262. stmt.BindCharCol(nCol++, id, sizeof(id));
  263. stmt.BindCharCol(nCol++, type, sizeof(type));
  264. stmt.BindCharCol(nCol++, up, sizeof(up));
  265. stmt.BindCharCol(nCol++, name, sizeof(name));
  266. list<CMonitorObject*> lstMo;
  267. while (true)
  268. {
  269. if (stmt.FetchNext() != 0)
  270. {
  271. break;
  272. }
  273. auto p = new CMonitorObject;
  274. p->id = id;
  275. p->type = type;
  276. p->up = up;
  277. p->name = name;
  278. //赋值节点名称
  279. if (p->type.compare("mo") == 0)
  280. {
  281. for (auto& it : m_mapMoMpInfo)
  282. {
  283. if (it.second->mo.compare(id) == 0)
  284. it.second->name = fmt::format("{}.{}", name, it.second->mp);
  285. }
  286. }
  287. if (p->id.compare(up) == 0)
  288. {
  289. swap(m_treeroot, p);
  290. delete p;
  291. p = nullptr;
  292. }
  293. else
  294. {
  295. lstMo.push_back(p);
  296. }
  297. }
  298. bool bret = true;
  299. if (m_treeroot == nullptr)
  300. {
  301. assert(0);
  302. bret = false;
  303. goto l;
  304. }
  305. GetChild(lstMo, m_treeroot);
  306. l:
  307. for (auto it = lstMo.begin(); it != lstMo.end(); ++it)
  308. delete (*it);
  309. lstMo.clear();
  310. //test
  311. //{
  312. // string momp = "HZHDJD21.X";
  313. // string name, name2;
  314. // GetStationNameByMomP(momp, name, name2);
  315. //}
  316. return TRUE;
  317. }
  318. BOOL CMonitorObjectMng::LoadHistoryData()
  319. {
  320. for (auto& it : m_mapMoMpImeiIdx)
  321. {
  322. string imei, idx;
  323. spiltByPoint(it.second, imei, idx);
  324. if (imei.length() > 5) CDeviceMng::Instance()->Insert(imei);
  325. }
  326. return TRUE;
  327. }
  328. bool CMonitorObjectMng::IMEI2MOMP(const std::string imei, const int idx, std::string& mo, std::string& mp)
  329. {
  330. auto& it = m_mapImeiIdxMoMp.find(concatStringByPoint(imei, to_string(idx)));
  331. if (it == m_mapImeiIdxMoMp.end()) return false;
  332. return spiltByPoint(it->second, mo, mp);
  333. }
  334. bool CMonitorObjectMng::IMEI2MOMP(const std::string& imei_idx, std::string& mo_mp)
  335. {
  336. auto& it = m_mapImeiIdxMoMp.find(imei_idx);
  337. if (it == m_mapImeiIdxMoMp.end()) return false;
  338. mo_mp = it->second;
  339. return true;
  340. }
  341. bool CMonitorObjectMng::MOMP2IMEI(const std::string& mo, const std::string& mp, std::string& imei, int& idx)
  342. {
  343. auto& it = m_mapMoMpImeiIdx.find(concatStringByPoint(mo, mp));
  344. if (it == m_mapMoMpImeiIdx.end()) return false;
  345. string idx2;
  346. if (!spiltByPoint(it->second, imei, idx2)) return false;
  347. idx = atoi(idx2.c_str());
  348. return true;
  349. }
  350. bool CMonitorObjectMng::MOMP2IMEI(const std::string& momp, std::string& imeiidx)
  351. {
  352. auto& it = m_mapMoMpImeiIdx.find(momp);
  353. if (it == m_mapMoMpImeiIdx.end()) return false;
  354. if (it->second.length() <= 0) return false;
  355. imeiidx = it->second;
  356. return true;
  357. }
  358. bool CMonitorObjectMng::MOMP2IMEI(const std::string& momp, std::string& imei, int& idx)
  359. {
  360. auto& it = m_mapMoMpImeiIdx.find(momp);
  361. if (it == m_mapMoMpImeiIdx.end()) return false;
  362. string idx2;
  363. if (!spiltByPoint(it->second, imei, idx2)) return false;
  364. idx = atoi(idx2.c_str());
  365. return true;
  366. }
  367. bool CMonitorObjectMng::GetStationNameByMomP(const std::string& momp, std::string& station, std::string& momp_name)
  368. {
  369. return GetStationNameByMomP(m_treeroot, momp, station, momp_name);
  370. }
  371. bool CMonitorObjectMng::GetStationNameByMomP(const std::string& mo, const std::string& mp, std::string& station, std::string& momp_name)
  372. {
  373. return GetStationNameByMomP(m_treeroot, mo + "." + mp, station, momp_name);
  374. }
  375. bool CMonitorObjectMng::GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3)
  376. {
  377. //auto& it = m_mapMoMpName.find(momp);
  378. //if (it == m_mapMoMpName.end()) return false;
  379. //if (it->second.size() < 3) return false;
  380. //name1 = it->second[0];
  381. //name2 = it->second[1];
  382. //name3 = it->second[2];
  383. //return true;
  384. auto it = GetMoMpInfo(momp);
  385. if (it)
  386. {
  387. name1 = it->name1;
  388. name2 = it->name2;
  389. name3 = it->name3;
  390. return true;
  391. }
  392. return false;
  393. }
  394. bool CMonitorObjectMng::GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3, std::string& out_name, std::string& in_name)
  395. {
  396. //auto& it = m_mapMoMpName.find(momp);
  397. //if (it == m_mapMoMpName.end()) return false;
  398. //if (it->second.size() < 5) return false;
  399. //name1 = it->second[0];
  400. //name2 = it->second[1];
  401. //name3 = it->second[2];
  402. //out_name = it->second[3];
  403. //in_name = it->second[4];
  404. auto it = GetMoMpInfo(momp);
  405. if (it)
  406. {
  407. name1 = it->name1;
  408. name2 = it->name2;
  409. name3 = it->name3;
  410. out_name = it->out_name;
  411. in_name = it->in_name;
  412. return true;
  413. }
  414. return false;
  415. }
  416. void CMonitorObjectMng::SetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3)
  417. {
  418. //auto& it = m_mapMoMpName.find(momp);
  419. //if (it == m_mapMoMpName.end())
  420. //{
  421. // std::vector<string> vct;
  422. // vct.push_back(name1);
  423. // vct.push_back(name2);
  424. // vct.push_back(name3);
  425. // m_mapMoMpName[momp] = vct;
  426. //}
  427. //else
  428. //{
  429. // it->second[0] = name1;
  430. // it->second[1] = name2;
  431. // it->second[2] = name3;
  432. //}
  433. {
  434. auto it = GetMoMpInfo(momp);
  435. if (it)
  436. {
  437. it->name1 = name1;
  438. it->name2 = name2;
  439. it->name3 = name3;
  440. it->name1utf = ANSItoUTF8(name1);
  441. it->name2utf = ANSItoUTF8(name2);
  442. it->name3utf = ANSItoUTF8(name3);
  443. }
  444. }
  445. }
  446. bool CMonitorObjectMng::GetDirectByMoMp(const std::string& momp, std::string& out_name, std::string& in_name)
  447. {
  448. auto it = GetMoMpInfo(momp);
  449. if (it == nullptr) return false;
  450. out_name = it->out_name;
  451. in_name = it->in_name;
  452. return true;
  453. }
  454. void CMonitorObjectMng::SetDirectByMoMp(const std::string& momp, std::string& direct1, std::string& direct2)
  455. {
  456. //auto& it = m_mapMoMpDirect.find(momp);
  457. //if (it == m_mapMoMpDirect.end())
  458. //{
  459. // std::vector<string> vct;
  460. // vct.push_back(direct1);
  461. // vct.push_back(direct2);
  462. // m_mapMoMpDirect[momp] = vct;
  463. //}
  464. //else
  465. //{
  466. // it->second[0] = direct1;
  467. // it->second[1] = direct2;
  468. //}
  469. {
  470. auto it = GetMoMpInfo(momp);
  471. if (it)
  472. {
  473. it->out_name = direct1;
  474. it->in_name = direct2;
  475. //it->name1utf = ANSItoUTF8(direct1);
  476. //it->name2utf = ANSItoUTF8(direct2);
  477. }
  478. }
  479. }
  480. bool CMonitorObjectMng::spiltByPoint(const std::string&src, std::string& dst1, std::string& dst2)
  481. {
  482. auto pos = src.find('.');
  483. if (pos == -1) return false;
  484. dst1 = src.substr(0, pos);
  485. dst2 = src.substr(pos + 1);
  486. return true;
  487. }
  488. std::string CMonitorObjectMng::concatStringByPoint(const std::string& src1, const std::string& src2)
  489. {
  490. stringstream ss;
  491. ss << src1 << "." << src2;
  492. return ss.str();
  493. }
  494. CMonitorObject* CMonitorObjectMng::GetTreeByID(CMonitorObject* p, const string& id)
  495. {
  496. if (p->id.compare(id) == 0)
  497. {
  498. return p;
  499. }
  500. else
  501. {
  502. for (const auto& it : p->m_lstMo)
  503. {
  504. auto pObj = GetTreeByID(it, id);
  505. if (pObj) return pObj;
  506. }
  507. }
  508. return nullptr;
  509. }
  510. CMonitorObject* CMonitorObjectMng::GetTreeByEpqID(CMonitorObject* p, uint16_t id)
  511. {
  512. if (p->eqpno == id)
  513. {
  514. return p;
  515. }
  516. else
  517. {
  518. for (const auto& it : p->m_lstMo)
  519. {
  520. auto pObj = GetTreeByEpqID(it, id);
  521. if (pObj) return pObj;
  522. }
  523. }
  524. return nullptr;
  525. }
  526. CMonitorObject* CMonitorObjectMng::GetTreeByID(const string& id)
  527. {
  528. CMonitorObject* pObject = nullptr;
  529. do {
  530. if (m_treeroot == nullptr) break;
  531. return GetTreeByID(m_treeroot, id);
  532. } while (false);
  533. return pObject;
  534. }
  535. CMonitorObject* CMonitorObjectMng::GetTreeByEpqID(uint16_t id)
  536. {
  537. CMonitorObject* pObject = nullptr;
  538. do {
  539. if (m_treeroot == nullptr) break;
  540. return GetTreeByEpqID(m_treeroot, id);
  541. } while (false);
  542. return pObject;
  543. }
  544. void CMonitorObjectMng::GetAllObjByType(CMonitorObject* p, std::vector<CMonitorObject*>& vctObj, const string& type)
  545. {
  546. if (p->type.compare(type) == 0)
  547. {
  548. vctObj.push_back(p);
  549. }
  550. for (auto& it : p->m_lstMo)
  551. {
  552. GetAllObjByType(it, vctObj, type);
  553. }
  554. }
  555. //获取所有Type对象
  556. bool CMonitorObjectMng::GetAllObjByType(std::vector<CMonitorObject*>& vctObj, const string& type)
  557. {
  558. do {
  559. if (m_treeroot == nullptr) break;
  560. GetAllObjByType(m_treeroot, vctObj, type);
  561. } while (false);
  562. return !vctObj.empty();
  563. }
  564. uint32_t CMonitorObjectMng::GeneralMoPack(uint8_t** pack, int* len)
  565. {
  566. if (m_treeroot == nullptr) return 0;
  567. auto doc = yyjson_mut_doc_new(nullptr);
  568. auto root = yyjson_mut_obj(doc);
  569. yyjson_mut_doc_set_root(doc, root);
  570. GeneralMoPack(m_treeroot, doc, root);
  571. size_t json_len;
  572. auto json = yyjson_mut_write(doc, 0, &json_len);
  573. yyjson_mut_doc_free(doc);
  574. int new_len = json_len + sizeof(HJDATAHEAD2) + 2;
  575. *pack = new uint8_t[new_len];
  576. memset(*pack, 0, new_len);
  577. auto no = CAppService::Instance()->GetPackNo();
  578. *len = CHjDataConver::conver_sendpack(*pack, (LPBYTE)json, json_len, 0, no, E_ZL_PROTOCAL::ZL_MO,
  579. OR_DATA_INFO(0, 0, 1, 2, OPT_TYPE::OPT_SYNC));
  580. free(json);
  581. return no;
  582. }
  583. void CMonitorObjectMng::GeneralMoPack(CMonitorObject* pObject, yyjson_mut_doc* doc, yyjson_mut_val* val)
  584. {
  585. yyjson_mut_obj_add_str(doc, val, "id", pObject->id.c_str());
  586. yyjson_mut_obj_add_str(doc, val, "name", pObject->name.c_str());
  587. yyjson_mut_obj_add_str(doc, val, "type", pObject->type.c_str());
  588. yyjson_mut_obj_add_str(doc, val, "up", pObject->up.c_str());
  589. yyjson_mut_val* arr = nullptr;
  590. if (pObject->m_lstMo.size() > 0)
  591. {
  592. arr = yyjson_mut_arr(doc);
  593. yyjson_mut_obj_add_val(doc, val, "child", arr);
  594. }
  595. for (auto& it : pObject->m_lstMo)
  596. {
  597. auto object = yyjson_mut_obj(doc);
  598. yyjson_mut_arr_add_val(arr, object);
  599. GeneralMoPack(it, doc, object);
  600. }
  601. }
  602. uint32_t CMonitorObjectMng::GeneralMpPack(uint8_t** pack, int* len)
  603. {
  604. if (m_mapMoMpInfo.size() == 0) return 0;
  605. auto doc = yyjson_mut_doc_new(nullptr);
  606. auto root = yyjson_mut_arr(doc);
  607. yyjson_mut_doc_set_root(doc, root);
  608. for (const auto& it : m_mapMoMpInfo)
  609. {
  610. auto ss = it.second;
  611. auto obj = yyjson_mut_obj(doc);
  612. yyjson_mut_arr_add_val(root, obj);
  613. string mo, mp, momp = it.first;
  614. spiltByPoint(momp, mo, mp);
  615. string station, mompname;
  616. CMonitorObjectMng::Instance()->GetStationNameByMomP(momp, station, mompname);
  617. string mo_name, mp_name;
  618. spiltByPoint(mompname, mo_name, mp_name);
  619. yyjson_mut_obj_add_strcpy(doc, obj, "station", station.c_str());
  620. yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name.c_str());
  621. yyjson_mut_obj_add_strcpy(doc, obj, "mp_name", mp_name.c_str());
  622. yyjson_mut_obj_add_strcpy(doc, obj, "mo", mo.c_str());
  623. yyjson_mut_obj_add_strcpy(doc, obj, "mp", mp.c_str());
  624. yyjson_mut_obj_add_strcpy(doc, obj, "name1", ss->name1.c_str());
  625. yyjson_mut_obj_add_strcpy(doc, obj, "name2", ss->name2.c_str());
  626. yyjson_mut_obj_add_strcpy(doc, obj, "name3", ss->name3.c_str());
  627. yyjson_mut_obj_add_strcpy(doc, obj, "direct1", ss->out_name.c_str());
  628. yyjson_mut_obj_add_strcpy(doc, obj, "direct2", ss->in_name.c_str());
  629. }
  630. size_t json_len;
  631. auto json = yyjson_mut_write(doc, 0, &json_len);
  632. yyjson_mut_doc_free(doc);
  633. *len = json_len + sizeof(HJDATAHEAD2) + 2;
  634. *pack = new uint8_t[*len];
  635. auto no = CAppService::Instance()->GetPackNo();
  636. CHjDataConver::conver_sendpack(*pack, (LPBYTE)json, json_len, 0, no, E_ZL_PROTOCAL::ZL_MP,
  637. OR_DATA_INFO(0, 0, 1, 2, OPT_TYPE::OPT_SYNC));
  638. free(json);
  639. return no;
  640. }
  641. void CMonitorObjectMng::UpdateZZJEPOS(const string& momp, DAOCHA_POSITION epos)
  642. {
  643. string mo, mp;
  644. spiltByPoint(momp, mo, mp);
  645. CString sql = fmt::format("UPDATE rm_map SET epos = {} where mo = '{}' and mp = '{}'", int(epos), mo, mp).c_str();
  646. auto ret = CDBConnectPool::Instance()->DBExecuteSQL(sql);
  647. if (ret)
  648. {
  649. auto lstEPOS = m_mapMoMpInfo[momp];
  650. lstEPOS->mapPos[time(0)] = (DAOCHA_POSITION)epos;
  651. if (lstEPOS->mapPos.size() > 10)
  652. {
  653. lstEPOS->mapPos.erase(lstEPOS->mapPos.begin());
  654. }
  655. }
  656. else
  657. {
  658. CSimpleLog::Error("更新语句错误:" + sql);
  659. }
  660. }
  661. //删除ZZJ历史记录,保留最新的一个
  662. void CMonitorObjectMng::ClearZZJHistroyEPOS(time_t t)
  663. {
  664. for (auto& item : m_mapMoMpInfo)
  665. {
  666. if (item.second == nullptr) continue;
  667. auto& epos = item.second->mapPos;
  668. if (epos.size() <= 1) continue;
  669. std::map<time_t, DAOCHA_POSITION> mapPos;
  670. mapPos[epos.rbegin()->first] = epos.rbegin()->second;
  671. epos.swap(mapPos);
  672. mapPos.clear();
  673. }
  674. }
  675. CMonitorObjectMng CMonitorObjectMng::obj;