#include "EngineerService.h" #include "SqlDBHelper.h" #include 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 *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 *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 *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 *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////////////////////