浏览代码

V0.1.6
1、添加了获取到的算法信息和设备信息对比的功能

Apple 7 月之前
父节点
当前提交
3dfeb6dcbf

+ 54 - 46
SecurePlayAuxServer/SPAServer.cpp

@@ -19,41 +19,10 @@ SPAServer::SPAServer()
     }
     }
 
 
     m_threadRunning = true;
     m_threadRunning = true;
+    /* 初始化WebAPI */
+    m_toEQMDataBase.initWebApi("http://192.1.3.133:31000/v6/", "", "4c2f9fc91c22dd98331e47af2e2964f4");
 
 
 
 
-    // m_fromSuperBrain.getToken();
-    // m_fromSuperBrain.getTaskTypeList(m_vecAlgorithmInfo);
-    // m_fromSuperBrain.getDeviceList(m_vecDeviceInfo);
-
-    // for(const auto& it : m_vecAlgorithmInfo)
-    // {
-    //     SPDLOG_LOGGER_INFO(m_logger, "ActionID:{} ActionName:{} ActionTaskID:{}", it.ActionID, it.ActionName, it.ActionTaskID);
-    // }
-    // for(const auto& it : m_vecDeviceInfo)
-    // {
-    //     SPDLOG_LOGGER_INFO(m_logger, "DeviceID:{} DeviceName:{} DeviceType:{}", it.DeviceID, it.DeviceName, it.DeviceType);
-    //     SPDLOG_LOGGER_INFO(m_logger, "Port:{} UserAccount:{} PWD:{}", it.DevicePort, it.UserAccount, it.UserPassword);
-    //     SPDLOG_LOGGER_INFO(m_logger, "ActionID:{} ActionName:{} ActionTaskID:{}", it.vecAlgorithmInfo[0].ActionID, it.vecAlgorithmInfo[0].ActionName, it.vecAlgorithmInfo[0].ActionTaskID);
-    // }
-
-    // m_fromRedis.setRedisIPAndPort("172.16.36.80", 32222);
-    // m_fromRedis.setRedisPassword("Ff1z@TOFr^iwd%Ra");
-    // m_fromRedis.connectRedis();
-    // std::string value;
-    // m_fromRedis.getRedisString("113:P100104000", value);
-    // SPDLOG_LOGGER_INFO(m_logger, "{}", value);
-    // m_fromRedis.disConnectRedis();
-
-    //|FTP|192.1.2.178:32021|lh|DWw7V9u0|
-
-    m_toEQMDataBase.initWebApi("http://192.1.3.133:31000/v6/", "", "4c2f9fc91c22dd98331e47af2e2964f4");
-    AlgorithmInfo info;
-    info.ActionID = "123";
-    info.ActionName = "test";
-    info.ActionTaskID = 456;
-    QVector<AlgorithmInfo> vecInfo;
-    vecInfo.push_back(info);
-    m_toEQMDataBase.writeAlgorithmInfo(vecInfo);
     
     
 }
 }
 
 
