GlobalInfo.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291
  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. listBbox.clear();
  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. listBbox = other.listBbox;
  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. listBbox = other.listBbox;
  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. listBbox.clear();
  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. /* 删除报警信息 */
  323. void ListIllegalInvasionInfo::deleteIllInfo(IllegalInvasionInfo& info)
  324. {
  325. for(auto it = listIll.begin(); it != listIll.end();)
  326. {
  327. if(it->RoomID == info.RoomID && it->RoomType == info.RoomType)
  328. {
  329. it = listIll.erase(it);
  330. }else {
  331. ++it;
  332. }
  333. }
  334. }
  335. void ListIllegalInvasionInfo::deleteIllInfo(int roomID, int roomType)
  336. {
  337. for(auto it = listIll.begin(); it != listIll.end();)
  338. {
  339. if(it->RoomID == roomID && it->RoomType == roomType)
  340. {
  341. it = listIll.erase(it);
  342. }else {
  343. ++it;
  344. }
  345. }
  346. }
  347. RoomIllegalInvasionInfo::RoomIllegalInvasionInfo(RoomIllegalInvasionInfo& o)
  348. {
  349. isAlarm = o.isAlarm;
  350. RoomID = o.RoomID;
  351. RoomType = o.RoomType;
  352. numMaxFace = o.numMaxFace;
  353. numMaxPerson = o.numMaxPerson;
  354. strBoxList = o.strBoxList;
  355. strMessage = o.strMessage;
  356. strImage = o.strImage;
  357. CameraID = o.CameraID;
  358. }
  359. RoomIllegalInvasionInfo& RoomIllegalInvasionInfo::operator=(RoomIllegalInvasionInfo& o)
  360. {
  361. if(this != &o) {
  362. isAlarm = o.isAlarm;
  363. RoomID = o.RoomID;
  364. RoomType = o.RoomType;
  365. numMaxFace = o.numMaxFace;
  366. numMaxPerson = o.numMaxPerson;
  367. strBoxList = o.strBoxList;
  368. strMessage = o.strMessage;
  369. strImage = o.strImage;
  370. CameraID = o.CameraID;
  371. }
  372. return *this;
  373. }
  374. /* 添加房间 */
  375. void ListRoomIll::addRoom(int RoomID, int RoomType)
  376. {
  377. auto p = findRoom(RoomID, RoomType);
  378. if(p == nullptr)
  379. {
  380. RoomIllegalInvasionInfo ill;
  381. ill.RoomID = RoomID;
  382. ill.RoomType = RoomType;
  383. listRoomIll.push_back(ill);
  384. }
  385. }
  386. /* 查找是否有相同的房间 */
  387. RoomIllegalInvasionInfo* ListRoomIll::findRoom(int RoomID, int RoomType)
  388. {
  389. for(auto& it : listRoomIll)
  390. {
  391. if(it.RoomID == RoomID && it.RoomType == RoomType)
  392. {
  393. return &it;
  394. }
  395. }
  396. return nullptr;
  397. }
  398. AlarmRuleInfo::AlarmRuleInfo()
  399. {
  400. LiveMinEnable = false;
  401. LiveMaxEnable = false;
  402. DicMinEnable = false;
  403. DicMaxEnable = false;
  404. LiveDicMinEnable = false;
  405. LiveDicMaxEnable = false;
  406. LiveMin = 0;
  407. LiveMax = 0;
  408. DicMin = 0;
  409. DicMax = 0;
  410. LiveDicMin = 0;
  411. LiveDicMax = 0;
  412. RuleName = "";
  413. }
  414. AlarmRuleInfo& AlarmRuleInfo::operator=(AlarmRuleInfo& other)
  415. {
  416. if(this != &other)
  417. {
  418. LiveMinEnable = other.LiveMinEnable;
  419. LiveMaxEnable = other.LiveMaxEnable;
  420. DicMinEnable = other.DicMinEnable;
  421. DicMaxEnable = other.DicMaxEnable;
  422. LiveDicMinEnable = other.LiveDicMinEnable;
  423. LiveDicMaxEnable = other.LiveDicMaxEnable;
  424. LiveMin = other.LiveMin;
  425. LiveMax = other.LiveMax;
  426. DicMin = other.DicMin;
  427. DicMax = other.DicMax;
  428. LiveDicMin = other.LiveDicMin;
  429. LiveDicMax = other.LiveDicMax;
  430. RuleName = other.RuleName;
  431. }
  432. return *this;
  433. }
  434. /* ====================================================================================
  435. * ************************** ListActionInfo成员函数 ****************************
  436. * ====================================================================================*/
  437. ActionInfo::ActionInfo()
  438. {
  439. RunState = RunTimeState::RUN_STATE_INIT;
  440. ChannelID = -1;
  441. RoomID = -1;
  442. CameraID = -1;
  443. RoomType = -1;
  444. ActionID = "";
  445. strRoomName = "";
  446. strActionName = "";
  447. }
  448. ActionInfo& ActionInfo::operator=(const ActionInfo& other)
  449. {
  450. if (this != &other)
  451. {
  452. ChannelID = other.ChannelID;
  453. RoomID = other.RoomID;
  454. CameraID = other.CameraID;
  455. ActionID = other.ActionID;
  456. strRoomName = other.strRoomName;
  457. RoomType = other.RoomType;
  458. }
  459. return *this;
  460. }
  461. bool ActionInfo::operator==(const ActionInfo& other)
  462. {
  463. if(ChannelID != other.ChannelID) {
  464. return false;
  465. }
  466. if(RoomID != other.RoomID) {
  467. return false;
  468. }
  469. if(CameraID != other.CameraID) {
  470. return false;
  471. }
  472. if(ActionID != other.ActionID) {
  473. return false;
  474. }
  475. if(RoomType != other.RoomType) {
  476. return false;
  477. }
  478. return true;
  479. }
  480. /* 对比除摄像机外的基础信息是否相等 */
  481. bool ActionInfo::isEqualBaseInfo(const ActionInfo& other)
  482. {
  483. if(ChannelID != other.ChannelID) {
  484. return false;
  485. }
  486. if(RoomID != other.RoomID) {
  487. return false;
  488. }
  489. if(ActionID != other.ActionID) {
  490. return false;
  491. }
  492. if(RoomType != other.RoomType) {
  493. return false;
  494. }
  495. return true;
  496. }
  497. /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */
  498. bool ListActionInfo::insertActionInfo(ActionInfo* info)
  499. {
  500. /* 先判断是否已经在列表中了 */
  501. if(findActionInList(info) == nullptr)
  502. {
  503. ActionInfo* pActionInfo = new ActionInfo;
  504. *pActionInfo = *info;
  505. listActionInfo.push_back(pActionInfo);
  506. }
  507. return true;
  508. }
  509. /* 删除信息 */
  510. bool ListActionInfo::deleteActionInfo(ActionInfo* info)
  511. {
  512. if(info == nullptr)
  513. {
  514. return false;
  515. }
  516. if(findActionInList(info) != nullptr)
  517. {
  518. listActionInfo.remove(info);
  519. delete info;
  520. info = nullptr;
  521. }
  522. return true;
  523. }
  524. /* 给算法添加摄像机,原有的会被替换掉 */
  525. bool ListActionInfo::addActionCamera(ActionInfo* pInfo)
  526. {
  527. auto pActionInfo = findActionIDInListNoCamera(pInfo);
  528. if(pActionInfo != nullptr)
  529. {
  530. pActionInfo->CameraID = pInfo->CameraID;
  531. }
  532. return true;
  533. }
  534. /* 清空算法中的摄像机信息 */
  535. void ListActionInfo::clearCameraList()
  536. {
  537. for(auto& it0 : listActionInfo)
  538. {
  539. it0->CameraID = -1;
  540. }
  541. }
  542. /* 清空设置成STOP或ERROR的Action */
  543. void ListActionInfo::clearStopAction()
  544. {
  545. for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();)
  546. {
  547. if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  548. {
  549. delete *it0;
  550. it0 = listActionInfo.erase(it0);
  551. }else {
  552. ++it0;
  553. }
  554. }
  555. }
  556. /* 查找算法ID是否已在列表中 */
  557. ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo)
  558. {
  559. for(const auto& it0 : listActionInfo)
  560. {
  561. if(*it0 == *pInfo)
  562. {
  563. return it0;
  564. }
  565. }
  566. return nullptr;
  567. }
  568. /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */
  569. ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo)
  570. {
  571. for(const auto& it0 : listActionInfo)
  572. {
  573. if(it0->isEqualBaseInfo(*pInfo))
  574. {
  575. return it0;
  576. }
  577. }
  578. return nullptr;
  579. }
  580. /* 清空容器 */
  581. void ListActionInfo::clear()
  582. {
  583. for(auto& it0 : listActionInfo)
  584. {
  585. delete it0;
  586. it0 = nullptr;
  587. }
  588. listActionInfo.clear();
  589. }
  590. /* ====================================================================================
  591. * *********************** ListRoomActionInfo成员函数 ***************************
  592. * ====================================================================================*/
  593. /* 对比频道信息、房间信息、算法ID是否相等 */
  594. bool RoomActionInfo::isEqualBaseInfo(const RoomActionInfo& other)
  595. {
  596. if(ChannelID != other.ChannelID) {
  597. return false;
  598. }
  599. if(RoomID != other.RoomID) {
  600. return false;
  601. }
  602. if(ActionID != other.ActionID) {
  603. return false;
  604. }
  605. if(RoomType != other.RoomType) {
  606. return false;
  607. }
  608. return true;
  609. }
  610. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  611. bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info)
  612. {
  613. /* 先判断是否已经在列表中了 */
  614. if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr)
  615. {
  616. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  617. *pRoomActionInfo = info;
  618. listRoomActionInfo.push_back(pRoomActionInfo);
  619. }
  620. return true;
  621. }
  622. /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */
  623. bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID)
  624. {
  625. /* 先判断是否已经在列表中了 */
  626. if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr)
  627. {
  628. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  629. pRoomActionInfo->RoomID = RoomID;
  630. pRoomActionInfo->ActionID = strActionID;
  631. listRoomActionInfo.push_back(pRoomActionInfo);
  632. }
  633. return true;
  634. }
  635. /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */
  636. bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo)
  637. {
  638. if(pInfo == nullptr)
  639. {
  640. return false;
  641. }
  642. for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0)
  643. {
  644. if(*it0 == pInfo)
  645. {
  646. listRoomActionInfo.erase(it0);
  647. delete pInfo;
  648. pInfo = nullptr;
  649. return true;
  650. }
  651. }
  652. return false;
  653. }
  654. /* 清空容器 */
  655. void ListRoomActionInfo::clear()
  656. {
  657. for(auto& it0 : listRoomActionInfo)
  658. {
  659. delete it0;
  660. it0 = nullptr;
  661. }
  662. listRoomActionInfo.clear();
  663. }
  664. /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */
  665. void ListRoomActionInfo::addActionInfo(const ActionInfo& info)
  666. {
  667. auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID);
  668. if(pRAInfo != nullptr)
  669. {
  670. pRAInfo->listCameraID.push_back(info.CameraID);
  671. }else {
  672. RoomActionInfo* pRoomActionInfo = new RoomActionInfo;
  673. pRoomActionInfo->ChannelID = info.ChannelID;
  674. pRoomActionInfo->RoomID = info.RoomID;
  675. pRoomActionInfo->ActionID = info.ActionID;
  676. pRoomActionInfo->RoomType = info.RoomType;
  677. pRoomActionInfo->strRoomName = info.strRoomName;
  678. pRoomActionInfo->listCameraID.push_back(info.CameraID);
  679. listRoomActionInfo.push_back(pRoomActionInfo);
  680. }
  681. }
  682. /* 清空算法对应的摄像机列表 */
  683. void ListRoomActionInfo::clearCameraList()
  684. {
  685. for(auto& it0 : listRoomActionInfo)
  686. {
  687. it0->listCameraID.clear();
  688. }
  689. }
  690. /* 清理设置为STOP或者ERROR的RoomAction */
  691. // void ListRoomActionInfo::clearStopRoomAction()
  692. // {
  693. // for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();)
  694. // {
  695. // if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR))
  696. // {
  697. // delete *it0;
  698. // it0 = listRoomActionInfo.erase(it0);
  699. // }else {
  700. // ++it0;
  701. // }
  702. // }
  703. // }
  704. /* 查找算法ID是否已在列表中 */
  705. RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID)
  706. {
  707. for(const auto& it0 : listRoomActionInfo)
  708. {
  709. if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID))
  710. {
  711. return it0;
  712. }
  713. }
  714. return nullptr;
  715. }
  716. FuncActionInfo::FuncActionInfo()
  717. {
  718. ChannelID = -1;
  719. appFunction = AppFunction::APP_NONE;
  720. RunState = RunTimeState::RUN_STATE_NONE;
  721. strFunctionName = "";
  722. StartTime = QDateTime::currentDateTime();
  723. EndTime = QDateTime::currentDateTime();
  724. listRoomCamActInfo.clear();
  725. }
  726. FuncActionInfo& FuncActionInfo::operator=(FuncActionInfo& other)
  727. {
  728. if(this != &other)
  729. {
  730. ChannelID = other.ChannelID;
  731. appFunction = other.appFunction;
  732. RunState = other.RunState;
  733. strFunctionName = other.strFunctionName;
  734. StartTime = other.StartTime;
  735. EndTime = other.EndTime;
  736. listRoomCamActInfo = other.listRoomCamActInfo;
  737. }
  738. return *this;
  739. }
  740. /* 添加算法信息 */
  741. bool FuncActionInfo::addActionInfo(const ActionInfo& info)
  742. {
  743. /* 根据此类的功能,添加算法信息 */
  744. if(appFunction == AppFunction::APP_NONE)
  745. {
  746. return false;
  747. }
  748. /* 将其添加到对应的房间 */
  749. bool isFind = false;
  750. for(auto& it0 : listRoomCamActInfo)
  751. {
  752. if((it0.RoomID == info.RoomID) && (it0.RoomType == info.RoomType))
  753. {
  754. isFind = true;
  755. it0.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
  756. }
  757. }
  758. /* 没找到这个房间,就创建 */
  759. if(!isFind)
  760. {
  761. RoomCamActInfo roomCamActInfo;
  762. roomCamActInfo.RoomID = info.RoomID;
  763. roomCamActInfo.RoomType = info.RoomType;
  764. roomCamActInfo.mapCameraAction.insert(std::make_pair(info.CameraID, info.ActionID));
  765. listRoomCamActInfo.push_back(roomCamActInfo);
  766. }
  767. return true;
  768. }
  769. /* 清空算法信息 */
  770. void FuncActionInfo::clearActionList()
  771. {
  772. listRoomCamActInfo.clear();
  773. }
  774. /**
  775. * @brief 添加应用信息,一个应用功能在一个频道内只有一个实例
  776. * 这里是添加应用功能和时间段信息
  777. *
  778. * @param func
  779. * @return true
  780. * @return false
  781. */
  782. bool ListFuncActInfo::addFuncActionInfo(const AppAndTimeInfo& func)
  783. {
  784. if(func.AppType == 0)
  785. {
  786. return false;
  787. }
  788. /* 解出这条信息里包含几个App,AppType按位计算,总共8个应用信息 */
  789. for(int i = 0; i < 8; ++i)
  790. {
  791. if(func.AppType & 0x01)
  792. {
  793. /* 查找有没有这个应用 */
  794. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ONWORK);
  795. if(pFuncActionInfo != nullptr)
  796. {
  797. /* 更新时间信息 */
  798. pFuncActionInfo->StartTime = func.StartTime;
  799. pFuncActionInfo->EndTime = func.EndTime;
  800. continue;
  801. }
  802. FuncActionInfo* fa = new FuncActionInfo;
  803. fa->ChannelID = func.ChannelID;
  804. fa->appFunction = AppFunction::APP_ONWORK;
  805. fa->strFunctionName = "人员在岗识别";
  806. fa->StartTime = func.StartTime;
  807. fa->EndTime = func.EndTime;
  808. listFuncActionInfo.push_back(fa);
  809. }
  810. else if(func.AppType & 0x02)
  811. {
  812. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_CONTRABAND);
  813. if(pFuncActionInfo != nullptr)
  814. {
  815. /* 更新时间信息 */
  816. pFuncActionInfo->StartTime = func.StartTime;
  817. pFuncActionInfo->EndTime = func.EndTime;
  818. continue;
  819. }
  820. FuncActionInfo* fa = new FuncActionInfo;
  821. fa->ChannelID = func.ChannelID;
  822. fa->appFunction = AppFunction::APP_CONTRABAND;
  823. fa->strFunctionName = "违禁品识别";
  824. fa->StartTime = func.StartTime;
  825. fa->EndTime = func.EndTime;
  826. listFuncActionInfo.push_back(fa);
  827. }
  828. else if (func.AppType & 0x04)
  829. {
  830. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ILLEGAL);
  831. if(pFuncActionInfo != nullptr)
  832. {
  833. /* 更新时间信息 */
  834. pFuncActionInfo->StartTime = func.StartTime;
  835. pFuncActionInfo->EndTime = func.EndTime;
  836. continue;
  837. }
  838. FuncActionInfo* fa = new FuncActionInfo;
  839. fa->ChannelID = func.ChannelID;
  840. fa->appFunction = AppFunction::APP_ILLEGAL;
  841. fa->strFunctionName = "非法入侵检测";
  842. fa->StartTime = func.StartTime;
  843. fa->EndTime = func.EndTime;
  844. listFuncActionInfo.push_back(fa);
  845. }
  846. else if (func.AppType & 0x08)
  847. {
  848. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_FATIGUE);
  849. if(pFuncActionInfo != nullptr)
  850. {
  851. /* 更新时间信息 */
  852. pFuncActionInfo->StartTime = func.StartTime;
  853. pFuncActionInfo->EndTime = func.EndTime;
  854. continue;
  855. }
  856. FuncActionInfo* fa = new FuncActionInfo;
  857. fa->ChannelID = func.ChannelID;
  858. fa->appFunction = AppFunction::APP_FATIGUE;
  859. fa->strFunctionName = "疲劳检测";
  860. fa->StartTime = func.StartTime;
  861. fa->EndTime = func.EndTime;
  862. listFuncActionInfo.push_back(fa);
  863. }
  864. else if (func.AppType & 0x10)
  865. {
  866. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_REGIONAL);
  867. if(pFuncActionInfo != nullptr)
  868. {
  869. /* 更新时间信息 */
  870. pFuncActionInfo->StartTime = func.StartTime;
  871. pFuncActionInfo->EndTime = func.EndTime;
  872. continue;
  873. }
  874. FuncActionInfo* fa = new FuncActionInfo;
  875. fa->ChannelID = func.ChannelID;
  876. fa->appFunction = AppFunction::APP_REGIONAL;
  877. fa->strFunctionName = "区域人员检测";
  878. fa->StartTime = func.StartTime;
  879. fa->EndTime = func.EndTime;
  880. listFuncActionInfo.push_back(fa);
  881. }
  882. else if (func.AppType & 0x20)
  883. {
  884. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_MOUSE);
  885. if(pFuncActionInfo != nullptr)
  886. {
  887. /* 更新时间信息 */
  888. pFuncActionInfo->StartTime = func.StartTime;
  889. pFuncActionInfo->EndTime = func.EndTime;
  890. continue;
  891. }
  892. FuncActionInfo* fa = new FuncActionInfo;
  893. fa->ChannelID = func.ChannelID;
  894. fa->appFunction = AppFunction::APP_MOUSE;
  895. fa->strFunctionName = "老鼠识别";
  896. fa->StartTime = func.StartTime;
  897. fa->EndTime = func.EndTime;
  898. listFuncActionInfo.push_back(fa);
  899. }
  900. else if (func.AppType & 0x40)
  901. {
  902. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_PLAYPHONE);
  903. if(pFuncActionInfo != nullptr)
  904. {
  905. /* 更新时间信息 */
  906. pFuncActionInfo->StartTime = func.StartTime;
  907. pFuncActionInfo->EndTime = func.EndTime;
  908. continue;
  909. }
  910. FuncActionInfo* fa = new FuncActionInfo;
  911. fa->ChannelID = func.ChannelID;
  912. fa->appFunction = AppFunction::APP_PLAYPHONE;
  913. fa->strFunctionName = "玩手机识别";
  914. fa->StartTime = func.StartTime;
  915. fa->EndTime = func.EndTime;
  916. listFuncActionInfo.push_back(fa);
  917. }
  918. else if (func.AppType & 0x80)
  919. {
  920. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_NOMASK);
  921. if(pFuncActionInfo != nullptr)
  922. {
  923. /* 更新时间信息 */
  924. pFuncActionInfo->StartTime = func.StartTime;
  925. pFuncActionInfo->EndTime = func.EndTime;
  926. continue;
  927. }
  928. FuncActionInfo* fa = new FuncActionInfo;
  929. fa->ChannelID = func.ChannelID;
  930. fa->appFunction = AppFunction::APP_NOMASK;
  931. fa->strFunctionName = "未戴口罩识别";
  932. fa->StartTime = func.StartTime;
  933. fa->EndTime = func.EndTime;
  934. listFuncActionInfo.push_back(fa);
  935. }
  936. else if (func.AppType & 0x0100)
  937. {
  938. auto pFuncActionInfo = findAppFunction(func.ChannelID, AppFunction::APP_ALLDOWN);
  939. if(pFuncActionInfo != nullptr)
  940. {
  941. /* 更新时间信息 */
  942. pFuncActionInfo->StartTime = func.StartTime;
  943. pFuncActionInfo->EndTime = func.EndTime;
  944. continue;
  945. }
  946. FuncActionInfo* fa = new FuncActionInfo;
  947. fa->ChannelID = func.ChannelID;
  948. fa->appFunction = AppFunction::APP_ALLDOWN;
  949. fa->strFunctionName = "摔倒识别";
  950. fa->StartTime = func.StartTime;
  951. fa->EndTime = func.EndTime;
  952. listFuncActionInfo.push_back(fa);
  953. }
  954. }
  955. return true;
  956. }
  957. /**
  958. * @brief 添加算法信息,根据传进来的算法ID,将其加入到对应的功能中
  959. *
  960. * @param info
  961. * @return true
  962. * @return false
  963. */
  964. bool ListFuncActInfo::addActionInfo(const ActionInfo& info)
  965. {
  966. if(info.ActionID.empty())
  967. {
  968. return false;
  969. }
  970. /* 人脸识别算法(人员在岗识别、非法入侵检测需要) */
  971. if(info.ActionID == g_actionList.ActFace)
  972. {
  973. /* 人员在岗识别 */
  974. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_ONWORK);
  975. if(pFuncActionInfo != nullptr)
  976. {
  977. pFuncActionInfo->addActionInfo(info);
  978. }
  979. /* 非法入侵检测 */
  980. pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_ILLEGAL);
  981. if(pFuncActionInfo != nullptr)
  982. {
  983. pFuncActionInfo->addActionInfo(info);
  984. }
  985. }
  986. /* 人员计数 */
  987. else if (info.ActionID == g_actionList.ActPersonNumber)
  988. {
  989. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_REGIONAL);
  990. if(pFuncActionInfo != nullptr)
  991. {
  992. pFuncActionInfo->addActionInfo(info);
  993. }
  994. }
  995. /* 违禁物品 */
  996. else if (info.ActionID == g_actionList.ActContraband)
  997. {
  998. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_CONTRABAND);
  999. if(pFuncActionInfo != nullptr)
  1000. {
  1001. pFuncActionInfo->addActionInfo(info);
  1002. }
  1003. }
  1004. /* 玩手机 */
  1005. else if (info.ActionID == g_actionList.ActPlayPhone)
  1006. {
  1007. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_PLAYPHONE);
  1008. if(pFuncActionInfo != nullptr)
  1009. {
  1010. pFuncActionInfo->addActionInfo(info);
  1011. }
  1012. }
  1013. /* 睡岗识别 */
  1014. else if (info.ActionID == g_actionList.ActSleep)
  1015. {
  1016. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_FATIGUE);
  1017. if(pFuncActionInfo != nullptr)
  1018. {
  1019. pFuncActionInfo->addActionInfo(info);
  1020. }
  1021. }
  1022. /* 疲劳检测 */
  1023. else if(info.ActionID == g_actionList.ActFatigueDetection)
  1024. {
  1025. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_FATIGUE);
  1026. if(pFuncActionInfo != nullptr)
  1027. {
  1028. pFuncActionInfo->addActionInfo(info);
  1029. }
  1030. }
  1031. /* 动物识别 */
  1032. else if (info.ActionID == g_actionList.ActAnimalDetect)
  1033. {
  1034. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_MOUSE);
  1035. if(pFuncActionInfo != nullptr)
  1036. {
  1037. pFuncActionInfo->addActionInfo(info);
  1038. }
  1039. }
  1040. /* 老鼠识别 */
  1041. else if (info.ActionID == g_actionList.ActMouseDetect)
  1042. {
  1043. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_MOUSE);
  1044. if(pFuncActionInfo != nullptr)
  1045. {
  1046. pFuncActionInfo->addActionInfo(info);
  1047. }
  1048. }
  1049. /* 口罩识别 */
  1050. else if (info.ActionID == g_actionList.ActMask)
  1051. {
  1052. auto pFuncActionInfo = findAppFunction(info.ChannelID, AppFunction::APP_NOMASK);
  1053. if(pFuncActionInfo != nullptr)
  1054. {
  1055. pFuncActionInfo->addActionInfo(info);
  1056. }
  1057. }
  1058. else {
  1059. SPDLOG_WARN("未知的算法ID: {}", info.ActionID);
  1060. return false;
  1061. }
  1062. return true;
  1063. }
  1064. /**
  1065. * @brief 清空无用的功能信息
  1066. * 摄像机和算法信息为空的,或者运行状态为STOP,都会被清理掉
  1067. *
  1068. */
  1069. void ListFuncActInfo::clearNoneFuncActionInfo()
  1070. {
  1071. for(auto it0 = listFuncActionInfo.begin(); it0 != listFuncActionInfo.end();)
  1072. {
  1073. if((*it0)->listRoomCamActInfo.empty() || ((*it0)->RunState == RunTimeState::RUN_STATE_STOP))
  1074. {
  1075. delete *it0;
  1076. it0 = listFuncActionInfo.erase(it0);
  1077. }else {
  1078. ++it0;
  1079. }
  1080. }
  1081. }
  1082. /* 清空算法列表 */
  1083. void ListFuncActInfo::clearActionList()
  1084. {
  1085. for(auto& it0 : listFuncActionInfo)
  1086. {
  1087. it0->listRoomCamActInfo.clear();
  1088. }
  1089. }
  1090. /* 查找应用信息 */
  1091. bool ListFuncActInfo::findAppFunction(const AppFunction func)
  1092. {
  1093. for(const auto& it0 : listFuncActionInfo)
  1094. {
  1095. if(it0->appFunction == func)
  1096. {
  1097. return true;
  1098. }
  1099. }
  1100. return false;
  1101. }
  1102. /* 根据频率和功能查找实例 */
  1103. FuncActionInfo* ListFuncActInfo::findAppFunction(const int ChannelID, const AppFunction func)
  1104. {
  1105. for(const auto& it0 : listFuncActionInfo)
  1106. {
  1107. if( (it0->appFunction == func) && (it0->ChannelID == ChannelID) )
  1108. {
  1109. return it0;
  1110. }
  1111. }
  1112. return nullptr;
  1113. }
  1114. /**
  1115. * @brief 查找这个应用信息
  1116. *
  1117. * @param func
  1118. * @return FuncActionInfo*
  1119. */
  1120. FuncActionInfo* ListFuncActInfo::findAppFunction(const FuncActionInfo& func)
  1121. {
  1122. for(const auto& it0 : listFuncActionInfo)
  1123. {
  1124. if(it0->ChannelID == func.ChannelID && it0->appFunction == func.appFunction)
  1125. {
  1126. return it0;
  1127. }
  1128. }
  1129. return nullptr;
  1130. }
  1131. /* ====================================================================================
  1132. * ************************** GlobalConfig成员函数 ******************************
  1133. * ====================================================================================*/
  1134. /* 创建实例 */
  1135. GlobalConfig g_config;
  1136. GlobalConfig::GlobalConfig()
  1137. {
  1138. ThreadSleepMS = 300;
  1139. }
  1140. /* 读取配置文件 */
  1141. bool GlobalConfig::readConfig(const QString& strConfigFile)
  1142. {
  1143. if(strConfigFile.isEmpty())
  1144. {
  1145. SPDLOG_ERROR("读取配置文件失败! 配置文件名为空");
  1146. return false;
  1147. }
  1148. SPDLOG_DEBUG("读取配置文件: {}", strConfigFile.toStdString());
  1149. QSettings settings(strConfigFile, QSettings::IniFormat);
  1150. settings.setIniCodec("UTF-8");
  1151. settings.beginGroup("System");
  1152. AppUpdateOnWorkTimeInterval = settings.value("WorkOnInfoSecond", 600).toInt(); /* 更新在岗信息的时间间隔 */
  1153. AppPeopleOnWork = settings.value("APPPEPOLEONWORK", 300).toInt(); /* 离岗时间 */
  1154. Contraband = settings.value("APPBADTHING", 50).toInt(); /* 违禁物品出现的时间 */
  1155. AppBadMan = settings.value("APPBADMAN", 50).toInt(); /* 非法入侵 */
  1156. AppTired = settings.value("APPTIRED", 50).toInt(); /* 疲劳检测时间 */
  1157. AppPeopleCont = settings.value("APPPEPOLECONT", 50).toInt(); /* 人员聚集时间 */
  1158. AppPlayPhone = settings.value("APPPLAYPHONE", 50).toInt(); /* 玩手机识别 */
  1159. AppMouse = settings.value("APPMOUSE", 50).toInt(); /* 手势识别 */
  1160. AppMask = settings.value("APPMASK", 5).toInt(); /* 戴口罩识别 */
  1161. CheckSet = settings.value("CHECKSET", 300).toInt(); /* 服务端多久检测一次配置 */
  1162. EventTimeValid = settings.value("EventTimeValid", 300).toInt(); /* 事件时间有效期 */
  1163. Key = settings.value("Key").toString().toStdString(); /* Key */
  1164. Secret = settings.value("Secret").toString().toStdString(); /* Secret */
  1165. settings.endGroup();
  1166. if(Key.empty() || Secret.empty())
  1167. {
  1168. SPDLOG_ERROR("读取配置文件失败! Key或Secret为空");
  1169. return false;
  1170. }
  1171. return true;
  1172. }
  1173. /* 打印读取到的值 */
  1174. void GlobalConfig::printValue()
  1175. {
  1176. SPDLOG_INFO("APPPEPOLEONWORK: {}", AppPeopleOnWork);
  1177. SPDLOG_INFO("APPBADTHING: {}", Contraband);
  1178. SPDLOG_INFO("APPBADMAN: {}", AppBadMan);
  1179. SPDLOG_INFO("APPTIRED: {}", AppTired);
  1180. SPDLOG_INFO("APPPEOPLECONT: {}", AppPeopleCont);
  1181. SPDLOG_INFO("APPPLAYPHONE: {}", AppPlayPhone);
  1182. SPDLOG_INFO("APPMOUSE: {}", AppMouse);
  1183. SPDLOG_INFO("APPMASK: {}", AppMask);
  1184. SPDLOG_INFO("CHECKSET: {}", CheckSet);
  1185. SPDLOG_INFO("EventTimeValid: {}", EventTimeValid);
  1186. }