MonitorObject.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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] = (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. if (!it->imei.empty())
  117. it->pDeivce = CDeviceMng::Instance()->Insert(imei);
  118. }
  119. {
  120. auto& it = m_mapMoMpName[momp];
  121. if (it.size() == 0)
  122. {
  123. it.emplace_back(name1);
  124. it.emplace_back(name2);
  125. it.emplace_back(name3);
  126. it.emplace_back(direct1); //伸出
  127. it.emplace_back(direct2); //缩进
  128. }
  129. else if (it.size() == 3)
  130. {
  131. it[0] = name1;
  132. it[1] = name2;
  133. it[2] = name3;
  134. it.emplace_back(direct1);
  135. it.emplace_back(direct2);
  136. }
  137. else if (it.size() == 5)
  138. {
  139. it[0] = name1;
  140. it[1] = name2;
  141. it[2] = name3;
  142. it[3] = direct1;
  143. it[4] = direct2;
  144. }
  145. else
  146. {
  147. it.clear();
  148. it.emplace_back(name1);
  149. it.emplace_back(name2);
  150. it.emplace_back(name3);
  151. it.emplace_back(direct1);
  152. it.emplace_back(direct2);
  153. }
  154. }
  155. {
  156. auto& it = m_mapMoMpDirect[momp];
  157. if (it.size() == 0)
  158. {
  159. it.push_back(direct1);
  160. it.push_back(direct2);
  161. }
  162. else if (it.size() == 2)
  163. {
  164. it[0] = direct1;
  165. it[1] = direct2;
  166. }
  167. else
  168. {
  169. it.clear();
  170. it.push_back(direct1);
  171. it.push_back(direct2);
  172. }
  173. }
  174. }
  175. return m_mapMoMpImeiIdx.size() + 1;
  176. }
  177. void CMonitorObjectMng::GetChild(std::list<CMonitorObject*>& lst, CMonitorObject* parent)
  178. {
  179. for (auto it = lst.begin(); it != lst.end(); ++it)
  180. {
  181. auto p = *it;
  182. if (p == nullptr) continue;
  183. if (p->id.compare(p->up) == 0)
  184. continue;
  185. if (p->up.compare(parent->id) == 0)
  186. {
  187. if (p->type.compare("mo") == 0)
  188. {
  189. for (auto& ik : m_mapMoMpImeiIdx)
  190. {
  191. //int ii = ik.first.find('.');
  192. //int jj = ik.first.find(p->id);
  193. string strName = p->id + '.';
  194. if (ik.first.find(strName) != -1)
  195. {
  196. auto pObject = new CMonitorObject;
  197. pObject->id = ik.first;
  198. pObject->name = p->name + "." + ik.first.substr(ik.first.find('.') + 1);
  199. pObject->type = "mo.mp";
  200. pObject->up = parent->id;
  201. pObject->parent = parent;
  202. pObject->eqpno = m_mapMoMpZZJNO[pObject->id];
  203. parent->m_lstMo.push_back(pObject);
  204. }
  205. }
  206. }
  207. else
  208. {
  209. p->parent = parent;
  210. parent->m_lstMo.push_back(p);
  211. *it = nullptr;
  212. GetChild(lst, p);
  213. }
  214. }
  215. }
  216. }
  217. bool CMonitorObjectMng::GetStationNameByMomP(CMonitorObject* pInfo, const std::string& momp, std::string& station, std::string& momp_name)
  218. {
  219. if (pInfo == nullptr) return false;
  220. if (pInfo->type.compare("mo.mp") == 0 && pInfo->id.compare(momp) == 0)
  221. {
  222. station = pInfo->up;
  223. momp_name = pInfo->name;
  224. return true;
  225. }
  226. for (const auto& it : pInfo->m_lstMo)
  227. {
  228. if (GetStationNameByMomP(it, momp, station, momp_name))
  229. return true;
  230. }
  231. return false;
  232. }
  233. void CMonitorObjectMng::Clear()
  234. {
  235. if (m_treeroot) delete m_treeroot;
  236. m_treeroot = nullptr;
  237. m_mapImeiIdxMoMp.clear();
  238. m_mapMoMpImeiIdx.clear();
  239. for (auto& it : m_mapMoMpInfo)
  240. delete it.second;
  241. m_mapMoMpInfo.clear();
  242. }
  243. BOOL CMonitorObjectMng::LoadMonitorTree()
  244. {
  245. Clear();
  246. if (!LoadMoMap()) return FALSE;
  247. char id[100];
  248. char type[50];
  249. char up[100];
  250. char name[100];
  251. CString sql = "SELECT [id],[type],[up],[name] FROM [rm_mo]";
  252. COdbcStatement stmt;
  253. if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
  254. {
  255. CSimpleLog::Error("执行语句失败" + sql);
  256. return FALSE;
  257. }
  258. int nCol = 1;
  259. stmt.BindCharCol(nCol++, id, sizeof(id));
  260. stmt.BindCharCol(nCol++, type, sizeof(type));
  261. stmt.BindCharCol(nCol++, up, sizeof(up));
  262. stmt.BindCharCol(nCol++, name, sizeof(name));
  263. list<CMonitorObject*> lstMo;
  264. while (true)
  265. {
  266. if (stmt.FetchNext() != 0)
  267. {
  268. break;
  269. }
  270. auto p = new CMonitorObject;
  271. p->id = id;
  272. p->type = type;
  273. p->up = up;
  274. p->name = name;
  275. //赋值节点名称
  276. if (p->type.compare("mo") == 0)
  277. {
  278. for (auto& it : m_mapMoMpInfo)
  279. {
  280. if (it.second->mo.compare(id) == 0)
  281. it.second->name = fmt::format("{}.{}", name, it.second->mp);
  282. }
  283. }
  284. if (p->id.compare(up) == 0)
  285. {
  286. swap(m_treeroot, p);
  287. delete p;
  288. p = nullptr;
  289. }
  290. else
  291. {
  292. lstMo.push_back(p);
  293. }
  294. }
  295. bool bret = true;
  296. if (m_treeroot == nullptr)
  297. {
  298. assert(0);
  299. bret = false;
  300. goto l;
  301. }
  302. GetChild(lstMo, m_treeroot);
  303. l:
  304. for (auto it = lstMo.begin(); it != lstMo.end(); ++it)
  305. delete (*it);
  306. lstMo.clear();
  307. //test
  308. //{
  309. // string momp = "HZHDJD21.X";
  310. // string name, name2;
  311. // GetStationNameByMomP(momp, name, name2);
  312. //}
  313. return TRUE;
  314. }
  315. BOOL CMonitorObjectMng::LoadHistoryData()
  316. {
  317. for (auto& it : m_mapMoMpImeiIdx)
  318. {
  319. string imei, idx;
  320. spiltByPoint(it.second, imei, idx);
  321. if (imei.length() > 5) CDeviceMng::Instance()->Insert(imei);
  322. }
  323. return TRUE;
  324. }
  325. bool CMonitorObjectMng::IMEI2MOMP(const std::string imei, const int idx, std::string& mo, std::string& mp)
  326. {
  327. auto& it = m_mapImeiIdxMoMp.find(concatStringByPoint(imei, to_string(idx)));
  328. if (it == m_mapImeiIdxMoMp.end()) return false;
  329. return spiltByPoint(it->second, mo, mp);
  330. }
  331. bool CMonitorObjectMng::IMEI2MOMP(const std::string& imei_idx, std::string& mo_mp)
  332. {
  333. auto& it = m_mapImeiIdxMoMp.find(imei_idx);
  334. if (it == m_mapImeiIdxMoMp.end()) return false;
  335. mo_mp = it->second;
  336. return true;
  337. }
  338. bool CMonitorObjectMng::MOMP2IMEI(const std::string& mo, const std::string& mp, std::string& imei, int& idx)
  339. {
  340. auto& it = m_mapMoMpImeiIdx.find(concatStringByPoint(mo, mp));
  341. if (it == m_mapMoMpImeiIdx.end()) return false;
  342. string idx2;
  343. if (!spiltByPoint(it->second, imei, idx2)) return false;
  344. idx = atoi(idx2.c_str());
  345. return true;
  346. }
  347. bool CMonitorObjectMng::MOMP2IMEI(const std::string& momp, std::string& imeiidx)
  348. {
  349. auto& it = m_mapMoMpImeiIdx.find(momp);
  350. if (it == m_mapMoMpImeiIdx.end()) return false;
  351. if (it->second.length() <= 0) return false;
  352. imeiidx = it->second;
  353. return true;
  354. }
  355. bool CMonitorObjectMng::MOMP2IMEI(const std::string& momp, std::string& imei, int& idx)
  356. {
  357. auto& it = m_mapMoMpImeiIdx.find(momp);
  358. if (it == m_mapMoMpImeiIdx.end()) return false;
  359. string idx2;
  360. if (!spiltByPoint(it->second, imei, idx2)) return false;
  361. idx = atoi(idx2.c_str());
  362. return true;
  363. }
  364. bool CMonitorObjectMng::GetStationNameByMomP(const std::string& momp, std::string& station, std::string& momp_name)
  365. {
  366. return GetStationNameByMomP(m_treeroot, momp, station, momp_name);
  367. }
  368. bool CMonitorObjectMng::GetStationNameByMomP(const std::string& mo, const std::string& mp, std::string& station, std::string& momp_name)
  369. {
  370. return GetStationNameByMomP(m_treeroot, mo + "." + mp, station, momp_name);
  371. }
  372. bool CMonitorObjectMng::GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3)
  373. {
  374. auto& it = m_mapMoMpName.find(momp);
  375. if (it == m_mapMoMpName.end()) return false;
  376. if (it->second.size() < 3) return false;
  377. name1 = it->second[0];
  378. name2 = it->second[1];
  379. name3 = it->second[2];
  380. return true;
  381. }
  382. bool CMonitorObjectMng::GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3, std::string& out_name, std::string& in_name)
  383. {
  384. auto& it = m_mapMoMpName.find(momp);
  385. if (it == m_mapMoMpName.end()) return false;
  386. if (it->second.size() < 5) return false;
  387. name1 = it->second[0];
  388. name2 = it->second[1];
  389. name3 = it->second[2];
  390. out_name = it->second[3];
  391. in_name = it->second[4];
  392. return true;
  393. }
  394. void CMonitorObjectMng::SetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3)
  395. {
  396. auto& it = m_mapMoMpName.find(momp);
  397. if (it == m_mapMoMpName.end())
  398. {
  399. std::vector<string> vct;
  400. vct.push_back(name1);
  401. vct.push_back(name2);
  402. vct.push_back(name3);
  403. m_mapMoMpName[momp] = vct;
  404. }
  405. else
  406. {
  407. it->second[0] = name1;
  408. it->second[1] = name2;
  409. it->second[2] = name3;
  410. }
  411. {
  412. auto it = GetMoMpInfo(momp);
  413. if (it)
  414. {
  415. it->name1 = name1;
  416. it->name2 = name2;
  417. it->name3 = name3;
  418. it->name1utf = ANSItoUTF8(name1);
  419. it->name2utf = ANSItoUTF8(name2);
  420. it->name3 = ANSItoUTF8(name3);
  421. }
  422. }
  423. }
  424. bool CMonitorObjectMng::GetDirectByMoMp(const std::string& momp, std::string& out_name, std::string& in_name)
  425. {
  426. auto it = GetMoMpInfo(momp);
  427. if (it == nullptr) return false;
  428. out_name = it->out_name;
  429. in_name = it->in_name;
  430. return true;
  431. }
  432. void CMonitorObjectMng::SetDirectByMoMp(const std::string& momp, std::string& direct1, std::string& direct2)
  433. {
  434. auto& it = m_mapMoMpDirect.find(momp);
  435. if (it == m_mapMoMpDirect.end())
  436. {
  437. std::vector<string> vct;
  438. vct.push_back(direct1);
  439. vct.push_back(direct2);
  440. m_mapMoMpDirect[momp] = vct;
  441. }
  442. else
  443. {
  444. it->second[0] = direct1;
  445. it->second[1] = direct2;
  446. }
  447. {
  448. auto it = GetMoMpInfo(momp);
  449. if (it)
  450. {
  451. it->out_name = direct1;
  452. it->in_name = direct2;
  453. //it->name1utf = ANSItoUTF8(direct1);
  454. //it->name2utf = ANSItoUTF8(direct2);
  455. }
  456. }
  457. }
  458. bool CMonitorObjectMng::spiltByPoint(const std::string&src, std::string& dst1, std::string& dst2)
  459. {
  460. auto pos = src.find('.');
  461. if (pos == -1) return false;
  462. dst1 = src.substr(0, pos);
  463. dst2 = src.substr(pos + 1);
  464. return true;
  465. }
  466. std::string CMonitorObjectMng::concatStringByPoint(const std::string& src1, const std::string& src2)
  467. {
  468. stringstream ss;
  469. ss << src1 << "." << src2;
  470. return ss.str();
  471. }
  472. CMonitorObject* CMonitorObjectMng::GetTreeByID(CMonitorObject* p, const string& id)
  473. {
  474. if (p->id.compare(id) == 0)
  475. {
  476. return p;
  477. }
  478. else
  479. {
  480. for (const auto& it : p->m_lstMo)
  481. {
  482. auto pObj = GetTreeByID(it, id);
  483. if (pObj) return pObj;
  484. }
  485. }
  486. return nullptr;
  487. }
  488. CMonitorObject* CMonitorObjectMng::GetTreeByEpqID(CMonitorObject* p, uint16_t id)
  489. {
  490. if (p->eqpno == id)
  491. {
  492. return p;
  493. }
  494. else
  495. {
  496. for (const auto& it : p->m_lstMo)
  497. {
  498. auto pObj = GetTreeByEpqID(it, id);
  499. if (pObj) return pObj;
  500. }
  501. }
  502. return nullptr;
  503. }
  504. CMonitorObject* CMonitorObjectMng::GetTreeByID(const string& id)
  505. {
  506. CMonitorObject* pObject = nullptr;
  507. do {
  508. if (m_treeroot == nullptr) break;
  509. return GetTreeByID(m_treeroot, id);
  510. } while (false);
  511. return pObject;
  512. }
  513. CMonitorObject* CMonitorObjectMng::GetTreeByEpqID(uint16_t id)
  514. {
  515. CMonitorObject* pObject = nullptr;
  516. do {
  517. if (m_treeroot == nullptr) break;
  518. return GetTreeByEpqID(m_treeroot, id);
  519. } while (false);
  520. return pObject;
  521. }
  522. void CMonitorObjectMng::GetAllObjByType(CMonitorObject* p, std::vector<CMonitorObject*>& vctObj, const string& type)
  523. {
  524. if (p->type.compare(type) == 0)
  525. {
  526. vctObj.push_back(p);
  527. }
  528. for (auto& it : p->m_lstMo)
  529. {
  530. GetAllObjByType(it, vctObj, type);
  531. }
  532. }
  533. //获取所有Type对象
  534. bool CMonitorObjectMng::GetAllObjByType(std::vector<CMonitorObject*>& vctObj, const string& type)
  535. {
  536. do {
  537. if (m_treeroot == nullptr) break;
  538. GetAllObjByType(m_treeroot, vctObj, type);
  539. } while (false);
  540. return !vctObj.empty();
  541. }
  542. uint32_t CMonitorObjectMng::GeneralMoPack(uint8_t** pack, int* len)
  543. {
  544. if (m_treeroot == nullptr) return 0;
  545. auto doc = yyjson_mut_doc_new(nullptr);
  546. auto root = yyjson_mut_obj(doc);
  547. yyjson_mut_doc_set_root(doc, root);
  548. GeneralMoPack(m_treeroot, doc, root);
  549. size_t json_len;
  550. auto json = yyjson_mut_write(doc, 0, &json_len);
  551. yyjson_mut_doc_free(doc);
  552. int new_len = json_len + sizeof(HJDATAHEAD2) + 2;
  553. *pack = new uint8_t[new_len];
  554. memset(*pack, 0, new_len);
  555. auto no = CAppService::Instance()->GetPackNo();
  556. *len = CHjDataConver::conver_sendpack(*pack, (LPBYTE)json, json_len, 0, no, E_ZL_PROTOCAL::ZL_MO,
  557. OR_DATA_INFO(0, 0, 1, 2, OPT_TYPE::OPT_SYNC));
  558. free(json);
  559. return no;
  560. }
  561. void CMonitorObjectMng::GeneralMoPack(CMonitorObject* pObject, yyjson_mut_doc* doc, yyjson_mut_val* val)
  562. {
  563. yyjson_mut_obj_add_str(doc, val, "id", pObject->id.c_str());
  564. yyjson_mut_obj_add_str(doc, val, "name", pObject->name.c_str());
  565. yyjson_mut_obj_add_str(doc, val, "type", pObject->type.c_str());
  566. yyjson_mut_obj_add_str(doc, val, "up", pObject->up.c_str());
  567. yyjson_mut_val* arr = nullptr;
  568. if (pObject->m_lstMo.size() > 0)
  569. {
  570. arr = yyjson_mut_arr(doc);
  571. yyjson_mut_obj_add_val(doc, val, "child", arr);
  572. }
  573. for (auto& it : pObject->m_lstMo)
  574. {
  575. auto object = yyjson_mut_obj(doc);
  576. yyjson_mut_arr_add_val(arr, object);
  577. GeneralMoPack(it, doc, object);
  578. }
  579. }
  580. uint32_t CMonitorObjectMng::GeneralMpPack(uint8_t** pack, int* len)
  581. {
  582. if (m_mapMoMpName.size() == 0) return 0;
  583. auto doc = yyjson_mut_doc_new(nullptr);
  584. auto root = yyjson_mut_arr(doc);
  585. yyjson_mut_doc_set_root(doc, root);
  586. for (const auto& it : m_mapMoMpName)
  587. {
  588. auto ss = it.second;
  589. if (ss.size() == 5)
  590. {
  591. auto obj = yyjson_mut_obj(doc);
  592. yyjson_mut_arr_add_val(root, obj);
  593. string mo, mp, momp = it.first;
  594. spiltByPoint(momp, mo, mp);
  595. string station, mompname;
  596. CMonitorObjectMng::Instance()->GetStationNameByMomP(momp, station, mompname);
  597. string mo_name, mp_name;
  598. spiltByPoint(mompname, mo_name, mp_name);
  599. yyjson_mut_obj_add_strcpy(doc, obj, "station", station.c_str());
  600. yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name.c_str());
  601. yyjson_mut_obj_add_strcpy(doc, obj, "mp_name", mp_name.c_str());
  602. yyjson_mut_obj_add_strcpy(doc, obj, "mo", mo.c_str());
  603. yyjson_mut_obj_add_strcpy(doc, obj, "mp", mp.c_str());
  604. yyjson_mut_obj_add_strcpy(doc, obj, "name1", ss[0].c_str());
  605. yyjson_mut_obj_add_strcpy(doc, obj, "name2", ss[1].c_str());
  606. yyjson_mut_obj_add_strcpy(doc, obj, "name3", ss[2].c_str());
  607. yyjson_mut_obj_add_strcpy(doc, obj, "direct1", ss[3].c_str());
  608. yyjson_mut_obj_add_strcpy(doc, obj, "direct2", ss[4].c_str());
  609. }
  610. }
  611. size_t json_len;
  612. auto json = yyjson_mut_write(doc, 0, &json_len);
  613. yyjson_mut_doc_free(doc);
  614. *len = json_len + sizeof(HJDATAHEAD2) + 2;
  615. *pack = new uint8_t[*len];
  616. auto no = CAppService::Instance()->GetPackNo();
  617. CHjDataConver::conver_sendpack(*pack, (LPBYTE)json, json_len, 0, no, E_ZL_PROTOCAL::ZL_MP,
  618. OR_DATA_INFO(0, 0, 1, 2, OPT_TYPE::OPT_SYNC));
  619. free(json);
  620. return no;
  621. }
  622. void CMonitorObjectMng::UpdateZZJEPOS(const string& momp, DAOCHA_POSITION epos)
  623. {
  624. string mo, mp;
  625. spiltByPoint(momp, mo, mp);
  626. CString sql = fmt::format("UPDATE rm_map SET epos = {} where mo = '{}' and mp = '{}'", int(epos), mo, mp).c_str();
  627. auto ret = CDBConnectPool::Instance()->DBExecuteSQL(sql);
  628. if (ret)
  629. {
  630. m_mapMoMpZZJEPOS[momp] = epos;
  631. }
  632. else
  633. {
  634. CSimpleLog::Error("更新语句错误:" + sql);
  635. }
  636. }
  637. CMonitorObjectMng CMonitorObjectMng::obj;