Преглед изворни кода

V0.2.8
1、完成了基础配置页面的数据库保存

apple пре 3 недеља
родитељ
комит
7461bae7ae

+ 2 - 2
SettingLibrary/DataBase/GlobalInfo.h

@@ -32,10 +32,10 @@ public:
     void setDefaultCompareItem(const CompareItemInfo_t& item);
     
 
-private:
-
+public:
     
 
+
 private:
     /* 对比项默认参数 */
     CompareItemInfo_t m_defaultCompareItem;

+ 45 - 2
SettingLibrary/DataManager/SystemConfig.cpp

@@ -1,9 +1,52 @@
 #include "SystemConfig.h"
 
+#include "spdlog/spdlog.h"
+#include "commonDefine.h"
+#include <string>
 
 /* 设置基础配置 */
 void SystemConfigInfo::setBaseConfig(const BaseConfig_t& config)
 {
-    baseConfig = config;
     m_baseConfigSrc = config;
-}
+}
+
+
+/* 将数据库的json转换成结构体 */
+bool SystemConfigInfo::getBaseConfigFromJson(const std::string& jsonStr)
+{
+    try {
+        nJson jsonConfig = nJson::parse(jsonStr);
+        m_baseConfigSrc.strServerIP = QString::fromStdString(jsonConfig["ServerIP"].get<std::string>());
+        m_baseConfigSrc.nRecordMode = jsonConfig["RecordMode"].get<int>();
+        m_baseConfigSrc.strDriverName = QString::fromStdString(jsonConfig["DriverName"].get<std::string>());
+        m_baseConfigSrc.nNotConsistency = jsonConfig["NotConsistency"].get<int>();
+        m_baseConfigSrc.isEnableMultiCore = jsonConfig["EnableMultiCore"].get<bool>();
+        m_baseConfigSrc.isEnableDebugLog = jsonConfig["EnableDebugLog"].get<bool>();
+        m_baseConfigSrc.isClearDirSystemOn = jsonConfig["ClearHistryDirOnStart"].get<bool>();
+        m_baseConfigSrc.isUsingSoundCardName = jsonConfig["useSoundCardName"].get<bool>();
+    }nJsonCatch
+
+    return true;
+}
+
+/* 将结构体转换成json */
+bool SystemConfigInfo::setBaseConfigToJson(const BaseConfig_t& baseConfig, std::string& strJson) const
+{
+    try {
+        nJson jsonConfig;
+        jsonConfig["ServerIP"] = baseConfig.strServerIP.toStdString();
+        jsonConfig["RecordMode"] = baseConfig.nRecordMode;
+        jsonConfig["DriverName"] = baseConfig.strDriverName.toStdString();
+        jsonConfig["NotConsistency"] = baseConfig.nNotConsistency;
+        jsonConfig["EnableMultiCore"] = baseConfig.isEnableMultiCore;
+        jsonConfig["EnableDebugLog"] = baseConfig.isEnableDebugLog;
+        jsonConfig["ClearHistryDirOnStart"] = baseConfig.isClearDirSystemOn;
+        jsonConfig["useSoundCardName"] = baseConfig.isUsingSoundCardName;
+
+        strJson = jsonConfig.dump();
+    }nJsonCatch
+
+    return true;
+}
+
+

+ 33 - 3
SettingLibrary/DataManager/SystemConfig.h

@@ -4,12 +4,30 @@
 
 #include "GlobalVariable.h"
 #include "SystemConfigStruct.h"
+#include <string>
+
+
+
+enum class eSystemConfigType
+{
+    eSCT_BaseConfig = 0,        // 基础配置
+    eSCT_CompareAI,             // AI对比
+    eSCT_NoiseDetect,           // 噪音检测
+    eSCT_Database,              // 数据库设置
+    eSCT_DetectPeriod           // 检测时段
+};
+
+
+#define Config_Base "ACAS_Base"                 // 基础配置
+#define Config_CompareAI "ACAS_CompareAI"       // AI对比配置
+#define Config_NoiseDetect "ACAS_NoiseDetect"   // 噪音检测配置
+#define Config_Database "ACAS_Database"         // 数据库设置
+#define Config_DetectPeriod "ACAS_DetectPeriod" // 检测时段配置
 
 /**
  * @brief ACA系统的设置信息
  * 
  */
