#include "limitupstockdecoder.h"
#include <QDebug>

LimitUpStockDecoder::LimitUpStockDecoder()
{

}

void LimitUpStockDecoder::decode(QList<QList<QVariant> > edatas,QString date)
{
    if(edatas.count() <= 1)
        return;
    QList<QVariant> headDatas = edatas.at(0);
    data.clear();
    parseStockHead(headDatas);
    qDebug() << " datas count :" << edatas.count();
    for (int row = 1; row < edatas.count();row++)
    {
        QList<QVariant> rowData = edatas.at(row);
        _limitUpStocksInfo param;
        for(int column = 0; column < rowData.count() ; column++)
        {
            if(rowData.at(column).toString().isEmpty())
            {
                qDebug() << "break";
                break;
            }
            if(m_wholeStocksKeyIndexs.value(column) == "code")
                param.code = rowData.at(column).toString();
            else if(m_wholeStocksKeyIndexs.value(column) == "tradeDay")
                param.tradeDay = rowData.at(column).toString();
        }
        if(param.code.isEmpty())
            continue;
        data.append(param);
    }

}

QString LimitUpStockDecoder::parseStockHead(QList<QVariant> headDatas)
{
    QString tradeDay = "";//暂时不查询交易日期
    for(int i = 0; i < headDatas.count(); i++)
    {
        QVariant value = headDatas[i];
        QString headValue = value.toString();
        if(headValue.contains(QStringLiteral("代码")))
        {
            m_wholeStocksKeyIndexs.insert(i,"code");
        }
        else if(headValue.contains(QStringLiteral("简称")))
        {
            m_wholeStocksKeyIndexs.insert(i,"name");
        }
        else if(headValue.contains(QStringLiteral("收盘价")))
        {
            m_wholeStocksKeyIndexs.insert(i,"close");
        }
        else if(headValue.contains(QStringLiteral("所属东财行业指数")) )
        {
            m_wholeStocksKeyIndexs.insert(i,"blemind2");
        }
        else if(headValue.contains(QStringLiteral("所属东财")) &&
                !headValue.contains(QStringLiteral("所属东财行业指数")))
        {
            m_wholeStocksKeyIndexs.insert(i,"blemind3");
        }
        else if(headValue.contains(QStringLiteral("日期")))
        {
            m_wholeStocksKeyIndexs.insert(i,"tradeDay");
        }
        qDebug() << "parseLimitUpStockHead : " <<m_wholeStocksKeyIndexs[i];
    }
    return tradeDay;
}

