#include "RunViewRefresh_AbnormalReport.h"

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

}

void RunViewRefresh_AbnormalReport::run()
{
    InteractiveData *pSingletonData = SINGLETON_CREATE(InteractiveData)();
    QReadLocker locker(&pSingletonData->m_dataCacheLock);

    QJsonDocument jsonDoc;
    QJsonObject jsonObjRoot;

    QJsonArray jsonArrExceptionTypeDict;
    QJsonArray jsonArrSeverityLevelDict;

    for (int i = 0; i < pSingletonData->m_dataCacheExceptionTypeDictCode.size(); ++i)
    {
        QString code = pSingletonData->m_dataCacheExceptionTypeDictCode.at(i);
        jsonArrExceptionTypeDict.append( pSingletonData->m_dataCacheExceptionTypeDictLabel.value(code));
    }

    for (int i = 0; i < pSingletonData->m_dataCacheSeverityLevelDictCode.size(); ++i)
    {
        QString code = pSingletonData->m_dataCacheSeverityLevelDictCode.at(i);
        jsonArrSeverityLevelDict.append( pSingletonData->m_dataCacheSeverityLevelDictLabel.value(code));
    }

    jsonObjRoot.insert("ExceptionTypeDict", jsonArrExceptionTypeDict);
    jsonObjRoot.insert("SeverityLevelDict", jsonArrSeverityLevelDict);

    jsonDoc.setObject(jsonObjRoot);
    QByteArray json = jsonDoc.toJson(QJsonDocument::Compact);
    setRespond(json);
}