-
 #define SysConfig SystemConfigInfo::instance()
 
 class SystemConfigInfo
@@ -26,16 +44,28 @@ public:
         return instance;
     }
 
+    /* 系统设置类型 */
+    const QMap<eSystemConfigType, std::string> mapSysConfigDesc = {
+        {eSystemConfigType::eSCT_BaseConfig, "基础配置"},
+        {eSystemConfigType::eSCT_CompareAI, "AI对比设置"},
+        {eSystemConfigType::eSCT_NoiseDetect, "噪音检测参数"},
+        {eSystemConfigType::eSCT_Database, "数据库设置信息"},
+        {eSystemConfigType::eSCT_DetectPeriod, "检测时段信息"}
+    };
+
 
     /* 获取未被修改的基础配置 */
     const BaseConfig_t& getBaseConfigSrc() const { return m_baseConfigSrc; }
     /* 设置基础配置 */
     void setBaseConfig(const BaseConfig_t& config);
+    /* 将数据库的json转换成结构体 */
+    bool getBaseConfigFromJson(const std::string& jsonStr);
+    /* 将结构体转换成json */
+    bool setBaseConfigToJson(const BaseConfig_t& baseConfig, std::string& strJson) const;
     
 
 public:
-    /* 基础配置 */
-    BaseConfig_t baseConfig;
+    
 
 private:
     /* 基础配置未被修改版本 */

+ 21 - 1
SettingLibrary/Modules/Basic/basicwidget.cpp

@@ -9,6 +9,7 @@
 #include "tipwidget.h"
 #include "SystemConfigStruct.h"
 #include "SystemConfig.h"
+#include <string>
 
 
 BasicWidget::BasicWidget(QWidget *parent) :
@@ -46,6 +47,17 @@ BasicWidget::BasicWidget(QWidget *parent) :
         ui->comBox_notConsistency->addItem(it.value(), it.key());
     }
 
+    /* 设置从数据库读取到的选项 */
+    const BaseConfig_t& baseConfig = SysConfig.getBaseConfigSrc();
+    ui->lineEdit_serverIP->setText(baseConfig.strServerIP);
+    ui->comBox_recordMode->setCurrentIndex(ui->comBox_recordMode->findData(baseConfig.nRecordMode));
+    ui->comBox_driverName->setCurrentText(baseConfig.strDriverName);
+    ui->comBox_notConsistency->setCurrentIndex(ui->comBox_notConsistency->findData(baseConfig.nNotConsistency));
+    ui->checkBox_enableMultiCPU->setChecked(baseConfig.isEnableMultiCore);
+    ui->checkBox_enableDebug->setChecked(baseConfig.isEnableDebugLog);
+    ui->checkBox_clearHistoryDir->setChecked(baseConfig.isClearDirSystemOn);
+    ui->checkBox_enableSoundCardName->setChecked(baseConfig.isUsingSoundCardName);
+
 
 }
 
@@ -109,7 +121,15 @@ bool BasicWidget::saveBasicSettingInfo()
         return true;
     }
 
-    // m_fromWebAPI->updateSystemConfig(const QString &key, const QString &value)
+    /* 将结构体转换成json字符串 */
+    std::string strJson;
+    SysConfig.setBaseConfigToJson(baseConfig, strJson);
+    if(!m_fromWebAPI->updateSystemConfig(Config_Base, strJson, SysConfig.mapSysConfigDesc[eSystemConfigType::eSCT_BaseConfig]))
+    {
+        SPDLOG_LOGGER_ERROR(m_logger, "更新基础配置信息失败");
+        return false;
+    }
+    SysConfig.setBaseConfig(baseConfig);  // 更新本地的基础配置信息
 
     return true;
 }

