GlobalVariable.cpp 35 KB

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