SPAServer.cpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. #include "SPAServer.h"
  2. #include "spdlog/spdlog.h"
  3. // #include "CurlHttp.h"
  4. #include <filesystem>
  5. // #include "CurlFtp.h"
  6. #include "ThreadPool/ThreadPool.h"
  7. #include <QApplication>
  8. #include <QVector>
  9. SPAServer::SPAServer()
  10. {
  11. m_logger = spdlog::get("SPAServer");
  12. if(m_logger == nullptr)
  13. {
  14. SPDLOG_ERROR("APAServer logger is nullptr");
  15. return;
  16. }
  17. /* 读取全局的配置文件 */
  18. QString strConfigFile = QApplication::applicationDirPath() + "/config.ini";
  19. if(!g_config.readConfig(strConfigFile))
  20. {
  21. /* 读取配置文件失败,直接退出程序 */
  22. return;
  23. }
  24. g_config.printValue();
  25. m_threadRunning = true;
  26. /* 初始化WebAPI */
  27. m_toEQMDataBase.initWebApi("http://192.1.3.133:31000/v6/", "", "4c2f9fc91c22dd98331e47af2e2964f4");
  28. /* 模拟违禁品算法ID,后续需要动态调整 */
  29. m_keyContraband = "OD210_026_005246_001-IZRTKyEx";
  30. }
  31. SPAServer::~SPAServer()
  32. {
  33. }
  34. /* 启动服务 */
  35. void SPAServer::startServer()
  36. {
  37. /* 添加获取基础信息的线程 */
  38. // CPPTP.add_task(&SPAServer::threadFromSuperBrain, this);
  39. /* 测试Redis读取并解析数据线程 */
  40. CameraThreadInfo info;
  41. info.RedisIP = "172.16.36.80";
  42. info.RedisPort = 32222;
  43. info.RedisPWD = "Ff1z@TOFr^iwd%Ra";
  44. info.DeviceID = 117;
  45. info.vecAction.push_back("OD210_026_005246_001-IZRTKyEx");
  46. m_keyContraband = "OD210_026_005246_001-IZRTKyEx";
  47. // CPPTP.add_task(&SPAServer::threadFromRedis, this, info);
  48. // threadFromRedis(info);
  49. }
  50. /**
  51. * @brief 从基础平台获取算法信息和设备信息的线程函数
  52. *
  53. */
  54. void SPAServer::threadFromSuperBrain()
  55. {
  56. SPDLOG_LOGGER_INFO(m_logger, "开启 fromSuperBrainThread 线程");
  57. /* 创建变量 */
  58. std::vector<AlgorithmInfo> vecAlgNewInfo;
  59. std::vector<DeviceInfo> vecDevNewInfo;
  60. /* 获取一次token,后续失效了再获取 */
  61. m_fromSuperBrain.getToken();
  62. while (m_threadRunning)
  63. {
  64. SPDLOG_LOGGER_INFO(m_logger, "刷新算法和设备信息");
  65. /* 先更新数据库的信息,防止从其他地方更改了数据库,这里没有刷新本地缓存 */
  66. m_toEQMDataBase.getAlgorithmInfo(m_vecEqmAlgInfo);
  67. m_toEQMDataBase.getDeviceInfo(m_vecEqmDevInfo);
  68. m_toEQMDataBase.getDeviceAlgorithmInfo(m_vecEqmDevInfo, m_listDevIDDelete);
  69. /* 从超脑获取基础信息 */
  70. m_fromSuperBrain.getTaskTypeList(vecAlgNewInfo);
  71. m_fromSuperBrain.getDeviceList(vecDevNewInfo);
  72. /* 处理算法信息 */
  73. bool algIsUpdate = processAlgorithmInfo(vecAlgNewInfo);
  74. /* 处理设备信息 */
  75. bool devIsUpdate = processDeviceInfo(vecDevNewInfo);
  76. vecAlgNewInfo.clear();
  77. vecDevNewInfo.clear();
  78. /* 更新算法详细信息 */
  79. m_mutexActionInfo.lock();
  80. m_toEQMDataBase.getActionInfo(m_listActionInfo);
  81. m_mutexActionInfo.unlock();
  82. std::this_thread::sleep_for(std::chrono::seconds(10));
  83. }
  84. }
  85. /* 处理算法信息,返回值为true,说明有改变,需要重新读取 */
  86. bool SPAServer::processAlgorithmInfo(std::vector<AlgorithmInfo> vecNewAlgInfo)
  87. {
  88. std::vector<AlgorithmInfo> vecAlgUpdate;
  89. std::vector<AlgorithmInfo> vecAlgDelete;
  90. /* 对比数据库表格信息,这里只有插入和删除,没有更新 */
  91. compareAlgorithmInfo(vecNewAlgInfo, vecAlgUpdate, vecAlgDelete);
  92. /* 更新数据库,先删除,再写入刷新 */
  93. bool isUpdate = false;
  94. if(vecAlgDelete.size() > 0)
  95. {
  96. SPDLOG_LOGGER_DEBUG(m_logger, "删除算法信息");
  97. m_toEQMDataBase.deleteAlgorithmInfo(vecAlgDelete);
  98. isUpdate = true;
  99. }
  100. if(vecAlgUpdate.size() > 0)
  101. {
  102. SPDLOG_LOGGER_DEBUG(m_logger, "写入算法信息");
  103. m_toEQMDataBase.writeAlgorithmInfo(vecAlgUpdate);
  104. isUpdate = true;
  105. }
  106. return isUpdate;
  107. }
  108. /**
  109. * @brief 处理设备信息
  110. *
  111. * @param vecNewDevInfo 传入新获取到的值
  112. * @return true 需要重新读取数据库,获取新的数据
  113. * @return false 无需读取数据库
  114. */
  115. bool SPAServer::processDeviceInfo(std::vector<DeviceInfo> vecNewDevInfo)
  116. {
  117. std::vector<DeviceInfo> vecDevInsert;
  118. std::vector<DeviceInfo> vecDevUpdate;
  119. std::vector<DeviceInfo> vecDevDelete;
  120. /*-------------------------------------------------------------------------
  121. ****** 这里只对比设备信息,不对比设备的算法信息,算法信息在下面单独对比 *******
  122. *------------------------------------------------------------------------*/
  123. /* 如果本地缓存没有数据,那么就全部插入 */
  124. if(m_vecEqmDevInfo.size() > 0)
  125. {
  126. for(auto& DevInfo : vecNewDevInfo)
  127. {
  128. bool isExist = false;
  129. for(auto& it0 : m_vecEqmDevInfo)
  130. {
  131. if(DevInfo.DeviceID == it0.DeviceID)
  132. {
  133. isExist = true;
  134. /* 对比其他项是否相等,不相等就更新 */
  135. if(DevInfo == it0)
  136. {
  137. continue;
  138. }else {
  139. vecDevUpdate.push_back(DevInfo);
  140. }
  141. break;
  142. }
  143. }
  144. if(!isExist)
  145. {
  146. vecDevInsert.push_back(DevInfo);
  147. }
  148. }
  149. }else {
  150. vecDevInsert = vecNewDevInfo;
  151. }
  152. /* 获取删除列表 */
  153. if(vecNewDevInfo.size() > 0)
  154. {
  155. bool isExist = false;
  156. for(const auto& it : m_vecEqmDevInfo)
  157. {
  158. isExist = false;
  159. for(const auto& it0 : vecNewDevInfo)
  160. {
  161. if(it.DeviceID == it0.DeviceID)
  162. {
  163. isExist = true;
  164. break;
  165. }
  166. }
  167. if(!isExist)
  168. {
  169. vecDevDelete.push_back(it);
  170. }
  171. }
  172. }else {
  173. vecDevDelete = m_vecEqmDevInfo;
  174. }
  175. bool isUpdate = false;
  176. /* 先删除多余的数据 */
  177. if(vecDevDelete.size() > 0)
  178. {
  179. SPDLOG_LOGGER_DEBUG(m_logger, "删除设备信息");
  180. m_toEQMDataBase.deleteDeviceInfo(vecDevDelete);
  181. isUpdate = true;
  182. }
  183. /* 更新数据 */
  184. if(vecDevUpdate.size() > 0)
  185. {
  186. SPDLOG_LOGGER_DEBUG(m_logger, "更新设备信息");
  187. m_toEQMDataBase.updateDeviceInfo(vecDevUpdate);
  188. isUpdate = true;
  189. }
  190. /* 插入数据 */
  191. if(vecDevInsert.size() > 0)
  192. {
  193. SPDLOG_LOGGER_DEBUG(m_logger, "插入设备信息");
  194. m_toEQMDataBase.insertDeviceInfo(vecDevInsert);
  195. isUpdate = true;
  196. }
  197. /*-------------------------------------------------------------------------
  198. ************* 处理设备和算子关联的表格,单独对比设备的算法信息 *************
  199. *------------------------------------------------------------------------*/
  200. /* 插入新的设备信息 */
  201. if(vecDevInsert.size() > 0)
  202. {
  203. SPDLOG_LOGGER_DEBUG(m_logger, "插入设备和算法关联表");
  204. m_toEQMDataBase.insertDeviceAlgorithmInfo(vecDevInsert);
  205. isUpdate = true;
  206. }
  207. vecDevUpdate.clear();
  208. /* 对比现有的设备是否需要更新算法 */
  209. compareDeviceAlgorithmInfo(vecNewDevInfo, vecDevUpdate);
  210. if(vecDevUpdate.size() > 0)
  211. {
  212. SPDLOG_LOGGER_DEBUG(m_logger, "更新设备和算法关联表, 更新设备数目:{}", vecDevUpdate.size());
  213. m_toEQMDataBase.updateDeviceAlgorithmInfo(vecDevUpdate);
  214. }
  215. /* 删除tActionCamer表中消失的设备信息 */
  216. if(m_listDevIDDelete.size() > 0)
  217. {
  218. SPDLOG_LOGGER_DEBUG(m_logger, "删除消失的设备关联的算法");
  219. m_toEQMDataBase.deleteDeviceAlgorithmInfo(m_listDevIDDelete);
  220. isUpdate = true;
  221. }
  222. return isUpdate;
  223. }
  224. /* 对比现有的数据和新获取到的数据,取出要删除和添加的数据 */
  225. void SPAServer::compareAlgorithmInfo(const std::vector<AlgorithmInfo>& vecNewInfo, std::vector<AlgorithmInfo>& vecAlgUpdate, std::vector<AlgorithmInfo>& vecAlgDelete)
  226. {
  227. /* 取出要添加的,如果本地缓存是0,那么全部都要添加 */
  228. if(m_vecEqmAlgInfo.size() > 0)
  229. {
  230. for(const auto& it : vecNewInfo)
  231. {
  232. bool isExist = false;
  233. for(const auto& it0 : m_vecEqmAlgInfo)
  234. {
  235. /* 如果存在就退出循环 */
  236. if(it.ActionID == it0.ActionID)
  237. {
  238. isExist = true;
  239. break;
  240. }
  241. }
  242. if(!isExist)
  243. {
  244. vecAlgUpdate.push_back(it);
  245. }
  246. }
  247. }else {
  248. vecAlgUpdate = vecNewInfo;
  249. }
  250. /* 取出要删除的,如果新的数据是0,那么全部都要删除 */
  251. if(vecNewInfo.size() > 0)
  252. {
  253. bool isExist = false;
  254. for(const auto& it : m_vecEqmAlgInfo)
  255. {
  256. isExist = false;
  257. for(const auto& it0 : vecNewInfo)
  258. {
  259. if(it.ActionID == it0.ActionID)
  260. {
  261. isExist = true;
  262. break;
  263. }
  264. }
  265. if(!isExist)
  266. {
  267. vecAlgDelete.push_back(it);
  268. }
  269. }
  270. }else {
  271. vecAlgDelete = m_vecEqmAlgInfo;
  272. }
  273. }
  274. /**
  275. * @brief 对比设备和算法关联表是否需要更新
  276. * 对比规则:
  277. * 1、这里只对比已有的设备ID,需要删除的ID在获取到tActionCamer表是就已经取出来了
  278. * 2、如果设备ID相等,那么进一步对比算法信息是否相等
  279. * 3、如果设备ID相等,但是算法信息数目不相等,那么直接加入更新列表
  280. * 4、如果设备ID相等,算法信息数目相等,进一步对比算法信息
  281. *
  282. * @param vecNewInfo
  283. * @param vecDevUpdate
  284. */
  285. void SPAServer::compareDeviceAlgorithmInfo(const std::vector<DeviceInfo>& vecNewInfo, std::vector<DeviceInfo>& vecDevUpdate)
  286. {
  287. vecDevUpdate.clear();
  288. for(const auto& it0 : vecNewInfo)
  289. {
  290. for(const auto& it1 : m_vecEqmDevInfo)
  291. {
  292. if(it0.DeviceID == it1.DeviceID)
  293. {
  294. /* 设备的算法信息数目不相等,直接加入更新列表 */
  295. if(it0.vecAlgorithmInfo.size() != it1.vecAlgorithmInfo.size())
  296. {
  297. vecDevUpdate.push_back(it0);
  298. break;
  299. }
  300. /* 设备的算法信息数目相等,进一步对比算法信息 */
  301. bool isEquality = true;
  302. for(const auto& it2 : it0.vecAlgorithmInfo)
  303. {
  304. bool isEq2 = false;
  305. for(const auto& it3 : it1.vecAlgorithmInfo)
  306. {
  307. /* 这里只对比算法ID */
  308. if(it2.ActionID != it3.ActionID)
  309. {
  310. continue;
  311. }else {
  312. isEq2 = true;
  313. break;
  314. }
  315. }
  316. if(!isEq2)
  317. {
  318. isEquality = false;
  319. break;
  320. }
  321. }
  322. if(!isEquality)
  323. {
  324. vecDevUpdate.push_back(it0);
  325. break;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. /**
  332. * @brief 从Redis获取数据线程函数,这个是摄像机线程
  333. * 一个设备一个线程,这个线程的相关变量只在这个线程中使用
  334. *
  335. * @param info
  336. */
  337. void SPAServer::threadFromRedis(const CameraThreadInfo& info)
  338. {
  339. SPDLOG_LOGGER_INFO(m_logger, "开启 fromRedisThread 线程,设备ID:{}", info.DeviceID);
  340. FromRedis fromRedis;
  341. fromRedis.setRedisIPAndPort(info.RedisIP, info.RedisPort);
  342. fromRedis.setRedisPassword(info.RedisPWD);
  343. if(fromRedis.connectRedis())
  344. {
  345. SPDLOG_LOGGER_INFO(m_logger, "连接Redis成功");
  346. }else {
  347. SPDLOG_LOGGER_ERROR(m_logger, "连接Redis失败");
  348. return;
  349. }
  350. CameraThreadInfo threadInfo = info;
  351. // std::string strKey = "117:OD210_026_005246_001-IZRTKyEx";
  352. /* 取出该设备的Key */
  353. std::vector<std::string> vecKey;
  354. for(const auto& it : info.vecAction)
  355. {
  356. std::string strKey = std::to_string(info.DeviceID) + ":" + it;
  357. vecKey.push_back(strKey);
  358. }
  359. std::string strRetValue;
  360. /* 进入线程循环 */
  361. while (m_threadRunning)
  362. {
  363. /* 循环读取这个设备关联的算法信息 */
  364. for(const auto& it : vecKey)
  365. {
  366. SPDLOG_LOGGER_INFO(m_logger, "读取Redis信息, Key: {}", it);
  367. if( !fromRedis.getRedisString(it, strRetValue) )
  368. {
  369. continue;
  370. }
  371. SPDLOG_LOGGER_TRACE(m_logger, "Redis Value:\n{}", strRetValue);
  372. /* 解析数据 */
  373. AlarmInfo alarmInfo;
  374. alarmInfo.ActionID = it.substr(it.find(":") + 1);
  375. /* 解析数据 */
  376. parseRedisData(strRetValue, alarmInfo);
  377. /* 信息时间有的效性判断,主要是记录Redis数据的有效性,是否长时间没有变化,排查错误时用的
  378. * 如果数据长时间数据不变,那么超脑那里就挂了,写入日志 */
  379. isEventTimeVaild(alarmInfo.EventTime);
  380. /* 是否需要写入EQM数据库判断
  381. * 人员计数和区域人员检测需要多次判断,其他的直接写入即可 */
  382. }
  383. std::this_thread::sleep_for(std::chrono::seconds(2));
  384. }
  385. return;
  386. }
  387. /* 解析Redis基础数据 */
  388. void SPAServer::parseRedisData(const std::string& strData, AlarmInfo& alarmInfo)
  389. {
  390. try
  391. {
  392. nJson json0;
  393. json0 = nJson::parse(strData);
  394. alarmInfo.AlarmID = json0["alarmId"].get<int>();
  395. alarmInfo.ChannelID = json0["channel"].get<int>();
  396. alarmInfo.PicUrl = json0["picUrl"].get<std::string>();
  397. alarmInfo.ImageInfo = json0["imageInfo"].get<std::string>();
  398. /* 解析时间,需要将时间中的“T”换成空格 */
  399. alarmInfo.StartTime = json0["beginTime"].get<std::string>();
  400. std::replace(alarmInfo.StartTime.begin(), alarmInfo.StartTime.end(), 'T', ' ');
  401. alarmInfo.EndTime = json0["endTime"].get<std::string>();
  402. std::replace(alarmInfo.EndTime.begin(), alarmInfo.EndTime.end(), 'T', ' ');
  403. alarmInfo.EventTime = json0["eventTime"].get<std::string>();
  404. std::replace(alarmInfo.EventTime.begin(), alarmInfo.EventTime.end(), 'T', ' ');
  405. /* 判断bBoxes有无数据,有数据就解析,没数据就直接返回了 */
  406. nJson json1 = json0["bBoxes"];
  407. std::string labelList; /* 记录违禁品 */
  408. std::string bboxList; /* 记录bbox */
  409. if(!json1.empty())
  410. {
  411. for(auto& it0 : json1)
  412. {
  413. /* 如果status是true,就不是报警,直接跳过 */
  414. bool status = it0["status"].get<bool>();
  415. if(status)
  416. {
  417. continue;
  418. }
  419. /* 这一条Box数据报警了将其内容存储起来 */
  420. alarmInfo.Is_Alarm = true;
  421. /* 解析label,违禁品关键字,先判断这个是不是违禁品检测的算法ID */
  422. if(alarmInfo.ActionID == m_keyContraband)
  423. {
  424. /* 解析报警,取出报警类型 */
  425. nJson label = it0["label"];
  426. for(auto& it1 : label)
  427. {
  428. std::string strLabel = it1.get<std::string>();
  429. /* 检测是否已经加入到字符串中了 */
  430. strLabel += "|";
  431. if(labelList.find(strLabel) != std::string::npos)
  432. {
  433. continue;
  434. }
  435. labelList += strLabel;
  436. }
  437. }
  438. /* 解析bbox,貌似是在图像中的位置 */
  439. nJson bbox = it0["bbox"];
  440. std::string strBbox;
  441. for(auto& it1 : bbox)
  442. {
  443. strBbox += std::to_string(it1.get<int>()) + ",";
  444. }
  445. /* 去掉最后一个“,” */
  446. if(!strBbox.empty())
  447. {
  448. strBbox.pop_back();
  449. }
  450. bboxList += strBbox + "|";
  451. }
  452. /* 去掉最后一个“|” */
  453. if(!labelList.empty())
  454. {
  455. labelList.pop_back();
  456. }
  457. if(!bboxList.empty())
  458. {
  459. bboxList.pop_back();
  460. }
  461. SPDLOG_LOGGER_DEBUG(m_logger, "违禁品列表:{}", labelList);
  462. SPDLOG_LOGGER_DEBUG(m_logger, "bbox列表:{}", bboxList);
  463. }
  464. /* 如果有报警的Box */
  465. if(alarmInfo.Is_Alarm)
  466. {
  467. /* 添加报警信息的提示信息 */
  468. alarmInfo.BboxList = bboxList;
  469. if( (alarmInfo.ActionID == m_keyContraband) && !labelList.empty() )
  470. {
  471. alarmInfo.ActionDes = fmt::format("出现违禁品[{}]告警", labelList);
  472. SPDLOG_LOGGER_INFO(m_logger, "{}", alarmInfo.ActionDes);
  473. }else {
  474. alarmInfo.ActionDes = json0["actionDes"].get<std::string>();
  475. }
  476. /* 判断有没有报警数据 */
  477. if(alarmInfo.ImageInfo.empty())
  478. {
  479. SPDLOG_LOGGER_ERROR(m_logger, "有报警区域,但是没有图片信息");
  480. return;
  481. }
  482. /* 如果是人员报警,就存储人员报警信息 */
  483. if(alarmInfo.ActionID == m_KeyFace)
  484. {
  485. nJson jsonArray = json0["personList"];
  486. for(auto& it : jsonArray)
  487. {
  488. PersonInfo personInfo;
  489. personInfo.PersonID = it["personId"].get<std::string>();
  490. personInfo.PersonName = it["personName"].get<std::string>();
  491. alarmInfo.vecPersonInfo.push_back(personInfo);
  492. }
  493. }
  494. }
  495. }
  496. catch (const nJson::parse_error& e)
  497. {
  498. SPDLOG_LOGGER_ERROR(m_logger, "解析Redis数据失败:{}, 错误ID:{}", e.what(), e.id);
  499. return;
  500. }
  501. catch (const nJson::type_error& e)
  502. {
  503. SPDLOG_LOGGER_ERROR(m_logger, "解析Redis数据失败:{}, 错误ID:{}", e.what(), e.id);
  504. return;
  505. }
  506. }
  507. /**
  508. * @brief 解析Redis的基础通用数据,不包含bBoxes数组数据
  509. *
  510. * @param strData Redis返回的源数据,JSON格式
  511. * @param alarmInfo 解析出来的数据
  512. */
  513. void SPAServer::parseRedisBaseData(const std::string& strData, AlarmInfo& alarmInfo)
  514. {
  515. try
  516. {
  517. nJson json0;
  518. json0 = nJson::parse(strData);
  519. alarmInfo.AlarmID = json0["alarmId"].get<int>();
  520. alarmInfo.ChannelID = json0["channel"].get<int>();
  521. alarmInfo.PicUrl = json0["picUrl"].get<std::string>();
  522. alarmInfo.ImageInfo = json0["imageInfo"].get<std::string>();
  523. /* 解析时间,需要将时间中的“T”换成空格 */
  524. alarmInfo.StartTime = json0["beginTime"].get<std::string>();
  525. std::replace(alarmInfo.StartTime.begin(), alarmInfo.StartTime.end(), 'T', ' ');
  526. alarmInfo.EndTime = json0["endTime"].get<std::string>();
  527. std::replace(alarmInfo.EndTime.begin(), alarmInfo.EndTime.end(), 'T', ' ');
  528. alarmInfo.EventTime = json0["eventTime"].get<std::string>();
  529. std::replace(alarmInfo.EventTime.begin(), alarmInfo.EventTime.end(), 'T', ' ');
  530. }
  531. catch (const nJson::parse_error& e)
  532. {
  533. SPDLOG_LOGGER_ERROR(m_logger, "解析Redis数据失败:{}, 错误ID:{}", e.what(), e.id);
  534. return;
  535. }
  536. catch (const nJson::type_error& e)
  537. {
  538. SPDLOG_LOGGER_ERROR(m_logger, "解析Redis数据失败:{}, 错误ID:{}", e.what(), e.id);
  539. return;
  540. }
  541. }
  542. /**
  543. * @brief 解析Redis的bBoxes数据,这个内容可能根据算法ID不同,内容不同
  544. *
  545. * @param strData
  546. * @param alarmInfo
  547. */
  548. void SPAServer::parseRedisBBoxesData(const std::string& strData, AlarmInfo& alarmInfo)
  549. {
  550. try
  551. {
  552. nJson json0;
  553. json0 = nJson::parse(strData);
  554. /* 判断bBoxes有无数据,有数据就解析,没数据就直接返回了 */
  555. nJson json1 = json0["bBoxes"];
  556. std::string labelList; /* 记录违禁品 */
  557. std::string bboxList; /* 记录bbox */
  558. if(!json1.empty())
  559. {
  560. for(auto& it0 : json1)
  561. {
  562. /* 如果status是true,就不是报警,直接跳过 */
  563. bool status = it0["status"].get<bool>();
  564. if(status)
  565. {
  566. continue;
  567. }
  568. /* 这一条Box数据报警了将其内容存储起来 */
  569. alarmInfo.Is_Alarm = true;
  570. /* 解析label,违禁品关键字,先判断这个是不是违禁品检测的算法ID */
  571. if(alarmInfo.ActionID == m_keyContraband)
  572. {
  573. /* 解析报警,取出报警类型 */
  574. nJson label = it0["label"];
  575. for(auto& it1 : label)
  576. {
  577. std::string strLabel = it1.get<std::string>();
  578. /* 检测是否已经加入到字符串中了 */
  579. strLabel += "|";
  580. if(labelList.find(strLabel) != std::string::npos)
  581. {
  582. continue;
  583. }
  584. labelList += strLabel;
  585. }
  586. }
  587. /* 解析bbox,貌似是在图像中的位置 */
  588. nJson bbox = it0["bbox"];
  589. std::string strBbox;
  590. for(auto& it1 : bbox)
  591. {
  592. strBbox += std::to_string(it1.get<int>()) + ",";
  593. }
  594. /* 去掉最后一个“,” */
  595. if(!strBbox.empty())
  596. {
  597. strBbox.pop_back();
  598. }
  599. bboxList += strBbox + "|";
  600. }
  601. /* 去掉最后一个“|” */
  602. if(!labelList.empty())
  603. {
  604. labelList.pop_back();
  605. }
  606. if(!bboxList.empty())
  607. {
  608. bboxList.pop_back();
  609. }
  610. SPDLOG_LOGGER_DEBUG(m_logger, "违禁品列表:{}", labelList);
  611. SPDLOG_LOGGER_DEBUG(m_logger, "bbox列表:{}", bboxList);
  612. }
  613. /* 如果有报警的Box,解析出报警的说明 */
  614. if(alarmInfo.Is_Alarm)
  615. {
  616. /* 添加报警信息的提示信息 */
  617. alarmInfo.BboxList = bboxList;
  618. /* 违禁品报警信息,违禁品列表不是空的,就添加补充的文字 */
  619. if( (alarmInfo.ActionID == m_keyContraband) && !labelList.empty() )
  620. {
  621. alarmInfo.ActionDes = fmt::format("出现违禁品[{}]告警", labelList);
  622. SPDLOG_LOGGER_INFO(m_logger, "{}", alarmInfo.ActionDes);
  623. }else {
  624. /* 其他报警信息,直接获取 */
  625. alarmInfo.ActionDes = json0["actionDes"].get<std::string>();
  626. }
  627. /* 判断有没有报警数据 */
  628. if(alarmInfo.ImageInfo.empty())
  629. {
  630. SPDLOG_LOGGER_WARN(m_logger, "有报警区域,但是没有图片信息");
  631. return;
  632. }
  633. /* 如果是人员报警,就存储人员报警信息 */
  634. if(alarmInfo.ActionID == m_KeyFace)
  635. {
  636. nJson jsonArray = json0["personList"];
  637. for(auto& it : jsonArray)
  638. {
  639. PersonInfo personInfo;
  640. personInfo.PersonID = it["personId"].get<std::string>();
  641. personInfo.PersonName = it["personName"].get<std::string>();
  642. alarmInfo.vecPersonInfo.push_back(personInfo);
  643. }
  644. }
  645. }
  646. }
  647. catch (const nJson::parse_error& e)
  648. {
  649. SPDLOG_LOGGER_ERROR(m_logger, "解析Redis数据失败:{}, 错误ID:{}", e.what(), e.id);
  650. return;
  651. }
  652. catch (const nJson::type_error& e)
  653. {
  654. SPDLOG_LOGGER_ERROR(m_logger, "解析Redis数据失败:{}, 错误ID:{}", e.what(), e.id);
  655. return;
  656. }
  657. }
  658. /**
  659. * @brief 判断时间是否长时间没有更新,默认的是600秒,超过这个时间Redis还未更新,可能是超脑挂了
  660. *
  661. * @param strTime
  662. * @return true
  663. * @return false
  664. */
  665. bool SPAServer::isEventTimeVaild(const std::string& strTime)
  666. {
  667. /* 获取当前时间 */
  668. std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
  669. /* 字符串转成时间 */
  670. std::istringstream iss(strTime);
  671. std::tm tmEvent = {};
  672. iss >> std::get_time(&tmEvent, "%Y-%m-%d %H:%M:%S");
  673. /* 时间差 */
  674. std::chrono::system_clock::time_point eventTime = std::chrono::system_clock::from_time_t(std::mktime(&tmEvent));
  675. std::chrono::duration<double> diff = now - eventTime;
  676. // SPDLOG_LOGGER_DEBUG(m_logger, "now:{} eventTime: {} 时间差:{}秒",now, eventTime, diff);
  677. if(diff.count() > 600)
  678. {
  679. // SPDLOG_LOGGER_ERROR(m_logger, "Redis数据长时间没有更新,EventTime:{}", strTime);
  680. return false;
  681. }
  682. return true;
  683. }
  684. /**
  685. * @brief 分派任务的线程
  686. 1、 线程定时刷新房间和摄像机的关联关系,以及和算法Action的关联关系
  687. 2、 将算法信息加入到不同的列表中
  688. 需要多个摄像机配合的加入到m_runListRoomActionInfo列表
  689. 不需要多个摄像机配合的加入到m_runListActionInfo列表
  690. 3、 每次刷新都会清空ActionInfo或者RoomActionInfo的摄像机列表,但是不会动其他基本信息,如果是列表中没有对应的信息,
  691. 就会创建新的ActionInfo,那么RunState的状态是INIT,需要开启新的线程
  692. 如果刷新完成后,算法对应的摄像机列表为空,那么对应的线程就会停止运行,将RunState设置为STOP,本线程的下一轮
  693. 循环就会删除这个ActionInfo
  694. */
  695. void SPAServer::threadRoomCamera()
  696. {
  697. /* 房间相机关联信息 */
  698. std::list<RoomCameraInfo> listRC;
  699. /* 创建连接数据库实例 */
  700. std::shared_ptr<ToEQMDataBase> toEQMDataBase = std::make_shared<ToEQMDataBase>();
  701. while (m_threadRunning)
  702. {
  703. /* 先获取EQM数据库信息,取出房间和摄像机关联信息 */
  704. m_mutexActionInfo.lock();
  705. toEQMDataBase->getActionInfo(m_listActionInfo);
  706. /* 取出每个房间的所有算法,int是RoomID,string是Action */
  707. // std::multimap<int, std::string> mapCameraActionID;
  708. m_mutexRunRAI.lock();
  709. /* 先清理已经退出的线程所用到的Action或者RoomAction */
  710. m_runListRoomActionInfo.clearStopRoomAction();
  711. m_runListActionInfo.clearStopAction();
  712. m_mutexRunActionInfo.lock();
  713. /* 将算法信息加入到不同的列表中
  714. * 需要多个摄像机配合的加入到m_runListRoomActionInfo列表
  715. * 不需要多个摄像机配合的加入到m_runListActionInfo列表
  716. * */
  717. m_runListRoomActionInfo.clearCameraList();
  718. m_runListActionInfo.clearCameraList();
  719. for(const auto& it : m_listActionInfo.getData())
  720. {
  721. if(it->ActionID == ActPersonWork || it->ActionID == ActPersonNumber)
  722. {
  723. m_runListRoomActionInfo.addActionInfo(*it);
  724. }else {
  725. m_runListActionInfo.addActionCamera(it);
  726. }
  727. }
  728. m_mutexActionInfo.unlock();
  729. /* 这个容器只用于多个摄像机融合的算法,一个房间的一个算法是一个线程 */
  730. for(const auto& it0 : m_runListRoomActionInfo.getData())
  731. {
  732. /* 人员在岗识别 */
  733. if(it0->ActionID == ActPersonWork)
  734. {
  735. SPDLOG_LOGGER_INFO(m_logger, "RoomID:{} 人员在岗识别", it0->RoomID);
  736. /* 判断是否需要创建新的线程 */
  737. if(it0->RunState == RunTimeState::RUN_STATE_INIT)
  738. {
  739. /* 创建新的线程 */
  740. CPPTP.add_task(&SPAServer::threadActPersonWork, this, it0);
  741. }
  742. }
  743. /* 区域人员检测 */
  744. else if (it0->ActionID == ActPersonNumber)
  745. {
  746. SPDLOG_LOGGER_INFO(m_logger, "RoomID:{} 区域人员检测", it0->RoomID);
  747. if(it0->RunState == RunTimeState::RUN_STATE_INIT)
  748. {
  749. CPPTP.add_task(&SPAServer::threadActPersonNumber, this, it0);
  750. }
  751. }
  752. }
  753. /* 这个容器用于不关联的算法信息,每个设备上的每个算法是一个线程
  754. * ActionInfo.RunState = RUN_STATE_INIT ,就是新增的算法,需要创建新的线程 */
  755. for(const auto& it0 : m_runListActionInfo.getData())
  756. {
  757. /* 违禁物品识别,不需要多个摄像机融合判断,多少个报警都直接上报 */
  758. if (it0->ActionID == ActContraband)
  759. {
  760. SPDLOG_LOGGER_INFO(m_logger, "RoomID:{} 违禁品检测", it0->RoomID);
  761. if(it0->RunState == RunTimeState::RUN_STATE_INIT)
  762. {
  763. CPPTP.add_task(&SPAServer::threadActContraband, this, it0);
  764. }
  765. }
  766. /* 非法入侵检测,这个也不需要摄像机融合 */
  767. else if (it0->ActionID == ActIllegalInvasion)
  768. {
  769. SPDLOG_LOGGER_INFO(m_logger, "RoomID:{} 非法入侵检测", it0->RoomID);
  770. }
  771. /* 疲劳检测,不需要摄像机融合检测,直接上报 */
  772. else if (it0->ActionID == ActFatigueDetection)
  773. {
  774. SPDLOG_LOGGER_INFO(m_logger, "RoomID:{} 疲劳检测", it0->RoomID);
  775. }
  776. }
  777. m_mutexRunRAI.unlock();
  778. m_mutexRunActionInfo.unlock();
  779. }
  780. }
  781. /* 将该算法对应的摄像机放入摄像机列表 */
  782. bool SPAServer::insertCameraToAction(RoomActionInfo* pRAInfo, std::list<RoomCameraInfo>& listRC, std::multimap<int, std::string>& mapCameraActionID)
  783. {
  784. for(const auto& rci : listRC)
  785. {
  786. if(rci.RoomID == pRAInfo->RoomID)
  787. {
  788. /* 这个摄像机在这个房间内,再判断这个摄像机有没有这个算法 */
  789. for(const auto& camID : rci.listCameraID)
  790. {
  791. for(const auto& cai : mapCameraActionID)
  792. {
  793. if(camID == cai.first)
  794. {
  795. /* 再判断这个摄像机的算法是否是当前需要的 */
  796. if(cai.second == pRAInfo->ActionID)
  797. {
  798. pRAInfo->listCameraID.push_back(camID);
  799. }
  800. }
  801. }
  802. }
  803. }
  804. }
  805. return true;
  806. }
  807. /* 更新房间、算法需要的摄像机个数,从内存中更新 */
  808. bool SPAServer::updateRoomActionCameraCount(std::shared_ptr<RoomActionInfo> pRAInfo)
  809. {
  810. std::lock_guard<std::mutex> look(m_mutexRunRAI);
  811. for(auto& it : m_runListRoomActionInfo.getData())
  812. {
  813. if((it->RoomID == pRAInfo->RoomID) && (it->ActionID == pRAInfo->ActionID))
  814. {
  815. it->listCameraID = pRAInfo->listCameraID;
  816. break;
  817. }
  818. }
  819. return true;
  820. }
  821. /* 更新算法的摄像机ID,这里是从内存中的数组里获取 */
  822. bool SPAServer::updateActionCameraID(std::shared_ptr<ActionInfo> pInfo)
  823. {
  824. pInfo->CameraID = -1;
  825. std::lock_guard<std::mutex> look(m_mutexRunActionInfo);
  826. for(auto& it : m_runListActionInfo.getData())
  827. {
  828. if(it->isEqualBaseInfo(*pInfo))
  829. {
  830. pInfo->CameraID = it->CameraID;
  831. break;
  832. }
  833. }
  834. return true;
  835. }
  836. /* 设置线程状态 */
  837. void SPAServer::setThreadState(std::shared_ptr<ActionInfo> pInfo, RunTimeState state)
  838. {
  839. std::lock_guard<std::mutex> look(m_mutexRunActionInfo);
  840. for(auto& it : m_runListActionInfo.getData())
  841. {
  842. if(it->isEqualBaseInfo(*pInfo))
  843. {
  844. it->RunState = state;
  845. break;
  846. }
  847. }
  848. }
  849. /**
  850. * @brief 人员在岗识别线程,应该是人脸识别线程,这个需要房间内多个摄像机共同识别
  851. 1、离岗判断条件:直播间无人算离岗(直播间所有摄像头的区域人员检测算法输出结果都为0时记为离岗开始,
  852. 当结果存在非0时记为离岗结束)
  853. 2、离岗输出结果:当判断出离岗行为时,依据人脸识别结果,找到离岗时间点前有人的最近一帧画面中的人员,
  854. 判断为离岗人员,并计算离岗时长,形成离岗记录(频率、机房、离岗人员、离岗开始时间、离岗结束时间、离
  855. 岗持续时长)
  856. 3、在岗时长计算方式:每天00:00:00-23:59:59人脸识别结果中所有人员名称的出现次数✖抽帧频率(如5秒抽
  857. 取1帧,则出现200次人名表示在岗1000秒时长),形成每日的人员在岗时长记录
  858. 4、报警判断条件:依据离岗次数和单次离岗时长进行报警,展示报警结果
  859. *
  860. * @param pRAInfo 传入房间ID和算法ID
  861. */
  862. void SPAServer::threadActPersonWork(RoomActionInfo* RAInfo)
  863. {
  864. SPDLOG_LOGGER_INFO(m_logger, "开启人员在岗识别线程,RoomID:{} ,Action:{}", RAInfo->RoomID, RAInfo->ActionID);
  865. /* 创建读取Redis的实例 */
  866. std::shared_ptr<FromRedis> fromRedis = std::make_shared<FromRedis>();
  867. /* 局部变量 */
  868. std::shared_ptr<RoomActionInfo> pRAInfo = std::make_shared<RoomActionInfo>();
  869. *pRAInfo = *RAInfo;
  870. int CameraCount = pRAInfo->listCameraID.size();
  871. /* 摄像机数目小于0就退出线程 */
  872. while (m_threadRunning)
  873. {
  874. /* 更新算法关联的摄像机个数 */
  875. pRAInfo->listCameraID.clear();
  876. updateRoomActionCameraCount(pRAInfo);
  877. CameraCount = pRAInfo->listCameraID.size();
  878. if(CameraCount == 0)
  879. {
  880. break;
  881. }
  882. /* 读取Redis数据 */
  883. for(const auto& camID : pRAInfo->listCameraID)
  884. {
  885. std::string strKey = std::to_string(camID) + ":" + pRAInfo->ActionID;
  886. std::string strRetValue;
  887. if(!fromRedis->getRedisString(strKey, strRetValue))
  888. {
  889. SPDLOG_LOGGER_ERROR(m_logger, "读取Redis数据失败, Key:{}", strKey);
  890. continue;
  891. }
  892. /* 解析数据 */
  893. AlarmInfo alarmInfo;
  894. parseRedisData(strRetValue, alarmInfo);
  895. }
  896. }
  897. }
  898. /**
  899. * @brief 区域人员检测,检测这个区域内的人数,不能少于多少人,不能多余多少人
  900. * 1、报警判断条件:直播间报警:当前频率所有直播间摄像头的区域人员检测算法输出结果均大于或小于设定人
  901. 数值时,记为报警行为,直接展示报警结果
  902. 2、录播间报警:当前频率所有录播间摄像头的区域人员检测算法输出结果均大于或小于设定人数值时,记为报
  903. 警行为,直接展示报警结果
  904. 3、直播间+录播间报警:当前频率直播间人数+录播间人数大于或小于设定人数值时,记为报警行为,直接展示
  905. 报警结果
  906. *
  907. * @param RAInfo 传入的房间ID和算法ID
  908. */
  909. void SPAServer::threadActPersonNumber(RoomActionInfo* RAInfo)
  910. {
  911. SPDLOG_LOGGER_INFO(m_logger, "开启区域人员检测线程,RoomID:{} ,Action:{}", RAInfo->RoomID, RAInfo->ActionID);
  912. /* 创建读取Redis的实例 */
  913. std::shared_ptr<FromRedis> fromRedis = std::make_shared<FromRedis>();
  914. /* 局部变量 */
  915. std::shared_ptr<RoomActionInfo> pRAInfo = std::make_shared<RoomActionInfo>();
  916. *pRAInfo = *RAInfo;
  917. int CameraCount = 0;
  918. /* 摄像机数目等于0就退出线程 */
  919. while (m_threadRunning)
  920. {
  921. /* 更新算法关联的摄像机个数 */
  922. pRAInfo->listCameraID.clear();
  923. updateRoomActionCameraCount(pRAInfo);
  924. CameraCount = pRAInfo->listCameraID.size();
  925. if(CameraCount == 0)
  926. {
  927. break;
  928. }
  929. /* 读取Redis数据 */
  930. for(const auto& camID : pRAInfo->listCameraID)
  931. {
  932. std::string strKey = std::to_string(camID) + ":" + pRAInfo->ActionID;
  933. std::string strRetValue;
  934. if(!fromRedis->getRedisString(strKey, strRetValue))
  935. {
  936. SPDLOG_LOGGER_ERROR(m_logger, "读取Redis数据失败, Key:{}", strKey);
  937. continue;
  938. }
  939. /* 解析数据 */
  940. AlarmInfo alarmInfo;
  941. parseRedisData(strRetValue, alarmInfo);
  942. }
  943. }
  944. }
  945. /**
  946. * @brief 违禁物品识别
  947. 报警判断条件:机房内出现摄像头的违禁物品识别算法输出结果包含指定违规内容时,记为报警行为,直接
  948. 展示报警结果
  949. 这里应该是不区分违禁物品是什么,只要有违禁物品就报警。如果一个违禁物品消失之前又出现了第二个违禁物品,
  950. 两个违禁物品都消失后,这次报警才会结束。
  951. *
  952. * @param info 线程信息
  953. */
  954. void SPAServer::threadActContraband(ActionInfo* info)
  955. {
  956. SPDLOG_LOGGER_INFO(m_logger, "开启违禁物品识别线程,RoomID:{} ,Action:{}", info->RoomID, info->ActionID);
  957. /* 创建读取Redis的实例 */
  958. std::shared_ptr<FromRedis> fromRedis = std::make_shared<FromRedis>();
  959. /* 局部变量,保存这个线程的信息 */
  960. std::shared_ptr<ActionInfo> pActInfo = std::make_shared<ActionInfo>();
  961. *pActInfo = *info;
  962. /* 摄像机ID小于0就退出线程 */
  963. while (m_threadRunning)
  964. {
  965. /* 更新算法关联的摄像机ID */
  966. updateActionCameraID(pActInfo);
  967. /* 如果摄像机ID是小于0,那么这个算法就没有对应的摄像机了,线程就退出了 */
  968. if(pActInfo->CameraID < 0)
  969. {
  970. break;
  971. }
  972. /* 读取Redis数据 */
  973. std::string strKey = std::to_string(pActInfo->CameraID) + ":" + pActInfo->ActionID;
  974. std::string strRetValue;
  975. if(!fromRedis->getRedisString(strKey, strRetValue))
  976. {
  977. SPDLOG_LOGGER_ERROR(m_logger, "读取Redis数据失败, Key:{}", strKey);
  978. continue;
  979. }
  980. /* 解析数据 */
  981. AlarmInfo alarmInfo;
  982. parseRedisBaseData(strRetValue, alarmInfo);
  983. parseRedisBBoxesData(strRetValue, alarmInfo);
  984. /* 判断事件的时效性,超过多少秒不更新就可能是超脑挂了 */
  985. if(isEventTimeVaild(alarmInfo.EventTime))
  986. {
  987. SPDLOG_LOGGER_WARN(m_logger, "Redis Key:{} 数据长时间没有更新,EventTime:{}",strKey, alarmInfo.EventTime);
  988. continue;
  989. }
  990. /* 判断有无报警记录,写入到EQM数据库 */
  991. }
  992. /* 设置线程退出的状态 */
  993. setThreadState(pActInfo, RunTimeState::RUN_STATE_STOP);
  994. SPDLOG_LOGGER_INFO(m_logger, "违禁物品识别线程退出,RoomID:{} ,CameraID, Action:{}", pActInfo->RoomID, pActInfo->CameraID, pActInfo->ActionID);
  995. }
  996. /**
  997. * @brief 非法入侵检测
  998. 1、野猫、宠物识别:报警判断条件:机房内出现摄像头的宠物识别算法输出报警结果时,记为报警行为,直接
  999. 展示报警结果
  1000. 2、无权限人员识别:报警判断条件:当判断出区域非法入侵行为时,依据人脸识别结果,判断是否为人脸库人
  1001. 员,非人脸库的人员时判断为非法入侵行为(背影需要报警需要结合区域人员检测算法判断)
  1002. *
  1003. * @param info
  1004. */
  1005. void SPAServer::threadActIllegalInvasion(ActionInfo* info)
  1006. {
  1007. SPDLOG_LOGGER_INFO(m_logger, "开启非法入侵检测线程,RoomID:{} ,Action:{}", info->RoomID, info->ActionID);
  1008. /* 创建读取Redis的实例 */
  1009. std::shared_ptr<FromRedis> fromRedis = std::make_shared<FromRedis>();
  1010. /* 局部变量,保存这个线程的信息 */
  1011. std::shared_ptr<ActionInfo> pActInfo = std::make_shared<ActionInfo>();
  1012. *pActInfo = *info;
  1013. /* 摄像机ID小于0就退出线程 */
  1014. while (m_threadRunning)
  1015. {
  1016. /* 更新算法关联的摄像机ID */
  1017. updateActionCameraID(pActInfo);
  1018. /* 如果摄像机ID是小于0,那么这个算法就没有对应的摄像机了,线程就退出了 */
  1019. if(pActInfo->CameraID < 0)
  1020. {
  1021. break;
  1022. }
  1023. /* 读取Redis数据 */
  1024. std::string strKey = std::to_string(pActInfo->CameraID) + ":" + pActInfo->ActionID;
  1025. std::string strRetValue;
  1026. if(!fromRedis->getRedisString(strKey, strRetValue))
  1027. {
  1028. SPDLOG_LOGGER_ERROR(m_logger, "读取Redis数据失败, Key:{}", strKey);
  1029. continue;
  1030. }
  1031. /* 解析数据 */
  1032. AlarmInfo alarmInfo;
  1033. parseRedisData(strRetValue, alarmInfo);
  1034. /* 判断事件的时效性,超过多少秒不更新就可能是超脑挂了 */
  1035. if(isEventTimeVaild(alarmInfo.EventTime))
  1036. {
  1037. SPDLOG_LOGGER_WARN(m_logger, "Redis Key:{} 数据长时间没有更新,EventTime:{}",strKey, alarmInfo.EventTime);
  1038. continue;
  1039. }
  1040. /* 判断有无报警记录,写入到EQM数据库 */
  1041. }
  1042. /* 设置线程退出的状态 */
  1043. setThreadState(pActInfo, RunTimeState::RUN_STATE_STOP);
  1044. SPDLOG_LOGGER_INFO(m_logger, "非法入侵检测线程退出,RoomID:{} ,CameraID:{}, Action:{}", pActInfo->RoomID, pActInfo->CameraID, pActInfo->ActionID);
  1045. }