#include "SystemLocalDao.h"

SystemLocalDao::SystemLocalDao()
{

}

QList<QMap<QString, QVariant>> SystemLocalDao::getInfomationTableColumns(QString tableName)
{
    QSqlDatabase dbLocal = CDbConnectionPool::instance().openConnection("local");
    QSqlQuery query(dbLocal);

    QList<QMap<QString, QVariant>> resultList;

    // 查询用户
    QString sql = "SELECT id, table_name, column_idx, column_name, column_text, column_value, "
                  "column_width_type, column_width, column_align, column_resize_mode FROM "
                  "zd_table_column WHERE table_name = :tableName ORDER BY column_idx ASC";

    query.prepare(sql);
    query.bindValue(":tableName", tableName);

//    qDebug() << sql << tableName;

    if (query.exec()) {
        while (query.next()) {
            QMap<QString, QVariant> item;
            item.insert("idx", query.value("column_idx"));
            item.insert("name", query.value("column_name"));
            item.insert("text", query.value("column_text"));
            item.insert("value", query.value("column_value"));
            item.insert("widthType", query.value("column_width_type"));
            item.insert("width", query.value("column_width"));
            item.insert("align", query.value("column_align"));
            item.insert("resizeMode", query.value("column_resize_mode"));

            resultList.append(item);
        }
    } else {
        LogUtil::PrintLog("ERROR", QString("查询表格列属性失败[tableName=%1][%2]").arg(tableName).arg(query.lastError().text()));
    }

    return resultList;
}
