123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959 |
- #include "include/httpthreadnum1.h"
- #include <QJsonArray>
- #include <QJsonDocument>
- #include <QJsonObject>
- TOnDevInfoChange callbackDevInfoChange;
- int EC_SetOnDevInfoChange(TOnDevInfoChange onChange, void* pUser);
- QString g_qsToken; //扩展
- QMutex g_QMutex_token;
- HttpThreadNum1::HttpThreadNum1()
- {
- //初始化postApi
- //在地址列表map中加入对应的地址
- //参数:数据类型和url地址
- m_HTN1MapApi.insert(EHTN1TYPE_LoginInfo, m_qsServiceUrl + "/token/api");
- m_HTN1MapApi.insert(EHTN1TYPE_GetAllCarState, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_DoStartUpCar, m_qsServiceUrl + "/v5/api");
- //新增接口
- m_HTN1MapApi.insert(EHTN1TYPE_ShutDownCar, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_RemoteRequest, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_DoStartWorkCar, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_AddCar, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_RenameCar, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_DeleteCar, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_TaskList, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_StopTask, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_CancelTask, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_GetSlagState, m_qsServiceUrl + "/v5/api");
- m_HTN1MapApi.insert(EHTN1TYPE_GetWarningState, m_qsServiceUrl + "/v5/api");
- //创建一个空的Qlist容器
- QList<QVariant> listTemp; //QVariant通用类型
- for (int i = 0; i < EHTN1TYPE_max; i++)
- {
- m_listStructReady.insert(i, listTemp);
- }
- }
- void HttpThreadNum1::init()
- {
- //使用qt自带的start启动线程
- this->start();
- }
- //适用于两种结构体类型所以使用void,传入后再分配强转成对应的类型
- //参数iType是QMap的键,structData是QMap的值列表中内容的地址
- //作用:将数据传入到双层容器中
- void HttpThreadNum1::postData(int iType, void* structData)
- {
- m_QMutex.lock();
-
- //创建一个接收QMap的值列表中的内容的变量
- QVariant qvariant;
- if (iType == EHTN1TYPE_LoginInfo)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_LoginInfo*)structData)); //将自定义结构体类型转换为QVariant类型
- }
- else if (iType == EHTN1TYPE_GetAllCarState)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_GetAllCarState*)structData));
- }
- else if (iType == EHTN1TYPE_DoStartUpCar)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_DoStartUpCar*)structData));
- }
- //新增双层容器加数据
- else if (iType == EHTN1TYPE_ShutDownCar)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_ShutDownCar*)structData));
- }
- else if (iType == EHTN1TYPE_RemoteRequest)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_RemoteRequest*)structData));
- }
- else if (iType == EHTN1TYPE_DoStartWorkCar)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_DoStartWorkCar*)structData));
- }
- else if (iType == EHTN1TYPE_AddCar)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_AddCar*)structData));
- }
- else if (iType == EHTN1TYPE_RenameCar)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_RenameCar*)structData));
- }
- else if (iType == EHTN1TYPE_DeleteCar)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_DeleteCar*)structData));
- }
- else if (iType == EHTN1TYPE_TaskList)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_TaskList*)structData));
- }
- else if (iType == EHTN1TYPE_StopTask)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_StopTask*)structData));
- }
- else if (iType == EHTN1TYPE_CancelTask)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_CancelTask*)structData));
- }
- else if (iType == EHTN1TYPE_GetSlagState)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_GetSlagState*)structData));
- }
- else if (iType == EHTN1TYPE_GetWarningState)
- {
- qvariant = QVariant::fromValue(*((S_HTN1_GetWarningState*)structData));
- }
- //使用下标操作符 [] 直接访问 QMap 中键为 iType 的值,该值是一个 QList<QVariant> 对象。
- //然后使用 append 函数将 qvariant 添加到该列表的末尾。
- //如果键 iType 在 m_listStructReady 中不存在,则会自动创建一个新的键值对,其中键为 iType,值为包含 qvariant 的新列表。
- m_listStructReady[iType].append(qvariant);
- m_QMutex.unlock();
- }
- void HttpThreadNum1::setToken(QString qsTok)
- {
- g_QMutex_token.lock();
- g_qsToken = qsTok;
- g_QMutex_token.unlock();
- }
- //初始化的时候调用,启动线程
- void HttpThreadNum1::run()
- {
- //为什么要创建 HttpClient 对象===为了可以在priPostData中调用HttpClient类的postQString方法
- HttpClient* m_pHttpClient = new HttpClient;
- while (true)
- {
- //创建一个临时的QMap映射容器存储请求数据队列
- QMap<int, QList<QVariant>> mapTemp;
- //清空全局的QMap映射容器,清空的时候加锁,防止和写入的时候冲突
- m_QMutex.lock();
- mapTemp = m_listStructReady;
- for (int i = 0; i < EHTN1TYPE_max; i++)
- {
- m_listStructReady[i].clear();
- }
- m_QMutex.unlock();
- //创建一个迭代器
- QMap<int, QList<QVariant>>::iterator iter;
-
- //遍历临时的QMap映射容器
- for (iter = mapTemp.begin(); iter != mapTemp.end(); iter++)
- {
- if (iter.value().count() > 0)
- {
- //遍历QList请求数据队列
- for (int i = 0; i < iter.value().count(); i++)
- {
- //将QMap中的所有内容全部发出去
- priPostData(iter.key(), iter.value()[i], m_pHttpClient);
- }
- }
- }
- msleep(10);
- }
- //TODO:回调
- //callbackDevInfoChange(iTemp,msg);
- }
- //将请求数据队列发送给服务器,并接收服务器返回的数据
- void HttpThreadNum1::priPostData(int iType, QVariant structData, void* voidPointer)
- {
- QVariant resultQVariant;
- //post请求数据
- //判断类型是登录消息类型
- if (iType == EHTN1TYPE_LoginInfo)
- {
- //创建一个结构体
- S_HTN1_LoginReturn resultStruct;
- //接收登录信息的内容
- S_HTN1_LoginInfo structTemp = structData.value<S_HTN1_LoginInfo>();
- //设置错误字段
- QString qsError = "出错";
- //设置接收到的字符串变量
- QString qsRevData = "";
- //实际上发过去的是string,使用json转是为了方便拼接
- QJsonObject qjsonObject;
- qjsonObject.insert("username", structTemp.username);
- qjsonObject.insert("password", structTemp.password);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- //postQString中传入url地址,登录的账号密码qstring类型的数据,报错信息,接收到的字符串
- //postQString返回为true的时候执行
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- //将接收到的json数据保存到json文件中
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- //这里也可以不用做错误判断
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- //将json对象中的内容传入结构体resultStruct中
- if (object.contains("message"))
- {
- resultStruct.message = object.value("message").toVariant().toString();
- }
- if (object.contains("uid"))
- {
- resultStruct.uid = object.value("uid").toVariant().toString();
- }
- if (object.contains("role_name"))
- {
- resultStruct.role_name = object.value("role_name").toVariant().toString();
- }
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- }
- }
- //将结构体转换为QVariant类型
- emit sig_result(EHTN1TYPE_LoginReturn, QVariant::fromValue(*((S_HTN1_LoginReturn*)&resultStruct)));
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_LoginReturn, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_GetAllCarState)
- {
- S_HTN1_ReturnAllCarState resultStruct;
- S_HTN1_GetAllCarState structTemp = structData.value<S_HTN1_GetAllCarState>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError))
- { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- //数组的转成document固定写法
- QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant());
- // if (variant.type() == QVariant::String) {
- if (!doucment2.isArray())
- {
- qDebug() << "不是数组";
- }
- //数组
- QJsonArray tempQJsonArray = doucment2.array();
- for (int i = 0; i < tempQJsonArray.count(); i++)
- {
- // 解析未发生错误
- if (tempQJsonArray[i].isObject())
- {
- if (tempQJsonArray[i].isObject()) { // JSON文档为对象
- S_HTN1_ReturnOneCarState sOneStruct;
- QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象
- if (object.contains("uuid"))
- {
- sOneStruct.uuid = object.value("uuid").toVariant().toString();
- }
- if (object.contains("name"))
- {
- sOneStruct.name = object.value("name").toVariant().toString();
- }
- if (object.contains("state"))
- {
- sOneStruct.state = object.value("state").toVariant().toInt();
- }
- if (object.contains("check_vehicle_direction"))
- {
- sOneStruct.check_vehicle_direction = object.value("check_vehicle_direction").toVariant().toBool();
- }
- if (object.contains("address"))
- {
- sOneStruct.address = object.value("address").toVariant().toString();
- }
- if (object.contains("current_vehicle_direction"))
- {
- sOneStruct.current_vehicle_direction = object.value("current_vehicle_direction").toVariant().toInt();
- }
- if (object.contains("current_vehicle_weight"))
- {
- sOneStruct.current_vehicle_weight = object.value("current_vehicle_weight").toVariant().toInt();
- }
- if (object.contains("vehicle_pot_state"))
- {
- sOneStruct.vehicle_pot_state = object.value("vehicle_pot_state").toVariant().toInt();
- }
- resultStruct.data.append(sOneStruct);
- }
- }
- }
- // }
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnAllCarState, QVariant::fromValue(*((S_HTN1_ReturnAllCarState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnAllCarState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_DoStartUpCar)
- {
- S_HTN1_ReturnStartUpState resultStruct;
- S_HTN1_DoStartUpCar structTemp = structData.value<S_HTN1_DoStartUpCar>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("uuid", structTemp.uuid);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- resultStruct.data = object.value("data").toVariant().toString();
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnStartUpState, QVariant::fromValue(*((S_HTN1_ReturnStartUpState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnStartUpState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_ShutDownCar)
- {
- S_HTN1_ReturnShutDownState resultStruct;
- S_HTN1_ShutDownCar structTemp = structData.value<S_HTN1_ShutDownCar>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("uuid", structTemp.uuid);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- resultStruct.data = object.value("data").toVariant().toString();
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnShutDownState, QVariant::fromValue(*((S_HTN1_ReturnShutDownState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnShutDownState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_RemoteRequest)
- {
- S_HTN1_ReturnRemoteRequestState resultStruct;
- S_HTN1_RemoteRequest structTemp = structData.value<S_HTN1_RemoteRequest>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("uuid", structTemp.uuid);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- resultStruct.data = object.value("data").toVariant().toString();
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnRemoteRequestState, QVariant::fromValue(*((S_HTN1_ReturnRemoteRequestState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnRemoteRequestState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_DoStartWorkCar)
- {
- S_HTN1_ReturnDoStartWorkState resultStruct;
- S_HTN1_DoStartWorkCar structTemp = structData.value<S_HTN1_DoStartWorkCar>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("uuid", structTemp.uuid);
- qjsonObject.insert("task_type", structTemp.task_type);
- qjsonObject.insert("target_point_name", structTemp.target_point_name);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- resultStruct.data = object.value("data").toVariant().toString();
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnStartWorkState, QVariant::fromValue(*((S_HTN1_ReturnDoStartWorkState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnStartWorkState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_AddCar)
- {
- S_HTN1_ReturnAddCarState resultStruct;
- S_HTN1_AddCar structTemp = structData.value<S_HTN1_AddCar>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("name", structTemp.name);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- resultStruct.data = object.value("data").toVariant().toString();
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnAddCarState, QVariant::fromValue(*((S_HTN1_ReturnAddCarState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnAddCarState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_RenameCar)
- {
- S_HTN1_ReturnReanmeCarState resultStruct;
- S_HTN1_RenameCar structTemp = structData.value<S_HTN1_RenameCar>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("uuid", structTemp.uuid);
- qjsonObject.insert("name", structTemp.name);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- //数组的转成document固定写法
- QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant());
- //数组
- QJsonArray tempQJsonArray = doucment2.array();
- for (int i = 0; i < tempQJsonArray.count(); i++)
- {
- // 解析未发生错误
- if (tempQJsonArray[i].isObject())
- {
- if (tempQJsonArray[i].isObject()) { // JSON文档为对象
- S_HTN1_ReturnReanmeCarState_data sOneStruct;
- QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象
- if (object.contains("uuid"))
- {
- sOneStruct.uuid = object.value("uuid").toVariant().toString();
- }
- if (object.contains("name"))
- {
- sOneStruct.name = object.value("name").toVariant().toString();
- }
- if (object.contains("update_at"))
- {
- sOneStruct.update_at = object.value("update_at").toVariant().toInt();
- }
- resultStruct.data.append(sOneStruct);
- }
- }
- }
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnRenameCarState, QVariant::fromValue(*((S_HTN1_ReturnReanmeCarState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnRenameCarState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_DeleteCar)
- {
- S_HTN1_ReturnDeleteCarState resultStruct;
- S_HTN1_DeleteCar structTemp = structData.value<S_HTN1_DeleteCar>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("uuid", structTemp.uuid);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- resultStruct.data = object.value("data").toVariant().toString();
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnDeleteCarState, QVariant::fromValue(*((S_HTN1_ReturnDeleteCarState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnDeleteCarState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_TaskList)
- {
- S_HTN1_ReturnTaskListData resultStruct;
- S_HTN1_TaskList structTemp = structData.value<S_HTN1_TaskList>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("page", structTemp.page);
- qjsonObject.insert("size", structTemp.size);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("page"))
- {
- resultStruct.page = object.value("page").toVariant().toInt();
- }
- if (object.contains("size"))
- {
- resultStruct.size = object.value("size").toVariant().toInt();
- }
- if (object.contains("total"))
- {
- resultStruct.total = object.value("total").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- //数组的转成document固定写法
- QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant());
- //数组
- QJsonArray tempQJsonArray = doucment2.array();
- for (int i = 0; i < tempQJsonArray.count(); i++)
- {
- // 解析未发生错误
- if (tempQJsonArray[i].isObject())
- {
- if (tempQJsonArray[i].isObject()) { // JSON文档为对象
- S_HTN1_ReturnTaskListData_data sOneStruct;
- QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象
- if (object.contains("uuid"))
- {
- sOneStruct.uuid = object.value("uuid").toVariant().toString();
- }
- if (object.contains("vehicle_uuid"))
- {
- sOneStruct.vehicle_uuid = object.value("vehicle_uuid").toVariant().toString();
- }
- if (object.contains("task_type"))
- {
- sOneStruct.task_type = object.value("task_type").toVariant().toInt();
- }
- if (object.contains("target_point_name"))
- {
- sOneStruct.target_point_name = object.value("target_point_name").toVariant().toString();
- }
- if (object.contains("task_state"))
- {
- sOneStruct.task_state = object.value("task_state").toVariant().toInt();
- }
- if (object.contains("create_at"))
- {
- sOneStruct.create_at = object.value("create_at").toVariant().toInt();
- }
- resultStruct.data.append(sOneStruct);
- }
- }
- }
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnTaskListData, QVariant::fromValue(*((S_HTN1_ReturnTaskListData*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnTaskListData, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_StopTask)
- {
- S_HTN1_ReturnStopTask resultStruct;
- S_HTN1_StopTask structTemp = structData.value<S_HTN1_StopTask>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("uuid", structTemp.uuid);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- resultStruct.data = object.value("data").toVariant().toString();
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnStopTask, QVariant::fromValue(*((S_HTN1_ReturnStopTask*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnStopTask, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_CancelTask)
- {
- S_HTN1_ReturnCancelTask resultStruct;
- S_HTN1_CancelTask structTemp = structData.value<S_HTN1_CancelTask>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- qjsonObject.insert("uuid", structTemp.uuid);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- resultStruct.data = object.value("data").toVariant().toString();
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnCancelTask, QVariant::fromValue(*((S_HTN1_ReturnCancelTask*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnCancelTask, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_GetSlagState)
- {
- S_HTN1_ReturnSlagState resultStruct;
- S_HTN1_GetSlagState structTemp = structData.value<S_HTN1_GetSlagState>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- //数组的转成document固定写法
- QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant());
- //数组
- QJsonArray tempQJsonArray = doucment2.array();
- for (int i = 0; i < tempQJsonArray.count(); i++)
- {
- // 解析未发生错误
- if (tempQJsonArray[i].isObject())
- {
- if (tempQJsonArray[i].isObject()) { // JSON文档为对象
- S_HTN1_ReturnSlagState_data sOneStruct;
- QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象
- if (object.contains("pot_name"))
- {
- sOneStruct.pot_name = object.value("pot_name").toVariant().toString();
- }
- if (object.contains("pot_status"))
- {
- sOneStruct.pot_status = object.value("pot_status").toVariant().toInt();
- }
- if (object.contains("pot_number"))
- {
- sOneStruct.pot_number = object.value("pot_number").toVariant().toInt();
- }
- resultStruct.data.append(sOneStruct);
- }
- }
- }
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnSlagState, QVariant::fromValue(*((S_HTN1_ReturnSlagState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnSlagState, EHTN1TYPE_error);
- }
- }
- else if (iType == EHTN1TYPE_GetWarningState)
- {
- S_HTN1_ReturnWarningState resultStruct;
- S_HTN1_GetWarningState structTemp = structData.value<S_HTN1_GetWarningState>();
- QString qsError = "出错";
- QString qsRevData = "";
- QJsonObject qjsonObject;
- // qDebug()<<structTemp->code;
- qjsonObject.insert("code", structTemp.code);
- QString qsPostData(QJsonDocument(qjsonObject).toJson()); //qjson转qstring
- if (((HttpClient*)voidPointer)->postQString(m_HTN1MapApi[iType], qsPostData, &qsError, &qsRevData))
- {
- QJsonParseError jsonError;
- QJsonDocument doucment = QJsonDocument::fromJson(qsRevData.toUtf8().data());
- if (!doucment.isNull() && (jsonError.error == QJsonParseError::NoError)) { // 解析未发生错误
- if (doucment.isObject()) { // JSON 文档为对象
- QJsonObject object = doucment.object(); // 转化为对象
- if (object.contains("code"))
- {
- resultStruct.code = object.value("code").toVariant().toInt();
- }
- if (object.contains("data"))
- {
- //数组的转成document固定写法
- QJsonDocument doucment2 = QJsonDocument::fromVariant(object.value("data").toVariant());
- //数组
- QJsonArray tempQJsonArray = doucment2.array();
- for (int i = 0; i < tempQJsonArray.count(); i++)
- {
- // 解析未发生错误
- if (tempQJsonArray[i].isObject())
- {
- if (tempQJsonArray[i].isObject()) { // JSON文档为对象
- S_HTN1_ReturnWarningState_data sOneStruct;
- QJsonObject object = tempQJsonArray[i].toObject(); //转化为对象
- if (object.contains("message"))
- {
- sOneStruct.message = object.value("message").toVariant().toString();
- }
- if (object.contains("create_at"))
- {
- sOneStruct.create_at = object.value("create_at").toVariant().toInt();
- }
- resultStruct.data.append(sOneStruct);
- }
- }
- }
- }
- }
- }
- emit sig_result(EHTN1TYPE_ReturnWarningState, QVariant::fromValue(*((S_HTN1_ReturnWarningState*)&resultStruct)));
- // qDebug()<<"http列表成功"<<qsRevData;
- }
- else
- {
- // qDebug()<<"连接失败"<<"发送连接失败信号";
- emit sig_result(EHTN1TYPE_ReturnWarningState, EHTN1TYPE_error);
- }
- }
- }
- //回调函数,暂时没有用
- int EC_SetOnDevInfoChange(TOnDevInfoChange onChange, void* pUser)
- {
- void* m_DevInfoUser = pUser;
- callbackDevInfoChange = onChange;
- printf("nnnn");
- return 0;
- }
|