#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
|