123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2021-11-03 15:16:14
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-05-13 10:11:19
- */
- #pragma once
- #include <iostream>
- #include <rapidjson/document.h>
- #include <rapidjson/rapidjson.h>
- #include <rapidjson/stringbuffer.h>
- #include <rapidjson/writer.h>
- #include <vector>
- #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;
- template <class T1, class T2>
- class NettyHttpResultMsg
- {
- public:
- std::string code;
- std::string msg;
-
- vector<T1> datas;
- vector<T2> 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<rapidjson::kParseCommentsFlag>(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);
- }
- }
- }
- return true;
- }
-
- int32_t ClearTable(std::string tableName)
- {
- return OK;
- }
- };
|