From 2ece96546ec80bf26013d005967cbfdc06156ee7 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期二, 17 六月 2025 16:32:41 +0800
Subject: [PATCH] 1. 添加配方管理类(数据库) 2. 修改用户管理和系统日志管理类的路径和名称 3. 修复合并代码导致系统日志管理窗口的资源异常的问题

---
 SourceCode/Bond/Servo/RecipeManager.h |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/RecipeManager.h b/SourceCode/Bond/Servo/RecipeManager.h
new file mode 100644
index 0000000..b5aceaa
--- /dev/null
+++ b/SourceCode/Bond/Servo/RecipeManager.h
@@ -0,0 +1,103 @@
+#ifndef RECIPE_MANAGER_H
+#define RECIPE_MANAGER_H
+
+#include <string>
+#include <vector>
+#include <mutex>
+#include <unordered_map>
+#include "Database.h"
+
+// 单个设备配方映射信息
+struct DeviceRecipe {
+    int nDeviceID;               // 设备ID
+    int nRecipeID;               // 该设备对应的子配方ID
+    std::string strPPID;         // 配方ID(主键)
+    std::string strDeviceName;   // 设备名称 
+};
+
+// 配方信息
+struct RecipeInfo {
+    std::string strPPID;         // 配方ID
+    std::string strDescription;  // 配方描述
+    std::string strCreateTime;   // 创建时间
+    std::vector<DeviceRecipe> vecDeviceList;  // 关联的设备信息列表
+};
+
+using RecipeMap = std::unordered_map<std::string, RecipeInfo>; // 按 PPID 映射的配方表
+
+class RecipeManager {
+public:
+    // 获取单例
+    static RecipeManager& getInstance();
+
+    // 初始化配方数据库
+    bool initRecipeTable();
+
+    // 销毁表或关闭连接
+    void termRecipeTable();
+    bool destroyRecipeTable();
+
+	// 检查 PPID 是否存在
+    bool ppidExists(const std::string& ppid);
+
+	// 检查设备是否存在于指定 PPID 的配方中
+	bool deviceExists(const std::string& ppid, int nDeviceID);
+
+    // 添加一个配方及其设备映射
+    bool addRecipe(const RecipeInfo& recipe);
+
+	// 添加设备到指定配方
+    bool addRecipeDevice(const std::string& ppid, const DeviceRecipe& device);
+
+	// 删除指定 PPID 的设备配方
+    bool deleteRecipeDeviceByID(const std::string& ppid, int nDeviceID);
+
+	// 删除指定 PPID 的设备配方(通过设备名称)
+    bool deleteRecipeDeviceByName(const std::string& ppid, const std::string& strDeviceName);
+
+    // 查询所有配方
+    std::vector<RecipeInfo> getAllRecipes();
+
+    // 按 PPID 查询配方
+    RecipeInfo getRecipeByPPID(const std::string& ppid);
+
+    // 根据 PPID 和设备ID 获取设备配方ID
+    int getDeviceRecipeIDByID(const std::string& ppid, int nDeviceID);
+
+    // 根据 PPID 和设备名称 获取设备配方ID
+    int getDeviceRecipeIDByName(const std::string& ppid, const std::string& strDeviceName);
+
+    // 删除指定 PPID 的配方
+    bool deleteRecipeByPPID(const std::string& ppid);
+
+    // 更新指定 PPID 的配方
+    bool updateRecipe(const RecipeInfo& recipe);
+
+	// 更新设备配方ID(通过 PPID 和设备ID)
+    bool updateDeviceRecipeIDByID(const std::string& ppid, int nDeviceID, int nNewRecipeID);
+
+	// 更新设备配方ID(通过 PPID 和设备名称)
+    bool updateDeviceRecipeIDByName(const std::string& ppid, const std::string& strDeviceName, int nNewRecipeID);
+
+    // 模拟插入数据(测试用)
+    void insertMockData();
+
+    // 读取配方文件(CSV 或 JSON)
+    bool readRecipeFile(const std::string& filename);
+
+    // 保存配方到文件
+    bool saveRecipeFile(const std::string& filename);
+
+private:
+    RecipeManager();
+    ~RecipeManager();
+
+    RecipeManager(const RecipeManager&) = delete;
+    RecipeManager& operator=(const RecipeManager&) = delete;
+
+private:
+    BL::Database* m_pDB;
+    static std::recursive_mutex m_mutex;
+};
+
+#endif // RECIPE_MANAGER_H
\ No newline at end of file

--
Gitblit v1.9.3