GlobalVariable.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. #include "GlobalVariable.h"
  2. #include "spdlog/spdlog.h"
  3. // #include "FuncBase.h"
  4. /* ====================================================================================
  5. * ******************************* 全局变量定义 **********************************
  6. * ====================================================================================*/
  7. int g_eventTimeVaild = 600; /* 事件时间有效性,单位秒,超过这个时间就认为是无效数据 */
  8. ActionList g_actionList; /* 全局算法列表 */
  9. /* ====================================================================================
  10. * *************************** DeviceInfo成员函数 *******************************
  11. * ====================================================================================*/
  12. /* 对比是否相等 */
  13. bool DeviceInfo::operator==(const DeviceInfo& other)
  14. {
  15. if(DeviceID != other.DeviceID) {
  16. return false;
  17. }
  18. else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
  19. return false;
  20. }
  21. else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
  22. return false;
  23. }
  24. else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
  25. return false;
  26. }
  27. return true;
  28. }
  29. /* 对比设备关联的算法信息是否相等 */
  30. bool DeviceInfo::isEqualAlgorithmInfo(const std::vector<AlgorithmInfo>& other)
  31. {
  32. /* 算法数目不相等,直接返回false */
  33. if(vecAlgorithmInfo.size() != other.size()) {
  34. return false;
  35. }else {
  36. /* 算法数目相等,进一步对比算法信息 */
  37. bool isEquality = true;
  38. /* 逐步对比算法信息 */
  39. for(const auto& it0 : vecAlgorithmInfo) {
  40. bool isEq2 = true;
  41. for(const auto& it1 : other) {
  42. if(it0 == it1) {
  43. continue;
  44. }else {
  45. isEq2 = false;
  46. break;
  47. }
  48. }
  49. if(!isEq2) {
  50. isEquality = false;
  51. break;
  52. }
  53. }
  54. if(!isEquality) {
  55. return false;
  56. }
  57. }
  58. return true;
  59. }
  60. /* ====================================================================================
  61. * ******************************* 各种报警信息 **********************************
  62. * ====================================================================================*/
  63. AlarmInfo::AlarmInfo()
  64. {
  65. Is_Alarm = false;
  66. Is_InsertEQM = false;
  67. Is_OnWork = false;
  68. AlarmID = 0;
  69. DeviceID = 0;
  70. RoomID = 0;
  71. ChannelID = 0;
  72. State = 0;
  73. OnWork = 0;
  74. StartTime = "";
  75. EndTime = "";
  76. EventTime = "";
  77. PicUrl = "";
  78. ImageInfo = "";
  79. // AppID = "";
  80. ActionID = "";
  81. ActionDes = "";
  82. FaceIDList = "";
  83. FaceNameList = "";
  84. listBbox.clear();
  85. listPersonInfo.clear();
  86. appFunction = AppFunction::APP_NONE;
  87. }
  88. AlarmInfo::AlarmInfo(const AlarmInfo& other)
  89. {
  90. Is_Alarm = other.Is_Alarm;
  91. Is_InsertEQM = other.Is_InsertEQM;
  92. Is_OnWork = other.Is_OnWork;
  93. AlarmID = other.AlarmID;
  94. DeviceID = other.DeviceID;
  95. RoomID = other.RoomID;
  96. ChannelID = other.ChannelID;
  97. State = other.State;
  98. OnWork = other.OnWork;
  99. StartTime = other.StartTime;
  100. EndTime = other.EndTime;
  101. EventTime = other.EventTime;
  102. PicUrl = other.PicUrl;
  103. ImageInfo = other.ImageInfo;
  104. // AppID = other.AppID;
  105. ActionID = other.ActionID;
  106. ActionDes = other.ActionDes;
  107. FaceIDList = other.FaceIDList;
  108. FaceNameList = other.FaceNameList;
  109. listBbox = other.listBbox;
  110. listPersonInfo = other.listPersonInfo;
  111. appFunction = other.appFunction;
  112. }
  113. AlarmInfo& AlarmInfo::operator=(AlarmInfo& other)
  114. {
  115. if(this != &other)
  116. {
  117. Is_Alarm = other.Is_Alarm;
  118. Is_InsertEQM = other.Is_InsertEQM;
  119. Is_OnWork = other.Is_OnWork;
  120. AlarmID = other.AlarmID;
  121. DeviceID = other.DeviceID;
  122. RoomID = other.RoomID;
  123. ChannelID = other.ChannelID;
  124. State = other.State;
  125. OnWork = other.OnWork;
  126. StartTime = other.StartTime;
  127. EndTime = other.EndTime;
  128. EventTime = other.EventTime;
  129. PicUrl = other.PicUrl;
  130. ImageInfo = other.ImageInfo;
  131. // AppID = other.AppID;
  132. ActionID = other.ActionID;
  133. ActionDes = other.ActionDes;
  134. FaceIDList = other.FaceIDList;
  135. FaceNameList = other.FaceNameList;
  136. listBbox = other.listBbox;
  137. listPersonInfo = other.listPersonInfo;
  138. appFunction = other.appFunction;
  139. }
  140. return *this;
  141. }
  142. /* 清空内容 */
  143. void AlarmInfo::reInit()
  144. {
  145. Is_Alarm = false;
  146. Is_InsertEQM = false;
  147. Is_OnWork = false;
  148. AlarmID = 0;
  149. DeviceID = 0;
  150. RoomID = 0;
  151. ChannelID = 0;
  152. State = 0;
  153. OnWork = 0;
  154. StartTime = "";
  155. EndTime = "";
  156. EventTime = "";
  157. PicUrl = "";
  158. ImageInfo = "";
  159. // AppID = "";
  160. ActionID = "";
  161. ActionDes = "";
  162. FaceIDList = "";
  163. FaceNameList = "";
  164. listBbox.clear();
  165. listPersonInfo.clear();
  166. appFunction = AppFunction::APP_NONE;
  167. }
  168. /* 获取人脸列表 */
  169. std::string AlarmInfo::getFaceIDListString()
  170. {
  171. std::string strFaceList = "";
  172. for(auto& it : listPersonInfo)
  173. {
  174. if(it.PersonID.size() < 0)
  175. {
  176. continue;
  177. }
  178. strFaceList += it.PersonID + ";" ;
  179. }
  180. /* 去掉最后的“;” */
  181. if(strFaceList.size() > 0)
  182. {
  183. strFaceList = strFaceList.substr(0, strFaceList.size() - 1);
  184. }
  185. return strFaceList;
  186. }
  187. /* 获取人脸名称列表 */
  188. std::string AlarmInfo::getFaceNameListString()
  189. {
  190. std::string strFaceName;
  191. for(auto& it : listPersonInfo)
  192. {
  193. if(it.PersonName.size() < 0)
  194. {
  195. continue;
  196. }
  197. strFaceName += it.PersonName + ";";
  198. }
  199. /* 去掉最后的“;” */
  200. if(strFaceName.size() > 0)
  201. {
  202. strFaceName = strFaceName.substr(0, strFaceName.size() - 1);
  203. }
  204. return strFaceName;
  205. }
  206. /**
  207. * @brief 添加报警信息
  208. *
  209. * @param info
  210. * @return true
  211. * @return false
  212. */
  213. bool ListAlarmInfo::addAlarmInfo(AlarmInfo& info)
  214. {
  215. /* 先查找有没有重复的 */
  216. auto p = findAlarmInfo(info);
  217. if(p != nullptr)
  218. {
  219. return false;
  220. }
  221. AlarmInfo* pNew = new AlarmInfo(info);
  222. listAlarmInfo.push_back(pNew);
  223. return true;
  224. }
  225. /**
  226. * @brief 检查列表中是是否有这个报警信息,这里只检查ChannelID、RoomID、CameraID、ActionID是否相等
  227. *
  228. * @param info
  229. * @return AlarmInfo*
  230. */
  231. AlarmInfo* ListAlarmInfo::findAlarmInfo(AlarmInfo& info)
  232. {
  233. for(auto& it0 : listAlarmInfo)
  234. {
  235. if(it0->ChannelID == info.ChannelID && it0->RoomID == info.RoomID && it0->DeviceID == info.DeviceID && it0->ActionID == info.ActionID)
  236. {
  237. return it0;
  238. }
  239. }
  240. return nullptr;
  241. }
  242. /* 删除报警记录 */
  243. void ListAlarmInfo::deleteAlarmInfo(AlarmInfo& info)
  244. {
  245. for(auto it = listAlarmInfo.begin(); it != listAlarmInfo.end();)
  246. {
  247. if((*it)->ChannelID == info.ChannelID && (*it)->RoomID == info.RoomID && (*it)->DeviceID == info.DeviceID && (*it)->ActionID == info.ActionID)
  248. {
  249. delete *it;
  250. it = listAlarmInfo.erase(it);
  251. }else {
  252. ++it;
  253. }
  254. }
  255. }
  256. /* 清空报警记录 */
  257. void ListAlarmInfo::clearAlarmInfo()
  258. {
  259. for(auto& it : listAlarmInfo)
  260. {
  261. delete it;
  262. }
  263. listAlarmInfo.clear();
  264. }
  265. /* 查找是否有相同的人脸信息 */
  266. bool RoomFaceInfo::findPersonInfo(const PersonInfo& info)
  267. {
  268. for(auto& it0 : listPersonInfo)
  269. {
  270. if(it0.PersonID == info.PersonID && it0.PersonName == info.PersonName)
  271. {
  272. return true;
  273. }
  274. }
  275. return false;
  276. }
  277. /* 添加房间人脸信息 */
  278. void ListRoomFaceInfo::addRoomFaceInfo(RoomFaceInfo& info)
  279. {
  280. /* 先查找有没有重复的 */
  281. auto p = findRoomFaceInfo(info);
  282. if(p != nullptr)
  283. {
  284. return;
  285. }
  286. listRoomFaceInfo.push_back(info);
  287. }
  288. /**
  289. * @brief 通过报警信息添加人脸信息
  290. *
  291. * @param info
  292. */
  293. void ListRoomFaceInfo::addRoomFaceInfo(AlarmInfo& info)
  294. {
  295. auto p = findRoomFaceInfo(info.ChannelID, info.RoomID, info.DeviceID);
  296. if(p == nullptr)
  297. {
  298. RoomFaceInfo rfi;
  299. rfi.ChannelID = info.ChannelID;
  300. rfi.RoomID = info.RoomID;
  301. rfi.CameraID = info.DeviceID;
  302. rfi.MaxNum = 0;
  303. rfi.MinNum = 0;
  304. rfi.StartTime = QDateTime::currentDateTime();
  305. listRoomFaceInfo.push_back(rfi);
  306. }
  307. /* 将人员信息加入到列表中,添加时会先查找有没有相同的信息 */
  308. for(auto& it0 : info.listPersonInfo)
  309. {
  310. if(!p->findPersonInfo(it0))
  311. {
  312. p->listPersonInfo.push_back(it0);
  313. }
  314. }
  315. }
  316. RoomFaceInfo* ListRoomFaceInfo::findRoomFaceInfo(RoomFaceInfo& info)
  317. {
  318. for(auto& it0 : listRoomFaceInfo)
  319. {
  320. if(it0.ChannelID == info.ChannelID && it0.RoomID == info.RoomID && it0.CameraID == info.CameraID)
  321. {
  322. return &it0;
  323. }
  324. }
  325. return nullptr;
  326. }
  327. /* 查找有没有相同的结构 */
  328. RoomFaceInfo* ListRoomFaceInfo::findRoomFaceInfo(int ChannelID, int RoomID, int CameraID)
  329. {
  330. for(auto& it0 : listRoomFaceInfo)
  331. {
  332. if(it0.ChannelID == ChannelID && it0.RoomID == RoomID && it0.CameraID == CameraID)
  333. {
  334. return &it0;
  335. }
  336. }
  337. return nullptr;
  338. }
  339. /* ====================================================================================
  340. * ************************** ListActionInfo成员函数 ****************************
  341. * ====================================================================================*/
  342. ActionInfo::ActionInfo()
  343. {
  344. RunState = RunTimeState::RUN_STATE_INIT;
  345. ChannelID = -1;
  346. RoomID = -1;
  347. CameraID = -1;
  348. RoomType = Enum_RoomType::ROOM_NONE;
  349. ActionID = "";
  350. strRoomName = "";
  351. strActionName = "";
  352. }
  353. ActionInfo& ActionInfo::operator=(const ActionInfo& other)
  354. {
  355. if (this != &other)
  356. {
  357. ChannelID = other.ChannelID;
  358. RoomID = other.RoomID;
  359. CameraID = other.CameraID;
  360. ActionID = other.ActionID;
  361. strRoomName = other.strRoomName;
  362. RoomType = other.RoomType;
  363. }
  364. return *this;
  365. }
  366. bool ActionInfo::operator==(const ActionInfo& other)
  367. {
  368. if(ChannelID != other.ChannelID) {
  369. return false;
  370. }
  371. if(RoomID != other.RoomID) {
  372. return false;
  373. }
  374. if(CameraID != other.CameraID) {
  375. return false;
  376. }
  377. if(ActionID != other.ActionID) {
  378. return false;
  379. }
  380. if(RoomType != other.RoomType) {
  381. return false;
  382. }
  383. return true;
  384. }
  385. /* 对比除摄像机外的基础信息是否相等 */
  386. bool ActionInfo::isEqualBaseInfo(const ActionInfo& other)
  387. {
  388. if(ChannelID != other.ChannelID) {
  389. return false;
  390. }
  391. if(RoomID != other.RoomID) {
  392. return false;
  393. }
  394. if(ActionID != other.ActionID) {
  395. return false;
  396. }
  397. if(RoomType != other.RoomType) {
  398. return false;
  399. }
  400. return true;
  401. }
  402. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  403. bool ListActionInfo::insertActionInfo(ActionInfo* info)
  404. {
  405. /* 先判断是否已经在列表中了 */
  406. if(findActionInList(info) == nullptr)
  407. {
  408. ActionInfo* pActionInfo = new ActionInfo;
  409. *pActionInfo = *info;
  410. listActionInfo.push_back(pActionInfo);
  411. }
  412. return true;
  413. }
  414. /* 删除信息 */
  415. bool ListActionInfo::deleteActionInfo(ActionInfo* info)
  416. {
  417. if(info == nullptr)
  418. {
  419. return false;
  420. }
  421. if(findActionInList(info) != nullptr)
  422. {
  423. listActionInfo.remove(info);
  424. delete info;
  425. info = nullptr;
  426. }
  427. return true;
  428. }
  429. /* 给算法添加摄像机,原有的会被替换掉 */
  430. bool ListActionInfo::addActionCamera(ActionInfo* pInfo)
  431. {
  432. auto pActionInfo = findActionIDInListNoCamera(pInfo);
  433. if(pActionInfo != nullptr)
  434. {
  435. pActionInfo->CameraID = pInfo->CameraID;
  436. }
  437. return true;
  438. }
  439. /* 清空算法中的摄像机信息 */
  440. void ListActionInfo::clearCameraList()
  441. {
  442. for(auto& it0 : listActionInfo)
  443. {
  444. it0->CameraID = -1;
  445. }
  446. }
  447. /* 清空设置成STOP或ERROR的Action */
  448. void ListActionInfo::clearStopAction()
  449. {
  450. for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();)
  451. {
  452. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  453. {
  454. delete *it0;
  455. it0 = listActionInfo.erase(it0);
  456. }else {
  457. ++it0;
  458. }
  459. }
  460. }
  461. /* 查找算法ID是否已在列表中 */
  462. ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
  463. {
  464. for(const auto& it0 : listActionInfo)
  465. {
  466. if(*it0 == *pInfo)
  467. {
  468. return it0;
  469. }
  470. }
  471. return nullptr;
  472. }
  473. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  474. ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo)
  475. {
  476. for(const auto& it0 : listActionInfo)
  477. {
  478. if(it0->isEqualBaseInfo(*pInfo))
  479. {
  480. return it0;
  481. }
  482. }
  483. return nullptr;
  484. }
  485. /* 清空容器 */
  486. void ListActionInfo::clear()
  487. {
  488. for(auto& it0 : listActionInfo)
  489. {
  490. delete it0;
  491. it0 = nullptr;
  492. }
  493. listActionInfo.clear();
  494. }
  495. /* ====================================================================================
  496. * *********************** ListRoomActionInfo成员函数 ***************************
  497. * ====================================================================================*/
  498. /* 对比频道信息、房间信息、算法ID是否相等 */
  499. bool RoomActionInfo::isEqualBaseInfo(const RoomActionInfo& other)
  500. {
  501. if(ChannelID != other.ChannelID) {
  502. return false;
  503. }
  504. if(RoomID != other.RoomID) {
  505. return false;
  506. }
  507. if(ActionID != other.ActionID) {
  508. return false;
  509. }
  510. if(RoomType != other.RoomType) {
  511. return false;
  512. }
  513. return true;
  514. }
  515. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  516. bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
  517. {
  518. /* 先判断是否已经在列表中了 */
  519. if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr)
  520. {
  521. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  522. *pRoomActionInfo = info;
  523. listRoomActionInfo.push_back(pRoomActionInfo);
  524. }
  525. return true;
  526. }
  527. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  528. bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID)
  529. {
  530. /* 先判断是否已经在列表中了 */
  531. if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr)
  532. {
  533. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  534. pRoomActionInfo->RoomID = RoomID;
  535. pRoomActionInfo->ActionID = strActionID;
  536. listRoomActionInfo.push_back(pRoomActionInfo);
  537. }
  538. return true;
  539. }
  540. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  541. bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo)
  542. {
  543. if(pInfo == nullptr)
  544. {
  545. return false;
  546. }
  547. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0)
  548. {
  549. if(*it0 == pInfo)
  550. {
  551. listRoomActionInfo.erase(it0);
  552. delete pInfo;
  553. pInfo = nullptr;
  554. return true;
  555. }
  556. }
  557. return false;
  558. }
  559. /* 清空容器 */
  560. void ListRoomActionInfo::clear()
  561. {
  562. for(auto& it0 : listRoomActionInfo)
  563. {
  564. delete it0;
  565. it0 = nullptr;
  566. }
  567. listRoomActionInfo.clear();
  568. }
  569. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  570. void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
  571. {
  572. auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
  573. if(pRAInfo != nullptr)
  574. {
  575. pRAInfo->listCameraID.push_back(info.CameraID);
  576. }else {
  577. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  578. pRoomActionInfo->ChannelID = info.ChannelID;
  579. pRoomActionInfo->RoomID = info.RoomID;
  580. pRoomActionInfo->ActionID = info.ActionID;
  581. pRoomActionInfo->RoomType = info.RoomType;
  582. pRoomActionInfo->strRoomName = info.strRoomName;
  583. pRoomActionInfo->listCameraID.push_back(info.CameraID);
  584. listRoomActionInfo.push_back(pRoomActionInfo);
  585. }
  586. }
  587. /* 清空算法对应的摄像机列表 */
  588. void ListRoomActionInfo::clearCameraList()
  589. {
  590. for(auto& it0 : listRoomActionInfo)
  591. {
  592. it0->listCameraID.clear();
  593. }
  594. }
  595. /* 清理设置为STOP或者ERROR的RoomAction */
  596. // void ListRoomActionInfo::clearStopRoomAction()
  597. // {
  598. // for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();)
  599. // {
  600. // if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  601. // {
  602. // delete *it0;
  603. // it0 = listRoomActionInfo.erase(it0);
  604. // }else {
  605. // ++it0;
  606. // }
  607. // }
  608. // }
  609. /* 查找算法ID是否已在列表中 */
  610. RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
  611. {
  612. for(const auto& it0 : listRoomActionInfo)
  613. {
  614. if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
  615. {
  616. return it0;
  617. }
  618. }
  619. return nullptr;
  620. }