123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2022-02-16 15:25:46
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-07-21 16:23:13
- */
- #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 "deviceBase.h"
- using namespace toolkit;
- using namespace std;
- enum DeviceType {
- DeviceGasV1 = 0,
- DeviceGasV2 = 1,
- DeviceUlt = 2,
- DevicePlayer = 3,
- DeviceGasV3 = 4
- };
- class ExpelDevice
- {
- public:
- int Id;
- std::string DeviceId;
- enum DeviceToken deviceToken;
- 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;
- if (doc.Parse<rapidjson::kParseCommentsFlag>(json.c_str()).HasParseError()) {
- 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{
- deviceToken = (enum DeviceToken)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 << deviceToken << deviceType << ServerIp << ServerCname << ServerCpwd << UpdateTime;
- return (std::string)sqlStream;
- }
- };
- #endif
|