From e8a27bb203fe2aff70390a5eca002d7438da9b0f Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期三, 22 十月 2025 14:24:34 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang
---
SourceCode/Bond/Servo/RecipeManager.cpp | 90 +++++++++++++++++++++++++++++++--------------
1 files changed, 62 insertions(+), 28 deletions(-)
diff --git a/SourceCode/Bond/Servo/RecipeManager.cpp b/SourceCode/Bond/Servo/RecipeManager.cpp
index ce7b91f..4a979d7 100644
--- a/SourceCode/Bond/Servo/RecipeManager.cpp
+++ b/SourceCode/Bond/Servo/RecipeManager.cpp
@@ -480,47 +480,65 @@
return m_pDB->executeQuery(query.str());
}
-bool RecipeManager::addDeviceRecipe(const std::string& deviceName, int nRecipeID, const std::string& strRecipeName) {
- if (!m_pDB || deviceName.empty() || nRecipeID <= 0 || strRecipeName.empty()) {
+bool RecipeManager::addDeviceRecipe(const std::string& strDeviceName, int nID, const std::string& strName, const std::string& strPara) {
+ if (!m_pDB || strDeviceName.empty() || nID <= 0 || strName.empty() || strPara.empty()) {
return false;
}
std::ostringstream sql;
- sql << "CREATE TABLE IF NOT EXISTS " << deviceName << "_Recipes ("
- << "recipe_id INTEGER PRIMARY KEY, "
- << "recipe_name TEXT NOT NULL"
+ sql << "CREATE TABLE IF NOT EXISTS " << strDeviceName << "_Recipes ("
+ << "recipe_id INTEGER PRIMARY KEY,"
+ << "recipe_name TEXT NOT NULL,"
+ << "recipe_para TEXT NOT NULL"
<< ");";
- m_pDB->executeQuery(sql.str());
+ bool bRet = m_pDB->executeQuery(sql.str());
+ if (!bRet) {
+ return false;
+ }
std::ostringstream ins;
- ins << "INSERT OR REPLACE INTO " << deviceName << "_Recipes (recipe_id, recipe_name) VALUES ("
- << nRecipeID << ", '" << strRecipeName << "');";
+ ins << "INSERT OR REPLACE INTO " << strDeviceName
+ << "_Recipes (recipe_id, recipe_name, recipe_para) VALUES ("
+ << nID << ", '" << strName << "', '" << strPara << "');";
std::lock_guard<std::recursive_mutex> lk(m_mutex);
return m_pDB->executeQuery(ins.str());
}
-bool RecipeManager::updateDeviceRecipe(const std::string& deviceName, int nRecipeID, const std::string& newName) {
- if (!m_pDB || deviceName.empty() || nRecipeID <= 0 || newName.empty()) {
+bool RecipeManager::updateDeviceRecipeName(const std::string& strDeviceName, int nID, const std::string& strNewName) {
+ if (!m_pDB || strDeviceName.empty() || nID <= 0 || strNewName.empty()) {
return false;
}
std::ostringstream sql;
- sql << "UPDATE " << deviceName << "_Recipes SET recipe_name='" << newName
- << "' WHERE recipe_id=" << nRecipeID << ";";
+ sql << "UPDATE " << strDeviceName << "_Recipes SET recipe_name='" << strNewName
+ << "' WHERE recipe_id=" << nID << ";";
std::lock_guard<std::recursive_mutex> lk(m_mutex);
return m_pDB->executeQuery(sql.str());
}
-std::string RecipeManager::getDeviceRecipeName(const std::string& deviceName, int nRecipeID) {
- if (!m_pDB || deviceName.empty() || nRecipeID <= 0) {
+bool RecipeManager::updateDeviceRecipePara(const std::string& strDeviceName, int nID, const std::string& strNewPara) {
+ if (!m_pDB || strDeviceName.empty() || nID <= 0) {
+ return false;
+ }
+
+ std::ostringstream sql;
+ sql << "UPDATE " << strDeviceName << "_Recipes SET recipe_para='" << strNewPara
+ << "' WHERE recipe_id=" << nID << ";";
+
+ std::lock_guard<std::recursive_mutex> lk(m_mutex);
+ return m_pDB->executeQuery(sql.str());
+}
+
+std::string RecipeManager::getDeviceRecipeName(const std::string& strDeviceName, int nID) {
+ if (!m_pDB || strDeviceName.empty() || nID <= 0) {
return "";
}
std::ostringstream sql;
- sql << "SELECT recipe_name FROM " << deviceName << "_Recipes "
- << "WHERE recipe_id=" << nRecipeID << " LIMIT 1;";
+ sql << "SELECT recipe_name FROM " << strDeviceName << "_Recipes "
+ << "WHERE recipe_id=" << nID << " LIMIT 1;";
auto rows = m_pDB->fetchResults(sql.str());
if (!rows.empty() && !rows[0].empty()) {
@@ -529,26 +547,42 @@
return "";
}
-bool RecipeManager::deleteDeviceRecipe(const std::string& deviceName, int nRecipeID) {
- if (!m_pDB || deviceName.empty() || nRecipeID <= 0) {
+std::string RecipeManager::getDeviceRecipePara(const std::string& strDeviceName, int nID) {
+ if (!m_pDB || strDeviceName.empty() || nID <= 0) {
+ return "";
+ }
+
+ std::ostringstream sql;
+ sql << "SELECT recipe_para FROM " << strDeviceName << "_Recipes "
+ << "WHERE recipe_id=" << nID << " LIMIT 1;";
+
+ auto rows = m_pDB->fetchResults(sql.str());
+ if (!rows.empty() && !rows[0].empty()) {
+ return rows[0][0];
+ }
+ return "";
+}
+
+bool RecipeManager::deleteDeviceRecipe(const std::string& strDeviceName, int nID) {
+ if (!m_pDB || strDeviceName.empty() || nID <= 0) {
return false;
}
std::ostringstream sql;
- sql << "DELETE FROM " << deviceName << "_Recipes WHERE recipe_id=" << nRecipeID << ";";
+ sql << "DELETE FROM " << strDeviceName << "_Recipes WHERE recipe_id=" << nID << ";";
std::lock_guard<std::recursive_mutex> lk(m_mutex);
return m_pDB->executeQuery(sql.str());
}
-std::vector<std::pair<int, std::string>> RecipeManager::getDeviceRecipes(const std::string& deviceName) {
+std::vector<std::pair<int, std::string>> RecipeManager::getDeviceRecipes(const std::string& strDeviceName) {
std::vector<std::pair<int, std::string>> out;
- if (!m_pDB || deviceName.empty()) {
+ if (!m_pDB || strDeviceName.empty()) {
return out;
}
std::ostringstream sql;
- sql << "SELECT recipe_id, recipe_name FROM " << deviceName << "_Recipes ORDER BY recipe_id;";
+ sql << "SELECT recipe_id, recipe_name FROM " << strDeviceName << "_Recipes ORDER BY recipe_id;";
auto rows = m_pDB->fetchResults(sql.str());
for (const auto& r : rows) {
@@ -579,13 +613,13 @@
addRecipe(recipe);
- addDeviceRecipe("Bonder1", 101, "鏍囧噯宸ヨ壓");
- addDeviceRecipe("Bonder1", 102, "鏀硅壇宸ヨ壓");
- addDeviceRecipe("Bonder1", 103, "楂橀�熸ā寮�");
+ addDeviceRecipe("Bonder1", 101, "鏍囧噯宸ヨ壓", "00");
+ addDeviceRecipe("Bonder1", 102, "鏀硅壇宸ヨ壓", "00");
+ addDeviceRecipe("Bonder1", 103, "楂橀�熸ā寮�", "00");
- addDeviceRecipe("Bonder2", 101, "鏍囧噯宸ヨ壓");
- addDeviceRecipe("Bonder2", 102, "鏀硅壇宸ヨ壓");
- addDeviceRecipe("Bonder2", 103, "楂橀�熸ā寮�");
+ addDeviceRecipe("Bonder2", 101, "鏍囧噯宸ヨ壓", "00");
+ addDeviceRecipe("Bonder2", 102, "鏀硅壇宸ヨ壓", "00");
+ addDeviceRecipe("Bonder2", 103, "楂橀�熸ā寮�", "00");
}
bool RecipeManager::readRecipeFile(const std::string& filename) {
--
Gitblit v1.9.3