From faa827b937e5cb4a13e0356368cbb263568f6416 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 16 May 2024 17:56:54 +0800 Subject: [PATCH] update --- db/db_service.cpp | 65 +++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/db/db_service.cpp b/db/db_service.cpp index 0f5d75c..67532f7 100644 --- a/db/db_service.cpp +++ b/db/db_service.cpp @@ -58,6 +58,26 @@ using namespace nlohmann; make_column("behavior", &UserBehaviorRecord::behavior), /**/ \ make_column("behaviorinfo", &UserBehaviorRecord::behaviorinfo)) +/******************************************************************************* + * 配置列表 * + *******************************************************************************/ +static Setting config_settings_table[] = { + {.id = 1, .name = "stoped_gs", .name_ch = "消毒停止过氧化氢溶度", .val_lower_limit = 0, .val_upper_limit = 2000, .permission_level = 0, .val = 1800}, + {.id = 2, .name = "continued_gs", .name_ch = "消毒继续过氧化氢溶度", .val_lower_limit = 0, .val_upper_limit = 2000, .permission_level = 0, .val = 1500}, + {.id = 3, .name = "stoped_satur", .name_ch = "消毒停止过氧化氢相对饱和度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 85}, + {.id = 4, .name = "continued_satur", .name_ch = "消毒继续过氧化氢相对饱和度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 70}, + {.id = 5, .name = "max_humidity", .name_ch = "允许消毒最大湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 90}, + {.id = 6, .name = "drainage_pump_speed", .name_ch = "排液蠕动泵转速", .val_lower_limit = 0, .val_upper_limit = 90, .permission_level = 0, .val = 90}, + {.id = 7, .name = "injection_pump_speed", .name_ch = "喷射蠕动泵转速", .val_lower_limit = 0, .val_upper_limit = 50, .permission_level = 0, .val = 50}, + {.id = 8, .name = "pre_heat_time_s", .name_ch = "预热时间", .val_lower_limit = 0, .val_upper_limit = 600, .permission_level = 0, .val = 120}, + {.id = 9, .name = "stoped_humi", .name_ch = "消毒停止相对湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 85}, + {.id = 10, .name = "continued_humi", .name_ch = "消毒继续相对湿度", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 70}, + {.id = 11, .name = "proportional_valve_default_value", .name_ch = "正负压默认开合比例", .val_lower_limit = 0, .val_upper_limit = 100, .permission_level = 0, .val = 10}, +}; + + +#define ZARRARY_SIZE(val) (sizeof(val) / sizeof(val[0])) + DBService::DBService(/* args */) {} void DBService::initialize() { @@ -115,35 +135,11 @@ id setting_name setting_name_ch val_upper_limit val_lower_limi auto storage = make_storage(SETTING_DB, SETTING_DB_STRUCT); storage.sync_schema(); - if (storage.get_all(where(c(&Setting::id) == 1)).size() == 0) // - storage.insert(Setting{1, "stoped_gs", "消毒停止过氧化氢溶度", 0, 2000, 0, 1800}); - - if (storage.get_all(where(c(&Setting::id) == 2)).size() == 0) - storage.insert(Setting{2, "continued_gs", "消毒继续过氧化氢溶度", 0, 2000, 0, 1500}); - - if (storage.get_all(where(c(&Setting::id) == 3)).size() == 0) - storage.insert(Setting{3, "stoped_satur", "消毒停止过氧化氢相对饱和度", 0, 100, 0, 85}); - - if (storage.get_all(where(c(&Setting::id) == 4)).size() == 0) - storage.insert(Setting{4, "continued_satur", "消毒继续过氧化氢相对饱和度", 0, 100, 0, 70}); - - if (storage.get_all(where(c(&Setting::id) == 5)).size() == 0) // - storage.insert(Setting{5, "max_humidity", "允许消毒最大湿度", 0, 100, 0, 90}); - - if (storage.get_all(where(c(&Setting::id) == 6)).size() == 0) - storage.insert(Setting{6, "drainage_pump_speed", "排液蠕动泵转速", 0, 90, 0, 90}); // g/min - - if (storage.get_all(where(c(&Setting::id) == 7)).size() == 0) - storage.insert(Setting{7, "injection_pump_speed", "喷射蠕动泵转速", 0, 50, 0, 50}); // g/min - - if (storage.get_all(where(c(&Setting::id) == 8)).size() == 0) // - storage.insert(Setting{8, "pre_heat_time_s", "预热时间", 0, 600, 0, 120}); - - if (storage.get_all(where(c(&Setting::id) == 9)).size() == 0) // - storage.insert(Setting{9, "stoped_humi", "消毒停止相对湿度", 0, 100, 0, 85}); - - if (storage.get_all(where(c(&Setting::id) == 10)).size() == 0) // - storage.insert(Setting{10, "continued_humi", "消毒继续相对湿度", 0, 100, 0, 70}); + for (size_t i = 0; i < ZARRARY_SIZE(config_settings_table); i++) { + if (storage.get_all(where(c(&Setting::id) == config_settings_table[i].id)).size() == 0) { + storage.insert(config_settings_table[i]); + } + } suc = true; } catch (const std::exception& e) { @@ -458,8 +454,8 @@ json DBService::getAllFormulaJson() { return jret; } -void DBService::addFormula(string formula_id, string loglevel, string stoped_gs, string continued_gs, string stoped_satur, string continued_satur, - string stoped_humi, string continued_humi, string injection_pump_speed) { +void DBService::addFormula(string formula_id, string loglevel, string stoped_gs, string continued_gs, string stoped_satur, string continued_satur, string stoped_humi, string continued_humi, + string injection_pump_speed) { lock_guard lock(lock_); auto formulatable = make_storage(FORMULA_DB, FORMULA_DB_STRUCT); @@ -479,10 +475,9 @@ void DBService::addFormula(string formula_id, string loglevel, string stoped_gs, formulatable.sync_schema(); } -void DBService::addFormula(string formula_id, int loglevel, int stoped_gs, int continued_gs, int stoped_satur, int continued_satur, int stoped_humi, - int continued_humi, int injection_pump_speed) { - addFormula(formula_id, to_string(loglevel), to_string(stoped_gs), to_string(continued_gs), to_string(stoped_satur), to_string(continued_satur), - to_string(stoped_humi), to_string(continued_humi), to_string(injection_pump_speed)); +void DBService::addFormula(string formula_id, int loglevel, int stoped_gs, int continued_gs, int stoped_satur, int continued_satur, int stoped_humi, int continued_humi, int injection_pump_speed) { + addFormula(formula_id, to_string(loglevel), to_string(stoped_gs), to_string(continued_gs), to_string(stoped_satur), to_string(continued_satur), to_string(stoped_humi), to_string(continued_humi), + to_string(injection_pump_speed)); } shared_ptr DBService::delFormula(int id) { lock_guard lock(lock_);