#include "RecognitionRecordsDao.h" RecognitionRecordsDao::RecognitionRecordsDao(QObject *parent) : BaseDao(parent) { } QVector<QVariantMap> RecognitionRecordsDao::findAllRecord() { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); // 查询语句 QString sql = "SELECT * FROM RECOGNITION_RECORDS"; // 执行查询 query.exec(sql); // 返回结果 QVector<QVariantMap> result; // 遍历查询结果 while (query.next()) { QVariantMap item; item.insert("id", query.value("id").toLongLong()); result.append(item); } // LOG_DEBUG(QString("查询RECOGNITION_RECORDS表的所有记录[记录数:%1]").arg(result.size()).toStdString()); return result; } QVariantMap RecognitionRecordsDao::findRecordById(QString id) { QVariantMap item; return item; } QString RecognitionRecordsDao::save(QVariantMap object) { // 新建查询 QSqlQuery query(ConnectionManager::getInstance()->getConnection()); qulonglong id = ConnectionManager::getInstance()->generateId(); // INSERT语句 QString sql = QString("INSERT INTO RECOGNITION_RECORDS (ID, PERSON_ID, DATETIME, REC_TYPE, DEV_CODE, DOOR_CODE, INOUT_TYPE) " "VALUES (:id, :personId, :datetime, :recType, :devCode, :doorCode, :inoutType)"); query.prepare(sql); query.bindValue(":id", id); query.bindValue(":personId", object.value("person_id").toString()); query.bindValue(":datetime", object.value("date_time").toString()); query.bindValue(":recType", object.value("rec_type").toString()); query.bindValue(":devCode", object.value("dev_code").toString()); query.bindValue(":doorCode", object.value("door_code").toString()); query.bindValue(":inoutType", object.value("inout_type").toString()); // 插入识别的log日志 QString logStr = QString("INSERT INTO RECOGNITION_LOG (ID, LOG_INFO) VALUES (:id, :logInfo)"); QSqlQuery logQuery(ConnectionManager::getInstance()->getConnection()); logQuery.prepare(logStr); logQuery.bindValue(":id", id); logQuery.bindValue(":logInfo", object.value("debug_info").toString()); // 开启事务 ConnectionManager::getInstance()->getConnection().transaction(); // 执行插入 bool success = query.exec(); logQuery.exec(); // 结束事务 ConnectionManager::getInstance()->getConnection().commit(); // 返回结果 if (success == true) { return QString("%1").arg(id); } else { return "-1"; } } bool RecognitionRecordsDao::edit(QVariantMap newObject, QString id) { return false; } bool RecognitionRecordsDao::dele(QString id) { return false; }