Forráskód Böngészése

V0.5.6
1、添加了设备信息查重的功能

Apple 1 hónapja
szülő
commit
2440679965

+ 30 - 0
SecurePlayAuxServer/GlobalInfo/GlobalVariable.cpp

@@ -15,6 +15,36 @@ int g_eventTimeVaild = 600;         /* 事件时间有效性,单位秒,超
  * ***************************    DeviceInfo成员函数    *******************************
  * ====================================================================================*/
 
+DeviceInfo::DeviceInfo(const DeviceInfo& other)
+ : PKID(other.PKID), 
+ DeviceID(other.DeviceID), 
+ DevicePort(other.DevicePort), 
+ DeviceName(other.DeviceName), 
+ DeviceSerial(other.DeviceSerial), 
+ DeviceType(other.DeviceType), 
+ DeviceIP(other.DeviceIP),
+ UserAccount(other.UserAccount), 
+ UserPassword(other.UserPassword), 
+ vecAlgorithmInfo(other.vecAlgorithmInfo)
+ {}
+
+DeviceInfo& DeviceInfo::operator=(const DeviceInfo& other) 
+{
+    if (this != &other) {
+        DeviceID = other.DeviceID;
+        DevicePort = other.DevicePort;
+        DeviceName = other.DeviceName;
+        DeviceSerial = other.DeviceSerial;
+        DeviceType = other.DeviceType;
+        DeviceIP = other.DeviceIP;
+        UserAccount = other.UserAccount;
+        UserPassword = other.UserPassword;
+        vecAlgorithmInfo = other.vecAlgorithmInfo;
+    }
+    return *this;
+}
+
+
 /* 对比是否相等 */
 bool DeviceInfo::operator==(const DeviceInfo& other)
 {

+ 2 - 25
SecurePlayAuxServer/GlobalInfo/GlobalVariable.h

@@ -131,31 +131,8 @@ struct DeviceInfo
     std::vector<AlgorithmInfo> vecAlgorithmInfo; /* 算法信息 */
 
     DeviceInfo() = default;
-    DeviceInfo(const DeviceInfo& other)
-        : PKID(other.PKID), 
-        DeviceID(other.DeviceID), 
-        DevicePort(other.DevicePort), 
-        DeviceName(other.DeviceName), 
-        DeviceSerial(other.DeviceSerial), 
-        DeviceType(other.DeviceType), 
-        DeviceIP(other.DeviceIP),
-        UserAccount(other.UserAccount), 
-        UserPassword(other.UserPassword), 
-        vecAlgorithmInfo(other.vecAlgorithmInfo) {}
-    DeviceInfo& operator=(const DeviceInfo& other) {
-        if (this != &other) {
-            DeviceID = other.DeviceID;
-            DevicePort = other.DevicePort;
-            DeviceName = other.DeviceName;
-            DeviceSerial = other.DeviceSerial;
-            DeviceType = other.DeviceType;
-            DeviceIP = other.DeviceIP;
-            UserAccount = other.UserAccount;
-            UserPassword = other.UserPassword;
-            vecAlgorithmInfo = other.vecAlgorithmInfo;
-        }
-        return *this;
-    }
+    DeviceInfo(const DeviceInfo& other);
+    DeviceInfo& operator=(const DeviceInfo& other);
     /* 对比是否相等 */
     bool operator==(const DeviceInfo& other);
 

+ 16 - 1
SecurePlayAuxServer/SPAServer.cpp

@@ -185,7 +185,7 @@ bool SPAServer::processAlgorithmInfo(std::vector<AlgorithmInfo> vecNewAlgInfo)
  * @return true 需要重新读取数据库,获取新的数据
  * @return false 无需读取数据库
  */
-bool SPAServer::processDeviceInfo(std::vector<DeviceInfo> vecNewDevInfo)
+bool SPAServer::processDeviceInfo(std::vector<DeviceInfo>& vecNewDevInfo)
 {
     std::vector<DeviceInfo> vecDevInsert;
     std::vector<DeviceInfo> vecDevUpdate;
@@ -195,6 +195,21 @@ bool SPAServer::processDeviceInfo(std::vector<DeviceInfo> vecNewDevInfo)
      ****** 这里只对比设备信息,不对比设备的算法信息,算法信息在下面单独对比 *******
      *------------------------------------------------------------------------*/
 
+    /* 先自身查重 */
+    for(auto it = m_vecEqmDevInfo.begin(); it != m_vecEqmDevInfo.end(); it++)
+    {
+        for(auto it0 = it + 1; it0 != m_vecEqmDevInfo.end();)
+        {
+            if(it->DeviceID == it0->DeviceID)
+            {
+                SPDLOG_LOGGER_DEBUG(m_logger, "设备ID: {} 重复", it->DeviceID);
+                it0 = m_vecEqmDevInfo.erase(it0);
+            }else {
+                ++it0;
+            }
+        }
+    }
+
     /* 如果本地缓存没有数据,那么就全部插入 */
     if(m_vecEqmDevInfo.size() > 0)
     {

+ 1 - 1
SecurePlayAuxServer/SPAServer.h

@@ -36,7 +36,7 @@ private:
     /* 处理算法信息,返回值为true,说明有改变,需要重新读取(不需要在服务里维护,手动配置) */
     bool processAlgorithmInfo(std::vector<AlgorithmInfo> vecNewAlgInfo);
     /* 处理设备信息,传入新获取到的值,返回true需要更新本地数据缓存 */
-    bool processDeviceInfo(std::vector<DeviceInfo> vecNewDevInfo);
+    bool processDeviceInfo(std::vector<DeviceInfo>& vecNewDevInfo);
     /* 对比算法信息现有的数据和新获取到的数据,取出要删除和添加的数据 */
     void compareAlgorithmInfo(const std::vector<AlgorithmInfo>& vecNewInfo, std::vector<AlgorithmInfo>& vecAlgUpdate, std::vector<AlgorithmInfo>& vecAlgDelete);
     /* 对比设备和算法关联表是否需要更新 */

+ 1 - 0
SecurePlayAuxServer/communication/FromSuperBrain.cpp

@@ -154,6 +154,7 @@ bool FromSuperBrain::getDeviceList(std::vector<DeviceInfo>& vecInfo)
         SPDLOG_LOGGER_ERROR(m_logger, "{}", response);
         return false;
     }
+    vecInfo.clear();
     // SPDLOG_LOGGER_TRACE(m_logger, "DeivceList: \n{}", nJson::parse(response).dump(4));
     /* 解析JSON信息 */
     try