Bladeren bron

V0.2.6
1、完成了获取和插入的接口

apple 3 weken geleden
bovenliggende
commit
f28b5bb910
2 gewijzigde bestanden met toevoegingen van 232 en 8 verwijderingen
  1. 55 0
      SQL/ACASetting.sql
  2. 177 8
      SettingLibrary/Network/FromWebAPI.cpp

+ 55 - 0
SQL/ACASetting.sql

@@ -28,3 +28,58 @@ FROM tACACompareItems;
 SELECT *
 FROM tACACompareItemRoad;
 
+
+#插入一条对比项信息
+INSERT INTO tACACompareItems 
+    (   ItemID, ItemName, ItemEnable, RoadCount, 
+        SilentEnable, SilentThreshold, SilentDuration, SilentSensitivity, 
+        OverloadEnable, OverloadThreshold, OverloadDuration, OverloadSensitivity, 
+        PhaseEnable, PhaseThreshold, PhaseDuration, PhaseSensitivity )
+VALUES
+    ( @itemID, @itemName, @itemEnable, @roadCount, 
+      @silentEnable, @silentThreshold, @silentDuration, @silentSensitivity, 
+      @overloadEnable, @overloadThreshold, @overloadDuration, @overloadSensitivity, 
+      @phaseEnable, @phaseThreshold, @phaseDuration, @phaseSensitivity );
+
+#通过ID更新对比项信息
+UPDATE tACACompareItems
+SET ItemName = @itemName, 
+    ItemEnable = @itemEnable,
+    RoadCount = @roadCount,
+    SilentEnable = @silentEnable,
+    SilentThreshold = @silentThreshold,
+    SilentDuration = @silentDuration,
+    SilentSensitivity = @silentSensitivity,
+    OverloadEnable = @overloadEnable,
+    OverloadThreshold = @overloadThreshold,
+    OverloadDuration = @overloadDuration,
+    OverloadSensitivity = @overloadSensitivity,
+    PhaseEnable = @phaseEnable,
+    PhaseThreshold = @phaseThreshold,
+    PhaseDuration = @phaseDuration,
+    PhaseSensitivity = @phaseSensitivity
+WHERE ItemID = 1;
+
+
+#插入一条对比项通道信息
+INSERT INTO tACACompareItemRoad 
+    ( ItemID, RoadNum, RoadName, RoadRecordEnable, SoundCardNum, 
+      SoundCardID, SoundCardName, SoundCardRoadNum, ChannelID, ChannelName )
+VALUES
+    ( @itemID, @roadNum, @roadName, @roadRecordEnable, @soundCardNum, 
+      @soundCardID, @soundCardName, @soundCardRoadNum, @channelID, @channelName );
+
+
+#通过ItemID和RoadNum更新对比项通道信息
+UPDATE tACACompareItemRoad
+SET RoadName = @roadName,
+    RoadRecordEnable = @roadRecordEnable,
+    SoundCardNum = @soundCardNum,
+    SoundCardID = @soundCardID,
+    SoundCardName = @soundCardName,
+    SoundCardRoadNum = @soundCardRoadNum,
+    ChannelID = @channelID,
+    ChannelName = @channelName
+WHERE ItemID = 1 AND RoadNum = 1;
+
+

+ 177 - 8
SettingLibrary/Network/FromWebAPI.cpp

@@ -1,7 +1,9 @@
 #include "FromWebAPI.h"
 
+#include "GlobalVariable.h"
 #include "commonDefine.h"
 #include <QString>
+#include <qchar.h>
 
 
 FromWebAPI::FromWebAPI()
@@ -47,25 +49,192 @@ bool FromWebAPI::getCompareItemInfo(QList<CompareItemInfo_t>& listItems)
     }
 
 
