From a03e6a4c3a51aca0ccda1c05cc1bfe23904e2198 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 04 九月 2025 16:48:14 +0800
Subject: [PATCH] 1. 在配方数据库中添加配方参数元数据
---
SourceCode/Bond/Servo/RecipeManager.cpp | 80 +++++++++++++++++++++++++++------------
SourceCode/Bond/Servo/RecipeManager.h | 12 +++--
SourceCode/Bond/Servo/PageRecipe.cpp | 7 ++-
3 files changed, 66 insertions(+), 33 deletions(-)
diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index 7ed085b..f19cae0 100644
--- a/SourceCode/Bond/Servo/PageRecipe.cpp
+++ b/SourceCode/Bond/Servo/PageRecipe.cpp
@@ -199,16 +199,16 @@
std::string strRecipeName = mgr.getDeviceRecipeName(pEq->getName(), item.second);
m_listPPID.SetItemText(index, 3, strRecipeName.c_str());
+ std::string strDescription;
auto iter = rawDatas.find(item.second);
if (iter != rawDatas.end()) {
- std::string strDescription;
pEq->parsingParams((const char*)iter->second.data(), iter->second.size(), strDescription);
m_listPPID.SetItemText(index, 4, strDescription.c_str());
}
if (strRecipeName.empty()) {
strRecipeName = std::to_string(item.second);
- mgr.addDeviceRecipe(pEq->getName(), item.second, strRecipeName);
+ mgr.addDeviceRecipe(pEq->getName(), item.second, strRecipeName, strDescription);
}
}
@@ -482,7 +482,8 @@
AfxMessageBox(_T("閰嶆柟鍚嶇О涓嶈兘涓虹┖锛�"));
return;
}
- if (RecipeManager::getInstance().updateDeviceRecipe(pEq->getName(), _ttoi(strID), std::string(CT2A(strText)))) {
+
+ if (RecipeManager::getInstance().updateDeviceRecipeName(pEq->getName(), _ttoi(strID), std::string(CT2A(strText)))) {
m_listPPID.SetItemText(nLine, 3, strText);
}
}
diff --git a/SourceCode/Bond/Servo/RecipeManager.cpp b/SourceCode/Bond/Servo/RecipeManager.cpp
index db65214..bc44b96 100644
--- a/SourceCode/Bond/Servo/RecipeManager.cpp
+++ b/SourceCode/Bond/Servo/RecipeManager.cpp
@@ -480,13 +480,13 @@
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 ("
+ sql << "CREATE TABLE IF NOT EXISTS " << strDeviceName << "_Recipes ("
<< "recipe_id INTEGER PRIMARY KEY,"
<< "recipe_name TEXT NOT NULL,"
<< "recipe_para TEXT NOT NULL"
@@ -494,34 +494,48 @@
m_pDB->executeQuery(sql.str());
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()) {
@@ -530,26 +544,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) {
@@ -580,13 +610,13 @@
addRecipe(recipe);
- addDeviceRecipe("Bonder1", 101, "鏍囧噯宸ヨ壓");
- addDeviceRecipe("Bonder1", 102, "鏀硅壇宸ヨ壓");
- addDeviceRecipe("Bonder1", 103, "楂橀�熸ā寮�");
+ addDeviceRecipe("Bonder1", 101, "鏍囧噯宸ヨ壓", "");
+ addDeviceRecipe("Bonder1", 102, "鏀硅壇宸ヨ壓", "");
+ addDeviceRecipe("Bonder1", 103, "楂橀�熸ā寮�", "");
- addDeviceRecipe("Bonder2", 101, "鏍囧噯宸ヨ壓");
- addDeviceRecipe("Bonder2", 102, "鏀硅壇宸ヨ壓");
- addDeviceRecipe("Bonder2", 103, "楂橀�熸ā寮�");
+ addDeviceRecipe("Bonder2", 101, "鏍囧噯宸ヨ壓", "");
+ addDeviceRecipe("Bonder2", 102, "鏀硅壇宸ヨ壓", "");
+ addDeviceRecipe("Bonder2", 103, "楂橀�熸ā寮�", "");
}
bool RecipeManager::readRecipeFile(const std::string& filename) {
diff --git a/SourceCode/Bond/Servo/RecipeManager.h b/SourceCode/Bond/Servo/RecipeManager.h
index 2ffba09..70837c0 100644
--- a/SourceCode/Bond/Servo/RecipeManager.h
+++ b/SourceCode/Bond/Servo/RecipeManager.h
@@ -101,11 +101,13 @@
// 鏇存柊璁惧閰嶆柟ID锛堥�氳繃 PPID 鍜岃澶囧悕绉帮級
bool updateDeviceRecipeIDByName(const std::string& ppid, const std::string& strDeviceName, int nNewRecipeID);
- bool addDeviceRecipe(const std::string& deviceName, int nRecipeID, const std::string& strRecipeName);
- bool updateDeviceRecipe(const std::string& deviceName, int nRecipeID, const std::string& newName);
- std::string getDeviceRecipeName(const std::string& deviceName, int nRecipeID);
- bool deleteDeviceRecipe(const std::string& deviceName, int nRecipeID);
- std::vector<std::pair<int, std::string>> getDeviceRecipes(const std::string& deviceName);
+ bool addDeviceRecipe(const std::string& strDeviceName, int nID, const std::string& strName, const std::string& strPara);
+ bool updateDeviceRecipeName(const std::string& strDeviceName, int nID, const std::string& strNewName);
+ bool updateDeviceRecipePara(const std::string& strDeviceName, int nID, const std::string& strNewPara);
+ std::string getDeviceRecipeName(const std::string& strDeviceName, int nID);
+ std::string getDeviceRecipePara(const std::string& strDeviceName, int nID);
+ bool deleteDeviceRecipe(const std::string& strDeviceName, int nID);
+ std::vector<std::pair<int, std::string>> getDeviceRecipes(const std::string& strDeviceName);
// 妯℃嫙鎻掑叆鏁版嵁锛堟祴璇曠敤锛�
void insertMockData();
--
Gitblit v1.9.3