/* * @Description: * @Version: 1.0 * @Autor: lishengyin * @Date: 2021-11-03 15:16:14 * @LastEditors: lishengyin * @LastEditTime: 2022-10-09 09:14:53 */ #pragma once #include #include #include #include #include #include #include "Util/logger.h" #include "Util/NoticeCenter.h" #include "Poller/EventPoller.h" #include "Util/SqlPool.h" #include "Network/TcpClient.h" #include "Poller/Timer.h" #include "Notices.h" using namespace std; using namespace toolkit; template class NettyHttpResultMsg { public: std::string code; std::string msg; vector datas; vector extendDatas; bool notOk; bool ok; public: NettyHttpResultMsg(){} ~NettyHttpResultMsg(){} /** * @description: json转码为对象 * @param {const std::string& json} json数据 * @return {*} */ bool jsonToObject(const std::string& json) { rapidjson::Document doc; if (doc.Parse(json.c_str()).HasParseError()) { return false; } // get members const auto end = doc.MemberEnd(); if (end == doc.FindMember("code") || !doc["code"].IsString()) { return false; } else { code = doc["code"].GetString(); } if (end == doc.FindMember("notOk") || !doc["notOk"].IsBool()) { return false; } else { notOk = doc["notOk"].GetBool(); } if (end == doc.FindMember("ok") || !doc["ok"].IsBool()) { return false; } else { ok = doc["ok"].GetBool(); } if (end != doc.FindMember("data")) { if(doc["data"].IsObject()){ T1 data; const rapidjson::Value& object = doc["data"]; if(!(data.jsonToObject(object))){ return false; } datas.push_back(data); }else if(doc["data"].IsArray()){ const rapidjson::Value& objs = doc["data"]; for (size_t i = 0; i < objs.Size(); i++) { const rapidjson::Value& obj = objs[i]; T1 data; if(!(data.jsonToObject(obj))){ return false; } datas.push_back(data); } } } if (end != doc.FindMember("extendData")) { if(doc["extendData"].IsObject()){ T2 extendData; const rapidjson::Value& object = doc["extendData"]; if(!(extendData.jsonToObject(object))){ return false; } extendDatas.push_back(extendData); }else if(doc["extendData"].IsArray()){ const rapidjson::Value& objs = doc["extendData"]; for (size_t i = 0; i < objs.Size(); ++i) { const rapidjson::Value& obj = objs[i]; T2 extendData; if(!(extendData.jsonToObject(obj))){ return false; } extendDatas.push_back(extendData); } } } if (end == doc.FindMember("ok")) { return false; } else { ok = doc["ok"].GetBool(); } return true; } int32_t ClearTable(std::string tableName) { vector> sqlRet; std::string sql = "truncate table MIVA_DB." + tableName; SqlWriter sqlTruncate(sql.c_str()); sqlTruncate << sqlRet; return OK; } };