#include "GlobalVariable.h" #include "spdlog/spdlog.h" // #include "FuncBase.h" /* ==================================================================================== * ******************************* 全局变量定义 ********************************** * ====================================================================================*/ int g_eventTimeVaild = 600; /* 事件时间有效性,单位秒,超过这个时间就认为是无效数据 */ /* ==================================================================================== * *************************** DeviceInfo成员函数 ******************************* * ====================================================================================*/ /* 对比是否相等 */ bool DeviceInfo::operator==(const DeviceInfo& other) { if(DeviceID != other.DeviceID) { return false; } else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) { return false; } else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) { return false; } else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) { return false; } return true; } /* 对比设备关联的算法信息是否相等 */ bool DeviceInfo::isEqualAlgorithmInfo(const std::vector& other) { /* 算法数目不相等,直接返回false */ if(vecAlgorithmInfo.size() != other.size()) { return false; }else { /* 算法数目相等,进一步对比算法信息 */ bool isEquality = true; /* 逐步对比算法信息 */ for(const auto& it0 : vecAlgorithmInfo) { bool isEq2 = true; for(const auto& it1 : other) { if(it0 == it1) { continue; }else { isEq2 = false; break; } } if(!isEq2) { isEquality = false; break; } } if(!isEquality) { return false; } } return true; } DetectPeriodInfo::DetectPeriodInfo() { ChannelID = 0; appFunction = AppFunction::APP_NONE; PeriodName = ""; PeriodType = Enum_PeriodType::PERIOD_ALL; listWeekTime.clear(); lastTime = QDateTime::fromString("1970-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"); } DetectPeriodInfo::DetectPeriodInfo(const DetectPeriodInfo& other) { ChannelID = other.ChannelID; appFunction = other.appFunction; PeriodName = other.PeriodName; PeriodType = other.PeriodType; listWeekTime = other.listWeekTime; lastTime = other.lastTime; } DetectPeriodInfo& DetectPeriodInfo::operator=(const DetectPeriodInfo& other) { if (this != &other) { ChannelID = other.ChannelID; appFunction = other.appFunction; PeriodName = other.PeriodName; PeriodType = other.PeriodType; listWeekTime = other.listWeekTime; lastTime = other.lastTime; } return *this; } /* ==================================================================================== * ******************************* 各种报警信息 ********************************** * ====================================================================================*/ AlarmInfo::AlarmInfo() { Is_Alarm = false; Is_InsertEQM = false; Is_OnWork = false; PKID = 0; AlarmID = 0; DeviceID = 0; RoomID = 0; ChannelID = 0; State = 0; OnWork = 0; StartTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"); EndTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"); EventTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"); // PicUrl = ""; ImageInfo = ""; // AppID = ""; ActionID = ""; ActionDes = ""; FaceIDList = ""; FaceNameList = ""; listBbox.clear(); listPersonInfo.clear(); appFunction = AppFunction::APP_NONE; } AlarmInfo::AlarmInfo(const AlarmInfo& other) { Is_Alarm = other.Is_Alarm; Is_InsertEQM = other.Is_InsertEQM; Is_OnWork = other.Is_OnWork; PKID = other.PKID; AlarmID = other.AlarmID; DeviceID = other.DeviceID; RoomID = other.RoomID; ChannelID = other.ChannelID; State = other.State; OnWork = other.OnWork; StartTime = other.StartTime; EndTime = other.EndTime; EventTime = other.EventTime; // PicUrl = other.PicUrl; ImageInfo = other.ImageInfo; // AppID = other.AppID; ActionID = other.ActionID; ActionDes = other.ActionDes; FaceIDList = other.FaceIDList; FaceNameList = other.FaceNameList; listBbox = other.listBbox; listPersonInfo = other.listPersonInfo; appFunction = other.appFunction; } AlarmInfo& AlarmInfo::operator=(AlarmInfo& other) { if(this != &other) { Is_Alarm = other.Is_Alarm; Is_InsertEQM = other.Is_InsertEQM; Is_OnWork = other.Is_OnWork; PKID = other.PKID; AlarmID = other.AlarmID; DeviceID = other.DeviceID; RoomID = other.RoomID; ChannelID = other.ChannelID; State = other.State; OnWork = other.OnWork; StartTime = other.StartTime; EndTime = other.EndTime; EventTime = other.EventTime; // PicUrl = other.PicUrl; ImageInfo = other.ImageInfo; // AppID = other.AppID; ActionID = other.ActionID; ActionDes = other.ActionDes; FaceIDList = other.FaceIDList; FaceNameList = other.FaceNameList; listBbox = other.listBbox; listPersonInfo = other.listPersonInfo; appFunction = other.appFunction; } return *this; } /* 清空内容 */ void AlarmInfo::reInit() { Is_Alarm = false; Is_InsertEQM = false; Is_OnWork = false; PKID = 0; AlarmID = 0; DeviceID = 0; RoomID = 0; ChannelID = 0; State = 0; OnWork = 0; StartTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"); EndTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"); EventTime = QDateTime::fromString("2000-01-01 00:00:00", "yyyy-MM-dd hh:mm:ss"); // PicUrl = ""; ImageInfo = ""; // AppID = ""; ActionID = ""; ActionDes = ""; FaceIDList = ""; FaceNameList = ""; listBbox.clear(); listPersonInfo.clear(); appFunction = AppFunction::APP_NONE; } /* 获取人脸列表 */ std::string AlarmInfo::getFaceIDListString() { std::string strFaceList = ""; for(auto& it : listPersonInfo) { if(it.PersonID.size() < 0) { continue; } strFaceList += it.PersonID + ";" ; } /* 去掉最后的“;” */ if(strFaceList.size() > 0) { strFaceList = strFaceList.substr(0, strFaceList.size() - 1); } return strFaceList; } /* 获取人脸名称列表 */ std::string AlarmInfo::getFaceNameListString() { std::string strFaceName; for(auto& it : listPersonInfo) { if(it.PersonName.size() < 0) { continue; } strFaceName += it.PersonName + ";"; } /* 去掉最后的“;” */ if(strFaceName.size() > 0) { strFaceName = strFaceName.substr(0, strFaceName.size() - 1); } return strFaceName; } /** * @brief 添加报警信息 * * @param info * @return true * @return false */ bool ListAlarmInfo::addAlarmInfo(AlarmInfo& info) { /* 先查找有没有重复的 */ auto p = findAlarmInfo(info); if(p != nullptr) { return false; } AlarmInfo* pNew = new AlarmInfo(info); listAlarmInfo.push_back(pNew); return true; } /** * @brief 检查列表中是是否有这个报警信息,这里只检查ChannelID、RoomID、CameraID、ActionID是否相等 * * @param info * @return AlarmInfo* */ AlarmInfo* ListAlarmInfo::findAlarmInfo(AlarmInfo& info) { for(auto& it0 : listAlarmInfo) { if(it0->ChannelID == info.ChannelID && it0->RoomID == info.RoomID && it0->DeviceID == info.DeviceID && it0->ActionID == info.ActionID) { return it0; } } return nullptr; } /* 删除报警记录 */ void ListAlarmInfo::deleteAlarmInfo(AlarmInfo& info) { for(auto it = listAlarmInfo.begin(); it != listAlarmInfo.end();) { if((*it)->ChannelID == info.ChannelID && (*it)->RoomID == info.RoomID && (*it)->DeviceID == info.DeviceID && (*it)->ActionID == info.ActionID) { delete *it; it = listAlarmInfo.erase(it); }else { ++it; } } } /* 清空报警记录 */ void ListAlarmInfo::clearAlarmInfo() { for(auto& it : listAlarmInfo) { delete it; } listAlarmInfo.clear(); } /* 查找是否有相同的人脸信息 */ bool RoomFaceInfo::findPersonInfo(const PersonInfo& info) { for(auto& it0 : listPersonInfo) { if(it0.PersonID == info.PersonID && it0.PersonName == info.PersonName) { return true; } } return false; } /* 添加房间人脸信息 */ void ListRoomFaceInfo::addRoomFaceInfo(RoomFaceInfo& info) { /* 先查找有没有重复的 */ auto p = findRoomFaceInfo(info); if(p != nullptr) { return; } listRoomFaceInfo.push_back(info); } /** * @brief 通过报警信息添加人脸信息 * * @param info */ void ListRoomFaceInfo::addRoomFaceInfo(AlarmInfo& info) { auto p = findRoomFaceInfo(info.ChannelID, info.RoomID, info.DeviceID); if(p == nullptr) { RoomFaceInfo rfi; rfi.ChannelID = info.ChannelID; rfi.RoomID = info.RoomID; rfi.CameraID = info.DeviceID; rfi.MaxNum = 0; rfi.MinNum = 0; rfi.StartTime = QDateTime::currentDateTime(); listRoomFaceInfo.push_back(rfi); } /* 将人员信息加入到列表中,添加时会先查找有没有相同的信息 */ for(auto& it0 : info.listPersonInfo) { if(!p->findPersonInfo(it0)) { p->listPersonInfo.push_back(it0); } } } RoomFaceInfo* ListRoomFaceInfo::findRoomFaceInfo(RoomFaceInfo& info) { for(auto& it0 : listRoomFaceInfo) { if(it0.ChannelID == info.ChannelID && it0.RoomID == info.RoomID && it0.CameraID == info.CameraID) { return &it0; } } return nullptr; } /* 查找有没有相同的结构 */ RoomFaceInfo* ListRoomFaceInfo::findRoomFaceInfo(int ChannelID, int RoomID, int CameraID) { for(auto& it0 : listRoomFaceInfo) { if(it0.ChannelID == ChannelID && it0.RoomID == RoomID && it0.CameraID == CameraID) { return &it0; } } return nullptr; } /* ==================================================================================== * ************************** ListActionInfo成员函数 **************************** * ====================================================================================*/ ActionInfo::ActionInfo() { RunState = RunTimeState::RUN_STATE_INIT; ChannelID = -1; RoomID = -1; CameraID = -1; RoomType = Enum_RoomType::ROOM_NONE; ActionID = ""; strRoomName = ""; strActionName = ""; } ActionInfo& ActionInfo::operator=(const ActionInfo& other) { if (this != &other) { ChannelID = other.ChannelID; RoomID = other.RoomID; CameraID = other.CameraID; ActionID = other.ActionID; strRoomName = other.strRoomName; RoomType = other.RoomType; } return *this; } bool ActionInfo::operator==(const ActionInfo& other) { if(ChannelID != other.ChannelID) { return false; } if(RoomID != other.RoomID) { return false; } if(CameraID != other.CameraID) { return false; } if(ActionID != other.ActionID) { return false; } if(RoomType != other.RoomType) { return false; } return true; } /* 对比除摄像机外的基础信息是否相等 */ bool ActionInfo::isEqualBaseInfo(const ActionInfo& other) { if(ChannelID != other.ChannelID) { return false; } if(RoomID != other.RoomID) { return false; } if(ActionID != other.ActionID) { return false; } if(RoomType != other.RoomType) { return false; } return true; } /* 添加关联信息,会自动进行重复判断,如果已有相同的信息,则跳过 */ bool ListActionInfo::insertActionInfo(ActionInfo* info) { /* 先判断是否已经在列表中了 */ if(findActionInList(info) == nullptr) { ActionInfo* pActionInfo = new ActionInfo; *pActionInfo = *info; listActionInfo.push_back(pActionInfo); } return true; } /* 删除信息 */ bool ListActionInfo::deleteActionInfo(ActionInfo* info) { if(info == nullptr) { return false; } if(findActionInList(info) != nullptr) { listActionInfo.remove(info); delete info; info = nullptr; } return true; } /* 给算法添加摄像机,原有的会被替换掉 */ bool ListActionInfo::addActionCamera(ActionInfo* pInfo) { auto pActionInfo = findActionIDInListNoCamera(pInfo); if(pActionInfo != nullptr) { pActionInfo->CameraID = pInfo->CameraID; } return true; } /* 清空算法中的摄像机信息 */ void ListActionInfo::clearCameraList() { for(auto& it0 : listActionInfo) { it0->CameraID = -1; } } /* 清空设置成STOP或ERROR的Action */ void ListActionInfo::clearStopAction() { for(auto it0 = listActionInfo.begin(); it0 != listActionInfo.end();) { if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR)) { delete *it0; it0 = listActionInfo.erase(it0); }else { ++it0; } } } /* 查找算法ID是否已在列表中 */ ActionInfo* ListActionInfo::findActionInList(ActionInfo* pInfo) { for(const auto& it0 : listActionInfo) { if(*it0 == *pInfo) { return it0; } } return nullptr; } /* 查找算法ID是否在列表中,这里查找不会对比摄像机ID */ ActionInfo* ListActionInfo::findActionIDInListNoCamera(ActionInfo* pInfo) { for(const auto& it0 : listActionInfo) { if(it0->isEqualBaseInfo(*pInfo)) { return it0; } } return nullptr; } /* 清空容器 */ void ListActionInfo::clear() { for(auto& it0 : listActionInfo) { delete it0; it0 = nullptr; } listActionInfo.clear(); } /* ==================================================================================== * *********************** ListRoomActionInfo成员函数 *************************** * ====================================================================================*/ /* 对比频道信息、房间信息、算法ID是否相等 */ bool RoomActionInfo::isEqualBaseInfo(const RoomActionInfo& other) { if(ChannelID != other.ChannelID) { return false; } if(RoomID != other.RoomID) { return false; } if(ActionID != other.ActionID) { return false; } if(RoomType != other.RoomType) { return false; } return true; } /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */ bool ListRoomActionInfo::insertRoomActionInfo(const RoomActionInfo& info) { /* 先判断是否已经在列表中了 */ if(findActionIDInList(info.ChannelID, info.RoomID, info.ActionID) == nullptr) { RoomActionInfo* pRoomActionInfo = new RoomActionInfo; *pRoomActionInfo = info; listRoomActionInfo.push_back(pRoomActionInfo); } return true; } /* 添加关联信息,会自动进行重复判断,如果已有相同的room和action关联信息,则跳过 */ bool ListRoomActionInfo::insertRoomActionInfo(const int ChannelID, const int RoomID, const std::string& strActionID) { /* 先判断是否已经在列表中了 */ if(findActionIDInList(ChannelID, RoomID, strActionID) == nullptr) { RoomActionInfo* pRoomActionInfo = new RoomActionInfo; pRoomActionInfo->RoomID = RoomID; pRoomActionInfo->ActionID = strActionID; listRoomActionInfo.push_back(pRoomActionInfo); } return true; } /* 删除一个容器,注意,这个不能在别的for循环中删除,只能单独删除 */ bool ListRoomActionInfo::deleteRoomActionInfo(RoomActionInfo* pInfo) { if(pInfo == nullptr) { return false; } for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end(); ++it0) { if(*it0 == pInfo) { listRoomActionInfo.erase(it0); delete pInfo; pInfo = nullptr; return true; } } return false; } /* 清空容器 */ void ListRoomActionInfo::clear() { for(auto& it0 : listRoomActionInfo) { delete it0; it0 = nullptr; } listRoomActionInfo.clear(); } /* 添加算法信息,根据传入的算法信息,自动将其加入到对应的容器中 */ void ListRoomActionInfo::addActionInfo(const ActionInfo& info) { auto pRAInfo = findActionIDInList(info.ChannelID, info.RoomID, info.ActionID); if(pRAInfo != nullptr) { pRAInfo->listCameraID.push_back(info.CameraID); }else { RoomActionInfo* pRoomActionInfo = new RoomActionInfo; pRoomActionInfo->ChannelID = info.ChannelID; pRoomActionInfo->RoomID = info.RoomID; pRoomActionInfo->ActionID = info.ActionID; pRoomActionInfo->RoomType = info.RoomType; pRoomActionInfo->strRoomName = info.strRoomName; pRoomActionInfo->listCameraID.push_back(info.CameraID); listRoomActionInfo.push_back(pRoomActionInfo); } } /* 清空算法对应的摄像机列表 */ void ListRoomActionInfo::clearCameraList() { for(auto& it0 : listRoomActionInfo) { it0->listCameraID.clear(); } } /* 清理设置为STOP或者ERROR的RoomAction */ // void ListRoomActionInfo::clearStopRoomAction() // { // for(auto it0 = listRoomActionInfo.begin(); it0 != listRoomActionInfo.end();) // { // if(( (*it0)->RunState == RunTimeState::RUN_STATE_STOP) || ((*it0)->RunState == RunTimeState::RUN_STATE_ERROR)) // { // delete *it0; // it0 = listRoomActionInfo.erase(it0); // }else { // ++it0; // } // } // } /* 查找算法ID是否已在列表中 */ RoomActionInfo* ListRoomActionInfo::findActionIDInList(const int chnID, const int RoomID, const std::string& strActionID) { for(const auto& it0 : listRoomActionInfo) { if((it0->RoomID == RoomID) && (it0->ActionID == strActionID) && (it0->ChannelID == chnID)) { return it0; } } return nullptr; } RoomCamActInfo::RoomCamActInfo() { RoomID = -1; RoomType = Enum_RoomType::ROOM_NONE; strRoomName = ""; mapCameraAction.clear(); } RoomCamActInfo::RoomCamActInfo(const RoomCamActInfo& other) \ { if (this != &other) { RoomID = other.RoomID; RoomType = other.RoomType; strRoomName = other.strRoomName; mapCameraAction = other.mapCameraAction; } } RoomCamActInfo& RoomCamActInfo::operator=(const RoomCamActInfo& other) { if (this != &other) { RoomID = other.RoomID; RoomType = other.RoomType; strRoomName = other.strRoomName; mapCameraAction = other.mapCameraAction; } return *this; } /* 添加摄像机算法 */ void RoomCamActInfo::addCameraAction(int CameraID, const std::string& ActionID) { auto it = mapCameraAction.find(CameraID); if(it == mapCameraAction.end()) { std::list list; list.push_back(ActionID); mapCameraAction.insert(std::make_pair(CameraID, list)); }else { it->second.push_back(ActionID); } }