-    /* 将json的key全部转换成小写 */
-    nJson jsonCompareItem;
-    if(!convertJsonKeyToLower(nJson::parse(strRet1.toStdString()), jsonCompareItem))
-    {
-        SPDLOG_LOGGER_ERROR(m_logger, "转换JSON键名为小写失败");
-        return false;
-    }
-    /* 解析数据 */
+    
+    /*---------------------------------- 解析对比项信息 ------------------------------*/
     try
     {
+        nJson jsonRet;
+        /* 将json的key全部转换成小写 */
+        if(!convertJsonKeyToLower(nJson::parse(strRet1.toStdString()), jsonRet))
+        {
+            SPDLOG_LOGGER_ERROR(m_logger, "转换JSON键名为小写失败");
+            return false;
+        }
+        int code = jsonRet["code"].get<int>();
+        if(code != 0)
+        {
+            SPDLOG_LOGGER_ERROR(m_logger, "获取对比项信息失败,错误码: {}, 错误信息: {}", code, jsonRet["message"].get<std::string>());
+            return false;
+        }
+        nJson jsonResult = jsonRet["result"];
+        
+        for(const auto& item : jsonResult)
+        {
+            CompareItemInfo_t compareItem;
+            compareItem.nID = item["itemid"].get<int>();
+            compareItem.strName = QString::fromStdString(item["itemname"].get<std::string>());
+            compareItem.isEnable = item["itemenable"].get<bool>();
+            compareItem.paramMute.isEnable = item["silentenable"].get<bool>();
+            compareItem.paramMute.nLen = item["silentduration"].get<int>();
+            compareItem.paramMute.threshold.nThreshold = item["silentthreshold"].get<uint64_t>();
+            compareItem.paramMute.nSensibility = item["silentsensibility"].get<int>();
+
+            compareItem.paramOverload.isEnable = item["overloadenable"].get<bool>();
+            compareItem.paramOverload.nLen = item["overloadduration"].get<int>();
+            compareItem.paramOverload.threshold.nThreshold = item["overloadthreshold"].get<uint64_t>();
+            compareItem.paramOverload.nSensibility = item["overloadsensibility"].get<int>();
+
+            compareItem.paramPhase.isEnable = item["phaseenable"].get<bool>();
+            compareItem.paramPhase.nLen = item["phaseduration"].get<int>();
+            compareItem.paramPhase.threshold.dThreshold = item["phasethreshold"].get<double>();
+            compareItem.paramPhase.nSensibility = item["phasesensibility"].get<int>();
+
+            listItems.append(compareItem);
+        }
+    }nJsonCatch
 
+    /*---------------------------------- 解析对比项录音通道信息 ------------------------------*/
+    try
+    {
+        /* 将json的key全部转换成小写 */
+        nJson jsonRet;
+        if(!convertJsonKeyToLower(nJson::parse(strRet1.toStdString()), jsonRet))
+        {
+            SPDLOG_LOGGER_ERROR(m_logger, "转换JSON键名为小写失败");
+            return false;
+        }
+        int code = jsonRet["code"].get<int>();
+        if(code != 0)
+        {
+            SPDLOG_LOGGER_ERROR(m_logger, "获取对比项通道信息失败,错误码: {}, 错误信息: {}", code, jsonRet["message"].get<std::string>());
+            return false;
+        }
+        nJson jsonResult = jsonRet["result"];
+        /* 使用迭代器获取对比项信息 */
+        auto it = listItems.begin();
+        for(const auto& item : jsonResult)
+        {
+            CompareItemRoadInfo_t roadInfo;
+            int itemID = item["itemid"].get<int>();
+            roadInfo.nCompareRoadNum = item["roadnum"].get<bool>();
+            roadInfo.strCompareRoadName = QString::fromStdString(item["roadname"].get<std::string>());
+            roadInfo.isEnableRecord = item["roadrecordenable"].get<bool>();
+            roadInfo.scRoadInfo.nSoundCardNum = item["soundcardnum"].get<int>();
+            roadInfo.scRoadInfo.strSoundCardID = QString::fromStdString(item["soundcardid"].get<std::string>());
+            roadInfo.scRoadInfo.strSoundCardName = QString::fromStdString(item["soundcardname"].get<std::string>());
+            roadInfo.scRoadInfo.roadInfo.nRoadNum = item["soundcardroadnum"].get<int>();
+            roadInfo.scRoadInfo.roadInfo.nChannelID = item["chnannelid"].get<int>();
+            roadInfo.scRoadInfo.roadInfo.strChannelName = QString::fromStdString(item["channelname"].get<std::string>());
+
+            /* 如果这个通道是当前迭代器的,就直接插入,如果不是则重新寻找 */
+            if(it->nID == itemID)
+            {
+                it->listRoads.append(roadInfo);
+            }else {
+                for(it = listItems.begin(); it != listItems.end(); ++it)
+                {
+                    if(it->nID == itemID)
+                    {
+                        it->listRoads.append(roadInfo);
+                        break;
+                    }
+                }
+            }
+        }
     }nJsonCatch
 
