123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- #include "EngineerService.h"
- #include "SqlDBHelper.h"
- #include <QDebug>
- EngineerService::EngineerService(QObject *parent) { }
- //////////////////////工程信息表-start////////////////////
- bool EngineerService::AddEngineerInfo(const EngineerInfo &engineerInfo)
- {
- bool ret = false;
- try {
- Transaction t(SqlDBHelper::getDatabase());
- InsertQuery query =
- t.insertInto("t_engineer_info(`engineer_name`, `demand_mind_id`, `programme_mind_id`, "
- "`general_mind_id`, `remark`, `task_name`, `estimate_time`, `estimate_objective`, "
- "`estimate_dept`, `estimate_person`, `positional_titles`, `create_time`, `update_time`)");
- 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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::QueryEngineerListByName(QList<EngineerInfo *> *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 EngineerService::QueryEngineerList(QList<EngineerInfo *> *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 EngineerService::QueryEngineerListByIndexSetId(QList<EngineerInfo *> *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 EngineerService::QueryEngineerListByMeasureFunctionId(QList<EngineerInfo *> *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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::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 EngineerService::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////////////////////
|