#include "RunHttpGet_selectIsMaterialsCabinetByCode.h"

#include "../user/config.h"
extern config *pconfig;


RunHttpGet_selectIsMaterialsCabinetByCode::RunHttpGet_selectIsMaterialsCabinetByCode(InteractiveTask *task, QMutex *mutex)
    : RunAbstract(task, mutex)
{

}



void RunHttpGet_selectIsMaterialsCabinetByCode::run()
{
    QByteArray outData = InteractiveHttp::http_get_selectIsMaterialsCabinetByCode();



    qDebug() << outData;

    // 解析 JSON 数据
    QJsonParseError parseError;
    QJsonDocument jsonDoc = QJsonDocument::fromJson(outData, &parseError);

    if (parseError.error != QJsonParseError::NoError)
    {
        qWarning() << "JSON 解析错误:" << parseError.errorString();
        return;
    }

    if (!jsonDoc.isObject())
    {
        qWarning() << "JSON 数据不是对象";
        return;
    }

    QJsonObject jsonObjRoot = jsonDoc.object();

    // 检查 code 字段
    if (jsonObjRoot["code"].toInt() == 200)
    {
        QJsonObject jsonObjData = jsonObjRoot["data"].toObject();
        QString cabinetId = jsonObjData.value("cabinetId").toString();

        pconfig->devId = cabinetId;
    }

}
