GlobalVariable.cpp 34 KB

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