123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560 |
- #include "DBServiceSet.h"
- #include "SqlDBHelper.h"
- #include <QDebug>
- 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<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 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<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 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<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 DBServiceSet::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 DBServiceSet::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 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<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 DBServiceSet::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 DBServiceSet::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 DBServiceSet::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 DBServiceSet::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 DBServiceSet::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 DBServiceSet::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;
- }
- //////////////////////common-end////////////////////
- /////////////////////方案持久化-start////////////////
- bool DBServiceSet::AddSchemeInfoList(const QList<SchemaEval *> &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<SchemaEval *> *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<TechnicalImport *> &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<TechnicalImport *> 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<TechnicalImport *> *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<NodeMatrixInfo *> &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<NodeMatrixInfo *> &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<NodeMatrixInfo *> 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<NodeMatrixInfo *> 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<NodeMatrixInfo *> *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<NodeMatrixInfo *> *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<NodeMatrixInfo *> *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<NodeMatrixInfo *> *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<NodeMatrixInfo *> *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<NodeMatrixInfo *> *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<NodeMatrixInfo *> *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::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<PlanInfo *> *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<PlanInfo *> *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<IndexSetPlanInfo *> 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<IndexSetPlanInfo *> 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<IndexSetPlanInfo *> *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////////////////////
|