123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- #include "DemandWeightService.h"
- #include "SqlDBHelper.h"
- #include <QDebug>
- DemandWeightService::DemandWeightService(QObject *parent) { }
- bool DemandWeightService::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 DemandWeightService::AddNodeWeightInfoList(const QList<DemandWeight *> &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 DemandWeightService::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 DemandWeightService::UpdateNodeValueList(const QList<DemandWeight *> 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 DemandWeightService::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 DemandWeightService::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 DemandWeightService::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 DemandWeightService::QueryByTableIndexAndTableMsg(QList<DemandWeight *> *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 DemandWeightService::QueryByTableIndexAndTableMsg(QList<DemandWeight *> *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 DemandWeightService::QueryByPageIndexAndTableMsg(QList<DemandWeight *> *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 DemandWeightService::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 DemandWeightService::QueryFirstDemandWeightByEngineerId(QList<DemandWeight *> *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 DemandWeightService::QueryLastDemandWeightByEngineerId(QList<DemandWeight *> *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 DemandWeightService::QueryFirstDemandWeightByEngineerId(QList<DemandWeight *> *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 DemandWeightService::QueryLastPageDemandWeightByEngineerId(QList<DemandWeight *> *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 DemandWeightService::QuerySecondDemandWeightByEngineerId(QList<DemandWeight *> *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 DemandWeightService::QuerySecondDemandWeightByEngineerIdAndMaxPage(QList<DemandWeight *> *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 DemandWeightService::QuerySecondDemandWeightByEngineerId(QList<DemandWeight *> *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;
- }
|