DBServiceSet.cpp 15 KB

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