GlobalInfo.cpp 34 KB

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