Просмотр исходного кода

V0.1.9
1、添加了设备和算法关联信息表的操作,但是还是有些问题

Apple 7 месяцев назад
Родитель
Сommit
3226754345

+ 26 - 21
SecurePlayAuxServer/GlobalInfo.h

@@ -91,41 +91,46 @@ struct DeviceInfo
     }
     /* 对比是否相等 */
     bool operator==(const DeviceInfo& other) const {
-        if(DeviceID != other.DeviceID)
-        {
+        if(DeviceID != other.DeviceID) {
             return false;
         }
-        if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP)
-        {
+        else if(DeviceName != other.DeviceName || DeviceIP != other.DeviceIP) {
             return false;
         }
-        if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType)
-        {
+        else if(DeviceSerial != other.DeviceSerial || DeviceType != other.DeviceType) {
             return false;
         }
-        if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword)
-        {
+        else if(DevicePort != other.DevicePort || UserAccount != other.UserAccount || UserPassword != other.UserPassword) {
             return false;
         }
-        /* 对比算法列表 */
-        if(vecAlgorithmInfo.size() != other.vecAlgorithmInfo.size())
-        {
+
+        return true;
+    }
+    /* 对比设备关联的算法信息是否相等 */
+    bool isEqualAlgorithmInfo(const DeviceInfo& other) const {
+        /* 算法数目不相等,直接返回false */
+        if(vecAlgorithmInfo.size() != other.vecAlgorithmInfo.size()) {
             return false;
-        }else
-        {
+        }else {
+            /* 算法数目相等,进一步对比算法信息 */
             bool isEquality = true;
-            for(size_t i = 0; i < vecAlgorithmInfo.size(); i++)
-            {
-                if(vecAlgorithmInfo[i] == other.vecAlgorithmInfo[i])
-                {
-                    continue;
-                }else {
+            /* 逐步对比算法信息 */
+            for(const auto& it0 : vecAlgorithmInfo) {
+                bool isEq2 = true;
+                for(const auto& it1 : other.vecAlgorithmInfo) {
+                    if(it0 == it1) {
+                        continue;
+                    }else {
+                        isEq2 = false;
+                        break;
+                    }
+                }
+                if(!isEq2) {
                     isEquality = false;
                     break;
                 }
             }
-            if(!isEquality)
-            {
+            if(!isEquality) {
                 return false;
             }
         }

+ 52 - 18
SecurePlayAuxServer/SPAServer.cpp

@@ -47,37 +47,32 @@ void SPAServer::fromSuperBrainThread()
 {
     SPDLOG_LOGGER_INFO(m_logger, "开启 fromSuperBrainThread 线程");
     /* 创建变量 */
-    std::vector<AlgorithmInfo> vecAlgInfo;
-    std::vector<DeviceInfo> vecDevInfo;
+    std::vector<AlgorithmInfo> vecAlgNewInfo;
+    std::vector<DeviceInfo> vecDevNewInfo;
     
     /* 从EQM数据库中读取到数据信息到内存中,后续对比需要 */
     m_toEQMDataBase.getAlgorithmInfo(m_vecEqmAlgInfo);
     m_toEQMDataBase.getDeviceInfo(m_vecEqmDevInfo);
+    m_toEQMDataBase.getDeviceAlgorithmInfo(m_vecEqmDevInfo);
     /* 获取一次token,后续失效了再获取 */
     m_fromSuperBrain.getToken();
     while (m_threadRunning)
     {
         SPDLOG_LOGGER_INFO(m_logger, "刷新算法和设备信息");
-        m_fromSuperBrain.getTaskTypeList(vecAlgInfo);
-        m_fromSuperBrain.getDeviceList(vecDevInfo);
+        /* 先更新数据库的信息,防止从其他地方并更改了数据库,这里没有刷新本地缓存 */
+        m_toEQMDataBase.getAlgorithmInfo(m_vecEqmAlgInfo);
+        m_toEQMDataBase.getDeviceInfo(m_vecEqmDevInfo);
+        /* 获取基础信息 */
+        m_fromSuperBrain.getTaskTypeList(vecAlgNewInfo);
+        m_fromSuperBrain.getDeviceList(vecDevNewInfo);
 
         /* 处理算法信息 */
-        bool algIsUpdate = processAlgorithmInfo(vecAlgInfo);
+        bool algIsUpdate = processAlgorithmInfo(vecAlgNewInfo);
         /* 处理设备信息 */
-        bool devIsUpdate = processDeviceInfo(vecDevInfo);
-        
-        /* 根据返回值刷新本地数据缓存 */
-        if(algIsUpdate)
-        {
-            m_toEQMDataBase.getAlgorithmInfo(m_vecEqmAlgInfo);
-        }
-        if(devIsUpdate)
-        {
-            m_toEQMDataBase.getDeviceInfo(m_vecEqmDevInfo);
-        }
+        bool devIsUpdate = processDeviceInfo(vecDevNewInfo);
 
-        vecAlgInfo.clear();
-        vecDevInfo.clear();
+        vecAlgNewInfo.clear();
+        vecDevNewInfo.clear();
         std::this_thread::sleep_for(std::chrono::seconds(10));
     }
 }
@@ -123,6 +118,9 @@ bool SPAServer::processDeviceInfo(std::vector<DeviceInfo> vecNewDevInfo)
     std::vector<DeviceInfo> vecDevUpdate;
     std::vector<DeviceInfo> vecDevDelete;
 
+    /**************************************************************************/
+    /* 这里只对比设备信息,不对比设备的算法信息,算法信息在下面单独对比 */
+
     /* 如果本地缓存没有数据,那么就全部插入 */
     if(m_vecEqmDevInfo.size() > 0)
     {
@@ -200,6 +198,42 @@ bool SPAServer::processDeviceInfo(std::vector<DeviceInfo> vecNewDevInfo)
         isUpdate = true;
     }
 
+    /**************************************************************************/
+    /* 处理设备和算子关联的表格,单独对比设备的算法信息 */
+
+    /* 插入新的设备信息 */
+    if(vecDevInsert.size() > 0)
+    {
+        SPDLOG_LOGGER_DEBUG(m_logger, "插入设备和算法关联表");
+        m_toEQMDataBase.insertDeviceAlgorithmInfo(vecDevInsert);
+        isUpdate = true;
+    }
+    /* 删除消失的设备信息 */
+    if(vecDevDelete.size() > 0)
+    {
+        SPDLOG_LOGGER_DEBUG(m_logger, "删除设备和算法关联表");
+        m_toEQMDataBase.deleteDeviceAlgorithmInfo(vecDevDelete);
+        isUpdate = true;
+    }
+
+    vecDevUpdate.clear();
+    /* 取出需要更新的设备 */
+    for(const auto& it0 : vecNewDevInfo)
+    {
+        /* 取出ID相等的设备 */
+        for(const auto& it1 : m_vecEqmDevInfo)
+        {
+            if(!it0.isEqualAlgorithmInfo(it1))
+            {
+                vecDevUpdate.push_back(it0);
+                break;
+            }
+        }
+        
+    }
+    SPDLOG_LOGGER_DEBUG(m_logger, "更新设备和算法关联表, 更新设备数目:{}", vecDevUpdate.size());
+    
+
 
     return isUpdate;
 }

+ 275 - 47
SecurePlayAuxServer/communication/ToEQMDataBase.cpp

@@ -170,23 +170,28 @@ bool ToEQMDataBase::getAlgorithmInfo(std::vector<AlgorithmInfo>& vecInfo)
     }
     /* 解析获取到的JSON数据 */
     // SPDLOG_LOGGER_DEBUG(m_logger,"\n{}",strRet.toStdString());
-    nJson json1 = nJson::parse(strRet.toStdString());
-    int retCode = json1["code"].get<int>();
-    if(retCode != 0)
-    {
-        SPDLOG_LOGGER_ERROR(m_logger,"获取tAction失败");
+    try {
+        nJson json1 = nJson::parse(strRet.toStdString());
+        int retCode = json1["code"].get<int>();
+        if(retCode != 0)
+        {
+            SPDLOG_LOGGER_ERROR(m_logger,"获取tAction失败");
+            return false;
+        }
+        nJson result = json1["result"];
+        for(auto& it : result)
+        {
+            AlgorithmInfo info;
+            info.ActionID = it["actionId"].is_null() ? "" : it["actionId"].get<std::string>();
+            info.ActionName = it["actionName"].get<std::string>();
+            info.ActionTaskID = it["actionTaskid"].get<int>();
+            // SPDLOG_LOGGER_DEBUG(m_logger,"ActionID:{}, ActionName:{}, ActionTaskID:{}",info.ActionID,info.ActionName,info.ActionTaskID);
+            vecInfo.push_back(info);
+        }
+    } catch (const nJson::parse_error& e) {
+        SPDLOG_LOGGER_ERROR(m_logger,"解析tAction数据失败:{}",e.what());
         return false;
     }
-    nJson result = json1["result"];
-    for(auto& it : result)
-    {
-        AlgorithmInfo info;
-        info.ActionID = it["actionId"].is_null() ? "" : it["actionId"].get<std::string>();
-        info.ActionName = it["actionName"].get<std::string>();
-        info.ActionTaskID = it["actionTaskid"].get<int>();
-        // SPDLOG_LOGGER_DEBUG(m_logger,"ActionID:{}, ActionName:{}, ActionTaskID:{}",info.ActionID,info.ActionName,info.ActionTaskID);
-        vecInfo.push_back(info);
-    }
 
     return true;
 }
@@ -210,14 +215,15 @@ bool ToEQMDataBase::insertDeviceInfo(std::vector<DeviceInfo>& vecInfo)
         nJson json0;
         json0["opName"] = "SPSS_InsertToCamerInfo";
         nJson json1;
+        /* 这里不知道是不是“?”运算符的等级是不是不够,不加括号会报错 */
         json1["camerID"] = it.DeviceID;
-        json1["camerName"] = it.DeviceName.empty() ? nullptr : it.DeviceName;
-        json1["camerIP"] = it.DeviceIP.empty() ? nullptr : it.DeviceIP;
+        json1["camerName"] =  it.DeviceName;
+        json1["camerIP"] = it.DeviceIP;
         json1["camerPort"] = it.DevicePort;
-        json1["camerUser"] = it.UserAccount.empty() ? nullptr : it.UserAccount;
-        json1["camerPwd"] = it.UserPassword.empty() ? nullptr : it.UserPassword;
-        json1["camerType"] = it.DeviceType.empty() ? nullptr : it.DeviceType;
-        json1["camerSerial"] = it.DeviceSerial.empty() ? nullptr : it.DeviceSerial;
+        json1["camerUser"] = it.UserAccount;
+        json1["camerPwd"] = it.UserPassword;
+        json1["camerType"] = it.DeviceType;
+        json1["camerSerial"] = it.DeviceSerial;
         json1["camerChannel"] = nullptr;
         json1["camerUrl"] = nullptr;
 
@@ -230,7 +236,29 @@ bool ToEQMDataBase::insertDeviceInfo(std::vector<DeviceInfo>& vecInfo)
             SPDLOG_LOGGER_DEBUG(m_logger,"插入设备信息失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
             isSuccess = false;
         }
-        SPDLOG_LOGGER_DEBUG(m_logger,"插入数据 {} 到 CamerInfo 成功!", it.DeviceID);
+        SPDLOG_LOGGER_DEBUG(m_logger,"插入ID {} 信息到 CamerInfo 成功!", it.DeviceID);
+    }
+    /* 插入信息到tActionCamer表 */
+    for(const auto& it0 : vecInfo)
+    {
+        for(const auto& it1 : it0.vecAlgorithmInfo)
+        {
+            nJson json0;
+            json0["opName"] = "SPSS_InsertToActionCamer";
+            nJson json1;
+            json1["actionID"] = it1.ActionID;
+            json1["camerID"] = it0.DeviceID;
+            json0["paramList"] = json1;
+            QString strCmd = QString::fromStdString(json0.dump());
+            QString strRet;
+            auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
+            if(ret < 0)
+            {
+                SPDLOG_LOGGER_DEBUG(m_logger,"插入设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
+                isSuccess = false;
+            }
+            SPDLOG_LOGGER_DEBUG(m_logger,"插入DeviceID {} 和 ActionID {} 到 ActionCamer 成功!", it0.DeviceID, it1.ActionID);
+        }
     }
 
     return isSuccess;
@@ -257,13 +285,13 @@ bool ToEQMDataBase::updateDeviceInfo(std::vector<DeviceInfo>& vecUpdateInfo)
         json0["opName"] = "SPSS_UpdateToCamerInfo";
         nJson json1;
         json1["camerID"] = it.DeviceID;
-        json1["camerName"] = it.DeviceName.empty() ? nullptr : it.DeviceName;
-        json1["camerIP"] = it.DeviceIP.empty() ? nullptr : it.DeviceIP;
+        json1["camerName"] =  it.DeviceName;
+        json1["camerIP"] = it.DeviceIP;
         json1["camerPort"] = it.DevicePort;
-        json1["camerUser"] = it.UserAccount.empty() ? nullptr : it.UserAccount;
-        json1["camerPwd"] = it.UserPassword.empty() ? nullptr : it.UserPassword;
-        json1["camerType"] = it.DeviceType.empty() ? nullptr : it.DeviceType;
-        json1["camerSerial"] = it.DeviceSerial.empty() ? nullptr : it.DeviceSerial;
+        json1["camerUser"] = it.UserAccount;
+        json1["camerPwd"] = it.UserPassword;
+        json1["camerType"] = it.DeviceType;
+        json1["camerSerial"] = it.DeviceSerial;
         json1["camerChannel"] = nullptr;
         json1["camerUrl"] = nullptr;
 
@@ -276,7 +304,7 @@ bool ToEQMDataBase::updateDeviceInfo(std::vector<DeviceInfo>& vecUpdateInfo)
             SPDLOG_LOGGER_DEBUG(m_logger,"更新设备信息失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
             isSuccess = false;
         }
-        SPDLOG_LOGGER_DEBUG(m_logger,"更新数据 {} 到 CamerInfo 成功!", it.DeviceID);
+        SPDLOG_LOGGER_DEBUG(m_logger,"更新ID {} 信息到 CamerInfo 成功!", it.DeviceID);
     }
 
 
@@ -342,32 +370,232 @@ bool ToEQMDataBase::getDeviceInfo(std::vector<DeviceInfo>& vecInfo)
     }
 
     /* 解析信息 */
-    nJson json1 = nJson::parse(strRet.toStdString());
-    int retCode = json1["code"].get<int>();
-    if(retCode != 0)
+    try {
+        nJson json1 = nJson::parse(strRet.toStdString());
+        int retCode = json1["code"].get<int>();
+        if(retCode != 0)
+        {
+            SPDLOG_LOGGER_ERROR(m_logger,"获取CamerInfo失败");
+            return false;
+        }
+        nJson result = json1["result"];
+        if(result.empty())
+        {
+            return false;
+        }
+        for(const auto& it : result)
+        {
+            // SPDLOG_LOGGER_DEBUG(m_logger,"camerID:{}",it["camerId"].get<int>());
+            DeviceInfo info;
+            info.DeviceID = it["camerId"].get<int>();
+            info.DeviceName = it["camerName"].is_null() ? "" : it["camerName"].get<std::string>();
+            info.DeviceIP = it["camerIp"].is_null() ? "" : it["camerIp"].get<std::string>();
+            info.DevicePort = it["camerPort"].is_null() ? 0 : it["camerPort"].get<int>();
+            info.UserAccount = it["camerUsr"].is_null() ? "" : it["camerUsr"].get<std::string>();
+            info.UserPassword = it["camerPwd"].is_null() ? "" : it["camerPwd"].get<std::string>();
+            info.DeviceType = it["camerType"].is_null() ? "" : it["camerType"].get<std::string>();
+            info.DeviceSerial = it["camerSerial"].is_null() ? "" : it["camerSerial"].get<std::string>();
+            
+
+            vecInfo.push_back(info);
+        }
+    }
+    catch (const nJson::parse_error& e) {
+        SPDLOG_LOGGER_ERROR(m_logger,"解析CamerInfo数据失败:{}, 错误ID:{}",e.what(), e.id);
+        return false;
+    }
+    catch (const nJson::type_error& e) {
+        SPDLOG_LOGGER_ERROR(m_logger,"解析CamerInfo数据失败:{}, 错误ID:{}",e.what(), e.id);
+        return false;
+    }
+
+
+    return true;
+}
+
+/* 插入设备和算法关联信息 */
+bool ToEQMDataBase::insertDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo)
+{
+    if(m_httpApi == nullptr)
     {
-        SPDLOG_LOGGER_ERROR(m_logger,"获取CamerInfo失败");
+        SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
         return false;
     }
-    nJson result = json1["result"];
-    if(result.empty())
+    /* 插入信息到tActionCamer表 */
+    bool isSuccess = true;
+    for(const auto& it0 : vecInfo)
     {
+        for(const auto& it1 : it0.vecAlgorithmInfo)
+        {
+            nJson json0;
+            json0["opName"] = "SPSS_InsertToActionCamer";
+            nJson json1;
+            json1["actionID"] = it1.ActionID;
+            json1["camerID"] = it0.DeviceID;
+            json0["paramList"] = json1;
+            QString strCmd = QString::fromStdString(json0.dump());
+            QString strRet;
+            auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
+            if(ret < 0)
+            {
+                SPDLOG_LOGGER_DEBUG(m_logger,"插入设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
+                isSuccess = false;
+            }
+            SPDLOG_LOGGER_DEBUG(m_logger,"插入DeviceID {} 和 ActionID {} 到 ActionCamer 成功!", it0.DeviceID, it1.ActionID);
+        }
+    }
+
+    return true;
+}
+
+/* 更新设备和算法关联表 */
+bool ToEQMDataBase::updateDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo)
+{
+    if(m_httpApi == nullptr)
+    {
+        SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
         return false;
     }
-    for(const auto& it : result)
+    /* 更新之前先删除相关的信息 */
+    for(const auto& it : vecInfo)
     {
-        // SPDLOG_LOGGER_DEBUG(m_logger,"camerID:{}",it["camerId"].get<int>());
-        DeviceInfo info;
-        info.DeviceID = it["camerId"].get<int>();
-        info.DeviceName = it["camerName"].is_null() ? "" : it["camerName"].get<std::string>();
-        info.DeviceIP = it["camerIp"].is_null() ? "" : it["camerIp"].get<std::string>();
-        info.DevicePort = it["camerPort"].is_null() ? 0 : it["camerPort"].get<int>();
-        info.UserAccount = it["camerUsr"].is_null() ? "" : it["camerUsr"].get<std::string>();
-        info.UserPassword = it["camerPwd"].is_null() ? "" : it["camerPwd"].get<std::string>();
-        info.DeviceType = it["camerType"].is_null() ? "" : it["camerType"].get<std::string>();
-        info.DeviceSerial = it["camerSerial"].is_null() ? "" : it["camerSerial"].get<std::string>();
+        nJson json0;
+        json0["opName"] = "SPSS_DeleteFromActionCamer";
+        nJson json1;
+        json1["camerID"] = it.DeviceID;
+        json0["paramList"] = json1;
+        QString strCmd = QString::fromStdString(json0.dump());
+        QString strRet;
+        auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Delete, strCmd, strRet);
+        if(ret < 0)
+        {
+            SPDLOG_LOGGER_DEBUG(m_logger,"删除设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
+            // return false;
+        }
+        SPDLOG_LOGGER_DEBUG(m_logger,"从 ActionCamer 删除DeviceID {} 成功!", it.DeviceID);
+    }
+    /* 插入信息到tActionCamer表 */
+    bool isSuccess = true;
+    for(const auto& it0 : vecInfo)
+    {
+        for(const auto& it1 : it0.vecAlgorithmInfo)
+        {
+            nJson json0;
+            json0["opName"] = "SPSS_InsertToActionCamer";
+            nJson json1;
+            json1["actionID"] = it1.ActionID;
+            json1["camerID"] = it0.DeviceID;
+            json0["paramList"] = json1;
+            QString strCmd = QString::fromStdString(json0.dump());
+            QString strRet;
+            auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Insert, strCmd, strRet);
+            if(ret < 0)
+            {
+                SPDLOG_LOGGER_DEBUG(m_logger,"插入设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
+                isSuccess = false;
+            }
+            SPDLOG_LOGGER_DEBUG(m_logger,"插入DeviceID {} 和 ActionID {} 到 ActionCamer 成功!", it0.DeviceID, it1.ActionID);
+        }
+    }
 
-        vecInfo.push_back(info);
+
+    return isSuccess;
+}
+
+/* 删除设备和算法关联表 */
+bool ToEQMDataBase::deleteDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo)
+{
+    if(m_httpApi == nullptr)
+    {
+        SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
+        return false;
+    }
+    bool isSuccess = true;
+    /* 更新之前先删除相关的信息 */
+    for(const auto& it : vecInfo)
+    {
+        nJson json0;
+        json0["opName"] = "SPSS_DeleteFromActionCamer";
+        nJson json1;
+        json1["camerID"] = it.DeviceID;
+        json0["paramList"] = json1;
+        QString strCmd = QString::fromStdString(json0.dump());
+        QString strRet;
+        auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Delete, strCmd, strRet);
+        if(ret < 0)
+        {
+            SPDLOG_LOGGER_DEBUG(m_logger,"删除设备信息到tActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
+            // return false;
+            isSuccess = false;
+        }
+        SPDLOG_LOGGER_DEBUG(m_logger,"从 ActionCamer 删除DeviceID {} 成功!", it.DeviceID);
+    }
+
+    return isSuccess;
+}
+
+/* 获取设备和算法信息关联表,需要先从EQM数据库中获取到设备信息 */
+bool ToEQMDataBase::getDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo)
+{
+    if(m_httpApi == nullptr)
+    {
+        SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
+        return false;
+    }
+    if(vecInfo.empty())
+    {
+        SPDLOG_LOGGER_WARN(m_logger,"Device info is empty");
+        return false;
+    }
+    nJson json0;
+    json0["opName"] = "SPSS_SelectFromActionCamer";
+    QString strCmd = QString::fromStdString(json0.dump());
+    QString strRet;
+    auto ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Select, strCmd, strRet);
+    if(ret < 0)
+    {
+        SPDLOG_LOGGER_DEBUG(m_logger,"获取ActionCamer失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
+        return false;
+    }
+    /* 解析信息 */
+    try {
+        nJson json1 = nJson::parse(strRet.toStdString());
+        int retCode = json1["code"].get<int>();
+        if(retCode != 0)
+        {
+            SPDLOG_LOGGER_ERROR(m_logger,"获取ActionCamer失败");
+            return false;
+        }
+        nJson result = json1["result"];
+        if(result.empty())
+        {
+            return false;
+        }
+        /* 根据缓存中的设备ID解析json字符串 */
+        for(auto& it0 : vecInfo)
+        {
+            for(auto& it1 : result)
+            {
+                /* 对比设备ID */
+                if(it0.DeviceID == it1["camerId"].get<int>())
+                {
+                    AlgorithmInfo info;
+                    info.ActionID = it1["actionId"].is_null() ? "" : it1["actionId"].get<std::string>();
+                    info.ActionName = it1["actionName"].is_null() ? "" : it1["actionName"].get<std::string>();
+                    info.ActionTaskID = it1["actionTaskid"].is_null() ? 0 : it1["actionTaskid"].get<int>();
+
+                    it0.vecAlgorithmInfo.push_back(info);
+                }
+            }
+        }
+    }
+    catch (const nJson::parse_error& e) {
+        SPDLOG_LOGGER_ERROR(m_logger,"解析ActionCamer数据失败:{}, 错误ID:{}",e.what(), e.id);
+        return false;
+    }
+    catch (const nJson::type_error& e) {
+        SPDLOG_LOGGER_ERROR(m_logger,"解析ActionCamer数据失败:{}, 错误ID:{}",e.what(), e.id);
+        return false;
     }
 
 

+ 8 - 0
SecurePlayAuxServer/communication/ToEQMDataBase.h

@@ -27,6 +27,14 @@ public:
     bool deleteDeviceInfo(std::vector<DeviceInfo>& vecDeleteInfo);
     /* 从EQM获取CamerInfo信息 */
     bool getDeviceInfo(std::vector<DeviceInfo>& vecInfo);
+    /* 插入设备和算法关联信息 */
+    bool insertDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo);
+    /* 更新设备和算法关联表 */
+    bool updateDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo);
+    /* 删除设备和算法关联表 */
+    bool deleteDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo);
+    /* 获取设备和算法信息关联表,需要先从EQM数据库中获取到设备信息 */
+    bool getDeviceAlgorithmInfo(std::vector<DeviceInfo>& vecInfo);
 
 private:
     std::shared_ptr<spdlog::logger> m_logger = nullptr;

+ 9 - 2
安播辅助服务程序说明.md

@@ -44,8 +44,15 @@
 4. `设备列表`获取的数据写入到EQM数据库的`tActionCamer`表格中,其对对应的关键字如下
     |设备列表|tActionCamer|
     |:--|:--|
-    |||
-
+    |deviceId|CamerId|
+    |deviceName|CamerName|
+    |deviceSerial|CamerSerial|
+    |deviceType|CamerType|
+    |port|CamerPort|
+    |userAccount|CamerUsr|
+    |userPWD|CamerPwd|
+    
+    
 ## 从Redis获取数据
 1. `Key`的组成:`%d : %s`, `DeviceID`, `算子编号`
 2. `算子编号`通过获取摄像头算法列表获取到这个设备的算法编号,关键字是`ability`,存放在EQM数据库的tAction表格的ActionID,既算法ID