123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- /*
- * @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 <iostream>
- #include <rapidjson/document.h>
- #include <rapidjson/rapidjson.h>
- #include <rapidjson/stringbuffer.h>
- #include <rapidjson/writer.h>
- #include "Util/SqlPool.h"
- #include "UtilBase.hpp"
- using namespace toolkit;
- using namespace std;
- using namespace gsd;
- //DeviceType enum use in Expel.cpp getControl(). Read from config.ini
- 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
|