+
     return true;
 }
 
 /* 添加对比项信息 */
 bool FromWebAPI::insertCompareItem(const QList<CompareItemInfo_t>& listItems)
 {
+    /*---------------------------------- 插入对比项信息 ------------------------------*/
+    try
+    {
+        int key = 1;
+        nJson jsonArray = nJson::array();
+        for(const auto& item : listItems)
+        {
+            nJson json0;
+            json0["opName"] = "ACAS_InsertCompareItem";
+            json0["Key"] = key++;
+
+            nJson jsonItem;
+            jsonItem["itemID"] = item.nID;
+            jsonItem["itemName"] = item.strName.toStdString();
+            jsonItem["itemEnable"] = item.isEnable;
+            jsonItem["roadCount"] = item.listRoads.size();
+
+            jsonItem["silentEnable"] = item.paramMute.isEnable;
+            jsonItem["silentDuration"] = item.paramMute.nLen;
+            jsonItem["silentThreshold"] = item.paramMute.threshold.nThreshold;
+            jsonItem["silentSensibility"] = item.paramMute.nSensibility;
+
+            jsonItem["overloadEnable"] = item.paramOverload.isEnable;
+            jsonItem["overloadDuration"] = item.paramOverload.nLen;
+            jsonItem["overloadThreshold"] = item.paramOverload.threshold.nThreshold;
+            jsonItem["overloadSensibility"] = item.paramOverload.nSensibility;
+
+            jsonItem["phaseEnable"] = item.paramPhase.isEnable;
+            jsonItem["phaseDuration"] = item.paramPhase.nLen;
+            jsonItem["phaseThreshold"] = item.paramPhase.threshold.dThreshold;
+            jsonItem["phaseSensibility"] = item.paramPhase.nSensibility;
+
+            json0["paramList"] = jsonItem;
+            jsonArray.push_back(json0);
+        }
+
+        QString strSend = QString::fromStdString(jsonArray.dump());
+        QString strRet;
+        int ret = m_httpApi->DBDoInterface(enDBOperatorType::EDBOT_BatchTransAction, strSend, strRet);
+        if(ret != 0)
+        {
+            SPDLOG_LOGGER_ERROR(m_logger, "添加对比项信息失败,错误码: {}, 错误信息: {}", ret, m_httpApi->DoGetLastError(&ret).toStdString());
+            return false;
+        }
+    }nJsonCatch
+
+    try
+    {
+        int Key = 1;
+        nJson jsonArray = nJson::array();
+        for(const auto& item : listItems)
+        {
+            for(const auto& road : item.listRoads)
+            {
+                nJson json1;
+                json1["opName"] = "ACAS_InsertCompareItemRoad";
+                json1["Key"] = Key++;
+
+                nJson jsonRoad;
+                jsonRoad["itemID"] = item.nID;
+                jsonRoad["roadNum"] = road.nCompareRoadNum;
+                jsonRoad["roadName"] = road.strCompareRoadName.toStdString();
+                jsonRoad["roadRecordEnable"] = road.isEnableRecord;
+
+                jsonRoad["soundCardNum"] = road.scRoadInfo.nSoundCardNum;
+                jsonRoad["soundCardID"] = road.scRoadInfo.strSoundCardID.toStdString();
+                jsonRoad["soundCardName"] = road.scRoadInfo.strSoundCardName.toStdString();
+                jsonRoad["soundCardRoadNum"] = road.scRoadInfo.roadInfo.nRoadNum;
+                jsonRoad["channelID"] = road.scRoadInfo.roadInfo.nChannelID;
+                jsonRoad["channelName"] = road.scRoadInfo.roadInfo.strChannelName.toStdString();
+
+                json1["paramList"] = jsonRoad;
+                jsonArray.push_back(json1);
+            }
+        }
+        QString strSend = QString::fromStdString(jsonArray.dump());
+        QString strRet;
+        int ret = m_httpApi->DBDoInterface(enDBOperatorType::EDBOT_BatchTransAction, strSend, strRet);
+        if(ret != 0)
+        {
+            SPDLOG_LOGGER_ERROR(m_logger, "添加对比项通道信息失败,错误码: {}, 错误信息: {}", ret, m_httpApi->DoGetLastError(&ret).toStdString());
+            return false;
+        }
+
+    }nJsonCatch
 
     return true;
 }