@@ -76,44 +45,83 @@ void SPAServer::startServer()
  */
  */
 void SPAServer::fromSuperBrainThread()
 void SPAServer::fromSuperBrainThread()
 {
 {
-    SPDLOG_LOGGER_DEBUG(m_logger, "开启 fromSuperBrainThread 线程");
+    SPDLOG_LOGGER_INFO(m_logger, "开启 fromSuperBrainThread 线程");
+    /* 创建变量 */
+    std::vector<AlgorithmInfo> vecAlgInfo;
+    std::vector<DeviceInfo> vecDevInfo;
+    std::vector<AlgorithmInfo> vecAlgUpdate;
+    std::vector<AlgorithmInfo> vecAlgDelete;
+    /* 从EQM数据库中读取到数据信息到内存中,后续对比需要 */
+    m_toEQMDataBase.getAlgorithmInfo(m_vecEqmAlgInfo);
     /* 获取一次token,后续失效了再获取 */
     /* 获取一次token,后续失效了再获取 */
     m_fromSuperBrain.getToken();
     m_fromSuperBrain.getToken();
     while (m_threadRunning)
     while (m_threadRunning)
     {
     {
-        SPDLOG_LOGGER_DEBUG(m_logger, "获取基础信息");
-        std::vector<AlgorithmInfo> vecAlgInfo;
-        std::vector<DeviceInfo> vecDevInfo;
+        SPDLOG_LOGGER_INFO(m_logger, "刷新算法和设备信息");
         m_fromSuperBrain.getTaskTypeList(vecAlgInfo);
         m_fromSuperBrain.getTaskTypeList(vecAlgInfo);
         m_fromSuperBrain.getDeviceList(vecDevInfo);
         m_fromSuperBrain.getDeviceList(vecDevInfo);
 
 
-        /* 对比数据库表格信息 */
-        std::vector<AlgorithmInfo> vecAlgUpdate;
-        std::vector<AlgorithmInfo> vecAlgDelete;
-        /* 取出要添加的 */
-        for(const auto& it : vecAlgInfo)
+        /* 对比数据库表格信息,这里只有插入和删除,没有更新 */
+        compareAlgorithmInfo(vecAlgInfo, vecAlgUpdate, vecAlgDelete);
+        /* 更新数据库,先删除,再写入刷新 */
+        if(vecAlgDelete.size() > 0)
+        {
+            SPDLOG_LOGGER_DEBUG(m_logger, "删除算法信息");
+            m_toEQMDataBase.deleteAlgorithmInfo(vecAlgDelete);
+        }
+        if(vecAlgUpdate.size() > 0)
+        {
+            SPDLOG_LOGGER_DEBUG(m_logger, "写入算法信息");
+            m_toEQMDataBase.writeAlgorithmInfo(vecAlgUpdate);
+        }
+
+        vecAlgInfo.clear();
+        vecDevInfo.clear();
+        vecAlgUpdate.clear();
+        vecAlgDelete.clear();
+        /* 再读取数据库,刷新本地存储 */
+        m_toEQMDataBase.getAlgorithmInfo(m_vecEqmAlgInfo);
+
+        std::this_thread::sleep_for(std::chrono::seconds(5));
+    }
+}
+
+/* 对比现有的数据和新获取到的数据,取出要删除和添加的数据 */
+void SPAServer::compareAlgorithmInfo(const std::vector<AlgorithmInfo>& vecNewInfo, std::vector<AlgorithmInfo>& vecAlgUpdate, std::vector<AlgorithmInfo>& vecAlgDelete)
+{
+    /* 取出要添加的,如果本地缓存是0,那么全部都要添加 */
+    if(m_vecEqmAlgInfo.size() > 0)
+    {
+        for(const auto& it : vecNewInfo)
         {
         {
             for(const auto& it0 : m_vecEqmAlgInfo)
             for(const auto& it0 : m_vecEqmAlgInfo)
             {
             {
                 if(it.ActionID != it0.ActionID)
                 if(it.ActionID != it0.ActionID)
                 {
                 {
                     vecAlgUpdate.push_back(it);
                     vecAlgUpdate.push_back(it);
+                    break;
                 }
                 }
             }
             }
         }
         }
-        /* 取出要删除的 */
+    }else {
+        vecAlgUpdate = vecNewInfo;
+    }
+    /* 取出要删除的,如果新的数据是0,那么全部都要删除 */
+    if(vecNewInfo.size() > 0)
+    {
         for(const auto& it : m_vecEqmAlgInfo)
         for(const auto& it : m_vecEqmAlgInfo)
         {
         {
-            for(const auto& it0 : vecAlgInfo)
+            for(const auto& it0 : vecNewInfo)
             {
             {
                 if(it.ActionID != it0.ActionID)
                 if(it.ActionID != it0.ActionID)
                 {
                 {
                     vecAlgDelete.push_back(it);
                     vecAlgDelete.push_back(it);
+                    break;
                 }
                 }
             }
             }
         }
         }
-
-        std::this_thread::sleep_for(std::chrono::seconds(10));
+    }else {
+        vecAlgDelete = m_vecEqmAlgInfo;
     }
     }
 }
 }
 
 

+ 2 - 0
SecurePlayAuxServer/SPAServer.h

@@ -21,6 +21,8 @@ public:
 private:
 private:
     /* 从基础平台获取算法信息和设备信息的线程函数 */
     /* 从基础平台获取算法信息和设备信息的线程函数 */
     void fromSuperBrainThread();
     void fromSuperBrainThread();
+    /* 对比现有的数据和新获取到的数据,取出要删除和添加的数据 */
+    void compareAlgorithmInfo(const std::vector<AlgorithmInfo>& vecNewInfo, std::vector<AlgorithmInfo>& vecAlgUpdate, std::vector<AlgorithmInfo>& vecAlgDelete);
 
 
 
 
 private:
 private:

