From 8d492d8d449d6aaff1825a99055298682ebf71b7 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 02 九月 2025 09:55:49 +0800
Subject: [PATCH] 1. 配方数据库管理表里面添加ID(下发JobDataS) 2. 如果任务没有创建,那么配方是当前选择的(不是默认第一个)

---
 SourceCode/Bond/Servo/RecipeManager.cpp |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/SourceCode/Bond/Servo/RecipeManager.cpp b/SourceCode/Bond/Servo/RecipeManager.cpp
index 1095038..8cb7a51 100644
--- a/SourceCode/Bond/Servo/RecipeManager.cpp
+++ b/SourceCode/Bond/Servo/RecipeManager.cpp
@@ -43,7 +43,8 @@
 
     const std::string createRecipeTable = R"(
         CREATE TABLE IF NOT EXISTS recipes (
-            ppid TEXT PRIMARY KEY NOT NULL,
+            id INTEGER PRIMARY KEY AUTOINCREMENT,
+            ppid TEXT NOT NULL UNIQUE,
             description TEXT,
             create_time TEXT DEFAULT (datetime('now', 'localtime'))
         );
@@ -283,6 +284,44 @@
     return vecPPID;
 }
 
+std::string RecipeManager::getPPIDById(int nId) {
+    if (!m_pDB) {
+        return {};
+    }
+
+    std::ostringstream query;
+    query << "SELECT ppid FROM recipes WHERE id = " << nId << ";";
+
+    auto rows = m_pDB->fetchResults(query.str());
+    if (rows.empty() || rows[0].empty()) {
+        return {};
+    }
+
+    return rows[0][0];
+}
+
+int RecipeManager::getIdByPPID(const std::string& ppid) {
+    if (!m_pDB) {
+        return -1;
+    }
+
+    std::ostringstream query;
+    query << "SELECT id FROM recipes WHERE ppid = '" << ppid << "';";
+
+    auto rows = m_pDB->fetchResults(query.str());
+    if (rows.empty() || rows[0].empty()) {
+        return -1;
+    }
+
+    try {
+        return std::stoi(rows[0][0]);
+    }
+    catch (...) {
+        std::cerr << "Invalid id value for PPID: " << ppid << std::endl;
+        return -1;
+    }
+}
+
 RecipeInfo RecipeManager::getRecipeByPPID(const std::string& ppid) {
     RecipeInfo info;
     auto rows = m_pDB->fetchResults("SELECT ppid, description, create_time FROM recipes WHERE ppid = '" + ppid + "';");

--
Gitblit v1.9.3