#include "DBServiceSet.h" #include "SqlDBHelper.h" #include DBServiceSet::DBServiceSet(QObject *parent) { } //////////////////////common-start//////////////////// int DBServiceSet::getNextId(QString tableName) { int nextId = -1; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT seq from sqlite_sequence WHERE name = '%1'").arg(tableName); QueryResult queryResult = t.execQuery(selectSql); if (queryResult.next()) { nextId = queryResult.value(0).toInt() + 1; } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return nextId; } //////////////////////common-end//////////////////// //////////////////////节点权重值持久化-start//////////////////// bool DBServiceSet::AddNodeWeightInfo(const DemandWeight &demandWeight) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); InsertQuery q = t.insertInto("t_demand_weight (engineer_id,expert_id, node_name, node_weight, " "node_value,table_index )"); q.values(demandWeight.engineerId, demandWeight.expertId, demandWeight.nodeName, demandWeight.nodeWeight, demandWeight.nodeValue, demandWeight.tableIndex) .exec(); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } /*批量节点信息新增*/ bool DBServiceSet::AddNodeWeightInfoList(const QList &demandWeightList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); for (int i = 0; i < demandWeightList.length(); i++) { DemandWeight *demandWeight = demandWeightList.at(i); InsertQuery q = t.insertInto("t_demand_weight (engineer_id,expert_id, node_name, node_weight, " "node_value,table_index,table_msg,is_valid,page_index )"); q.values(demandWeight->engineerId, demandWeight->expertId, demandWeight->nodeName, demandWeight->nodeWeight, demandWeight->nodeValue, demandWeight->tableIndex, demandWeight->tableMsg, demandWeight->isValid, demandWeight->pageIndex) .exec(); t.commit(); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } /*修改节点值*/ bool DBServiceSet::UpdateNodeValue(const DemandWeight &demandWeight) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_demand_weight") .set("NODE_VALUE", demandWeight.nodeValue) .set("NODE_WEIGHT", demandWeight.nodeWeight) .where("ENGINEER_ID = ? and expert_id = ? and node_name = ? ", demandWeight.engineerId, demandWeight.expertId, demandWeight.nodeName); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateNodeValueList(const QList demandWeightList) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; for (int i = 0; i < demandWeightList.length(); i++) { DemandWeight *demandWeight = demandWeightList.at(i); QString updateSql = QString("UPDATE t_demand_weight SET NODE_VALUE ='%1' , NODE_WEIGHT = '%2' " "WHERE ENGINEER_ID =%3 AND expert_id =%4" " AND node_name = '%5' AND table_index =%6 and table_msg ='%7' and page_index=%8") .arg(demandWeight->nodeValue) .arg(demandWeight->nodeWeight) .arg(demandWeight->engineerId) .arg(demandWeight->expertId) .arg(demandWeight->nodeName) .arg(demandWeight->tableIndex) .arg(demandWeight->tableMsg) .arg(demandWeight->pageIndex); // qDebug() << updateSql; query.exec(updateSql); ret = true; } return ret; } bool DBServiceSet::QueryByTableIndexAndTableMsg(int expertId, int engineerId, int tableIndex, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "=%1 and engineer_id =%2 and table_index=%3 and table_msg='%4'") .arg(QString::number(expertId)) .arg(QString::number(engineerId)) .arg(QString::number(tableIndex)) .arg(tableMsg); // qDebug() << "sql===" << selectSql; if (query.exec(selectSql)) { if (query.next()) { ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryByTableIndexAndTableMsg(QString expertId, int engineerId, int tableIndex, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "='%1' and engineer_id =%2 and table_index=%3 and table_msg='%4'") .arg(expertId) .arg(QString::number(engineerId)) .arg(QString::number(tableIndex)) .arg(tableMsg); // qDebug() << "sql===" << selectSql; if (query.exec(selectSql)) { if (query.next()) { ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryByTableIndexAndTableMsgAndPage(QString expertId, int engineerId, int tableIndex, QString tableMsg, int page) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "='%1' and engineer_id =%2 and table_index=%3 and table_msg='%4' and page_index=%5") .arg(expertId) .arg(QString::number(engineerId)) .arg(QString::number(tableIndex)) .arg(tableMsg) .arg(page); // qDebug() << "sql===" << selectSql; if (query.exec(selectSql)) { if (query.next()) { ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryByTableIndexAndTableMsg(QList *demandWeightList, int expertId, int engineerId, int tableIndex, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "=%1 and engineer_id =%2 and table_index=%3 and table_msg='%4'") .arg(QString::number(expertId)) .arg(QString::number(engineerId)) .arg(QString::number(tableIndex)) .arg(tableMsg); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeight->tableMsg = query.value(7).toString(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryByTableIndexAndTableMsg(QList *demandWeightList, QString expertId, int engineerId, int tableIndex, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "='%1' and engineer_id =%2 and table_index=%3 and table_msg='%4'") .arg(expertId) .arg(QString::number(engineerId)) .arg(QString::number(tableIndex)) .arg(tableMsg); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeight->tableMsg = query.value(7).toString(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryByPageIndexAndTableMsg(QList *demandWeightList, QString expertId, int engineerId, int pageIndex, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "='%1' and engineer_id =%2 and page_index=%3 and table_msg='%4'") .arg(expertId) .arg(QString::number(engineerId)) .arg(QString::number(pageIndex)) .arg(tableMsg); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeight->tableMsg = query.value(7).toString(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::updateValidByExperIdAndEngineerId(int expertId, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; try { QString updateSql = QString("UPDATE t_demand_weight SET is_valid =1 " "WHERE ENGINEER_ID =%1 AND expert_id =%2") .arg(engineerId) .arg(expertId); // qDebug() << updateSql; query.exec(updateSql); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryFirstDemandWeightByEngineerId(QList *demandWeightList, int expertId, int engineerId, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "=%1 and engineer_id =%2 and table_msg = " "'%3' and table_index = 0") .arg(QString::number(expertId)) .arg(QString::number(engineerId)) .arg(tableMsg); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryLastDemandWeightByEngineerId(QList *demandWeightList, int expertId, int engineerId, QString tableMsg, int tableIndex) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "=%1 and engineer_id =%2 and table_msg = " "'%3' and table_index = %4") .arg(QString::number(expertId)) .arg(QString::number(engineerId)) .arg(tableMsg) .arg(QString::number(tableIndex)); qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryFirstDemandWeightByEngineerId(QList *demandWeightList, QString expertId, int engineerId, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "='%1' and engineer_id =%2 and table_msg = " "'%3' and table_index = 0") .arg(expertId) .arg(QString::number(engineerId)) .arg(tableMsg); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryLastPageDemandWeightByEngineerId(QList *demandWeightList, QString expertId, int engineerId, QString tableMsg, int page) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "='%1' and engineer_id =%2 and table_msg = " "'%3' and page_index = %4") .arg(expertId) .arg(QString::number(engineerId)) .arg(tableMsg) .arg(page); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QuerySecondDemandWeightByEngineerId(QList *demandWeightList, int expertId, int engineerId, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "=%1 and engineer_id =%2 and table_msg = " "'%3' and table_index != 0") .arg(QString::number(expertId)) .arg(QString::number(engineerId)) .arg(tableMsg); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QuerySecondDemandWeightByEngineerIdAndMaxPage(QList *demandWeightList, int expertId, int engineerId, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "=%1 and engineer_id =%2 and table_msg = " "'%3' and page_index = (select max(page_index) from t_demand_weight where expert_id " "=%1 and engineer_id =%2 and table_msg = '%3' ) order by table_index ") .arg(QString::number(expertId)) .arg(QString::number(engineerId)) .arg(tableMsg); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QuerySecondDemandWeightByEngineerId(QList *demandWeightList, QString expertId, int engineerId, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_demand_weight where expert_id " "='%1' and engineer_id =%2 and table_msg = " "'%3' and table_index != 0") .arg(expertId) .arg(QString::number(engineerId)) .arg(tableMsg); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { DemandWeight *demandWeight = new DemandWeight(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeight->nodeWeight = query.value(5).toDouble(); demandWeight->tableIndex = query.value(6).toInt(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } //////////////////////common-end//////////////////// /////////////////////方案持久化-start//////////////// bool DBServiceSet::AddSchemeInfoList(const QList &schemeList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); for (int i = 0; i < schemeList.length(); i++) { SchemaEval *scheme = schemeList.at(i); InsertQuery q = t.insertInto("t_scheme_info (engineer_id,name,remark,value_str,score)"); q.values(scheme->engineerId, scheme->name, scheme->remark, scheme->valueStr, scheme->score).exec(); t.commit(); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::DeleteSchemeByEngineerId(int engineerId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.deleteFrom("t_scheme_info").where("engineer_id = ?", engineerId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QuerySchemeInfoByEngineerId(QList *schemeList, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,engineer_id,name,remark,value_str " ",score from t_scheme_info where " " engineer_id =%1 ") .arg(QString::number(engineerId)); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { SchemaEval *scheme = new SchemaEval(); scheme->id = query.value(0).toInt(); scheme->engineerId = query.value(1).toInt(); scheme->name = query.value(2).toString(); scheme->remark = query.value(3).toString(); scheme->valueStr = query.value(4).toString(); scheme->score = query.value(5).toDouble(); schemeList->append(scheme); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } ///////////////////////common-end///////////////////// //////////////////////技术重要度持久化-start//////////////////// bool DBServiceSet::AddTechnicalImportInfo(const TechnicalImport &technicalImport) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); InsertQuery q = t.insertInto("t_technical_import (engineer_id,expert_id,node_name,node_value)"); q.values(technicalImport.engineerId, technicalImport.expertId, technicalImport.nodeName, technicalImport.nodeValue) .exec(); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } /*批量节点信息新增*/ bool DBServiceSet::AddTechnicalImportInfoList(const QList &technicalImportList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); for (int i = 0; i < technicalImportList.length(); i++) { TechnicalImport *technical = technicalImportList.at(i); InsertQuery q = t.insertInto("t_technical_import (engineer_id,expert_id,node_name,node_value)"); q.values(technical->engineerId, technical->expertId, technical->nodeName, technical->nodeValue).exec(); t.commit(); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateTechnicalImportInfoList(const QList technicalImportList) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; for (int i = 0; i < technicalImportList.length(); i++) { TechnicalImport *demandWeight = technicalImportList.at(i); QString updateSql = QString("UPDATE t_technical_import SET NODE_VALUE ='%1' " "WHERE ENGINEER_ID =%2 AND expert_id =%3" " AND node_name = '%4' ") .arg(demandWeight->nodeValue) .arg(demandWeight->engineerId) .arg(demandWeight->expertId) .arg(demandWeight->nodeName); // qDebug() << updateSql; query.exec(updateSql); ret = true; } return ret; } bool DBServiceSet::QueryTechnicalImportInfoByEngineerId(QList *demandWeightList, int expertId, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_technical_import where " "expert_id =%1 and engineer_id =%2 ") .arg(QString::number(expertId)) .arg(QString::number(engineerId)); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { TechnicalImport *demandWeight = new TechnicalImport(); demandWeight->id = query.value(0).toInt(); demandWeight->engineerId = query.value(1).toInt(); demandWeight->expertId = query.value(2).toInt(); demandWeight->nodeName = query.value(3).toString(); demandWeight->nodeValue = query.value(4).toDouble(); demandWeightList->append(demandWeight); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryTechnicalImportInfoByEngineerId(int expertId, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select * from t_technical_import where " "expert_id =%1 and engineer_id =%2 ") .arg(QString::number(expertId)) .arg(QString::number(engineerId)); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { if (query.next()) { ret = true; } } else { qDebug() << query.lastError(); } return ret; } //////////////////////common-end//////////////////// //////////////////////节点矩阵信息表-start//////////////////// bool DBServiceSet::AddNodeMatrixInfo(const NodeMatrixInfo &nodeMatrixInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); InsertQuery q = t.insertInto("t_node_matrix_info (expert_name, engineer_id, node, " "abscissa, ordinate, " "node_value, expert_id,mind_name,write_date,mark)"); q.values(nodeMatrixInfo.expertName, nodeMatrixInfo.engineerId, nodeMatrixInfo.node, nodeMatrixInfo.abscissa, nodeMatrixInfo.ordinate, nodeMatrixInfo.nodeValue, nodeMatrixInfo.expertId, nodeMatrixInfo.mindId, nodeMatrixInfo.writeDate.toString(), nodeMatrixInfo.mark) .exec(); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } /*批量节点信息新增*/ bool DBServiceSet::AddNodeMatrixInfoList(const QList &jbInfoList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); for (int i = 0; i < jbInfoList.length(); i++) { NodeMatrixInfo *nodeMatrixInfo = jbInfoList.at(i); InsertQuery query = t.insertInto("t_node_matrix_info (expert_name, engineer_id, node, abscissa, " "ordinate, " "node_value, expert_id,mind_id,write_date,mark,table_msg)"); query.values(nodeMatrixInfo->expertName, nodeMatrixInfo->engineerId, nodeMatrixInfo->node, nodeMatrixInfo->abscissa, nodeMatrixInfo->ordinate, nodeMatrixInfo->nodeValue, nodeMatrixInfo->expertId, nodeMatrixInfo->mindId, nodeMatrixInfo->writeDate.toString(), nodeMatrixInfo->mark, nodeMatrixInfo->tableMsg) .exec(); t.commit(); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } /*批量节点信息新增----专家端*/ bool DBServiceSet::AddNodeMatrixInfoList2(const QList &jbInfoList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase2()); for (int i = 0; i < jbInfoList.length(); i++) { NodeMatrixInfo *nodeMatrixInfo = jbInfoList.at(i); InsertQuery query = t.insertInto("t_node_matrix_info (expert_name, engineer_id, node, abscissa, " "ordinate, " "node_value, expert_id,mind_id,write_date,mark,table_msg,tab_index)"); query.values(nodeMatrixInfo->expertName, nodeMatrixInfo->engineerId, nodeMatrixInfo->node, nodeMatrixInfo->abscissa, nodeMatrixInfo->ordinate, nodeMatrixInfo->nodeValue, nodeMatrixInfo->expertId, nodeMatrixInfo->mindId, nodeMatrixInfo->writeDate.toString(), nodeMatrixInfo->mark, nodeMatrixInfo->tableMsg, nodeMatrixInfo->tabIndex) .exec(); t.commit(); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } /*修改节点值*/ bool DBServiceSet::UpdateNodeMatrixNodeValue(const NodeMatrixInfo &nodeMatrixInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_node_matrix_info") .set("NODE_VALUE", nodeMatrixInfo.nodeValue) .where("ENGINEER_ID = ? and expert_name = and abscissa = ? and " "ordinate = ? ", nodeMatrixInfo.engineerId, nodeMatrixInfo.expertName, nodeMatrixInfo.abscissa, nodeMatrixInfo.ordinate); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateNodeMatrixNodeValueList(const QList jbInfoList) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; for (int i = 0; i < jbInfoList.length(); i++) { NodeMatrixInfo *nodeMatrixInfo = jbInfoList.at(i); QString updateSql = QString("UPDATE t_node_matrix_info SET NODE_VALUE ='%1' WHERE " "ENGINEER_ID = %2 AND expert_name = '%3'" " AND abscissa = '%4' AND ordinate = '%5' and table_msg = '%6' " "and mark = '%7'") .arg(nodeMatrixInfo->nodeValue) .arg(nodeMatrixInfo->engineerId) .arg(nodeMatrixInfo->expertName) .arg(nodeMatrixInfo->abscissa) .arg(nodeMatrixInfo->ordinate) .arg(nodeMatrixInfo->tableMsg) .arg(nodeMatrixInfo->mark); // qDebug() << updateSql; query.exec(updateSql); ret = true; } return ret; } bool DBServiceSet::UpdateNodeMatrixNodeValueList2(const QList jbInfoList) { QSqlDatabase db = SqlDBHelper::getDatabase2(); QSqlQuery query(db); bool ret = false; for (int i = 0; i < jbInfoList.length(); i++) { NodeMatrixInfo *nodeMatrixInfo = jbInfoList.at(i); QString updateSql = QString("UPDATE t_node_matrix_info SET NODE_VALUE ='%1' WHERE " "ENGINEER_ID = %2 AND expert_name = '%3'" " AND abscissa = '%4' AND ordinate = '%5' and table_msg = '%6' " "and mark = '%7' and tab_index = '%8'") .arg(nodeMatrixInfo->nodeValue) .arg(nodeMatrixInfo->engineerId) .arg(nodeMatrixInfo->expertName) .arg(nodeMatrixInfo->abscissa) .arg(nodeMatrixInfo->ordinate) .arg(nodeMatrixInfo->tableMsg) .arg(nodeMatrixInfo->mark) .arg(nodeMatrixInfo->tabIndex); // qDebug() << updateSql; query.exec(updateSql); ret = true; } return ret; } /*根据专家姓名和工程id获取节点信息*/ bool DBServiceSet::QueryNodeMatrixListByExpertNameAndEngineerId(QString expertName, int engineerId, QString tableMsg, QString mark) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_id,write_date from " "t_node_matrix_info where expert_name " "= '%1' and engineer_id ='%2' and table_msg='%3' and mark = '%4'") .arg(expertName) .arg(QString::number(engineerId)) .arg(tableMsg) .arg(mark); if (query.exec(selectSql)) { if (query.next()) { ret = true; } } else { qDebug() << query.lastError(); } qDebug() << ret; return ret; } /*根据专家姓名和工程id获取节点信息*/ bool DBServiceSet::QueryNodeMatrixListByExpertIdAndEngineerId(QString expertId, int engineerId, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_id,write_date from " "t_node_matrix_info where expert_id " "= '%1' and engineer_id ='%2' and table_msg='%3'") .arg(expertId) .arg(QString::number(engineerId)) .arg(tableMsg); // qDebug() << selectSql; if (query.exec(selectSql)) { if (query.next()) { ret = true; } } else { qDebug() << query.lastError(); } // qDebug() << ret; return ret; } bool DBServiceSet::QueryNodeMatrixListByExpertNameAndEngineerId(QList *nodeMatrixInfoList, QString expertName, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_id,write_date from " "t_node_matrix_info where expert_name " "= '%1' and engineer_id ='%2'") .arg(expertName) .arg(QString::number(engineerId)); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo(); nodeMatrixInfo->id = query.value(0).toInt(); nodeMatrixInfo->expertName = query.value(1).toString(); nodeMatrixInfo->node = query.value(2).toString(); nodeMatrixInfo->engineerId = query.value(3).toInt(); nodeMatrixInfo->abscissa = query.value(4).toString(); nodeMatrixInfo->ordinate = query.value(5).toString(); nodeMatrixInfo->nodeValue = query.value(6).toString(); nodeMatrixInfo->expertId = query.value(7).toInt(); nodeMatrixInfo->mindId = query.value(8).toInt(); nodeMatrixInfo->writeDate = query.value(9).toDateTime(); nodeMatrixInfo->mark = query.value(10).toString(); nodeMatrixInfoList->append(nodeMatrixInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryNodeMatrixListByExpertNameAndEngineerId2(QString expertName, int engineerId, QString tableMsg, QString mark, int tabIndex) { QSqlDatabase db = SqlDBHelper::getDatabase2(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_id,write_date from " "t_node_matrix_info where expert_name " "= '%1' and engineer_id ='%2' and table_msg='%3' and mark = '%4' and tab_index = '%5'") .arg(expertName) .arg(QString::number(engineerId)) .arg(tableMsg) .arg(mark) .arg(tabIndex); if (query.exec(selectSql)) { if (query.next()) { ret = true; } } else { qDebug() << query.lastError(); } qDebug() << ret; return ret; } bool DBServiceSet::QueryNodesByExpertNameAndEngineerId2(QList *nodeMatrixInfoList, QString expertName, int engineerId, QString tableMsg, QString mark, int tabIndex) { QSqlDatabase db = SqlDBHelper::getDatabase2(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_id,write_date from " "t_node_matrix_info where expert_name " "= '%1' and engineer_id ='%2' and table_msg='%3' and mark = '%4' and tab_index = '%5'") .arg(expertName) .arg(QString::number(engineerId)) .arg(tableMsg) .arg(mark) .arg(tabIndex); // qDebug() << "----" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo(); nodeMatrixInfo->id = query.value(0).toInt(); nodeMatrixInfo->expertName = query.value(1).toString(); nodeMatrixInfo->node = query.value(2).toString(); nodeMatrixInfo->engineerId = query.value(3).toInt(); nodeMatrixInfo->abscissa = query.value(4).toString(); nodeMatrixInfo->ordinate = query.value(5).toString(); nodeMatrixInfo->nodeValue = query.value(6).toString(); nodeMatrixInfo->expertId = query.value(7).toInt(); nodeMatrixInfo->mindId = query.value(8).toInt(); nodeMatrixInfo->writeDate = query.value(9).toDateTime(); nodeMatrixInfo->mark = query.value(10).toString(); nodeMatrixInfoList->append(nodeMatrixInfo); } ret = true; } } else { qDebug() << query.lastError(); } qDebug() << ret; return ret; } bool DBServiceSet::QueryNodeValueByUserIdAndEngineerId(int experId, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_id,write_date from " "t_node_matrix_info where expert_id " "= '%1' and engineer_id ='%2'") .arg(QString::number(experId)) .arg(QString::number(engineerId)); // qDebug() << "selectSql=" << selectSql; if (query.exec(selectSql)) { if (query.next()) { ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryNodeMatrixListByExpertIdAndEngineerId(QList *nodeMatrixInfoList, int expertId, int engineerId, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_id,write_date from " "t_node_matrix_info where expert_id " "= '%1' and engineer_id ='%2' and table_msg ='%3'") .arg(QString::number(expertId)) .arg(QString::number(engineerId)) .arg(tableMsg); // qDebug() << "selectSql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo(); nodeMatrixInfo->id = query.value(0).toInt(); nodeMatrixInfo->expertName = query.value(1).toString(); nodeMatrixInfo->node = query.value(2).toString(); nodeMatrixInfo->engineerId = query.value(3).toInt(); nodeMatrixInfo->abscissa = query.value(4).toString(); nodeMatrixInfo->ordinate = query.value(5).toString(); nodeMatrixInfo->nodeValue = query.value(6).toString(); nodeMatrixInfo->expertId = query.value(7).toInt(); nodeMatrixInfo->mindId = query.value(8).toInt(); nodeMatrixInfo->writeDate = query.value(9).toDateTime(); nodeMatrixInfo->mark = query.value(10).toString(); nodeMatrixInfoList->append(nodeMatrixInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryNodeMatrixListByExpertIdAndEngineerId2(QList *nodeMatrixInfoList, int expertId, int engineerId, QString tableMsg) { QSqlDatabase db = SqlDBHelper::getDatabase2(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_id,write_date from " "t_node_matrix_info where expert_id " "= '%1' and engineer_id ='%2' and table_msg ='%3'") .arg(QString::number(expertId)) .arg(QString::number(engineerId)) .arg(tableMsg); // qDebug() << "selectSql=" << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo(); nodeMatrixInfo->id = query.value(0).toInt(); nodeMatrixInfo->expertName = query.value(1).toString(); nodeMatrixInfo->node = query.value(2).toString(); nodeMatrixInfo->engineerId = query.value(3).toInt(); nodeMatrixInfo->abscissa = query.value(4).toString(); nodeMatrixInfo->ordinate = query.value(5).toString(); nodeMatrixInfo->nodeValue = query.value(6).toString(); nodeMatrixInfo->expertId = query.value(7).toInt(); nodeMatrixInfo->mindId = query.value(8).toInt(); nodeMatrixInfo->writeDate = query.value(9).toDateTime(); nodeMatrixInfo->mark = query.value(10).toString(); nodeMatrixInfoList->append(nodeMatrixInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } /*根据专家姓名查询对应的节点信息*/ bool DBServiceSet::QueryNodeMatrixListByExpertName(QList *nodeMatrixInfoList, QString expertName) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_name,write_date from " "t_node_matrix_info where expert_name = '%1'") .arg(expertName); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo(); nodeMatrixInfo->id = query.value(0).toInt(); nodeMatrixInfo->expertName = query.value(1).toString(); nodeMatrixInfo->node = query.value(2).toString(); nodeMatrixInfo->engineerId = query.value(3).toInt(); nodeMatrixInfo->abscissa = query.value(4).toString(); nodeMatrixInfo->ordinate = query.value(5).toString(); nodeMatrixInfo->nodeValue = query.value(6).toString(); nodeMatrixInfo->expertId = query.value(7).toInt(); nodeMatrixInfo->mindId = query.value(8).toInt(); nodeMatrixInfo->writeDate = query.value(9).toDateTime(); nodeMatrixInfo->mark = query.value(10).toString(); nodeMatrixInfoList->append(nodeMatrixInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } /*根据专家姓名编号对应的节点信息*/ bool DBServiceSet::QueryNodeMatrixListByExpertId(QList *nodeMatrixInfoList, int expertId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id,mind_name,write_date from " "t_node_matrix_info where expert_id = '%1'") .arg(expertId); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo(); nodeMatrixInfo->id = query.value(0).toInt(); nodeMatrixInfo->expertName = query.value(1).toString(); nodeMatrixInfo->node = query.value(2).toString(); nodeMatrixInfo->engineerId = query.value(3).toInt(); nodeMatrixInfo->abscissa = query.value(4).toString(); nodeMatrixInfo->ordinate = query.value(5).toString(); nodeMatrixInfo->nodeValue = query.value(6).toString(); nodeMatrixInfo->expertId = query.value(7).toInt(); nodeMatrixInfo->mindId = query.value(8).toInt(); nodeMatrixInfo->writeDate = query.value(9).toDateTime(); nodeMatrixInfo->mark = query.value(10).toString(); nodeMatrixInfoList->append(nodeMatrixInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } /*根据工程编号查询对应的节点信息*/ bool DBServiceSet::QueryNodeMatrixListByEngineerId(QList *nodeMatrixInfoList, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, " "node_value, expert_id ,mind_name,write_date from " "t_node_matrix_info where engineer_id = '%1'") .arg(engineerId); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo(); nodeMatrixInfo->id = query.value(0).toInt(); nodeMatrixInfo->expertName = query.value(1).toString(); nodeMatrixInfo->node = query.value(2).toString(); nodeMatrixInfo->engineerId = query.value(3).toInt(); nodeMatrixInfo->abscissa = query.value(4).toString(); nodeMatrixInfo->ordinate = query.value(5).toString(); nodeMatrixInfo->nodeValue = query.value(6).toString(); nodeMatrixInfo->expertId = query.value(7).toInt(); nodeMatrixInfo->mindId = query.value(8).toInt(); nodeMatrixInfo->writeDate = query.value(9).toDateTime(); nodeMatrixInfo->mark = query.value(10).toString(); nodeMatrixInfoList->append(nodeMatrixInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } /*根据工程编号删除对应的节点信息*/ bool DBServiceSet::DeleteNodeMatrixListByEngineerId(int engineerId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.deleteFrom("t_node_matrix_info").where("engineer_id = ?", engineerId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } /*根据专家名称删除对应的节点信息*/ bool DBServiceSet::DeleteNodeMatrixListByExpertName(QString expertName) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.deleteFrom("t_node_matrix_info").where("expert_name = ?", expertName); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } /*根据专家编号删除对应的节点信息*/ bool DBServiceSet::DeleteNodeMatrixListByExpertId(int expertId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.deleteFrom("t_node_matrix_info").where("expert_id = ?", expertId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } //////////////////////节点矩阵信息表-end//////////////////// //////////////////////工程信息表-start//////////////////// bool DBServiceSet::AddEngineerInfo(const EngineerInfo &engineerInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); InsertQuery query = t.insertInto("t_engineer_info(engineer_name,index_set_id,schema_set_id," "measure_function_id,remark,effect_name_str)"); NonQueryResult result = query.values(engineerInfo.engineerName, engineerInfo.indexSetId, engineerInfo.schemaEvalId, engineerInfo.measureFunctionId, engineerInfo.remark, engineerInfo.effectNameStr) .exec(); t.commit(); qDebug() << "---------" << result.lastInsertId(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } int DBServiceSet::AddEngineerInfoReturnId(const EngineerInfo &engineerInfo) { int ret = -1; try { Transaction t(SqlDBHelper::getDatabase()); InsertQuery query = t.insertInto("t_engineer_info(engineer_name,index_set_id,schema_set_id," "measure_function_id,remark,effect_name_str)"); NonQueryResult result = query.values(engineerInfo.engineerName, engineerInfo.indexSetId, engineerInfo.schemaEvalId, engineerInfo.measureFunctionId, engineerInfo.remark, engineerInfo.effectNameStr) .exec(); t.commit(); ret = result.lastInsertId().toInt(); } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateEngineerInfo(const EngineerInfo &engineerInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_engineer_info") .set("engineer_name", engineerInfo.engineerName) .set("index_set_id", engineerInfo.indexSetId) .set("schema_set_id", engineerInfo.schemaEvalId) .set("measure_function_id", engineerInfo.measureFunctionId) .set("effect_name_str", engineerInfo.effectNameStr) .where("engineer_id = ?", engineerInfo.engineerId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateEngineerIndex(int enjId, int indexId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_engineer_info").set("index_set_id", indexId).where("engineer_id = ?", enjId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateEngineerMessaure(int enjId, int messaureId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_engineer_info").set("measure_function_id", messaureId).where("engineer_id = ?", enjId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateEngineerSchema(int enjId, int schemaId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_engineer_info").set("schema_set_id", schemaId).where("engineer_id = ?", enjId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateNameById(QString name, int id) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_engineer_info").set("engineer_name", name).where("engineer_id = ?", id); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryEngineerByEngineerId(EngineerInfo *engineerInfo, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, " "measure_function_id,remark,effect_name_str FROM " "t_engineer_info WHERE engineer_id = %1") .arg(engineerId); // qDebug() << "sql= " << selectSql; if (query.exec(selectSql)) { if (query.next()) { if (query.isNull(0) == false) { engineerInfo->engineerId = query.value(0).toInt(); engineerInfo->engineerName = query.value(1).toString(); engineerInfo->indexSetId = query.value(2).toInt(); engineerInfo->schemaEvalId = query.value(3).toInt(); engineerInfo->measureFunctionId = query.value(4).toInt(); engineerInfo->remark = query.value(5).toString(); engineerInfo->effectNameStr = query.value(6).toString(); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryEngineerByEngineerName(EngineerInfo *engineerInfo, QString engineerName) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, " "measure_function_id,remark,effect_name_str FROM " "t_engineer_info WHERE engineer_name = '%1'") .arg(engineerName); if (query.exec(selectSql)) { if (query.next()) { if (query.isNull(0) == false) { engineerInfo->engineerId = query.value(0).toInt(); engineerInfo->engineerName = query.value(1).toString(); engineerInfo->indexSetId = query.value(2).toInt(); engineerInfo->schemaEvalId = query.value(3).toInt(); engineerInfo->measureFunctionId = query.value(4).toInt(); engineerInfo->remark = query.value(5).toString(); engineerInfo->effectNameStr = query.value(6).toString(); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryEngineerListByName(QList *engineerInfoList, QString engineerName) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, " "measure_function_id,remark,effect_name_str " "FROM t_engineer_info WHERE engineer_name like '%1'") .arg("%" + engineerName + "%"); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { EngineerInfo *engineerInfo = new EngineerInfo(); engineerInfo->engineerId = query.value(0).toInt(); engineerInfo->engineerName = query.value(1).toString(); engineerInfo->indexSetId = query.value(2).toInt(); engineerInfo->schemaEvalId = query.value(3).toInt(); engineerInfo->measureFunctionId = query.value(4).toInt(); engineerInfo->remark = query.value(5).toString(); engineerInfo->effectNameStr = query.value(6).toString(); engineerInfoList->append(engineerInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryEngineerList(QList *engineerInfoList) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; try { QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, " "measure_function_id,remark,effect_name_str FROM t_engineer_info"); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { EngineerInfo *engineerInfo = new EngineerInfo(); engineerInfo->engineerId = query.value(0).toInt(); engineerInfo->engineerName = query.value(1).toString(); engineerInfo->indexSetId = query.value(2).toInt(); engineerInfo->schemaEvalId = query.value(3).toInt(); engineerInfo->measureFunctionId = query.value(4).toInt(); engineerInfo->remark = query.value(5).toString(); engineerInfo->effectNameStr = query.value(6).toString(); engineerInfoList->append(engineerInfo); } } } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryEngineerListByIndexSetId(QList *engineerInfoList, int indexSetId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, " "measure_function_id,remark,effect_name_str FROM " "t_engineer_info WHERE index_set_id = %1") .arg(indexSetId); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { EngineerInfo *engineerInfo = new EngineerInfo(); engineerInfo->engineerId = query.value(0).toInt(); engineerInfo->engineerName = query.value(1).toString(); engineerInfo->indexSetId = query.value(2).toInt(); engineerInfo->schemaEvalId = query.value(3).toInt(); engineerInfo->measureFunctionId = query.value(4).toInt(); engineerInfo->remark = query.value(5).toString(); engineerInfo->effectNameStr = query.value(6).toString(); engineerInfoList->append(engineerInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryEngineerListByMeasureFunctionId(QList *engineerInfoList, int measureFunctionId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, " "measure_function_id,remark FROM " "t_engineer_info WHERE measure_function_id = %1") .arg(measureFunctionId); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { EngineerInfo *engineerInfo = new EngineerInfo(); engineerInfo->engineerId = query.value(0).toInt(); engineerInfo->engineerName = query.value(1).toString(); engineerInfo->indexSetId = query.value(2).toInt(); engineerInfo->schemaEvalId = query.value(3).toInt(); engineerInfo->measureFunctionId = query.value(4).toInt(); engineerInfo->remark = query.value(5).toString(); engineerInfoList->append(engineerInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::DeleteEngineerByEngineerId(int engineerId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.deleteFrom("t_engineer_info").where("engineer_id = ?", engineerId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::DeleteEngineerByIndexSetId(int indexSetId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.deleteFrom("t_engineer_info").where("index_set_id = ?", indexSetId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::DeleteEngineerByMeasureFunctionId(int measureFunctionId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.deleteFrom("t_engineer_info").where("measure_function_id = ?", measureFunctionId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } //删除所有工程 bool DBServiceSet::DeleteEngineers() { bool ret = false; try { QSqlDatabase db = SqlDBHelper::getDatabase(); db.exec("delete from t_engineer_info"); db.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryChlidNodeByPId(int pid, QString dbName, QString mindPath) { QSqlDatabase db; if (QSqlDatabase::contains(dbName)) { db = QSqlDatabase::database(dbName); } else { db = QSqlDatabase::addDatabase("QSQLITE", dbName); db.setDatabaseName(mindPath); } if (!db.open()) { qDebug() << "test.db Open failed!"; } // qDebug() << "open=" << db.isOpen(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT * from " "mind_data WHERE pid = %1") .arg(pid); // qDebug() << "sql=" << selectSql; if (query.exec(selectSql)) { if (query.next()) { // qDebug() << "cunzai"; ret = true; } else { // qDebug() << "bucunzai"; } } else { qDebug() << query.lastError(); } db.close(); // qDebug() << "------" << ret; return ret; } //删除资源包中多余工程 bool DBServiceSet::DeleteEngineerNotInId(int id, QString dbPath) { QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(dbPath); if (!db.open()) { qDebug() << "test.db Open failed!"; } QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_engineer_info WHERE engineer_id != %1").arg(id); QString deleteUserConfig = QString("DELETE FROM t_user_config WHERE engineer_id != %1").arg(id); QString deleteUser = QString("DELETE FROM t_user_info WHERE id not in (select user_id FROM t_user_config WHERE " "engineer_id = %1)") .arg(id); QString deleteNodeValue = QString("DELETE FROM t_node_matrix_info "); QString deleteTechnical = QString("DELETE FROM t_technical_import"); QString deleteScheme = QString("DELETE FROM t_scheme_info "); QString deleteDemand = QString("DELETE FROM t_demand_weight"); QString deletePlan = QString("DELETE FROM t_plan_info"); QString deletePlanIndex = QString("DELETE FROM t_plan_index"); if (query.exec(deleteSql)) { query.exec(deleteUserConfig); query.exec(deleteUser); query.exec(deleteNodeValue); query.exec(deleteTechnical); query.exec(deleteScheme); query.exec(deleteDemand); query.exec(deletePlan); query.exec(deletePlanIndex); ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } db.close(); return ret; } //////////////////////工程信息表-end//////////////////// //////////////////////用户信息表-start//////////////////// int DBServiceSet::AddUserInfo(const UserInfo &userInfo) { int returnId = -1; try { returnId = getNextId("t_user_info"); Transaction t(SqlDBHelper::getDatabase()); InsertQuery query = t.insertInto("t_user_info (user_name, user_no, password, role, post, " "major,work_position,education_degree,phone,project_id,write_time)"); NonQueryResult result = query.values(userInfo.userName, userInfo.userNo, userInfo.password, userInfo.role, userInfo.post, userInfo.major, userInfo.workPosition, userInfo.educationDegree, userInfo.phone, userInfo.projectId, userInfo.writeTime) .exec(); t.commit(); returnId = result.lastInsertId().toInt(); } catch (const DBException &ex) { qDebug() << ex.lastError.text(); returnId = -1; } return returnId; } /*暂时用id修改*/ bool DBServiceSet::UpdateUserInfo(const UserInfo &userInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_user_info") .set("user_name", userInfo.userName) .set("user_no", userInfo.userNo) .set("password", userInfo.password) .set("role", userInfo.role) .set("post", userInfo.post) .set("major", userInfo.major) .set("work_position", userInfo.workPosition) .set("education_degree", userInfo.educationDegree) .set("phone", userInfo.phone) .set("remark", userInfo.remark) .set("project_id", userInfo.projectId) .where("id=?", userInfo.id); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateUserPassword(QString userNo, QString password) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_user_info").set("password", password).where("user_no=?", userNo); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateUserById(QString userNo, QString password, int id) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_user_info").set("password", password).set("user_no", userNo).where("id=?", id); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryUserInfoById(UserInfo *userInfo, int userId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,remark,project_id," "write_time from " "t_user_info WHERE id = %1") .arg(userId); if (query.exec(selectSql)) { if (query.next()) { if (query.isNull(0) == false) { userInfo->id = query.value(0).toInt(); userInfo->userName = query.value(1).toString(); userInfo->userNo = query.value(2).toString(); userInfo->password = query.value(3).toString(); userInfo->role = static_cast(query.value(4).toInt()); userInfo->post = query.value(5).toString(); userInfo->major = query.value(6).toString(); userInfo->workPosition = query.value(7).toString(); userInfo->educationDegree = query.value(8).toString(); userInfo->phone = query.value(9).toString(); userInfo->remark = query.value(10).toString(); userInfo->projectId = query.value(11).toString(); userInfo->writeTime = query.value(12).toString(); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryUserInfoByUnserInfo(const UserInfo ¶mInfo, UserInfo &queryInfo) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,project_id,write_time from " "t_user_info WHERE 1 = 1 "); if (!paramInfo.userName.isNull() && !paramInfo.userName.isEmpty()) { selectSql += " and user_name = '" + paramInfo.userName + "'"; } if (!paramInfo.userNo.isNull() && !paramInfo.userNo.isEmpty()) { selectSql += " and user_no = '" + paramInfo.userNo + "'"; } if (!paramInfo.post.isNull() && !paramInfo.post.isEmpty()) { selectSql += " and post = '" + paramInfo.post + "'"; } if (!paramInfo.major.isNull() && !paramInfo.major.isEmpty()) { selectSql += " and major = '" + paramInfo.major + "'"; } if (!paramInfo.workPosition.isNull() && !paramInfo.workPosition.isEmpty()) { selectSql += " and work_position = '" + paramInfo.workPosition + "'"; } if (!paramInfo.educationDegree.isNull() && !paramInfo.educationDegree.isEmpty()) { selectSql += " and education_degree = '" + paramInfo.educationDegree + "'"; } if (!paramInfo.phone.isNull() && !paramInfo.phone.isEmpty()) { selectSql += " and phone = '" + paramInfo.phone + "'"; } if (!paramInfo.projectId.isNull() && !paramInfo.projectId.isEmpty()) { selectSql += " and project_id = '" + paramInfo.projectId + "'"; } int role = paramInfo.role; if (role == 0) { selectSql += " and role != '" + QString::number(role) + "'"; } else { selectSql += " and role = '" + QString::number(role) + "'"; } if (query.exec(selectSql)) { if (query.next()) { queryInfo = paramInfo; queryInfo.id = query.value(0).toInt(); ret = true; } } else { qDebug() << query.lastError(); } return ret; } /*获取到用户列表*/ bool DBServiceSet::QueryUserListByEngineerId(QList *userInfoList, int engineerId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,remark,project_id," "write_time " "from t_user_info" " WHERE id in (select uc.user_id from t_user_config uc where " "uc.engineer_id = %1 and uc.is_valid =1 )") .arg(engineerId); // qDebug() << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { UserInfo *userInfo = new UserInfo(); userInfo->id = query.value(0).toInt(); userInfo->userName = query.value(1).toString(); userInfo->userNo = query.value(2).toString(); userInfo->password = query.value(3).toString(); userInfo->role = static_cast(query.value(4).toInt()); userInfo->post = query.value(5).toString(); userInfo->major = query.value(6).toString(); userInfo->workPosition = query.value(7).toString(); userInfo->educationDegree = query.value(8).toString(); userInfo->phone = query.value(9).toString(); userInfo->remark = query.value(10).toString(); userInfo->projectId = query.value(11).toString(); userInfo->writeTime = query.value(12).toString(); userInfoList->append(userInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryUserListByColumnAndColumnValue(QList *userInfoList, QString columnName, QString columnValue) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,remark,project_id," "write_time " "from t_user_info" " WHERE %1 = '%2'") .arg(columnName) .arg(columnValue); // qDebug() << selectSql; if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { UserInfo *userInfo = new UserInfo(); userInfo->id = query.value(0).toInt(); userInfo->userName = query.value(1).toString(); userInfo->userNo = query.value(2).toString(); userInfo->password = query.value(3).toString(); userInfo->role = static_cast(query.value(4).toInt()); userInfo->post = query.value(5).toString(); userInfo->major = query.value(6).toString(); userInfo->workPosition = query.value(7).toString(); userInfo->educationDegree = query.value(8).toString(); userInfo->phone = query.value(9).toString(); userInfo->remark = query.value(10).toString(); userInfo->projectId = query.value(11).toString(); userInfo->writeTime = query.value(12).toString(); userInfoList->append(userInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryUserList(QList *userInfoList) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,remark,project_id," "write_time from t_user_info"); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { UserInfo *userInfo = new UserInfo(); userInfo->id = query.value(0).toInt(); userInfo->userName = query.value(1).toString(); userInfo->userNo = query.value(2).toString(); userInfo->password = query.value(3).toString(); userInfo->role = static_cast(query.value(4).toInt()); userInfo->post = query.value(5).toString(); userInfo->major = query.value(6).toString(); userInfo->workPosition = query.value(7).toString(); userInfo->educationDegree = query.value(8).toString(); userInfo->phone = query.value(9).toString(); userInfo->remark = query.value(10).toString(); userInfo->projectId = query.value(11).toString(); userInfo->writeTime = query.value(12).toString(); userInfoList->append(userInfo); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryUserListNotAdmin(QList *userInfoList) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; try { QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,remark,project_id," "write_time from t_user_info where role !=0"); if (query.exec(selectSql)) { while (query.next()) { if (query.isNull(0) == false) { UserInfo *userInfo = new UserInfo(); userInfo->id = query.value(0).toInt(); userInfo->userName = query.value(1).toString(); userInfo->userNo = query.value(2).toString(); userInfo->password = query.value(3).toString(); userInfo->role = static_cast(query.value(4).toInt()); userInfo->post = query.value(5).toString(); userInfo->major = query.value(6).toString(); userInfo->workPosition = query.value(7).toString(); userInfo->educationDegree = query.value(8).toString(); userInfo->phone = query.value(9).toString(); userInfo->remark = query.value(10).toString(); userInfo->projectId = query.value(11).toString(); userInfo->writeTime = query.value(12).toString(); userInfoList->append(userInfo); } } } else { qDebug() << query.lastError(); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::DeleteUserById(int Id) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_user_info WHERE id = %1").arg(Id); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } //删除除管理管外的所有用户 bool DBServiceSet::DeleteUserByRole(int roleType) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_user_info WHERE role != %1").arg(roleType); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryUserByNoAndPassword(UserInfo *userInfo, QString userNo, QString password) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,remark,project_id," "write_time from " "t_user_info WHERE user_no = %1 and password = %2") .arg("'" + userNo + "'") .arg("'" + password + "'"); if (query.exec(selectSql)) { if (query.next()) { if (query.isNull(0) == false) { userInfo->id = query.value(0).toInt(); userInfo->userName = query.value(1).toString(); userInfo->userNo = query.value(2).toString(); userInfo->password = query.value(3).toString(); userInfo->role = static_cast(query.value(4).toInt()); userInfo->post = query.value(5).toString(); userInfo->major = query.value(6).toString(); userInfo->workPosition = query.value(7).toString(); userInfo->educationDegree = query.value(8).toString(); userInfo->phone = query.value(9).toString(); userInfo->remark = query.value(10).toString(); userInfo->projectId = query.value(11).toString(); userInfo->writeTime = query.value(12).toString(); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryUserByNo(UserInfo *userInfo, QString userNo) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,remark,project_id," "write_time from " "t_user_info WHERE user_no = %1 ") .arg("'" + userNo + "'"); if (query.exec(selectSql)) { if (query.next()) { if (query.isNull(0) == false) { userInfo->id = query.value(0).toInt(); userInfo->userName = query.value(1).toString(); userInfo->userNo = query.value(2).toString(); userInfo->password = query.value(3).toString(); userInfo->role = static_cast(query.value(4).toInt()); userInfo->post = query.value(5).toString(); userInfo->major = query.value(6).toString(); userInfo->workPosition = query.value(7).toString(); userInfo->educationDegree = query.value(8).toString(); userInfo->phone = query.value(9).toString(); userInfo->remark = query.value(10).toString(); userInfo->projectId = query.value(11).toString(); userInfo->writeTime = query.value(12).toString(); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryUserInfoById2(UserInfo *userInfo, int userId) { QSqlDatabase db = SqlDBHelper::getDatabase2(); QSqlQuery query(db); bool ret = false; QString selectSql = QString("SELECT id, user_name,user_no,password,role,post, " "major,work_position,education_degree,phone,remark,project_id," "write_time from " "t_user_info WHERE id = %1") .arg(userId); qDebug() << selectSql; if (query.exec(selectSql)) { if (query.next()) { if (query.isNull(0) == false) { userInfo->id = query.value(0).toInt(); userInfo->userName = query.value(1).toString(); userInfo->userNo = query.value(2).toString(); userInfo->password = query.value(3).toString(); userInfo->role = static_cast(query.value(4).toInt()); userInfo->post = query.value(5).toString(); userInfo->major = query.value(6).toString(); userInfo->workPosition = query.value(7).toString(); userInfo->educationDegree = query.value(8).toString(); userInfo->phone = query.value(9).toString(); userInfo->remark = query.value(10).toString(); userInfo->projectId = query.value(11).toString(); userInfo->writeTime = query.value(12).toString(); } ret = true; } } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::UpdateUserInfo2(const UserInfo &userInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase2()); t.update("t_user_info") .set("user_name", userInfo.userName) .set("user_no", userInfo.userNo) .set("password", userInfo.password) .set("role", userInfo.role) .set("post", userInfo.post) .set("major", userInfo.major) .set("work_position", userInfo.workPosition) .set("education_degree", userInfo.educationDegree) .set("phone", userInfo.phone) .set("remark", userInfo.remark) .set("project_id", userInfo.projectId) .where("id=?", userInfo.id); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } int DBServiceSet::AddUserInfo2(const UserInfo &userInfo) { int returnId = -1; try { Transaction t(SqlDBHelper::getDatabase2()); InsertQuery query = t.insertInto("t_user_info (id,user_name, user_no, password, role, post, " "major,work_position,education_degree,phone,project_id,write_time)"); NonQueryResult result = query.values(userInfo.id, userInfo.userName, userInfo.userNo, userInfo.password, userInfo.role, userInfo.post, userInfo.major, userInfo.workPosition, userInfo.educationDegree, userInfo.phone, userInfo.projectId, userInfo.writeTime) .exec(); t.commit(); returnId = result.lastInsertId().toInt(); } catch (const DBException &ex) { qDebug() << ex.lastError.text(); returnId = -1; } return returnId; } //////////////////////用户信息表-end//////////////////// //////////////////////评估方案信息表-start//////////////////// bool DBServiceSet::AddPlanInfo(const PlanInfo &planInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); InsertQuery q = t.insertInto("t_plan_info (plan_name, engineer_id, desc,create_time)"); q.values(planInfo.planName, planInfo.engineerId, planInfo.desc, QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz")) .exec(); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdatePlanInfo(const PlanInfo &planInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_plan_info") .set("plan_name", planInfo.planName) .set("engineer_id", planInfo.engineerId) .set("desc", planInfo.desc) .set("update_time", QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz")) .where("id=?", planInfo.id); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryPlanInfoById(PlanInfo *planInfo, int planId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, plan_name,engineer_id, desc from t_plan_info " " WHERE id = %1") .arg(planId); QueryResult queryResult = t.execQuery(selectSql); if (queryResult.next()) { planInfo->id = queryResult.value(0).toInt(); planInfo->planName = queryResult.value(1).toString(); planInfo->engineerId = queryResult.value(2).toInt(); planInfo->desc = queryResult.value(3).toString(); ret = true; } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryPlanListByColumnAndColumnValue(QList *planInfoList, QString columnName, QString columnValue) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, plan_name,engineer_id, desc from t_plan_info " " WHERE %1 = '%2'") .arg(columnName) .arg(columnValue); QueryResult queryResult = t.execQuery(selectSql); while (queryResult.next()) { PlanInfo *planInfo = new PlanInfo(); planInfo->id = queryResult.value(0).toInt(); planInfo->planName = queryResult.value(1).toString(); planInfo->engineerId = queryResult.value(2).toInt(); planInfo->desc = queryResult.value(3).toString(); planInfoList->append(planInfo); ret = true; } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryPlanList(QList *planInfoList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, plan_name,engineer_id, desc from t_plan_info "); QueryResult queryResult = t.execQuery(selectSql); while (queryResult.next()) { PlanInfo *planInfo = new PlanInfo(); planInfo->id = queryResult.value(0).toInt(); planInfo->planName = queryResult.value(1).toString(); planInfo->engineerId = queryResult.value(2).toInt(); planInfo->desc = queryResult.value(3).toString(); planInfoList->append(planInfo); ret = true; } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::DeletePlanById(int planId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_plan_info WHERE id = %1").arg(planId); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } //////////////////////评估方案信息表-end//////////////////// //////////////////////指标体系评估方案关系信息表-start//////////////////// /*批量信息新增*/ bool DBServiceSet::AddIndexSetPlanInfoList(const QList planInfoList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString insertTime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz"); for (int i = 0; i < planInfoList.length(); i++) { IndexSetPlanInfo *indexSetPlanInfo = planInfoList.at(i); InsertQuery query = t.insertInto("t_plan_index (index_set_id, plan_id, weight, create_time)"); query.values(indexSetPlanInfo->indexSetId, indexSetPlanInfo->planId, indexSetPlanInfo->weight, insertTime) .exec(); } t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateIndexSetPlanInfo(const IndexSetPlanInfo &planInfo) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_plan_index") .set("weight", planInfo.weight) .set("update_time", QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz")) .where("index_set_id =? and plan_id=?", planInfo.indexSetId, planInfo.planId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateIndexSetPlanInfoList(const QList planInfoList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString updateTime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz"); for (int i = 0; i < planInfoList.length(); i++) { IndexSetPlanInfo *indexSetPlanInfo = planInfoList.at(i); t.update("t_plan_index") .set("weight", indexSetPlanInfo->weight) .set("update_time", updateTime) .where("index_set_id =? and plan_id=?", indexSetPlanInfo->indexSetId, indexSetPlanInfo->planId); } t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::DeleteIndexSetPlanById(int Id) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_plan_index WHERE id = %1").arg(Id); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::DeleteIndexSetPlanByPlanId(int planId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_plan_index WHERE plan_id = %1").arg(planId); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::DeleteIndexSetPlanByIndexSetId(int indexSetId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_plan_index WHERE index_set_id = %1").arg(indexSetId); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::QueryIndexSetPlanInfo(IndexSetPlanInfo *planInfo, int Id) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, plan_id,index_set_id,weight from t_plan_index " " WHERE id = %1") .arg(Id); QueryResult queryResult = t.execQuery(selectSql); if (queryResult.next()) { planInfo->id = queryResult.value(0).toInt(); planInfo->planId = queryResult.value(1).toInt(); planInfo->indexSetId = queryResult.value(2).toInt(); planInfo->weight = queryResult.value(3).toDouble(); ret = true; } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryIndexSetPlanListByColumnAndColumnValue(QList *planInfoList, QString columnName, QString columnValue) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, plan_id,index_set_id,weight from " "t_plan_index where %1 = '%2' ") .arg(columnName) .arg(columnValue); QueryResult queryResult = t.execQuery(selectSql); while (queryResult.next()) { IndexSetPlanInfo *planInfo = new IndexSetPlanInfo(); planInfo->id = queryResult.value(0).toInt(); planInfo->planId = queryResult.value(1).toInt(); planInfo->indexSetId = queryResult.value(2).toInt(); planInfo->weight = queryResult.value(3).toDouble(); planInfoList->append(planInfo); ret = true; } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } //////////////////////指标体系评估方案关系信息表-end//////////////////// //////////////////////用户工程配置-start//////////////////// int DBServiceSet::AddUserConfig(const UserConfig &cfg) { int returnId = -1; try { returnId = getNextId("t_user_config"); Transaction t(SqlDBHelper::getDatabase()); InsertQuery query = t.insertInto("t_user_config (user_id, engineer_id, " "weight, create_time, update_time,user_name)"); NonQueryResult result = query.values(cfg.userId, cfg.engineerId, cfg.weight, cfg.createTime, cfg.updateTime, cfg.userName) .exec(); t.commit(); returnId = result.lastInsertId().toInt(); } catch (const DBException &ex) { qDebug() << ex.lastError.text(); returnId = -1; } return returnId; } //添加配置信息 bool DBServiceSet::AddUserConfigList(QList cfgList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); for (auto cfg : cfgList) { InsertQuery query = t.insertInto("t_user_config (user_id, engineer_id, " "weight, create_time, update_time,user_name)"); NonQueryResult result = query.values(cfg->userId, cfg->engineerId, cfg->weight * 100, cfg->createTime, cfg->updateTime, cfg->userName) .exec(); t.commit(); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } int DBServiceSet::QueryUserWeightSum(int engineerId) { int returnId = -1; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT sum(weight) from t_user_config " " WHERE engineer_id = %1 and is_valid =1") .arg(engineerId); QueryResult queryResult = t.execQuery(selectSql); if (queryResult.next()) { returnId = queryResult.value(0).toInt(); } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); returnId = -1; } return returnId; } int DBServiceSet::QueryUserWeightSum(int engineerId, int userId) { int returnId = -1; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT sum(weight) from t_user_config " " WHERE engineer_id = %1 and user_id != %2 and is_valid =1") .arg(engineerId) .arg(userId); QueryResult queryResult = t.execQuery(selectSql); if (queryResult.next()) { returnId = queryResult.value(0).toInt(); } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); returnId = -1; } return returnId; } bool DBServiceSet::UpdateUserConfig(const UserConfig &cfg) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_user_config") .set("user_id", cfg.userId) .set("engineer_id", cfg.engineerId) .set("weight", cfg.weight) .set("user_name", cfg.userName) .set("update_time", QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz")) .where("id=?", cfg.id); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::UpdateUserValid(int userId, int flag) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); t.update("t_user_config") .set("is_valid", flag) .set("update_time", QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz")) .where("user_id=?", userId); t.commit(); ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryUserConfigInfoById(UserConfig *cfg, int cfgId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, user_id, engineer_id, weight, " "create_time, update_time,user_name from t_user_config " " WHERE id = %1") .arg(cfgId); QueryResult queryResult = t.execQuery(selectSql); if (queryResult.next()) { cfg->id = queryResult.value(0).toInt(); cfg->userId = queryResult.value(1).toInt(); cfg->engineerId = queryResult.value(2).toInt(); cfg->weight = queryResult.value(3).toDouble(); cfg->createTime = queryResult.value(4).toString(); cfg->updateTime = queryResult.value(5).toString(); cfg->userName = queryResult.value(6).toString(); ret = true; } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryUserConfigListInfoByUserIdAndEngineerId(UserConfig *cfg, int userId, int engineerId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, user_id, engineer_id, weight, " "create_time, update_time,user_name from t_user_config " " WHERE user_id = %1 and engineer_id = %2") .arg(userId) .arg(engineerId); QueryResult queryResult = t.execQuery(selectSql); if (queryResult.next()) { cfg->id = queryResult.value(0).toInt(); cfg->userId = queryResult.value(1).toInt(); cfg->engineerId = queryResult.value(2).toInt(); cfg->weight = queryResult.value(3).toDouble(); cfg->createTime = queryResult.value(4).toString(); cfg->updateTime = queryResult.value(5).toString(); cfg->userName = queryResult.value(6).toString(); ret = true; } } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryUserConfigListInfoByEngineerId(QList *userCfgList, int engineerId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, user_id, engineer_id, weight, " "create_time, update_time,user_name from t_user_config" " WHERE engineer_id = %1 and is_valid =1 ") .arg(engineerId); QueryResult queryResult = t.execQuery(selectSql); while (queryResult.next()) { UserConfig *cfg = new UserConfig(); cfg->id = queryResult.value(0).toInt(); cfg->userId = queryResult.value(1).toInt(); cfg->engineerId = queryResult.value(2).toInt(); cfg->weight = queryResult.value(3).toDouble(); cfg->createTime = queryResult.value(4).toString(); cfg->updateTime = queryResult.value(5).toString(); cfg->userName = queryResult.value(6).toString(); userCfgList->append(cfg); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryUserConfigListInfoByUserId(QList *userCfgList, int userId) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, user_id, engineer_id, weight, " "create_time, update_time,user_name from t_user_config" " WHERE user_id = %1 and is_valid=1 ") .arg(userId); QueryResult queryResult = t.execQuery(selectSql); while (queryResult.next()) { UserConfig *cfg = new UserConfig(); cfg->id = queryResult.value(0).toInt(); cfg->userId = queryResult.value(1).toInt(); cfg->engineerId = queryResult.value(2).toInt(); cfg->weight = queryResult.value(3).toDouble(); cfg->createTime = queryResult.value(4).toString(); cfg->updateTime = queryResult.value(5).toString(); cfg->userName = queryResult.value(6).toString(); userCfgList->append(cfg); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::QueryAllUserConfig(QList *userCfgList) { bool ret = false; try { Transaction t(SqlDBHelper::getDatabase()); QString selectSql = QString("SELECT id, user_id, engineer_id, weight, " "create_time, update_time,user_name from t_user_config"); QueryResult queryResult = t.execQuery(selectSql); while (queryResult.next()) { UserConfig *cfg = new UserConfig(); cfg->id = queryResult.value(0).toInt(); cfg->userId = queryResult.value(1).toInt(); cfg->engineerId = queryResult.value(2).toInt(); cfg->weight = queryResult.value(3).toDouble(); cfg->createTime = queryResult.value(4).toString(); cfg->updateTime = queryResult.value(5).toString(); cfg->userName = queryResult.value(6).toString(); userCfgList->append(cfg); } ret = true; } catch (const DBException &ex) { qDebug() << ex.lastError.text(); } return ret; } bool DBServiceSet::DeleteUserConfigById(int cfgId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_user_config WHERE id = %1").arg(cfgId); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::DeleteUserConfigByEngineerId(int enjId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_user_config WHERE engineer_id = %1").arg(enjId); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } bool DBServiceSet::DeleteUserConfigByUserId(int userId) { QSqlDatabase db = SqlDBHelper::getDatabase(); QSqlQuery query(db); bool ret = false; QString deleteSql = QString("DELETE FROM t_user_config WHERE user_id = %1").arg(userId); if (query.exec(deleteSql)) { ret = true; qDebug() << "deleteSql success!"; } else { qDebug() << query.lastError(); } return ret; } //////////////////////用户工程配置-end////////////////////