#include "RunMaterialExceptionRefreshListModel.h"
#include "InteractiveData.h"

#include "RunHttpGet_getIsMaterialsLoanExceptionPage.h"

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

}

void RunMaterialExceptionRefreshListModel::run()
{
    // 访问http
    RunHttpGet_getIsMaterialsLoanExceptionPage::http_get_getIsMaterialsLoanExceptionPage();

    InteractiveData *pSingletonData = SINGLETON_CREATE(InteractiveData)();

    // 清理缓存
    QMetaObject::invokeMethod(&pSingletonData->m_modelMaterialException, "clear", Qt::QueuedConnection);

    QReadLocker locker(&pSingletonData->m_dataCacheLock);

    for (int i = 0; i < pSingletonData->m_dataCacheMaterialLoadRfid.size(); ++i)
    {
        QString infoRfid = pSingletonData->m_dataCacheMaterialLoadRfid.at(i);

        QVariantMap info;
        info["materialsRfid"] = infoRfid;
        info["materialsName"] = pSingletonData->m_dataCacheMaterialLoanName[infoRfid].isEmpty() ?
            "未知物资" : pSingletonData->m_dataCacheMaterialLoanName[infoRfid];
        // info["materialsRfid"] = pSingletonData->m_dataCacheMaterialLoanRfid[infoId];
        info["materialsTypePicture"] = pSingletonData->m_dataCacheMaterialLoanTypePicture[infoRfid].isEmpty() ?
                 "qrc:/png/unknown.png" : pSingletonData->m_dataCacheMaterialLoanTypePicture[infoRfid];

        QMetaObject::invokeMethod(&pSingletonData->m_modelMaterialException, "append", Qt::QueuedConnection,
                                  Q_ARG(QVariantMap, info));


    }

}
