/* * @Description: * @Version: 1.0 * @Autor: lishengyin * @Date: 2022-02-16 15:25:46 * @LastEditors: lishengyin * @LastEditTime: 2022-09-28 14:19:17 */ #ifndef __EXPELDEVICE_H_ #define __EXPELDEVICE_H_ #include #include #include #include #include #include "Util/SqlPool.h" #include "UtilBase.hpp" using namespace toolkit; using namespace std; using namespace gsd; enum DeviceType { DevicePlayerV1 = 0, DeviceGasV1 = 1, DevicePlayerV2 = 2, DevicePlayerV3 = 3, DevicePlayerV4 = 4, DeviceGasV2 = 5, DevicePlayerV5 = 6 }; class ExpelDevice { public: int Id; std::string DeviceId; enum ContorlGear::DeviceTools tool = ContorlGear::DeviceTools::serial; enum DeviceType deviceType; std::string UpdateTime; std::string ServerIp; std::string ServerCname; std::string ServerCpwd; public: ExpelDevice(){} ~ExpelDevice(){} /** * @description: json转换为对象 * @param {string&} json * @return {*} */ bool JsonToObject(std::string& json){ rapidjson::Document doc; doc.Parse(json.c_str()); if(!doc.IsObject()){ return false; } // get members const auto end = doc.MemberEnd(); // json_type if(end == doc.FindMember("DeviceId") || !doc["DeviceId"].IsString()) { return false; }else{ DeviceId = doc["DeviceId"].GetString(); } // json_type if(end == doc.FindMember("DeviceToken") || !doc["DeviceToken"].IsString()) { return false; }else{ tool = (enum ContorlGear::DeviceTools)atoi(doc["DeviceToken"].GetString()); } if (end == doc.FindMember("DeviceType") || !doc["DeviceType"].IsString()) { return false; } else { deviceType = (enum DeviceType)atoi(doc["DeviceType"].GetString()); } if (end == doc.FindMember("ServerIp") || !doc["ServerIp"].IsString()) { return false; } else { ServerIp = doc["ServerIp"].GetString(); } if (end == doc.FindMember("ServerCname") || !doc["ServerCname"].IsString()) { return false; } else { ServerCname = doc["ServerCname"].GetString(); } if (end == doc.FindMember("ServerCpwd") || !doc["ServerCpwd"].IsString()) { return false; } else { ServerCpwd = doc["ServerCpwd"].GetString(); } return true; } /** * @description: object转换为sql * @param {*} * @return {*} */ std::string ObjectToSql(){ SqlStream sqlStream("insert into gsdDB.`DeviceList` (Id, DeviceId, DeviceToken, DeviceType, ServerIp, ServerCname, ServerCpwd, UpdateTime,ISDELETE)\ values ('?','?','?','?','?','?','?','?','0')\ on duplicate key update Id=VALUES(Id), DeviceId=VALUES(DeviceId),\ DeviceToken=VALUES(DeviceToken), DeviceType=VALUES(DeviceType), \ ServerIp=VALUES(ServerIp), ServerCname=VALUES(ServerCname), \ ServerCpwd=VALUES(ServerCpwd), UpdateTime=VALUES(UpdateTime),\ ISDELETE=VALUES(ISDELETE)"); sqlStream << Id << DeviceId << tool << deviceType << ServerIp << ServerCname << ServerCpwd << UpdateTime; return (std::string)sqlStream; } }; #endif