DBServiceSet.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. #include "DBServiceSet.h"
  2. #include "SqlDBHelper.h"
  3. #include <QDebug>
  4. DBServiceSet::DBServiceSet(QObject *parent) { }
  5. //////////////////////common-start////////////////////
  6. int DBServiceSet::getNextId(QString tableName)
  7. {
  8. int nextId = -1;
  9. try {
  10. Transaction t(SqlDBHelper::getDatabase());
  11. QString selectSql = QString("SELECT seq from sqlite_sequence WHERE name = '%1'").arg(tableName);
  12. QueryResult queryResult = t.execQuery(selectSql);
  13. if (queryResult.next()) {
  14. nextId = queryResult.value(0).toInt() + 1;
  15. }
  16. } catch (const DBException &ex) {
  17. qDebug() << ex.lastError.text();
  18. }
  19. return nextId;
  20. }
  21. //////////////////////common-end////////////////////
  22. /////////////////////方案持久化-start////////////////
  23. bool DBServiceSet::AddSchemeInfoList(const QList<SchemaEval *> &schemeList)
  24. {
  25. bool ret = false;
  26. try {
  27. Transaction t(SqlDBHelper::getDatabase());
  28. for (int i = 0; i < schemeList.length(); i++) {
  29. SchemaEval *scheme = schemeList.at(i);
  30. InsertQuery q = t.insertInto("t_scheme_info (engineer_id,name,remark,value_str,score)");
  31. q.values(scheme->engineerId, scheme->name, scheme->remark, scheme->valueStr, scheme->score).exec();
  32. t.commit();
  33. }
  34. ret = true;
  35. } catch (const DBException &ex) {
  36. qDebug() << ex.lastError.text();
  37. }
  38. return ret;
  39. }
  40. bool DBServiceSet::DeleteSchemeByEngineerId(int engineerId)
  41. {
  42. bool ret = false;
  43. try {
  44. Transaction t(SqlDBHelper::getDatabase());
  45. t.deleteFrom("t_scheme_info").where("engineer_id = ?", engineerId);
  46. t.commit();
  47. ret = true;
  48. } catch (const DBException &ex) {
  49. qDebug() << ex.lastError.text();
  50. }
  51. return ret;
  52. }
  53. bool DBServiceSet::QuerySchemeInfoByEngineerId(QList<SchemaEval *> *schemeList, int engineerId)
  54. {
  55. QSqlDatabase db = SqlDBHelper::getDatabase();
  56. QSqlQuery query(db);
  57. bool ret = false;
  58. QString selectSql = QString("select id,engineer_id,name,remark,value_str "
  59. ",score from t_scheme_info where "
  60. " engineer_id =%1 ")
  61. .arg(QString::number(engineerId));
  62. // qDebug() << "sql=" << selectSql;
  63. if (query.exec(selectSql)) {
  64. while (query.next()) {
  65. if (query.isNull(0) == false) {
  66. SchemaEval *scheme = new SchemaEval();
  67. scheme->id = query.value(0).toInt();
  68. scheme->engineerId = query.value(1).toInt();
  69. scheme->name = query.value(2).toString();
  70. scheme->remark = query.value(3).toString();
  71. scheme->valueStr = query.value(4).toString();
  72. scheme->score = query.value(5).toDouble();
  73. schemeList->append(scheme);
  74. }
  75. ret = true;
  76. }
  77. } else {
  78. qDebug() << query.lastError();
  79. }
  80. return ret;
  81. }
  82. ///////////////////////common-end/////////////////////
  83. //////////////////////技术重要度持久化-start////////////////////
  84. bool DBServiceSet::AddTechnicalImportInfo(const TechnicalImport &technicalImport)
  85. {
  86. bool ret = false;
  87. try {
  88. Transaction t(SqlDBHelper::getDatabase());
  89. InsertQuery q = t.insertInto("t_technical_import (engineer_id,expert_id,node_name,node_value)");
  90. q.values(technicalImport.engineerId, technicalImport.expertId, technicalImport.nodeName,
  91. technicalImport.nodeValue)
  92. .exec();
  93. t.commit();
  94. ret = true;
  95. } catch (const DBException &ex) {
  96. qDebug() << ex.lastError.text();
  97. }
  98. return ret;
  99. }
  100. /*批量节点信息新增*/
  101. bool DBServiceSet::AddTechnicalImportInfoList(const QList<TechnicalImport *> &technicalImportList)
  102. {
  103. bool ret = false;
  104. try {
  105. Transaction t(SqlDBHelper::getDatabase());
  106. for (int i = 0; i < technicalImportList.length(); i++) {
  107. TechnicalImport *technical = technicalImportList.at(i);
  108. InsertQuery q = t.insertInto("t_technical_import (engineer_id,expert_id,node_name,node_value)");
  109. q.values(technical->engineerId, technical->expertId, technical->nodeName, technical->nodeValue).exec();
  110. t.commit();
  111. }
  112. ret = true;
  113. } catch (const DBException &ex) {
  114. qDebug() << ex.lastError.text();
  115. }
  116. return ret;
  117. }
  118. bool DBServiceSet::UpdateTechnicalImportInfoList(const QList<TechnicalImport *> technicalImportList)
  119. {
  120. QSqlDatabase db = SqlDBHelper::getDatabase();
  121. QSqlQuery query(db);
  122. bool ret = false;
  123. for (int i = 0; i < technicalImportList.length(); i++) {
  124. TechnicalImport *demandWeight = technicalImportList.at(i);
  125. QString updateSql = QString("UPDATE t_technical_import SET NODE_VALUE ='%1' "
  126. "WHERE ENGINEER_ID =%2 AND expert_id =%3"
  127. " AND node_name = '%4' ")
  128. .arg(demandWeight->nodeValue)
  129. .arg(demandWeight->engineerId)
  130. .arg(demandWeight->expertId)
  131. .arg(demandWeight->nodeName);
  132. // qDebug() << updateSql;
  133. query.exec(updateSql);
  134. ret = true;
  135. }
  136. return ret;
  137. }
  138. bool DBServiceSet::QueryTechnicalImportInfoByEngineerId(QList<TechnicalImport *> *demandWeightList, int expertId,
  139. int engineerId)
  140. {
  141. QSqlDatabase db = SqlDBHelper::getDatabase();
  142. QSqlQuery query(db);
  143. bool ret = false;
  144. QString selectSql = QString("select * from t_technical_import where "
  145. "expert_id =%1 and engineer_id =%2 ")
  146. .arg(QString::number(expertId))
  147. .arg(QString::number(engineerId));
  148. // qDebug() << "sql=" << selectSql;
  149. if (query.exec(selectSql)) {
  150. while (query.next()) {
  151. if (query.isNull(0) == false) {
  152. TechnicalImport *demandWeight = new TechnicalImport();
  153. demandWeight->id = query.value(0).toInt();
  154. demandWeight->engineerId = query.value(1).toInt();
  155. demandWeight->expertId = query.value(2).toInt();
  156. demandWeight->nodeName = query.value(3).toString();
  157. demandWeight->nodeValue = query.value(4).toDouble();
  158. demandWeightList->append(demandWeight);
  159. }
  160. ret = true;
  161. }
  162. } else {
  163. qDebug() << query.lastError();
  164. }
  165. return ret;
  166. }
  167. bool DBServiceSet::QueryTechnicalImportInfoByEngineerId(int expertId, int engineerId)
  168. {
  169. QSqlDatabase db = SqlDBHelper::getDatabase();
  170. QSqlQuery query(db);
  171. bool ret = false;
  172. QString selectSql = QString("select * from t_technical_import where "
  173. "expert_id =%1 and engineer_id =%2 ")
  174. .arg(QString::number(expertId))
  175. .arg(QString::number(engineerId));
  176. // qDebug() << "sql=" << selectSql;
  177. if (query.exec(selectSql)) {
  178. if (query.next()) {
  179. ret = true;
  180. }
  181. } else {
  182. qDebug() << query.lastError();
  183. }
  184. return ret;
  185. }
  186. //////////////////////common-end////////////////////
  187. //////////////////////节点矩阵信息表-start////////////////////
  188. //////////////////////节点矩阵信息表-end////////////////////
  189. //////////////////////评估方案信息表-start////////////////////
  190. bool DBServiceSet::AddPlanInfo(const PlanInfo &planInfo)
  191. {
  192. bool ret = false;
  193. try {
  194. Transaction t(SqlDBHelper::getDatabase());
  195. InsertQuery q = t.insertInto("t_plan_info (plan_name, engineer_id, desc,create_time)");
  196. q.values(planInfo.planName, planInfo.engineerId, planInfo.desc,
  197. QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz"))
  198. .exec();
  199. t.commit();
  200. ret = true;
  201. } catch (const DBException &ex) {
  202. qDebug() << ex.lastError.text();
  203. }
  204. return ret;
  205. }
  206. bool DBServiceSet::UpdatePlanInfo(const PlanInfo &planInfo)
  207. {
  208. bool ret = false;
  209. try {
  210. Transaction t(SqlDBHelper::getDatabase());
  211. t.update("t_plan_info")
  212. .set("plan_name", planInfo.planName)
  213. .set("engineer_id", planInfo.engineerId)
  214. .set("desc", planInfo.desc)
  215. .set("update_time", QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz"))
  216. .where("id=?", planInfo.id);
  217. t.commit();
  218. ret = true;
  219. } catch (const DBException &ex) {
  220. qDebug() << ex.lastError.text();
  221. }
  222. return ret;
  223. }
  224. bool DBServiceSet::QueryPlanInfoById(PlanInfo *planInfo, int planId)
  225. {
  226. bool ret = false;
  227. try {
  228. Transaction t(SqlDBHelper::getDatabase());
  229. QString selectSql = QString("SELECT id, plan_name,engineer_id, desc from t_plan_info "
  230. " WHERE id = %1")
  231. .arg(planId);
  232. QueryResult queryResult = t.execQuery(selectSql);
  233. if (queryResult.next()) {
  234. planInfo->id = queryResult.value(0).toInt();
  235. planInfo->planName = queryResult.value(1).toString();
  236. planInfo->engineerId = queryResult.value(2).toInt();
  237. planInfo->desc = queryResult.value(3).toString();
  238. ret = true;
  239. }
  240. } catch (const DBException &ex) {
  241. qDebug() << ex.lastError.text();
  242. }
  243. return ret;
  244. }
  245. bool DBServiceSet::QueryPlanListByColumnAndColumnValue(QList<PlanInfo *> *planInfoList, QString columnName,
  246. QString columnValue)
  247. {
  248. bool ret = false;
  249. try {
  250. Transaction t(SqlDBHelper::getDatabase());
  251. QString selectSql = QString("SELECT id, plan_name,engineer_id, desc from t_plan_info "
  252. " WHERE %1 = '%2'")
  253. .arg(columnName)
  254. .arg(columnValue);
  255. QueryResult queryResult = t.execQuery(selectSql);
  256. while (queryResult.next()) {
  257. PlanInfo *planInfo = new PlanInfo();
  258. planInfo->id = queryResult.value(0).toInt();
  259. planInfo->planName = queryResult.value(1).toString();
  260. planInfo->engineerId = queryResult.value(2).toInt();
  261. planInfo->desc = queryResult.value(3).toString();
  262. planInfoList->append(planInfo);
  263. ret = true;
  264. }
  265. } catch (const DBException &ex) {
  266. qDebug() << ex.lastError.text();
  267. }
  268. return ret;
  269. }
  270. bool DBServiceSet::QueryPlanList(QList<PlanInfo *> *planInfoList)
  271. {
  272. bool ret = false;
  273. try {
  274. Transaction t(SqlDBHelper::getDatabase());
  275. QString selectSql = QString("SELECT id, plan_name,engineer_id, desc from t_plan_info ");
  276. QueryResult queryResult = t.execQuery(selectSql);
  277. while (queryResult.next()) {
  278. PlanInfo *planInfo = new PlanInfo();
  279. planInfo->id = queryResult.value(0).toInt();
  280. planInfo->planName = queryResult.value(1).toString();
  281. planInfo->engineerId = queryResult.value(2).toInt();
  282. planInfo->desc = queryResult.value(3).toString();
  283. planInfoList->append(planInfo);
  284. ret = true;
  285. }
  286. } catch (const DBException &ex) {
  287. qDebug() << ex.lastError.text();
  288. }
  289. return ret;
  290. }
  291. bool DBServiceSet::DeletePlanById(int planId)
  292. {
  293. QSqlDatabase db = SqlDBHelper::getDatabase();
  294. QSqlQuery query(db);
  295. bool ret = false;
  296. QString deleteSql = QString("DELETE FROM t_plan_info WHERE id = %1").arg(planId);
  297. if (query.exec(deleteSql)) {
  298. ret = true;
  299. qDebug() << "deleteSql success!";
  300. } else {
  301. qDebug() << query.lastError();
  302. }
  303. return ret;
  304. }
  305. //////////////////////评估方案信息表-end////////////////////
  306. //////////////////////指标体系评估方案关系信息表-start////////////////////
  307. /*批量信息新增*/
  308. bool DBServiceSet::AddIndexSetPlanInfoList(const QList<IndexSetPlanInfo *> planInfoList)
  309. {
  310. bool ret = false;
  311. try {
  312. Transaction t(SqlDBHelper::getDatabase());
  313. QString insertTime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz");
  314. for (int i = 0; i < planInfoList.length(); i++) {
  315. IndexSetPlanInfo *indexSetPlanInfo = planInfoList.at(i);
  316. InsertQuery query = t.insertInto("t_plan_index (index_set_id, plan_id, weight, create_time)");
  317. query.values(indexSetPlanInfo->indexSetId, indexSetPlanInfo->planId, indexSetPlanInfo->weight, insertTime)
  318. .exec();
  319. }
  320. t.commit();
  321. ret = true;
  322. } catch (const DBException &ex) {
  323. qDebug() << ex.lastError.text();
  324. }
  325. return ret;
  326. }
  327. bool DBServiceSet::UpdateIndexSetPlanInfo(const IndexSetPlanInfo &planInfo)
  328. {
  329. bool ret = false;
  330. try {
  331. Transaction t(SqlDBHelper::getDatabase());
  332. t.update("t_plan_index")
  333. .set("weight", planInfo.weight)
  334. .set("update_time", QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz"))
  335. .where("index_set_id =? and plan_id=?", planInfo.indexSetId, planInfo.planId);
  336. t.commit();
  337. ret = true;
  338. } catch (const DBException &ex) {
  339. qDebug() << ex.lastError.text();
  340. }
  341. return ret;
  342. }
  343. bool DBServiceSet::UpdateIndexSetPlanInfoList(const QList<IndexSetPlanInfo *> planInfoList)
  344. {
  345. bool ret = false;
  346. try {
  347. Transaction t(SqlDBHelper::getDatabase());
  348. QString updateTime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss.zzz");
  349. for (int i = 0; i < planInfoList.length(); i++) {
  350. IndexSetPlanInfo *indexSetPlanInfo = planInfoList.at(i);
  351. t.update("t_plan_index")
  352. .set("weight", indexSetPlanInfo->weight)
  353. .set("update_time", updateTime)
  354. .where("index_set_id =? and plan_id=?", indexSetPlanInfo->indexSetId, indexSetPlanInfo->planId);
  355. }
  356. t.commit();
  357. ret = true;
  358. } catch (const DBException &ex) {
  359. qDebug() << ex.lastError.text();
  360. }
  361. return ret;
  362. }
  363. bool DBServiceSet::DeleteIndexSetPlanById(int Id)
  364. {
  365. QSqlDatabase db = SqlDBHelper::getDatabase();
  366. QSqlQuery query(db);
  367. bool ret = false;
  368. QString deleteSql = QString("DELETE FROM t_plan_index WHERE id = %1").arg(Id);
  369. if (query.exec(deleteSql)) {
  370. ret = true;
  371. qDebug() << "deleteSql success!";
  372. } else {
  373. qDebug() << query.lastError();
  374. }
  375. return ret;
  376. }
  377. bool DBServiceSet::DeleteIndexSetPlanByPlanId(int planId)
  378. {
  379. QSqlDatabase db = SqlDBHelper::getDatabase();
  380. QSqlQuery query(db);
  381. bool ret = false;
  382. QString deleteSql = QString("DELETE FROM t_plan_index WHERE plan_id = %1").arg(planId);
  383. if (query.exec(deleteSql)) {
  384. ret = true;
  385. qDebug() << "deleteSql success!";
  386. } else {
  387. qDebug() << query.lastError();
  388. }
  389. return ret;
  390. }
  391. bool DBServiceSet::DeleteIndexSetPlanByIndexSetId(int indexSetId)
  392. {
  393. QSqlDatabase db = SqlDBHelper::getDatabase();
  394. QSqlQuery query(db);
  395. bool ret = false;
  396. QString deleteSql = QString("DELETE FROM t_plan_index WHERE index_set_id = %1").arg(indexSetId);
  397. if (query.exec(deleteSql)) {
  398. ret = true;
  399. qDebug() << "deleteSql success!";
  400. } else {
  401. qDebug() << query.lastError();
  402. }
  403. return ret;
  404. }
  405. bool DBServiceSet::QueryIndexSetPlanInfo(IndexSetPlanInfo *planInfo, int Id)
  406. {
  407. bool ret = false;
  408. try {
  409. Transaction t(SqlDBHelper::getDatabase());
  410. QString selectSql = QString("SELECT id, plan_id,index_set_id,weight from t_plan_index "
  411. " WHERE id = %1")
  412. .arg(Id);
  413. QueryResult queryResult = t.execQuery(selectSql);
  414. if (queryResult.next()) {
  415. planInfo->id = queryResult.value(0).toInt();
  416. planInfo->planId = queryResult.value(1).toInt();
  417. planInfo->indexSetId = queryResult.value(2).toInt();
  418. planInfo->weight = queryResult.value(3).toDouble();
  419. ret = true;
  420. }
  421. } catch (const DBException &ex) {
  422. qDebug() << ex.lastError.text();
  423. }
  424. return ret;
  425. }
  426. bool DBServiceSet::QueryIndexSetPlanListByColumnAndColumnValue(QList<IndexSetPlanInfo *> *planInfoList,
  427. QString columnName, QString columnValue)
  428. {
  429. bool ret = false;
  430. try {
  431. Transaction t(SqlDBHelper::getDatabase());
  432. QString selectSql = QString("SELECT id, plan_id,index_set_id,weight from "
  433. "t_plan_index where %1 = '%2' ")
  434. .arg(columnName)
  435. .arg(columnValue);
  436. QueryResult queryResult = t.execQuery(selectSql);
  437. while (queryResult.next()) {
  438. IndexSetPlanInfo *planInfo = new IndexSetPlanInfo();
  439. planInfo->id = queryResult.value(0).toInt();
  440. planInfo->planId = queryResult.value(1).toInt();
  441. planInfo->indexSetId = queryResult.value(2).toInt();
  442. planInfo->weight = queryResult.value(3).toDouble();
  443. planInfoList->append(planInfo);
  444. ret = true;
  445. }
  446. } catch (const DBException &ex) {
  447. qDebug() << ex.lastError.text();
  448. }
  449. return ret;
  450. }
  451. //////////////////////指标体系评估方案关系信息表-end////////////////////