EngineerService.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. #include "EngineerService.h"
  2. #include "SqlDBHelper.h"
  3. #include <QDebug>
  4. EngineerService::EngineerService(QObject *parent) { }
  5. //////////////////////工程信息表-start////////////////////
  6. bool EngineerService::AddEngineerInfo(const EngineerInfo &engineerInfo)
  7. {
  8. bool ret = false;
  9. try {
  10. Transaction t(SqlDBHelper::getDatabase());
  11. InsertQuery query =
  12. t.insertInto("t_engineer_info(`engineer_name`, `demand_mind_id`, `programme_mind_id`, "
  13. "`general_mind_id`, `remark`, `task_name`, `estimate_time`, `estimate_objective`, "
  14. "`estimate_dept`, `estimate_person`, `positional_titles`, `create_time`, `update_time`)");
  15. NonQueryResult result =
  16. query.values(engineerInfo.engineerName, engineerInfo.indexSetId, engineerInfo.schemaEvalId,
  17. engineerInfo.measureFunctionId, engineerInfo.remark, engineerInfo.effectNameStr)
  18. .exec();
  19. t.commit();
  20. qDebug() << "---------" << result.lastInsertId();
  21. ret = true;
  22. } catch (const DBException &ex) {
  23. qDebug() << ex.lastError.text();
  24. }
  25. return ret;
  26. }
  27. int EngineerService::AddEngineerInfoReturnId(const EngineerInfo &engineerInfo)
  28. {
  29. int ret = -1;
  30. try {
  31. Transaction t(SqlDBHelper::getDatabase());
  32. InsertQuery query = t.insertInto("t_engineer_info(engineer_name,index_set_id,schema_set_id,"
  33. "measure_function_id,remark,effect_name_str)");
  34. NonQueryResult result =
  35. query.values(engineerInfo.engineerName, engineerInfo.indexSetId, engineerInfo.schemaEvalId,
  36. engineerInfo.measureFunctionId, engineerInfo.remark, engineerInfo.effectNameStr)
  37. .exec();
  38. t.commit();
  39. ret = result.lastInsertId().toInt();
  40. } catch (const DBException &ex) {
  41. qDebug() << ex.lastError.text();
  42. }
  43. return ret;
  44. }
  45. bool EngineerService::UpdateEngineerInfo(const EngineerInfo &engineerInfo)
  46. {
  47. bool ret = false;
  48. try {
  49. Transaction t(SqlDBHelper::getDatabase());
  50. t.update("t_engineer_info")
  51. .set("engineer_name", engineerInfo.engineerName)
  52. .set("index_set_id", engineerInfo.indexSetId)
  53. .set("schema_set_id", engineerInfo.schemaEvalId)
  54. .set("measure_function_id", engineerInfo.measureFunctionId)
  55. .set("effect_name_str", engineerInfo.effectNameStr)
  56. .where("engineer_id = ?", engineerInfo.engineerId);
  57. t.commit();
  58. ret = true;
  59. } catch (const DBException &ex) {
  60. qDebug() << ex.lastError.text();
  61. }
  62. return ret;
  63. }
  64. bool EngineerService::UpdateEngineerIndex(int enjId, int indexId)
  65. {
  66. bool ret = false;
  67. try {
  68. Transaction t(SqlDBHelper::getDatabase());
  69. t.update("t_engineer_info").set("index_set_id", indexId).where("engineer_id = ?", enjId);
  70. t.commit();
  71. ret = true;
  72. } catch (const DBException &ex) {
  73. qDebug() << ex.lastError.text();
  74. }
  75. return ret;
  76. }
  77. bool EngineerService::UpdateEngineerMessaure(int enjId, int messaureId)
  78. {
  79. bool ret = false;
  80. try {
  81. Transaction t(SqlDBHelper::getDatabase());
  82. t.update("t_engineer_info").set("measure_function_id", messaureId).where("engineer_id = ?", enjId);
  83. t.commit();
  84. ret = true;
  85. } catch (const DBException &ex) {
  86. qDebug() << ex.lastError.text();
  87. }
  88. return ret;
  89. }
  90. bool EngineerService::UpdateEngineerSchema(int enjId, int schemaId)
  91. {
  92. bool ret = false;
  93. try {
  94. Transaction t(SqlDBHelper::getDatabase());
  95. t.update("t_engineer_info").set("schema_set_id", schemaId).where("engineer_id = ?", enjId);
  96. t.commit();
  97. ret = true;
  98. } catch (const DBException &ex) {
  99. qDebug() << ex.lastError.text();
  100. }
  101. return ret;
  102. }
  103. bool EngineerService::UpdateNameById(QString name, int id)
  104. {
  105. bool ret = false;
  106. try {
  107. Transaction t(SqlDBHelper::getDatabase());
  108. t.update("t_engineer_info").set("engineer_name", name).where("engineer_id = ?", id);
  109. t.commit();
  110. ret = true;
  111. } catch (const DBException &ex) {
  112. qDebug() << ex.lastError.text();
  113. }
  114. return ret;
  115. }
  116. bool EngineerService::QueryEngineerByEngineerId(EngineerInfo *engineerInfo, int engineerId)
  117. {
  118. QSqlDatabase db = SqlDBHelper::getDatabase();
  119. QSqlQuery query(db);
  120. bool ret = false;
  121. QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, "
  122. "measure_function_id,remark,effect_name_str FROM "
  123. "t_engineer_info WHERE engineer_id = %1")
  124. .arg(engineerId);
  125. // qDebug() << "sql= " << selectSql;
  126. if (query.exec(selectSql)) {
  127. if (query.next()) {
  128. if (query.isNull(0) == false) {
  129. engineerInfo->engineerId = query.value(0).toInt();
  130. engineerInfo->engineerName = query.value(1).toString();
  131. engineerInfo->indexSetId = query.value(2).toInt();
  132. engineerInfo->schemaEvalId = query.value(3).toInt();
  133. engineerInfo->measureFunctionId = query.value(4).toInt();
  134. engineerInfo->remark = query.value(5).toString();
  135. engineerInfo->effectNameStr = query.value(6).toString();
  136. }
  137. ret = true;
  138. }
  139. } else {
  140. qDebug() << query.lastError();
  141. }
  142. return ret;
  143. }
  144. bool EngineerService::QueryEngineerByEngineerName(EngineerInfo *engineerInfo, QString engineerName)
  145. {
  146. QSqlDatabase db = SqlDBHelper::getDatabase();
  147. QSqlQuery query(db);
  148. bool ret = false;
  149. QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, "
  150. "measure_function_id,remark,effect_name_str FROM "
  151. "t_engineer_info WHERE engineer_name = '%1'")
  152. .arg(engineerName);
  153. if (query.exec(selectSql)) {
  154. if (query.next()) {
  155. if (query.isNull(0) == false) {
  156. engineerInfo->engineerId = query.value(0).toInt();
  157. engineerInfo->engineerName = query.value(1).toString();
  158. engineerInfo->indexSetId = query.value(2).toInt();
  159. engineerInfo->schemaEvalId = query.value(3).toInt();
  160. engineerInfo->measureFunctionId = query.value(4).toInt();
  161. engineerInfo->remark = query.value(5).toString();
  162. engineerInfo->effectNameStr = query.value(6).toString();
  163. }
  164. ret = true;
  165. }
  166. } else {
  167. qDebug() << query.lastError();
  168. }
  169. return ret;
  170. }
  171. bool EngineerService::QueryEngineerListByName(QList<EngineerInfo *> *engineerInfoList, QString engineerName)
  172. {
  173. QSqlDatabase db = SqlDBHelper::getDatabase();
  174. QSqlQuery query(db);
  175. bool ret = false;
  176. QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, "
  177. "measure_function_id,remark,effect_name_str "
  178. "FROM t_engineer_info WHERE engineer_name like '%1'")
  179. .arg("%" + engineerName + "%");
  180. if (query.exec(selectSql)) {
  181. while (query.next()) {
  182. if (query.isNull(0) == false) {
  183. EngineerInfo *engineerInfo = new EngineerInfo();
  184. engineerInfo->engineerId = query.value(0).toInt();
  185. engineerInfo->engineerName = query.value(1).toString();
  186. engineerInfo->indexSetId = query.value(2).toInt();
  187. engineerInfo->schemaEvalId = query.value(3).toInt();
  188. engineerInfo->measureFunctionId = query.value(4).toInt();
  189. engineerInfo->remark = query.value(5).toString();
  190. engineerInfo->effectNameStr = query.value(6).toString();
  191. engineerInfoList->append(engineerInfo);
  192. }
  193. ret = true;
  194. }
  195. } else {
  196. qDebug() << query.lastError();
  197. }
  198. return ret;
  199. }
  200. bool EngineerService::QueryEngineerList(QList<EngineerInfo *> *engineerInfoList)
  201. {
  202. QSqlDatabase db = SqlDBHelper::getDatabase();
  203. QSqlQuery query(db);
  204. bool ret = false;
  205. try {
  206. QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, "
  207. "measure_function_id,remark,effect_name_str FROM t_engineer_info");
  208. if (query.exec(selectSql)) {
  209. while (query.next()) {
  210. if (query.isNull(0) == false) {
  211. EngineerInfo *engineerInfo = new EngineerInfo();
  212. engineerInfo->engineerId = query.value(0).toInt();
  213. engineerInfo->engineerName = query.value(1).toString();
  214. engineerInfo->indexSetId = query.value(2).toInt();
  215. engineerInfo->schemaEvalId = query.value(3).toInt();
  216. engineerInfo->measureFunctionId = query.value(4).toInt();
  217. engineerInfo->remark = query.value(5).toString();
  218. engineerInfo->effectNameStr = query.value(6).toString();
  219. engineerInfoList->append(engineerInfo);
  220. }
  221. }
  222. }
  223. ret = true;
  224. } catch (const DBException &ex) {
  225. qDebug() << ex.lastError.text();
  226. }
  227. return ret;
  228. }
  229. bool EngineerService::QueryEngineerListByIndexSetId(QList<EngineerInfo *> *engineerInfoList, int indexSetId)
  230. {
  231. QSqlDatabase db = SqlDBHelper::getDatabase();
  232. QSqlQuery query(db);
  233. bool ret = false;
  234. QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, "
  235. "measure_function_id,remark,effect_name_str FROM "
  236. "t_engineer_info WHERE index_set_id = %1")
  237. .arg(indexSetId);
  238. if (query.exec(selectSql)) {
  239. while (query.next()) {
  240. if (query.isNull(0) == false) {
  241. EngineerInfo *engineerInfo = new EngineerInfo();
  242. engineerInfo->engineerId = query.value(0).toInt();
  243. engineerInfo->engineerName = query.value(1).toString();
  244. engineerInfo->indexSetId = query.value(2).toInt();
  245. engineerInfo->schemaEvalId = query.value(3).toInt();
  246. engineerInfo->measureFunctionId = query.value(4).toInt();
  247. engineerInfo->remark = query.value(5).toString();
  248. engineerInfo->effectNameStr = query.value(6).toString();
  249. engineerInfoList->append(engineerInfo);
  250. }
  251. ret = true;
  252. }
  253. } else {
  254. qDebug() << query.lastError();
  255. }
  256. return ret;
  257. }
  258. bool EngineerService::QueryEngineerListByMeasureFunctionId(QList<EngineerInfo *> *engineerInfoList,
  259. int measureFunctionId)
  260. {
  261. QSqlDatabase db = SqlDBHelper::getDatabase();
  262. QSqlQuery query(db);
  263. bool ret = false;
  264. QString selectSql = QString("SELECT engineer_id, engineer_name, index_set_id, schema_set_id, "
  265. "measure_function_id,remark FROM "
  266. "t_engineer_info WHERE measure_function_id = %1")
  267. .arg(measureFunctionId);
  268. if (query.exec(selectSql)) {
  269. while (query.next()) {
  270. if (query.isNull(0) == false) {
  271. EngineerInfo *engineerInfo = new EngineerInfo();
  272. engineerInfo->engineerId = query.value(0).toInt();
  273. engineerInfo->engineerName = query.value(1).toString();
  274. engineerInfo->indexSetId = query.value(2).toInt();
  275. engineerInfo->schemaEvalId = query.value(3).toInt();
  276. engineerInfo->measureFunctionId = query.value(4).toInt();
  277. engineerInfo->remark = query.value(5).toString();
  278. engineerInfoList->append(engineerInfo);
  279. }
  280. ret = true;
  281. }
  282. } else {
  283. qDebug() << query.lastError();
  284. }
  285. return ret;
  286. }
  287. bool EngineerService::DeleteEngineerByEngineerId(int engineerId)
  288. {
  289. bool ret = false;
  290. try {
  291. Transaction t(SqlDBHelper::getDatabase());
  292. t.deleteFrom("t_engineer_info").where("engineer_id = ?", engineerId);
  293. t.commit();
  294. ret = true;
  295. } catch (const DBException &ex) {
  296. qDebug() << ex.lastError.text();
  297. }
  298. return ret;
  299. }
  300. bool EngineerService::DeleteEngineerByIndexSetId(int indexSetId)
  301. {
  302. bool ret = false;
  303. try {
  304. Transaction t(SqlDBHelper::getDatabase());
  305. t.deleteFrom("t_engineer_info").where("index_set_id = ?", indexSetId);
  306. t.commit();
  307. ret = true;
  308. } catch (const DBException &ex) {
  309. qDebug() << ex.lastError.text();
  310. }
  311. return ret;
  312. }
  313. bool EngineerService::DeleteEngineerByMeasureFunctionId(int measureFunctionId)
  314. {
  315. bool ret = false;
  316. try {
  317. Transaction t(SqlDBHelper::getDatabase());
  318. t.deleteFrom("t_engineer_info").where("measure_function_id = ?", measureFunctionId);
  319. t.commit();
  320. ret = true;
  321. } catch (const DBException &ex) {
  322. qDebug() << ex.lastError.text();
  323. }
  324. return ret;
  325. }
  326. //删除所有工程
  327. bool EngineerService::DeleteEngineers()
  328. {
  329. bool ret = false;
  330. try {
  331. QSqlDatabase db = SqlDBHelper::getDatabase();
  332. db.exec("delete from t_engineer_info");
  333. db.commit();
  334. ret = true;
  335. } catch (const DBException &ex) {
  336. qDebug() << ex.lastError.text();
  337. }
  338. return ret;
  339. }
  340. bool EngineerService::QueryChlidNodeByPId(int pid, QString dbName, QString mindPath)
  341. {
  342. QSqlDatabase db;
  343. if (QSqlDatabase::contains(dbName)) {
  344. db = QSqlDatabase::database(dbName);
  345. } else {
  346. db = QSqlDatabase::addDatabase("QSQLITE", dbName);
  347. db.setDatabaseName(mindPath);
  348. }
  349. if (!db.open()) {
  350. qDebug() << "test.db Open failed!";
  351. }
  352. // qDebug() << "open=" << db.isOpen();
  353. QSqlQuery query(db);
  354. bool ret = false;
  355. QString selectSql = QString("SELECT * from "
  356. "mind_data WHERE pid = %1")
  357. .arg(pid);
  358. // qDebug() << "sql=" << selectSql;
  359. if (query.exec(selectSql)) {
  360. if (query.next()) {
  361. // qDebug() << "cunzai";
  362. ret = true;
  363. } else {
  364. // qDebug() << "bucunzai";
  365. }
  366. } else {
  367. qDebug() << query.lastError();
  368. }
  369. db.close();
  370. // qDebug() << "------" << ret;
  371. return ret;
  372. }
  373. //删除资源包中多余工程
  374. bool EngineerService::DeleteEngineerNotInId(int id, QString dbPath)
  375. {
  376. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
  377. db.setDatabaseName(dbPath);
  378. if (!db.open()) {
  379. qDebug() << "test.db Open failed!";
  380. }
  381. QSqlQuery query(db);
  382. bool ret = false;
  383. QString deleteSql = QString("DELETE FROM t_engineer_info WHERE engineer_id != %1").arg(id);
  384. QString deleteUserConfig = QString("DELETE FROM t_user_config WHERE engineer_id != %1").arg(id);
  385. QString deleteUser = QString("DELETE FROM t_user_info WHERE id not in (select user_id FROM t_user_config WHERE "
  386. "engineer_id = %1)")
  387. .arg(id);
  388. QString deleteNodeValue = QString("DELETE FROM t_node_matrix_info ");
  389. QString deleteTechnical = QString("DELETE FROM t_technical_import");
  390. QString deleteScheme = QString("DELETE FROM t_scheme_info ");
  391. QString deleteDemand = QString("DELETE FROM t_demand_weight");
  392. QString deletePlan = QString("DELETE FROM t_plan_info");
  393. QString deletePlanIndex = QString("DELETE FROM t_plan_index");
  394. if (query.exec(deleteSql)) {
  395. query.exec(deleteUserConfig);
  396. query.exec(deleteUser);
  397. query.exec(deleteNodeValue);
  398. query.exec(deleteTechnical);
  399. query.exec(deleteScheme);
  400. query.exec(deleteDemand);
  401. query.exec(deletePlan);
  402. query.exec(deletePlanIndex);
  403. ret = true;
  404. qDebug() << "deleteSql success!";
  405. } else {
  406. qDebug() << query.lastError();
  407. }
  408. db.close();
  409. return ret;
  410. }
  411. //////////////////////工程信息表-end////////////////////