+ 76 - 4
SecurePlayAuxServer/communication/ToEQMDataBase.cpp

@@ -64,7 +64,7 @@ bool ToEQMDataBase::initWebApi(const QString& url, const QString& serverIP, cons
 
 
 
 
 /* 写入算法信息,写入tAction表 */
 /* 写入算法信息,写入tAction表 */
-bool ToEQMDataBase::writeAlgorithmInfo(QVector<AlgorithmInfo>& vecInfo)
+bool ToEQMDataBase::writeAlgorithmInfo(std::vector<AlgorithmInfo>& vecInfo)
 {
 {
     if(m_httpApi == nullptr)
     if(m_httpApi == nullptr)
     {
     {
@@ -74,8 +74,6 @@ bool ToEQMDataBase::writeAlgorithmInfo(QVector<AlgorithmInfo>& vecInfo)
 
 
     for(const auto& it : vecInfo)
     for(const auto& it : vecInfo)
     {
     {
-        QJsonDocument doc;
-        QJsonObject obj0;
         QString retStr;
         QString retStr;
         /* 操作名称,现在一次性将设备位置和线条信息都下载下来 */
         /* 操作名称,现在一次性将设备位置和线条信息都下载下来 */
         nJson json0;
         nJson json0;
@@ -91,7 +89,81 @@ bool ToEQMDataBase::writeAlgorithmInfo(QVector<AlgorithmInfo>& vecInfo)
         {
         {
             SPDLOG_LOGGER_DEBUG(m_logger,"写入tAction失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
             SPDLOG_LOGGER_DEBUG(m_logger,"写入tAction失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
         }
         }
-        SPDLOG_LOGGER_DEBUG(m_logger,"写入tAction成功!");
+        SPDLOG_LOGGER_DEBUG(m_logger,"写入一条算法 {} 到 tAction成功!", it.ActionID);
+    }
+
+    return true;
+}
+
+/* 删除算法信息 */
+bool ToEQMDataBase::deleteAlgorithmInfo(std::vector<AlgorithmInfo>& vecDeleteInfo)
+{
+    if(m_httpApi == nullptr)
+    {
+        SPDLOG_LOGGER_ERROR(m_logger,"WebApi is nullptr");
+        return false;
+    }
+
+    for(const auto& it : vecDeleteInfo)
+    {
+        nJson json0;
+        json0["opName"] = "SPSS_DeleteFromAction";
+        nJson json1;
+        json1["actionID"] = it.ActionID;
+        json0["paramList"] = json1;
+        QString strCmd = QString::fromStdString(json0.dump());
+        QString strRet;
+        int ret = m_httpApi->DBQDoInterface(enDBOperatorType::EDBOT_Delete, strCmd, strRet);
+        if(ret < 0)
+        {
+            SPDLOG_LOGGER_DEBUG(m_logger,"删除tAction失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
+        }
+        SPDLOG_LOGGER_DEBUG(m_logger,"从tAction 删除算法 {} 成功!", it.ActionID);
+    }
+
+
+    return true;
+}
+
+/* 获取tAction数据 */
+bool ToEQMDataBase::getAlgorithmInfo(std::vector<AlgorithmInfo>& vecInfo)
+{
+    if(m_httpApi == nullptr)
+    {
+        SPDLOG_LOGGER_ERROR(m_logger, "WebAPI is nullptr");
+        return false;
+    }
+    /* 清空内容 */
+    vecInfo.clear();
+
+    nJson json0;
+    json0["opName"] = "SPSS_SelectFromAction";
+    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,"获取tAction失败:{}, 错误信息:{}",ret,m_httpApi->DoGetLastError(&ret).toStdString());
+        return false;
+    }
+    /* 解析获取到的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失败");
+        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;
     return true;

+ 5 - 1
SecurePlayAuxServer/communication/ToEQMDataBase.h

@@ -14,7 +14,11 @@ public:
     /* 初始化WebAPI */
     /* 初始化WebAPI */
     bool initWebApi(const QString& url,const QString& serverIP,const QString& serID);
     bool initWebApi(const QString& url,const QString& serverIP,const QString& serID);
     /* 写入算法信息,写入tAction表 */
     /* 写入算法信息,写入tAction表 */
-    bool writeAlgorithmInfo(QVector<AlgorithmInfo>& vecInfo);
+    bool writeAlgorithmInfo(std::vector<AlgorithmInfo>& vecInfo);
+    /* 删除算法信息 */
+    bool deleteAlgorithmInfo(std::vector<AlgorithmInfo>& vecDeleteInfo);
+    /* 获取tAction数据 */
+    bool getAlgorithmInfo(std::vector<AlgorithmInfo>& vecInfo);
 
 
 private:
 private:
     std::shared_ptr<spdlog::logger> m_logger = nullptr;
     std::shared_ptr<spdlog::logger> m_logger = nullptr;

+ 1 - 1
SecurePlayAuxServer/main.cpp

@@ -31,7 +31,7 @@ int main(int argc, char* argv[])
     CPPTP.setThreadMaxNum(256);
     CPPTP.setThreadMaxNum(256);
 
 
     SPAServer server;
     SPAServer server;
-    // server.startServer();
+    server.startServer();
 
 
     return app.exec();
     return app.exec();
 }
 }

+ 127 - 0
json.json

@@ -230,4 +230,131 @@
         }
         }
     ],
     ],
     "success": true
     "success": true
+}
+
+
+{
+    "code": 0,
+    "result": [
+        {
+            "pkid": 1,
+            "actionId": "M100121000",
+            "actionTaskid": 112,
+            "actionName": "疲劳检测"
+        },
+        {
+            "pkid": 2,
+            "actionId": "M100101000",
+            "actionTaskid": 104,
+            "actionName": "未戴口罩"
+        },
+        {
+            "pkid": 3,
+            "actionId": "M100107000",
+            "actionTaskid": 105,
+            "actionName": "吸烟识别"
+        },
+        {
+            "pkid": 4,
+            "actionId": "P100104000",
+            "actionTaskid": 106,
+            "actionName": "人员计数"
+        },
+        {
+            "pkid": 5,
+            "actionId": "C100107000",
+            "actionTaskid": 107,
+            "actionName": "违禁物品"
+        },
+        {
+            "pkid": 6,
+            "actionId": "E100111000",
+            "actionTaskid": 109,
+            "actionName": "动物识别"
+        },
+        {
+            "pkid": 7,
+            "actionId": "P100101000",
+            "actionTaskid": 111,
+            "actionName": "人脸识别"
+        },
+        {
+            "pkid": 8,
+            "actionId": "C100109000",
+            "actionTaskid": 110,
+            "actionName": "老鼠识别"
+        },
+        {
+            "pkid": 9,
+            "actionId": "M100105000",
+            "actionTaskid": 108,
+            "actionName": "睡岗识别"
+        },
+        {
+            "pkid": 10,
+            "actionId": "M100102000",
+            "actionTaskid": 103,
+            "actionName": "玩手机识别"
+        },
+        {
+            "pkid": 11,
+            "actionId": "002976",
+            "actionTaskid": 113,
+            "actionName": "摔倒识别"
+        },
+        {
+            "pkid": 12,
+            "actionId": "004160",
+            "actionTaskid": 118,
+            "actionName": "离岗识别"
+        },
+        {
+            "pkid": 21,
+            "actionId": "OD210_021_001879_001-IZRTKyEx",
+            "actionTaskid": 47,
+            "actionName": "未戴口罩识别"
+        },
+        {
+            "pkid": 22,
+            "actionId": "OD210_021_002162_002-IZRTKyEx",
+            "actionTaskid": 49,
+            "actionName": "违禁品检测"
+        },
+        {
+            "pkid": 23,
+            "actionId": "OD210_021_001871_051-IZRTKyEx",
+            "actionTaskid": 54,
+            "actionName": "摔倒识别"
+        },
+        {
+            "pkid": 24,
+            "actionId": "VC004_021_002601_026-IZRTKyEx",
+            "actionTaskid": 16,
+            "actionName": "人脸识别"
+        },
+        {
+            "pkid": 25,
+            "actionId": "OD210_021_001866_001",
+            "actionTaskid": 53,
+            "actionName": "玩手机识别"
+        },
+        {
+            "pkid": 26,
+            "actionId": "OD210_101_004533_002-IZRTKyEx",
+            "actionTaskid": 46,
+            "actionName": "港口异物识别"
+        },
+        {
+            "pkid": 27,
+            "actionId": "OD210_210_002111_001-IZRTKyEx",
+            "actionTaskid": 38,
+            "actionName": "人员识别"
+        },
+        {
+            "pkid": 28,
+            "actionId": "OD210_101_004362_006-IZRTKyEx",
+            "actionTaskid": 56,
+            "actionName": "盯屏"
+        }
+    ]
 }
 }