123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- #include "SchemeInfoService.h"
- #include "SqlDBHelper.h"
- #include <QDebug>
- SchemeInfoService::SchemeInfoService(QObject *parent) { }
- /////////////////////方案持久化-start////////////////
- bool SchemeInfoService::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 (project_id,name,remark,value_str,score,file_path,type)");
- q.values(scheme->engineerId, scheme->name, scheme->remark, scheme->valueStr, scheme->score,
- scheme->filePath, scheme->type)
- .exec();
- t.commit();
- }
- ret = true;
- } catch (const DBException &ex) {
- qDebug() << ex.lastError.text();
- }
- return ret;
- }
- bool SchemeInfoService::DeleteSchemeByEngineerId(int engineerId)
- {
- bool ret = false;
- try {
- Transaction t(SqlDBHelper::getDatabase());
- t.deleteFrom("t_scheme_info").where("project_id = ?", engineerId);
- t.commit();
- ret = true;
- } catch (const DBException &ex) {
- qDebug() << ex.lastError.text();
- }
- return ret;
- }
- bool SchemeInfoService::QuerySchemeInfoByEngineerId(QList<SchemaEval *> *schemeList, int engineerId, int type)
- {
- QSqlDatabase db = SqlDBHelper::getDatabase();
- QSqlQuery query(db);
- bool ret = false;
- QString selectSql = QString("select id,project_id,name,remark,value_str "
- ",score,file_path,type from t_scheme_info where "
- " project_id =%1 and type = %2 ")
- .arg(QString::number(engineerId))
- .arg(type);
- // 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();
- scheme->filePath = query.value(6).toString();
- scheme->type = query.value(7).toInt();
- schemeList->append(scheme);
- }
- }
- ret = true;
- } else {
- qDebug() << query.lastError();
- }
- return ret;
- }
- bool SchemeInfoService::UpdateValueStrById(int id, QString valueStr)
- {
- bool ret = false;
- try {
- Transaction t(SqlDBHelper::getDatabase());
- t.update("t_scheme_info").set("value_str", valueStr).where("id = ?", id);
- t.commit();
- ret = true;
- } catch (const DBException &ex) {
- qDebug() << ex.lastError.text();
- }
- return ret;
- }
- bool SchemeInfoService::addScheme(const SchemaEval &scheme)
- {
- bool ret = false;
- try {
- Transaction t(SqlDBHelper::getDatabase());
- InsertQuery q = t.insertInto("t_scheme_info (project_id,name,remark,value_str,score,file_path,type)");
- q.values(scheme.engineerId, scheme.name, scheme.remark, scheme.valueStr, scheme.score, scheme.filePath,
- scheme.type)
- .exec();
- t.commit();
- ret = true;
- } catch (const DBException &ex) {
- qDebug() << ex.lastError.text();
- }
- return ret;
- }
- bool SchemeInfoService::updateSchemeScore(const int &id, const double &score)
- {
- bool ret = false;
- try {
- Transaction t(SqlDBHelper::getDatabase());
- t.update("t_scheme_info").set("score", score).where("id = ?", id);
- t.commit();
- ret = true;
- } catch (const DBException &ex) {
- qDebug() << ex.lastError.text();
- }
- return ret;
- }
- bool SchemeInfoService::deleteScheme(int id)
- {
- bool ret = false;
- try {
- Transaction t(SqlDBHelper::getDatabase());
- t.deleteFrom("t_scheme_info").where("id = ?", id);
- t.commit();
- ret = true;
- } catch (const DBException &ex) {
- qDebug() << ex.lastError.text();
- }
- return ret;
- }
- bool SchemeInfoService::addUniqueGCEData(const SchemaEval &scheme)
- {
- SchemaEval s;
- bool qRet = queryGCEData(s, scheme.engineerId, scheme.name);
- if (qRet == false) {
- return false;
- }
- if (s.id < 0) {
- return addScheme(scheme);
- } else {
- return UpdateValueStrById(s.id, scheme.valueStr);
- }
- }
- bool SchemeInfoService::queryGCEData(SchemaEval &scheme, int projId, QString name)
- {
- QSqlDatabase db = SqlDBHelper::getDatabase();
- QSqlQuery query(db);
- bool ret = false;
- QString selectSql = QString("select id,project_id,name,remark,value_str "
- ",score,file_path,type from t_scheme_info where "
- " project_id =%1 and name = '%2' and type = 2")
- .arg(QString::number(projId))
- .arg(name);
- qDebug() << "sql=" << selectSql;
- if (query.exec(selectSql)) {
- while (query.next()) {
- 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();
- scheme.filePath = query.value(6).toString();
- scheme.type = query.value(7).toInt();
- }
- ret = true;
- } else {
- qDebug() << query.lastError();
- }
- return ret;
- }
- ///////////////////////common-end/////////////////////
|