+ 4 - 4
SettingLibrary/Network/FromWebAPI.cpp

@@ -522,7 +522,7 @@ bool FromWebAPI::getSystemConfig(QMap<std::string, std::string>& mapConfig)
 }
 
 /* 更新系统配置信息  */
-bool FromWebAPI::updateSystemConfig(const QString& key, const QString& value, const QString& desc)
+bool FromWebAPI::updateSystemConfig(const std::string& key, const std::string& value, const std::string& desc)
 {
     try
     {
@@ -530,9 +530,9 @@ bool FromWebAPI::updateSystemConfig(const QString& key, const QString& value, co
         json0["opName"] = "ACAS_UpdateSystemConfigInfo";
         
         nJson jsonData;
-        jsonData["configKey"] = key.toStdString();
-        jsonData["configValue"] = value.toStdString();
-        jsonData["configDesc"] = desc.toStdString();
+        jsonData["configKey"] = key;
+        jsonData["configValue"] = value;
+        jsonData["configDesc"] = desc;
         json0["paramList"] = jsonData;
     
         QString strSend = QString::fromStdString(json0.dump());

+ 2 - 1
SettingLibrary/Network/FromWebAPI.h

@@ -4,6 +4,7 @@
 #include "spdlog/spdlog.h"
 #include "WebAPIBase.h"
 #include "GlobalVariable.h"
+#include <string>
 
 
 class FromWebAPI : public WebAPIBase
@@ -36,7 +37,7 @@ public:
     /* 获取系统配置信息 */
     bool getSystemConfig(QMap<std::string, std::string>& mapConfig);
     /* 更新系统配置信息  */
-    bool updateSystemConfig(const QString& key, const QString& value, const QString& desc = QString());
+    bool updateSystemConfig(const std::string& key, const std::string& value, const std::string& desc = std::string());
     
 
 private:

+ 47 - 0
SettingLibrary/setinfomanager.cpp

@@ -7,6 +7,7 @@
 
 #include "FromWebAPI.h"
 
+#include "SystemConfig.h"
 #include "spdlog/spdlog.h"
 #include "GlobalInfo.h"
 #include "GlobalVariable.h"
@@ -178,3 +179,49 @@ bool SetInfoManager::initWebAPI()
 }
 
 
+/* 获取数据库中系统设置参数 */
+bool SetInfoManager::getSystemConfig()
+{
+    if(m_fromWebAPI == nullptr)
+    {
+        SPDLOG_ERROR("WebAPI 未初始化");
+        return false;
+    }
+    QMap<std::string, std::string> mapConfig;
+    if(!m_fromWebAPI->getSystemConfig(mapConfig))
+    {
+        return false;
+    }
+    /* 将获取到的配置转换成结构体 */
+    for(auto it = mapConfig.begin(); it != mapConfig.end(); ++it)
+    {
+        if(Config_Base == it.key())
+        {
+            if(!SysConfig.getBaseConfigFromJson(it.value()))
+            {
+                SPDLOG_ERROR("获取基础配置失败");
+            }
+        }
+        else if(Config_CompareAI == it.key())
+        {
+        }
+        else if(Config_NoiseDetect == it.key())
+        {
+        }
+        else if(Config_Database == it.key())
+        {
+        }
+        else if(Config_DetectPeriod == it.key())
+        {
+        }
+        else
+        {
+            SPDLOG_ERROR("未知的系统配置项: {}", it.key());
+            return false;
+        }
+    }
+
+    return true;
+}
+
+

+ 2 - 0
SettingLibrary/setinfomanager.h

@@ -35,6 +35,8 @@ private:
     void setDefaultCompareItem();
     /* 初始化WebAPI */
     bool initWebAPI();
+    /* 获取数据库中系统设置参数 */
+    bool getSystemConfig();
 
 private:
     stInitData m_initData;      // 初始化数据