From 576e5fc2d2db7d106dc264c685d5a59849082d1f Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 19 六月 2025 17:41:52 +0800
Subject: [PATCH] 1. 添加JOB Data交互
---
SourceCode/Bond/Servo/RecipeManager.h | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 109 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/RecipeManager.h b/SourceCode/Bond/Servo/RecipeManager.h
new file mode 100644
index 0000000..a51e14d
--- /dev/null
+++ b/SourceCode/Bond/Servo/RecipeManager.h
@@ -0,0 +1,109 @@
+#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);
+
+ // 更新 PPID(通过旧 PPID 和新 PPID)
+ bool updatePPID(const std::string& oldPPID, const std::string& newPPID);
+
+ // 更新配方描述(通过 PPID)
+ bool updateDescription(const std::string& ppid, const std::string& newDescription);
+
+ // 更新设备配方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