| | |
| | | #define VSSLOCALSETTINGTBL_Sqlite_MANAGER_H
|
| | |
|
| | | #include "../model/VssLocalSettingTbl.h"
|
| | | #include "BaseDao.h"
|
| | | #include "BaseSqliteDao.h"
|
| | |
|
| | | #define VSSLocalSettingTbl_Sqlite_TABLE_NAME "VSSLocalSettingTbl"
|
| | |
|
| | |
| | | /**
|
| | | * 本地国标配置管理类
|
| | | */
|
| | | class VssLocalSettingTblSqliteDao : public BaseDao {
|
| | | class VssLocalSettingTblSqliteDao : public BaseSqliteDao {
|
| | | private:
|
| | | /** 本地国标配置构造函数 */
|
| | | VssLocalSettingTblSqliteDao() {}
|
| | | private:
|
| | | LDBTool* lDBTool;
|
| | |
|
| | | QSqlDatabase* m_db;
|
| | | QSqlTableModel *m_pModel;
|
| | | QMutex* m_mutexVisit;
|
| | | public:
|
| | | void setLDBTool(LDBTool* lDBTool) {
|
| | | this->lDBTool = lDBTool;
|
| | | this->m_db = lDBTool->get_m_db();
|
| | | this->m_pModel = lDBTool->get_m_pModel();
|
| | | this->m_mutexVisit = lDBTool->get_m_mutexVisit();
|
| | | }
|
| | | public:
|
| | | /** 本地国标配置单例模式 */
|
| | | static VssLocalSettingTblSqliteDao* instance() {
|
| | |
| | | QMutexLocker mutexLocker(m_mutexVisit);//TODO
|
| | | QSqlTableModel pModel(NULL, *m_db);
|
| | | pModel.setTable(VSSLocalSettingTbl_Sqlite_TABLE_NAME);
|
| | | for (auto whereKeyValue : whereKeyValues ) {
|
| | | pModel.setFilter(QObject::tr((string(whereKeyValue.first)+" = '%1'").c_str()).arg(QString::fromUtf8(whereKeyValue.second.c_str())));
|
| | | }
|
| | | pModel.setFilter(QObject::tr(getWhereColumnNameValuePair(whereKeyValues).c_str()));
|
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange
|
| | | pModel.select();
|
| | |
|
| | |
| | | Json::Value updateVssLocalSettingTbl(std::map<std::string, std::string>& keyValuesToUpdate,
|
| | | std::map<std::string, std::string>& whereKeyValues) {
|
| | | Json::Value responseJsonValue;
|
| | | responseJsonValue["message"] = "删除失败!";
|
| | | responseJsonValue["message"] = "更新失败!";
|
| | | responseJsonValue["success"] = "false";
|
| | | QMutexLocker mutexLocker(m_mutexVisit);//TODO
|
| | | QSqlTableModel pModel(NULL, *m_db);
|
| | | pModel.setTable(VSSLocalSettingTbl_Sqlite_TABLE_NAME);
|
| | | for (auto whereKeyValue : whereKeyValues) {
|
| | | pModel.setFilter(QObject::tr((whereKeyValue.first + " = '%1'").c_str()).arg(QString::fromStdString(whereKeyValue.second)));
|
| | | }
|
| | | pModel.setFilter(QObject::tr(getWhereColumnNameValuePair(whereKeyValues).c_str()));
|
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange
|
| | | pModel.select();
|
| | |
|
| | |
| | | if (pModel.submitAll()) {
|
| | | m_db->commit();//提交
|
| | | responseJsonValue["success"] = "true";
|
| | | responseJsonValue["message"] = "删除成功!";
|
| | | responseJsonValue["message"] = "更新成功!";
|
| | | } else {
|
| | | m_db->rollback();//回滚
|
| | | ERR("updateLDeviceTable ,pModel_load Error: " << pModel.lastError().text().toStdString());
|
| | |
| | | }
|
| | |
|
| | | /** 更新创建二级设备表 keyValuesToUpdate 需要更新的列名和列值对; whereKeyValues 列名和列值条件 */
|
| | | bool updateVssLocalSettingTbl(std::map<std::string, std::string>& keyValuesToUpdate,
|
| | | Json::Value updateVssLocalSettingTbl(std::map<std::string, std::string>& keyValuesToUpdate,
|
| | | string whereKey,
|
| | | string whereValue) {
|
| | | std::map<std::string, std::string> whereKeyValues;
|
| | | whereKeyValues[whereKey] = whereValue;
|
| | | return update(keyValuesToUpdate, VSSLocalSettingTbl_TABLE_NAME, whereKeyValues);
|
| | | return updateVssLocalSettingTbl(keyValuesToUpdate, whereKeyValues);
|
| | | }
|
| | |
|
| | | /** 查询本地国标配置列表 querySql 要查询的sql语句 */
|
| | |
| | | std::list<Record_Cut_Video_info> lst;
|
| | | QSqlTableModel pModel(NULL, *m_db);
|
| | | pModel.setTable(VSSLocalSettingTbl_Sqlite_TABLE_NAME);;
|
| | | for (auto whereKeyValue : whereKeyValues ) {
|
| | | pModel.setFilter(QObject::tr((string(whereKeyValue.first)+" = '%1'").c_str()).arg(QString::fromUtf8(whereKeyValue.second.c_str())));
|
| | | }
|
| | | pModel.setFilter(QObject::tr(getWhereColumnNameValuePair(whereKeyValues).c_str()));
|
| | | pModel.setEditStrategy(QSqlTableModel::OnManualSubmit);//OnManualSubmit OnFieldChange
|
| | | pModel.select();
|
| | |
|
| | |
| | | return findVssLocalSettingTblList(whereKeyValues);
|
| | | }
|
| | |
|
| | | /** 查询map列表 querySql 要查询的sql语句 */
|
| | | vector<map<string, string>> findMapList(string querySql) {
|
| | | return findList(querySql);
|
| | | }
|
| | |
|
| | | /** 执行sql语句 */
|
| | | bool execute(string sql) {
|
| | | return exec(move(sql));
|
| | | }
|
| | |
|
| | | /** map转model类 */
|
| | | VssLocalSettingTbl mapToModel(map<string, string>& rowData) {
|
| | | VssLocalSettingTbl vssLocalSettingTbl;
|
| | | string IDValue = rowData[VssLocalSettingTbl_ID];
|
| | | if (IDValue.length() != 0 && IDValue != "NULL") {
|
| | | vssLocalSettingTbl.ID = std::stoi(IDValue);
|
| | | }
|
| | | string ServerIpValue = rowData[VssLocalSettingTbl_ServerIp];
|
| | | if (ServerIpValue.length() != 0 && ServerIpValue != "NULL") {
|
| | | vssLocalSettingTbl.ServerIp = ServerIpValue;
|
| | | }
|
| | | string ServerPortValue = rowData[VssLocalSettingTbl_ServerPort];
|
| | | if (ServerPortValue.length() != 0 && ServerPortValue != "NULL") {
|
| | | vssLocalSettingTbl.ServerPort = ServerPortValue;
|
| | | }
|
| | | string ServerIdValue = rowData[VssLocalSettingTbl_ServerId];
|
| | | if (ServerIdValue.length() != 0 && ServerIdValue != "NULL") {
|
| | | vssLocalSettingTbl.ServerId = ServerIdValue;
|
| | | }
|
| | | string UserAuthIdValue = rowData[VssLocalSettingTbl_UserAuthId];
|
| | | if (UserAuthIdValue.length() != 0 && UserAuthIdValue != "NULL") {
|
| | | vssLocalSettingTbl.UserAuthId = UserAuthIdValue;
|
| | | }
|
| | | string PasswordValue = rowData[VssLocalSettingTbl_Password];
|
| | | if (PasswordValue.length() != 0 && PasswordValue != "NULL") {
|
| | | vssLocalSettingTbl.Password = PasswordValue;
|
| | | }
|
| | | string UpdateTimeValue = rowData[VssLocalSettingTbl_UpdateTime];
|
| | | if (UpdateTimeValue.length() != 0 && UpdateTimeValue != "NULL") {
|
| | | vssLocalSettingTbl.UpdateTime = UpdateTimeValue;
|
| | | }
|
| | | return vssLocalSettingTbl;
|
| | | }
|
| | |
|
| | | };
|
| | |
|