GlobalInfo.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  1. #include "GlobalInfo.h"
  2. #include <QSettings>
  3. #include "spdlog/spdlog.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. AlarmID = 0;
  67. DeviceID = 0;
  68. RoomID = 0;
  69. ChannelID = 0;
  70. State = 0;
  71. OnWork = 0;
  72. StartTime = "";
  73. EndTime = "";
  74. EventTime = "";
  75. PicUrl = "";
  76. ImageInfo = "";
  77. AppID = "";
  78. ActionID = "";
  79. ActionDes = "";
  80. FaceIDList = "";
  81. FaceNameList = "";
  82. BboxList = "";
  83. }
  84. AlarmInfo::AlarmInfo(const AlarmInfo& other)
  85. {
  86. Is_Alarm = other.Is_Alarm;
  87. AlarmID = other.AlarmID;
  88. DeviceID = other.DeviceID;
  89. RoomID = other.RoomID;
  90. ChannelID = other.ChannelID;
  91. State = other.State;
  92. OnWork = other.OnWork;
  93. StartTime = other.StartTime;
  94. EndTime = other.EndTime;
  95. EventTime = other.EventTime;
  96. PicUrl = other.PicUrl;
  97. ImageInfo = other.ImageInfo;
  98. AppID = other.AppID;
  99. ActionID = other.ActionID;
  100. ActionDes = other.ActionDes;
  101. FaceIDList = other.FaceIDList;
  102. FaceNameList = other.FaceNameList;
  103. BboxList = other.BboxList;
  104. vecPersonInfo = other.vecPersonInfo;
  105. }
  106. AlarmInfo& AlarmInfo::operator=(AlarmInfo& other)
  107. {
  108. if(this != &other)
  109. {
  110. Is_Alarm = other.Is_Alarm;
  111. AlarmID = other.AlarmID;
  112. DeviceID = other.DeviceID;
  113. RoomID = other.RoomID;
  114. ChannelID = other.ChannelID;
  115. State = other.State;
  116. OnWork = other.OnWork;
  117. StartTime = other.StartTime;
  118. EndTime = other.EndTime;
  119. EventTime = other.EventTime;
  120. PicUrl = other.PicUrl;
  121. ImageInfo = other.ImageInfo;
  122. AppID = other.AppID;
  123. ActionID = other.ActionID;
  124. ActionDes = other.ActionDes;
  125. FaceIDList = other.FaceIDList;
  126. FaceNameList = other.FaceNameList;
  127. BboxList = other.BboxList;
  128. vecPersonInfo = other.vecPersonInfo;
  129. }
  130. return *this;
  131. }
  132. /* 清空内容 */
  133. void AlarmInfo::reInit()
  134. {
  135. Is_Alarm = false;
  136. AlarmID = 0;
  137. DeviceID = 0;
  138. RoomID = 0;
  139. ChannelID = 0;
  140. State = 0;
  141. OnWork = 0;
  142. StartTime = "";
  143. EndTime = "";
  144. EventTime = "";
  145. PicUrl = "";
  146. ImageInfo = "";
  147. AppID = "";
  148. ActionID = "";
  149. ActionDes = "";
  150. FaceIDList = "";
  151. FaceNameList = "";
  152. BboxList = "";
  153. }
  154. /**
  155. * @brief 添加报警信息
  156. *
  157. * @param info
  158. * @return true
  159. * @return false
  160. */
  161. bool ListAlarmInfo::addAlarmInfo(AlarmInfo& info)
  162. {
  163. /* 先查找有没有重复的 */
  164. auto p = findAlarmInfo(info);
  165. if(p != nullptr)
  166. {
  167. return false;
  168. }
  169. listAlarmInfo.push_back(info);
  170. return true;
  171. }
  172. /**
  173. * @brief 检查列表中是是否有这个报警信息,这里只检查ChannelID、RoomID、CameraID、ActionID是否相等
  174. *
  175. * @param info
  176. * @return AlarmInfo*
  177. */
  178. AlarmInfo* ListAlarmInfo::findAlarmInfo(AlarmInfo& info)
  179. {
  180. for(auto& it0 : listAlarmInfo)
  181. {
  182. if(it0.ChannelID == info.ChannelID && it0.RoomID == info.RoomID && it0.DeviceID == info.DeviceID && it0.ActionID == info.ActionID)
  183. {
  184. return &it0;
  185. }
  186. }
  187. return nullptr;
  188. }
  189. /* 查找是否有相同的人脸信息 */
  190. bool RoomFaceInfo::findPersonInfo(const PersonInfo& info)
  191. {
  192. for(auto& it0 : listPersonInfo)
  193. {
  194. if(it0.PersonID == info.PersonID && it0.PersonName == info.PersonName)
  195. {
  196. return true;
  197. }
  198. }
  199. return false;
  200. }
  201. /* 添加房间人脸信息 */
  202. void ListRoomFaceInfo::addRoomFaceInfo(RoomFaceInfo& info)
  203. {
  204. /* 先查找有没有重复的 */
  205. auto p = findRoomFaceInfo(info);
  206. if(p != nullptr)
  207. {
  208. return;
  209. }
  210. listRoomFaceInfo.push_back(info);
  211. }
  212. /**
  213. * @brief 通过报警信息添加人脸信息
  214. *
  215. * @param info
  216. */
  217. void ListRoomFaceInfo::addRoomFaceInfo(AlarmInfo& info)
  218. {
  219. auto p = findRoomFaceInfo(info.ChannelID, info.RoomID, info.DeviceID);
  220. if(p == nullptr)
  221. {
  222. RoomFaceInfo rfi;
  223. rfi.ChannelID = info.ChannelID;
  224. rfi.RoomID = info.RoomID;
  225. rfi.CameraID = info.DeviceID;
  226. rfi.MaxNum = 0;
  227. rfi.MinNum = 0;
  228. rfi.StartTime = QDateTime::currentDateTime();
  229. listRoomFaceInfo.push_back(rfi);
  230. }
  231. /* 将人员信息加入到列表中,添加时会先查找有没有相同的信息 */
  232. for(auto& it0 : info.vecPersonInfo)
  233. {
  234. if(!p->findPersonInfo(it0))
  235. {
  236. p->listPersonInfo.push_back(it0);
  237. }
  238. }
  239. }
  240. RoomFaceInfo* ListRoomFaceInfo::findRoomFaceInfo(RoomFaceInfo& info)
  241. {
  242. for(auto& it0 : listRoomFaceInfo)
  243. {
  244. if(it0.ChannelID == info.ChannelID && it0.RoomID == info.RoomID && it0.CameraID == info.CameraID)
  245. {
  246. return &it0;
  247. }
  248. }
  249. return nullptr;
  250. }
  251. /* 查找有没有相同的结构 */
  252. RoomFaceInfo* ListRoomFaceInfo::findRoomFaceInfo(int ChannelID, int RoomID, int CameraID)
  253. {
  254. for(auto& it0 : listRoomFaceInfo)
  255. {
  256. if(it0.ChannelID == ChannelID && it0.RoomID == RoomID && it0.CameraID == CameraID)
  257. {
  258. return &it0;
  259. }
  260. }
  261. return nullptr;
  262. }
  263. IllegalInvasionInfo::IllegalInvasionInfo(IllegalInvasionInfo& other)
  264. {
  265. isInsertEQM = other.isInsertEQM;
  266. PKID = other.PKID;
  267. CameraID = other.CameraID;
  268. RoomID = other.RoomID;
  269. ChannelID = other.ChannelID;
  270. RoomType = other.RoomType;
  271. FirstTime = other.FirstTime;
  272. strActionDec = other.strActionDec;
  273. strImageInfo = other.strImageInfo;
  274. }
  275. IllegalInvasionInfo& IllegalInvasionInfo::operator=(IllegalInvasionInfo& other)
  276. {
  277. if(this != &other)
  278. {
  279. isInsertEQM = other.isInsertEQM;
  280. PKID = other.PKID;
  281. CameraID = other.CameraID;
  282. RoomID = other.RoomID;
  283. ChannelID = other.ChannelID;
  284. RoomType = other.RoomType;
  285. FirstTime = other.FirstTime;
  286. strActionDec = other.strActionDec;
  287. strImageInfo = other.strImageInfo;
  288. }
  289. return *this;
  290. }
  291. /* 添加信息 */
  292. void ListIllegalInvasionInfo::addIllInfo(IllegalInvasionInfo& info)
  293. {
  294. if(findIllInfo(info) == nullptr)
  295. {
  296. listIll.push_back(info);
  297. }
  298. }
  299. /* 查找相同的信息 */
  300. IllegalInvasionInfo* ListIllegalInvasionInfo::findIllInfo(IllegalInvasionInfo& info)
  301. {
  302. for(auto& it : listIll)
  303. {
  304. if(it.RoomID == info.RoomID && it.RoomType == info.RoomType)
  305. {
  306. return &it;
  307. }
  308. }
  309. return nullptr;
  310. }
  311. IllegalInvasionInfo* ListIllegalInvasionInfo::findIllInfo(int roomID, int roomType)
  312. {
  313. for(auto& it : listIll)
  314. {
  315. if(it.RoomID == roomID && it.RoomType == roomType)
  316. {
  317. return &it;
  318. }
  319. }
  320. return nullptr;
  321. }
  322. RoomIllegalInvasionInfo::RoomIllegalInvasionInfo(RoomIllegalInvasionInfo& o)
  323. {
  324. isAlarm = o.isAlarm;
  325. RoomID = o.RoomID;
  326. RoomType = o.RoomType;
  327. numMaxFace = o.numMaxFace;
  328. numMaxPerson = o.numMaxPerson;
  329. strBoxList = o.strBoxList;
  330. strMessage = o.strMessage;
  331. strImage = o.strImage;
  332. CameraID = o.CameraID;
  333. }
  334. RoomIllegalInvasionInfo& RoomIllegalInvasionInfo::operator=(RoomIllegalInvasionInfo& o)
  335. {
  336. if(this != &o) {
  337. isAlarm = o.isAlarm;
  338. RoomID = o.RoomID;
  339. RoomType = o.RoomType;
  340. numMaxFace = o.numMaxFace;
  341. numMaxPerson = o.numMaxPerson;
  342. strBoxList = o.strBoxList;
  343. strMessage = o.strMessage;
  344. strImage = o.strImage;
  345. CameraID = o.CameraID;
  346. }
  347. return *this;
  348. }
  349. /* 添加房间 */
  350. void ListRoomIll::addRoom(int RoomID, int RoomType)
  351. {
  352. auto p = findRoom(RoomID, RoomType);
  353. if(p == nullptr)
  354. {
  355. RoomIllegalInvasionInfo ill;
  356. ill.RoomID = RoomID;
  357. ill.RoomType = RoomType;
  358. listRoomIll.push_back(ill);
  359. }
  360. }
  361. /* 查找是否有相同的房间 */
  362. RoomIllegalInvasionInfo* ListRoomIll::findRoom(int RoomID, int RoomType)
  363. {
  364. for(auto& it : listRoomIll)
  365. {
  366. if(it.RoomID == RoomID && it.RoomType == RoomType)
  367. {
  368. return &it;
  369. }
  370. }
  371. return nullptr;
  372. }
  373. AlarmRuleInfo::AlarmRuleInfo()
  374. {
  375. LiveMinEnable = false;
  376. LiveMaxEnable = false;
  377. DicMinEnable = false;
  378. DicMaxEnable = false;
  379. LiveDicMinEnable = false;
  380. LiveDicMaxEnable = false;
  381. LiveMin = 0;
  382. LiveMax = 0;
  383. DicMin = 0;
  384. DicMax = 0;
  385. LiveDicMin = 0;
  386. LiveDicMax = 0;
  387. RuleName = "";
  388. }
  389. AlarmRuleInfo& AlarmRuleInfo::operator=(AlarmRuleInfo& other)
  390. {
  391. if(this != &other)
  392. {
  393. LiveMinEnable = other.LiveMinEnable;
  394. LiveMaxEnable = other.LiveMaxEnable;
  395. DicMinEnable = other.DicMinEnable;
  396. DicMaxEnable = other.DicMaxEnable;
  397. LiveDicMinEnable = other.LiveDicMinEnable;
  398. LiveDicMaxEnable = other.LiveDicMaxEnable;
  399. LiveMin = other.LiveMin;
  400. LiveMax = other.LiveMax;
  401. DicMin = other.DicMin;
  402. DicMax = other.DicMax;
  403. LiveDicMin = other.LiveDicMin;
  404. LiveDicMax = other.LiveDicMax;
  405. RuleName = other.RuleName;
  406. }
  407. return *this;
  408. }
  409. /* ====================================================================================
  410. * ************************** ListActionInfo成员函数 ****************************
  411. * ====================================================================================*/
  412. ActionInfo::ActionInfo()
  413. {
  414. RunState = RunTimeState::RUN_STATE_INIT;
  415. ChannelID = -1;
  416. RoomID = -1;
  417. CameraID = -1;
  418. RoomType = -1;
  419. ActionID = "";
  420. strRoomName = "";
  421. strActionName = "";
  422. }
  423. ActionInfo& ActionInfo::operator=(const ActionInfo& other)
  424. {
  425. if (this != &other)
  426. {
  427. ChannelID = other.ChannelID;
  428. RoomID = other.RoomID;
  429. CameraID = other.CameraID;
  430. ActionID = other.ActionID;
  431. strRoomName = other.strRoomName;
  432. RoomType = other.RoomType;
  433. }
  434. return *this;
  435. }
  436. bool ActionInfo::operator==(const ActionInfo& other)
  437. {
  438. if(ChannelID != other.ChannelID) {
  439. return false;
  440. }
  441. if(RoomID != other.RoomID) {
  442. return false;
  443. }
  444. if(CameraID != other.CameraID) {
  445. return false;
  446. }
  447. if(ActionID != other.ActionID) {
  448. return false;
  449. }
  450. if(RoomType != other.RoomType) {
  451. return false;
  452. }
  453. return true;
  454. }
  455. /* 对比除摄像机外的基础信息是否相等 */
  456. bool ActionInfo::isEqualBaseInfo(const ActionInfo& other)
  457. {
  458. if(ChannelID != other.ChannelID) {
  459. return false;
  460. }
  461. if(RoomID != other.RoomID) {
  462. return false;
  463. }
  464. if(ActionID != other.ActionID) {
  465. return false;
  466. }
  467. if(RoomType != other.RoomType) {
  468. return false;
  469. }
  470. return true;
  471. }
  472. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  473. bool ListActionInfo::insertActionInfo(ActionInfo* info)
  474. {
  475. /* 先判断是否已经在列表中了 */
  476. if(findActionInList(info) == nullptr)
  477. {
  478. ActionInfo* pActionInfo = new ActionInfo;
  479. *pActionInfo = *info;
  480. listActionInfo.push_back(pActionInfo);
  481. }
  482. return true;
  483. }
  484. /* 删除信息 */
  485. bool ListActionInfo::deleteActionInfo(ActionInfo* info)
  486. {
  487. if(info == nullptr)
  488. {
  489. return false;
  490. }
  491. if(findActionInList(info) != nullptr)
  492. {
  493. listActionInfo.remove(info);
  494. delete info;
  495. info = nullptr;
  496. }
  497. return true;
  498. }
  499. /* 给算法添加摄像机,原有的会被替换掉 */
  500. bool ListActionInfo::addActionCamera(ActionInfo* pInfo)
  501. {
  502. auto pActionInfo = findActionIDInListNoCamera(pInfo);
  503. if(pActionInfo != nullptr)
  504. {
  505. pActionInfo->CameraID = pInfo->CameraID;
  506. }
  507. return true;
  508. }
  509. /* 清空算法中的摄像机信息 */
  510. void ListActionInfo::clearCameraList()
  511. {
  512. for(auto& it0 : listActionInfo)
  513. {
  514. it0->CameraID = -1;
  515. }
  516. }
  517. /* 清空设置成STOP或ERROR的Action */
  518. void ListActionInfo::clearStopAction()
  519. {
  520. for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();)
  521. {
  522. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  523. {
  524. delete *it0;
  525. it0 = listActionInfo.erase(it0);
  526. }else {
  527. ++it0;
  528. }
  529. }
  530. }
  531. /* 查找算法ID是否已在列表中 */
  532. ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
  533. {
  534. for(const auto& it0 : listActionInfo)
  535. {
  536. if(*it0 == *pInfo)
  537. {
  538. return it0;
  539. }
  540. }
  541. return nullptr;
  542. }
  543. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  544. ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo)
  545. {
  546. for(const auto& it0 : listActionInfo)
  547. {
  548. if(it0->isEqualBaseInfo(*pInfo))
  549. {
  550. return it0;
  551. }
  552. }
  553. return nullptr;
  554. }
  555. /* 清空容器 */
  556. void ListActionInfo::clear()
  557. {
  558. for(auto& it0 : listActionInfo)
  559. {
  560. delete it0;
  561. it0 = nullptr;
  562. }
  563. listActionInfo.clear();
  564. }
  565. /* ====================================================================================
  566. * *********************** ListRoomActionInfo成员函数 ***************************
  567. * ====================================================================================*/
  568. /* 对比频道信息、房间信息、算法ID是否相等 */
  569. bool RoomActionInfo::isEqualBaseInfo(const RoomActionInfo& other)
  570. {
  571. if(ChannelID != other.ChannelID) {
  572. return false;
  573. }
  574. if(RoomID != other.RoomID) {
  575. return false;
  576. }
  577. if(ActionID != other.ActionID) {
  578. return false;
  579. }
  580. if(RoomType != other.RoomType) {
  581. return false;
  582. }
  583. return true;
  584. }
  585. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  586. bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
  587. {
  588. /* 先判断是否已经在列表中了 */
  589. if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr)
  590. {
  591. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  592. *pRoomActionInfo = info;
  593. listRoomActionInfo.push_back(pRoomActionInfo);
  594. }
  595. return true;
  596. }
  597. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  598. bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID)
  599. {
  600. /* 先判断是否已经在列表中了 */
  601. if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr)
  602. {
  603. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  604. pRoomActionInfo->RoomID = RoomID;
  605. pRoomActionInfo->ActionID = strActionID;
  606. listRoomActionInfo.push_back(pRoomActionInfo);
  607. }
  608. return true;
  609. }
  610. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  611. bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo)
  612. {
  613. if(pInfo == nullptr)
  614. {
  615. return false;
  616. }
  617. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0)
  618. {
  619. if(*it0 == pInfo)
  620. {
  621. listRoomActionInfo.erase(it0);
  622. delete pInfo;
  623. pInfo = nullptr;
  624. return true;
  625. }
  626. }
  627. return false;
  628. }
  629. /* 清空容器 */
  630. void ListRoomActionInfo::clear()
  631. {
  632. for(auto& it0 : listRoomActionInfo)
  633. {
  634. delete it0;
  635. it0 = nullptr;
  636. }
  637. listRoomActionInfo.clear();
  638. }
  639. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  640. void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
  641. {
  642. auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
  643. if(pRAInfo != nullptr)
  644. {
  645. pRAInfo->listCameraID.push_back(info.CameraID);
  646. }else {
  647. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  648. pRoomActionInfo->ChannelID = info.ChannelID;
  649. pRoomActionInfo->RoomID = info.RoomID;
  650. pRoomActionInfo->ActionID = info.ActionID;
  651. pRoomActionInfo->RoomType = info.RoomType;
  652. pRoomActionInfo->strRoomName = info.strRoomName;
  653. pRoomActionInfo->listCameraID.push_back(info.CameraID);
  654. listRoomActionInfo.push_back(pRoomActionInfo);
  655. }
  656. }
  657. /* 清空算法对应的摄像机列表 */
  658. void ListRoomActionInfo::clearCameraList()
  659. {
  660. for(auto& it0 : listRoomActionInfo)
  661. {
  662. it0->listCameraID.clear();
  663. }
  664. }
  665. /* 清理设置为STOP或者ERROR的RoomAction */
  666. // void ListRoomActionInfo::clearStopRoomAction()
  667. // {
  668. // for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();)
  669. // {
  670. // if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  671. // {
  672. // delete *it0;
  673. // it0 = listRoomActionInfo.erase(it0);
  674. // }else {
  675. // ++it0;
  676. // }
  677. // }
  678. // }
  679. /* 查找算法ID是否已在列表中 */
  680. RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
  681. {
  682. for(const auto& it0 : listRoomActionInfo)
  683. {
  684. if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
  685. {
  686. return it0;
  687. }
  688. }
  689. return nullptr;
  690. }
  691. FuncActionInfo::FuncActionInfo()
  692. {
  693. ChannelID = -1;
  694. appFunction = AppFunction::APP_NONE;
  695. RunState = RunTimeState::RUN_STATE_NONE;
  696. strFunctionName = "";
  697. StartTime = QDateTime::currentDateTime();
  698. EndTime = QDateTime::currentDateTime();
  699. listRoomCamActInfo.clear();
  700. }
  701. FuncActionInfo& FuncActionInfo::operator=(FuncActionInfo& other)
  702. {
  703. if(this != &other)
  704. {
  705. ChannelID = other.ChannelID;
  706. appFunction = other.appFunction;
  707. RunState = other.RunState;
  708. strFunctionName = other.strFunctionName;
  709. StartTime = other.StartTime;
  710. EndTime = other.EndTime;
  711. listRoomCamActInfo = other.listRoomCamActInfo;
  712. }
  713. return *this;
  714. }
  715. /* 添加算法信息 */
  716. bool FuncActionInfo::addActionInfo(const ActionInfo& info)
  717. {
  718. /* 根据此类的功能,添加算法信息 */
  719. if(appFunction == AppFunction::APP_NONE)
  720. {
  721. return false;
  722. }
  723. /* 将其添加到对应的房间 */
  724. bool isFind = false;
  725. for(auto& it0 : listRoomCamActInfo)
  726. {
  727. if((it0.RoomID == info.RoomID) && (it0.RoomType == info.RoomType))
  728. {
  729. isFind = true;
  730. it0.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
  731. }
  732. }
  733. /* 没找到这个房间,就创建 */
  734. if(!isFind)
  735. {
  736. RoomCamActInfo roomCamActInfo;
  737. roomCamActInfo.RoomID = info.RoomID;
  738. roomCamActInfo.RoomType = info.RoomType;
  739. roomCamActInfo.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
  740. listRoomCamActInfo.push_back(roomCamActInfo);
  741. }
  742. return true;
  743. }
  744. /* 清空算法信息 */
  745. void FuncActionInfo::clearActionList()
  746. {
  747. listRoomCamActInfo.clear();
  748. }
  749. /**
  750. * @brief 添加应用信息,一个应用功能在一个频道内只有一个实例
  751. * 这里是添加应用功能和时间段信息
  752. *
  753. * @param func
  754. * @return true
  755. * @return false
  756. */
  757. bool ListFuncActInfo::addFuncActionInfo(const AppAndTimeInfo& func)
  758. {
  759. if(func.AppType == 0)
  760. {
  761. return false;
  762. }
  763. /* 解出这条信息里包含几个App,AppType按位计算,总共8个应用信息 */
  764. for(int i = 0; i < 8; ++i)
  765. {
  766. if(func.AppType & 0x01)
  767. {
  768. /* 查找有没有这个应用 */
  769. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ONWORK);
  770. if(pFuncActionInfo != nullptr)
  771. {
  772. /* 更新时间信息 */
  773. pFuncActionInfo->StartTime = func.StartTime;
  774. pFuncActionInfo->EndTime = func.EndTime;
  775. continue;
  776. }
  777. FuncActionInfo* fa = new FuncActionInfo;
  778. fa->ChannelID = func.ChannelID;
  779. fa->appFunction = AppFunction::APP_ONWORK;
  780. fa->strFunctionName = "人员在岗识别";
  781. fa->StartTime = func.StartTime;
  782. fa->EndTime = func.EndTime;
  783. listFuncActionInfo.push_back(fa);
  784. }
  785. else if(func.AppType & 0x02)
  786. {
  787. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_CONTRABAND);
  788. if(pFuncActionInfo != nullptr)
  789. {
  790. /* 更新时间信息 */
  791. pFuncActionInfo->StartTime = func.StartTime;
  792. pFuncActionInfo->EndTime = func.EndTime;
  793. continue;
  794. }
  795. FuncActionInfo* fa = new FuncActionInfo;
  796. fa->ChannelID = func.ChannelID;
  797. fa->appFunction = AppFunction::APP_CONTRABAND;
  798. fa->strFunctionName = "违禁品识别";
  799. fa->StartTime = func.StartTime;
  800. fa->EndTime = func.EndTime;
  801. listFuncActionInfo.push_back(fa);
  802. }
  803. else if (func.AppType & 0x04)
  804. {
  805. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ILLEGAL);
  806. if(pFuncActionInfo != nullptr)
  807. {
  808. /* 更新时间信息 */
  809. pFuncActionInfo->StartTime = func.StartTime;
  810. pFuncActionInfo->EndTime = func.EndTime;
  811. continue;
  812. }
  813. FuncActionInfo* fa = new FuncActionInfo;
  814. fa->ChannelID = func.ChannelID;
  815. fa->appFunction = AppFunction::APP_ILLEGAL;
  816. fa->strFunctionName = "非法入侵检测";
  817. fa->StartTime = func.StartTime;
  818. fa->EndTime = func.EndTime;
  819. listFuncActionInfo.push_back(fa);
  820. }
  821. else if (func.AppType & 0x08)
  822. {
  823. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_FATIGUE);
  824. if(pFuncActionInfo != nullptr)
  825. {
  826. /* 更新时间信息 */
  827. pFuncActionInfo->StartTime = func.StartTime;
  828. pFuncActionInfo->EndTime = func.EndTime;
  829. continue;
  830. }
  831. FuncActionInfo* fa = new FuncActionInfo;
  832. fa->ChannelID = func.ChannelID;
  833. fa->appFunction = AppFunction::APP_FATIGUE;
  834. fa->strFunctionName = "疲劳检测";
  835. fa->StartTime = func.StartTime;
  836. fa->EndTime = func.EndTime;
  837. listFuncActionInfo.push_back(fa);
  838. }
  839. else if (func.AppType & 0x10)
  840. {
  841. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_REGIONAL);
  842. if(pFuncActionInfo != nullptr)
  843. {
  844. /* 更新时间信息 */
  845. pFuncActionInfo->StartTime = func.StartTime;
  846. pFuncActionInfo->EndTime = func.EndTime;
  847. continue;
  848. }
  849. FuncActionInfo* fa = new FuncActionInfo;
  850. fa->ChannelID = func.ChannelID;
  851. fa->appFunction = AppFunction::APP_REGIONAL;
  852. fa->strFunctionName = "区域人员检测";
  853. fa->StartTime = func.StartTime;
  854. fa->EndTime = func.EndTime;
  855. listFuncActionInfo.push_back(fa);
  856. }
  857. else if (func.AppType & 0x20)
  858. {
  859. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_MOUSE);
  860. if(pFuncActionInfo != nullptr)
  861. {
  862. /* 更新时间信息 */
  863. pFuncActionInfo->StartTime = func.StartTime;
  864. pFuncActionInfo->EndTime = func.EndTime;
  865. continue;
  866. }
  867. FuncActionInfo* fa = new FuncActionInfo;
  868. fa->ChannelID = func.ChannelID;
  869. fa->appFunction = AppFunction::APP_MOUSE;
  870. fa->strFunctionName = "老鼠识别";
  871. fa->StartTime = func.StartTime;
  872. fa->EndTime = func.EndTime;
  873. listFuncActionInfo.push_back(fa);
  874. }
  875. else if (func.AppType & 0x40)
  876. {
  877. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_PLAYPHONE);
  878. if(pFuncActionInfo != nullptr)
  879. {
  880. /* 更新时间信息 */
  881. pFuncActionInfo->StartTime = func.StartTime;
  882. pFuncActionInfo->EndTime = func.EndTime;
  883. continue;
  884. }
  885. FuncActionInfo* fa = new FuncActionInfo;
  886. fa->ChannelID = func.ChannelID;
  887. fa->appFunction = AppFunction::APP_PLAYPHONE;
  888. fa->strFunctionName = "玩手机识别";
  889. fa->StartTime = func.StartTime;
  890. fa->EndTime = func.EndTime;
  891. listFuncActionInfo.push_back(fa);
  892. }
  893. else if (func.AppType & 0x80)
  894. {
  895. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_NOMASK);
  896. if(pFuncActionInfo != nullptr)
  897. {
  898. /* 更新时间信息 */
  899. pFuncActionInfo->StartTime = func.StartTime;
  900. pFuncActionInfo->EndTime = func.EndTime;
  901. continue;
  902. }
  903. FuncActionInfo* fa = new FuncActionInfo;
  904. fa->ChannelID = func.ChannelID;
  905. fa->appFunction = AppFunction::APP_NOMASK;
  906. fa->strFunctionName = "未戴口罩识别";
  907. fa->StartTime = func.StartTime;
  908. fa->EndTime = func.EndTime;
  909. listFuncActionInfo.push_back(fa);
  910. }
  911. else if (func.AppType & 0x0100)
  912. {
  913. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ALLDOWN);
  914. if(pFuncActionInfo != nullptr)
  915. {
  916. /* 更新时间信息 */
  917. pFuncActionInfo->StartTime = func.StartTime;
  918. pFuncActionInfo->EndTime = func.EndTime;
  919. continue;
  920. }
  921. FuncActionInfo* fa = new FuncActionInfo;
  922. fa->ChannelID = func.ChannelID;
  923. fa->appFunction = AppFunction::APP_ALLDOWN;
  924. fa->strFunctionName = "摔倒识别";
  925. fa->StartTime = func.StartTime;
  926. fa->EndTime = func.EndTime;
  927. listFuncActionInfo.push_back(fa);
  928. }
  929. }
  930. return true;
  931. }
  932. /**
  933. * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
  934. *
  935. * @param info
  936. * @return true
  937. * @return false
  938. */
  939. bool ListFuncActInfo::addActionInfo(const ActionInfo& info)
  940. {
  941. if(info.ActionID.empty())
  942. {
  943. return false;
  944. }
  945. /* 人脸识别算法(人员在岗识别、非法入侵检测需要) */
  946. if(info.ActionID == g_actionList.ActFace)
  947. {
  948. /* 人员在岗识别 */
  949. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_ONWORK);
  950. if(pFuncActionInfo != nullptr)
  951. {
  952. pFuncActionInfo->addActionInfo(info);
  953. }
  954. /* 非法入侵检测 */
  955. pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_ILLEGAL);
  956. if(pFuncActionInfo != nullptr)
  957. {
  958. pFuncActionInfo->addActionInfo(info);
  959. }
  960. }
  961. /* 人员计数 */
  962. else if (info.ActionID == g_actionList.ActPersonNumber)
  963. {
  964. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_REGIONAL);
  965. if(pFuncActionInfo != nullptr)
  966. {
  967. pFuncActionInfo->addActionInfo(info);
  968. }
  969. }
  970. /* 违禁物品 */
  971. else if (info.ActionID == g_actionList.ActContraband)
  972. {
  973. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_CONTRABAND);
  974. if(pFuncActionInfo != nullptr)
  975. {
  976. pFuncActionInfo->addActionInfo(info);
  977. }
  978. }
  979. /* 玩手机 */
  980. else if (info.ActionID == g_actionList.ActPlayPhone)
  981. {
  982. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_PLAYPHONE);
  983. if(pFuncActionInfo != nullptr)
  984. {
  985. pFuncActionInfo->addActionInfo(info);
  986. }
  987. }
  988. /* 睡岗识别 */
  989. else if (info.ActionID == g_actionList.ActSleep)
  990. {
  991. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_FATIGUE);
  992. if(pFuncActionInfo != nullptr)
  993. {
  994. pFuncActionInfo->addActionInfo(info);
  995. }
  996. }
  997. /* 疲劳检测 */
  998. else if(info.ActionID == g_actionList.ActFatigueDetection)
  999. {
  1000. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_FATIGUE);
  1001. if(pFuncActionInfo != nullptr)
  1002. {
  1003. pFuncActionInfo->addActionInfo(info);
  1004. }
  1005. }
  1006. /* 动物识别 */
  1007. else if (info.ActionID == g_actionList.ActAnimalDetect)
  1008. {
  1009. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_MOUSE);
  1010. if(pFuncActionInfo != nullptr)
  1011. {
  1012. pFuncActionInfo->addActionInfo(info);
  1013. }
  1014. }
  1015. /* 老鼠识别 */
  1016. else if (info.ActionID == g_actionList.ActMouseDetect)
  1017. {
  1018. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_MOUSE);
  1019. if(pFuncActionInfo != nullptr)
  1020. {
  1021. pFuncActionInfo->addActionInfo(info);
  1022. }
  1023. }
  1024. /* 口罩识别 */
  1025. else if (info.ActionID == g_actionList.ActMask)
  1026. {
  1027. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_NOMASK);
  1028. if(pFuncActionInfo != nullptr)
  1029. {
  1030. pFuncActionInfo->addActionInfo(info);
  1031. }
  1032. }
  1033. else {
  1034. SPDLOG_WARN("未知的算法ID: {}", info.ActionID);
  1035. return false;
  1036. }
  1037. return true;
  1038. }
  1039. /**
  1040. * @brief 清空无用的功能信息
  1041. * 摄像机和算法信息为空的,或者运行状态为STOP,都会被清理掉
  1042. *
  1043. */
  1044. void ListFuncActInfo::clearNoneFuncActionInfo()
  1045. {
  1046. for(auto it0 = listFuncActionInfo.begin(); it0 != listFuncActionInfo.end();)
  1047. {
  1048. if((*it0)->listRoomCamActInfo.empty() || ((*it0)->RunState == RunTimeState::RUN_STATE_STOP))
  1049. {
  1050. delete *it0;
  1051. it0 = listFuncActionInfo.erase(it0);
  1052. }else {
  1053. ++it0;
  1054. }
  1055. }
  1056. }
  1057. /* 清空算法列表 */
  1058. void ListFuncActInfo::clearActionList()
  1059. {
  1060. for(auto& it0 : listFuncActionInfo)
  1061. {
  1062. it0->listRoomCamActInfo.clear();
  1063. }
  1064. }
  1065. /* 查找应用信息 */
  1066. bool ListFuncActInfo::findAppFunction(const AppFunction func)
  1067. {
  1068. for(const auto& it0 : listFuncActionInfo)
  1069. {
  1070. if(it0->appFunction == func)
  1071. {
  1072. return true;
  1073. }
  1074. }
  1075. return false;
  1076. }
  1077. /* 根据频率和功能查找实例 */
  1078. FuncActionInfo* ListFuncActInfo::findAppFunction(const int ChannelID, const AppFunction func)
  1079. {
  1080. for(const auto& it0 : listFuncActionInfo)
  1081. {
  1082. if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
  1083. {
  1084. return it0;
  1085. }
  1086. }
  1087. return nullptr;
  1088. }
  1089. /**
  1090. * @brief 查找这个应用信息
  1091. *
  1092. * @param func
  1093. * @return FuncActionInfo*
  1094. */
  1095. FuncActionInfo* ListFuncActInfo::findAppFunction(const FuncActionInfo& func)
  1096. {
  1097. for(const auto& it0 : listFuncActionInfo)
  1098. {
  1099. if(it0->ChannelID == func.ChannelID && it0->appFunction == func.appFunction)
  1100. {
  1101. return it0;
  1102. }
  1103. }
  1104. return nullptr;
  1105. }
  1106. /* ====================================================================================
  1107. * ************************** GlobalConfig成员函数 ******************************
  1108. * ====================================================================================*/
  1109. /* 创建实例 */
  1110. GlobalConfig g_config;
  1111. GlobalConfig::GlobalConfig()
  1112. {
  1113. ThreadSleepMS = 300;
  1114. }
  1115. /* 读取配置文件 */
  1116. bool GlobalConfig::readConfig(const QString& strConfigFile)
  1117. {
  1118. if(strConfigFile.isEmpty())
  1119. {
  1120. SPDLOG_ERROR("读取配置文件失败! 配置文件名为空");
  1121. return false;
  1122. }
  1123. SPDLOG_DEBUG("读取配置文件: {}", strConfigFile.toStdString());
  1124. QSettings settings(strConfigFile, QSettings::IniFormat);
  1125. settings.setIniCodec("UTF-8");
  1126. settings.beginGroup("System");
  1127. AppUpdateOnWorkTimeInterval = settings.value("WorkOnInfoSecond", 600).toInt(); /* 更新在岗信息的时间间隔 */
  1128. AppPeopleOnWork = settings.value("APPPEPOLEONWORK", 300).toInt(); /* 离岗时间 */
  1129. Contraband = settings.value("APPBADTHING", 50).toInt(); /* 违禁物品出现的时间 */
  1130. AppBadMan = settings.value("APPBADMAN", 50).toInt(); /* 非法入侵 */
  1131. AppTired = settings.value("APPTIRED", 50).toInt(); /* 疲劳检测时间 */
  1132. AppPeopleCont = settings.value("APPPEPOLECONT", 50).toInt(); /* 人员聚集时间 */
  1133. AppPlayPhone = settings.value("APPPLAYPHONE", 50).toInt(); /* 玩手机识别 */
  1134. AppMouse = settings.value("APPMOUSE", 50).toInt(); /* 手势识别 */
  1135. AppMask = settings.value("APPMASK", 5).toInt(); /* 戴口罩识别 */
  1136. CheckSet = settings.value("CHECKSET", 300).toInt(); /* 服务端多久检测一次配置 */
  1137. EventTimeValid = settings.value("EventTimeValid", 300).toInt(); /* 事件时间有效期 */
  1138. Key = settings.value("Key").toString().toStdString(); /* Key */
  1139. Secret = settings.value("Secret").toString().toStdString(); /* Secret */
  1140. settings.endGroup();
  1141. if(Key.empty() || Secret.empty())
  1142. {
  1143. SPDLOG_ERROR("读取配置文件失败! Key或Secret为空");
  1144. return false;
  1145. }
  1146. return true;
  1147. }
  1148. /* 打印读取到的值 */
  1149. void GlobalConfig::printValue()
  1150. {
  1151. SPDLOG_INFO("APPPEPOLEONWORK: {}", AppPeopleOnWork);
  1152. SPDLOG_INFO("APPBADTHING: {}", Contraband);
  1153. SPDLOG_INFO("APPBADMAN: {}", AppBadMan);
  1154. SPDLOG_INFO("APPTIRED: {}", AppTired);
  1155. SPDLOG_INFO("APPPEOPLECONT: {}", AppPeopleCont);
  1156. SPDLOG_INFO("APPPLAYPHONE: {}", AppPlayPhone);
  1157. SPDLOG_INFO("APPMOUSE: {}", AppMouse);
  1158. SPDLOG_INFO("APPMASK: {}", AppMask);
  1159. SPDLOG_INFO("CHECKSET: {}", CheckSet);
  1160. SPDLOG_INFO("EventTimeValid: {}", EventTimeValid);
  1161. }