#ifndef RECIPE_MANAGER_H #define RECIPE_MANAGER_H #include #include #include #include #include "Database.h" // µ¥¸öÉ豸Åä·½Ó³ÉäÐÅÏ¢ struct DeviceRecipe { int nDeviceID; // É豸ID int nRecipeID; // ×ÓÅä·½ID std::string strDeviceName; // É豸Ãû³Æ std::string strRecipeName; // ×ÓÅä·½Ãû³Æ }; // Åä·½ÐÅÏ¢ struct RecipeInfo { std::string strPPID; // Åä·½ID std::string strDescription; // Åä·½ÃèÊö std::string strCreateTime; // ´´½¨Ê±¼ä std::vector vecDeviceList; // ¹ØÁªµÄÉ豸ÐÅÏ¢Áбí }; using RecipeMap = std::unordered_map; // °´ 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 getAllRecipes(); // ¸ù¾Ý PPID »òÃèÊö²éѯÅä·½ std::vector getRecipesByKeyword(const std::string& keyword); // »ñÈ¡ËùÓÐ PPID std::vector getAllPPID() const; // °´ 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); 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> getDeviceRecipes(const std::string& deviceName); // Ä£Äâ²åÈëÊý¾Ý£¨²âÊÔÓã© 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