Browse Source

更新配方修改接口

master
zhaohe 2 years ago
parent
commit
1885e2eb0a
  1. 17
      src/db/db_service.cpp
  2. 1
      src/db/db_service.hpp
  3. 2
      src/db/user_behavior_des.cpp
  4. 1
      src/db/user_behavior_des.hpp
  5. 40
      src/main_control_service.cpp

17
src/db/db_service.cpp

@ -500,6 +500,23 @@ shared_ptr<db::Formula> DBService::delFormula(int id) {
return make_shared<Formula>(formula[0]); return make_shared<Formula>(formula[0]);
} }
shared_ptr<db::Formula> DBService::updateFormula(shared_ptr<db::Formula> var_formula) {
lock_guard<recursive_mutex> lock(lock_);
if (var_formula == nullptr) {
return nullptr;
}
auto formulatable = make_storage(FORMULA_DB, FORMULA_DB_STRUCT);
formulatable.sync_schema();
auto formula = formulatable.get_all<Formula>(where(c(&Formula::id) == var_formula->id));
if (formula.size() == 0) {
return nullptr;
}
formulatable.update(*var_formula);
formulatable.sync_schema();
return var_formula;
}
shared_ptr<db::Formula> DBService::updateFormula(int id, string column, string val) { shared_ptr<db::Formula> DBService::updateFormula(int id, string column, string val) {
lock_guard<recursive_mutex> lock(lock_); lock_guard<recursive_mutex> lock(lock_);

1
src/db/db_service.hpp

@ -155,6 +155,7 @@ class DBService : public enable_shared_from_this<DBService> {
int injection_pump_speed); int injection_pump_speed);
shared_ptr<db::Formula> delFormula(int id); shared_ptr<db::Formula> delFormula(int id);
shared_ptr<db::Formula> updateFormula(int id, string column, string val); shared_ptr<db::Formula> updateFormula(int id, string column, string val);
shared_ptr<db::Formula> updateFormula(shared_ptr<db::Formula> formula);
shared_ptr<db::Formula> getFormula(int id); shared_ptr<db::Formula> getFormula(int id);

2
src/db/user_behavior_des.cpp

@ -30,6 +30,8 @@ string user_behavior_to_str(user_behavior_t behavior) {
return "删除配方"; return "删除配方";
case kbehavior_update_formula: case kbehavior_update_formula:
return "更新配方"; return "更新配方";
case kbehavior_update_formula_name:
return "更新配方名称";
case kbehavior_do_disinfection: case kbehavior_do_disinfection:
return "开始消毒"; return "开始消毒";
case kbehavior_stop_disinfection: case kbehavior_stop_disinfection:

1
src/db/user_behavior_des.hpp

@ -31,6 +31,7 @@ typedef enum {
kbehavior_update_setting_val_on_disinfection = 15, kbehavior_update_setting_val_on_disinfection = 15,
kbehavior_export_disinfection_data = 16, kbehavior_export_disinfection_data = 16,
kbehavior_export_user_action_data = 17, kbehavior_export_user_action_data = 17,
kbehavior_update_formula_name = 18,
} user_behavior_t; } user_behavior_t;
string user_behavior_to_str(user_behavior_t behavior); string user_behavior_to_str(user_behavior_t behavior);

40
src/main_control_service.cpp

@ -618,6 +618,46 @@ void MainControlService::processFrontEndMessage_processFormulaCmd(weak_ptr<WebSo
} }
return; return;
} }
if (cmdstr == "updateFormula2") {
int id = jsonGet<int>(cmd["id"]);
string formula_id = cmd["formula_id"];
int loglevel = jsonGet<int>(cmd["loglevel"]);
int stoped_gs = jsonGet<int>(cmd["stoped_gs"]);
int continued_gs = jsonGet<int>(cmd["continued_gs"]);
int stoped_satur = jsonGet<int>(cmd["stoped_satur"]);
int continued_satur = jsonGet<int>(cmd["continued_satur"]);
int stoped_humi = jsonGet<int>(cmd["stoped_humi"]);
int continued_humi = jsonGet<int>(cmd["continued_humi"]);
int injection_pump_speed = jsonGet<int>(cmd["injection_pump_speed"]);
shared_ptr<Formula> formula = m_dbService->getFormula(id);
string oldname = formula->formula_id;
formula->formula_id = formula_id;
formula->loglevel = std::to_string(loglevel);
formula->stoped_gs = std::to_string(stoped_gs);
formula->continued_gs = std::to_string(continued_gs);
formula->stoped_satur = std::to_string(stoped_satur);
formula->continued_satur = std::to_string(continued_satur);
formula->stoped_humi = std::to_string(stoped_humi);
formula->continued_humi = std::to_string(continued_humi);
formula->injection_pump_speed = std::to_string(injection_pump_speed);
if (!formula) {
logger->error("formula id {} not exist", id);
receipt["ackcode"] = err::zecode(err::kdb_operate_error);
receipt["ackcodeInfo"] = err::zecode2str(err::kdb_operate_error);
return;
}
m_dbService->updateFormula(formula);
if (oldname != formula_id) {
m_dbService->addUserBehaviorRecord(m_deviceStateService->getLoginUid(), kbehavior_update_formula_name,
fmt::format("({}->{})", oldname, formula->formula_id));
}
m_dbService->addUserBehaviorRecord(m_deviceStateService->getLoginUid(), kbehavior_update_formula, fmt::format("({})", formula->formula_id));
return;
}
} }
void MainControlService::processFrontEndMessage_processBehaviorRecordCmd(weak_ptr<WebSocket> webSocket, json& cmd, json& receipt) { void MainControlService::processFrontEndMessage_processBehaviorRecordCmd(weak_ptr<WebSocket> webSocket, json& cmd, json& receipt) {
string cmdstr = cmd["command"]; string cmdstr = cmd["command"];

Loading…
Cancel
Save