NodeMatrixService.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. #include "NodeMatrixService.h"
  2. #include "SqlDBHelper.h"
  3. #include <QDebug>
  4. NodeMatrixService::NodeMatrixService(QObject *parent) { }
  5. bool NodeMatrixService::AddNodeMatrixInfo(const NodeMatrixInfo &nodeMatrixInfo)
  6. {
  7. bool ret = false;
  8. try {
  9. Transaction t(SqlDBHelper::getDatabase());
  10. InsertQuery q = t.insertInto("t_node_matrix_info (expert_name, engineer_id, node, "
  11. "abscissa, ordinate, "
  12. "node_value, expert_id,mind_name,write_date,mark,str_uuid)");
  13. q.values(nodeMatrixInfo.expertName, nodeMatrixInfo.engineerId, nodeMatrixInfo.node, nodeMatrixInfo.abscissa,
  14. nodeMatrixInfo.ordinate, nodeMatrixInfo.nodeValue, nodeMatrixInfo.expertId, nodeMatrixInfo.mindId,
  15. nodeMatrixInfo.writeDate.toString(), nodeMatrixInfo.mark, nodeMatrixInfo.strUuid)
  16. .exec();
  17. t.commit();
  18. ret = true;
  19. } catch (const DBException &ex) {
  20. qDebug() << ex.lastError.text();
  21. }
  22. return ret;
  23. }
  24. /*批量节点信息新增*/
  25. bool NodeMatrixService::AddNodeMatrixInfoList(const QList<NodeMatrixInfo *> &jbInfoList)
  26. {
  27. bool ret = false;
  28. try {
  29. Transaction t(SqlDBHelper::getDatabase());
  30. for (int i = 0; i < jbInfoList.length(); i++) {
  31. NodeMatrixInfo *nodeMatrixInfo = jbInfoList.at(i);
  32. InsertQuery query = t.insertInto("t_node_matrix_info (expert_name, engineer_id, node, abscissa, "
  33. "ordinate, "
  34. "node_value, expert_id,mind_id,write_date,mark,table_msg,str_uuid)");
  35. query.values(nodeMatrixInfo->expertName, nodeMatrixInfo->engineerId, nodeMatrixInfo->node,
  36. nodeMatrixInfo->abscissa, nodeMatrixInfo->ordinate, nodeMatrixInfo->nodeValue,
  37. nodeMatrixInfo->expertId, nodeMatrixInfo->mindId, nodeMatrixInfo->writeDate.toString(),
  38. nodeMatrixInfo->mark, nodeMatrixInfo->tableMsg, nodeMatrixInfo->strUuid)
  39. .exec();
  40. t.commit();
  41. }
  42. ret = true;
  43. } catch (const DBException &ex) {
  44. qDebug() << ex.lastError.text();
  45. }
  46. return ret;
  47. }
  48. /*批量节点信息新增----专家端*/
  49. bool NodeMatrixService::AddNodeMatrixInfoList2(const QList<NodeMatrixInfo *> &jbInfoList)
  50. {
  51. bool ret = false;
  52. try {
  53. Transaction t(SqlDBHelper::getDatabase2());
  54. for (int i = 0; i < jbInfoList.length(); i++) {
  55. NodeMatrixInfo *nodeMatrixInfo = jbInfoList.at(i);
  56. InsertQuery query = t.insertInto("t_node_matrix_info (expert_name, engineer_id, node, abscissa, "
  57. "ordinate, "
  58. "node_value, expert_id,mind_id,write_date,mark,table_msg,tab_index)");
  59. query.values(nodeMatrixInfo->expertName, nodeMatrixInfo->engineerId, nodeMatrixInfo->node,
  60. nodeMatrixInfo->abscissa, nodeMatrixInfo->ordinate, nodeMatrixInfo->nodeValue,
  61. nodeMatrixInfo->expertId, nodeMatrixInfo->mindId, nodeMatrixInfo->writeDate.toString(),
  62. nodeMatrixInfo->mark, nodeMatrixInfo->tableMsg, nodeMatrixInfo->tabIndex)
  63. .exec();
  64. t.commit();
  65. }
  66. ret = true;
  67. } catch (const DBException &ex) {
  68. qDebug() << ex.lastError.text();
  69. }
  70. return ret;
  71. }
  72. /*修改节点值*/
  73. bool NodeMatrixService::UpdateNodeMatrixNodeValue(const NodeMatrixInfo &nodeMatrixInfo)
  74. {
  75. bool ret = false;
  76. try {
  77. Transaction t(SqlDBHelper::getDatabase());
  78. t.update("t_node_matrix_info")
  79. .set("NODE_VALUE", nodeMatrixInfo.nodeValue)
  80. .where("ENGINEER_ID = ? and expert_name = and abscissa = ? and "
  81. "ordinate = ? ",
  82. nodeMatrixInfo.engineerId, nodeMatrixInfo.expertName, nodeMatrixInfo.abscissa,
  83. nodeMatrixInfo.ordinate);
  84. t.commit();
  85. ret = true;
  86. } catch (const DBException &ex) {
  87. qDebug() << ex.lastError.text();
  88. }
  89. return ret;
  90. }
  91. bool NodeMatrixService::UpdateNodeMatrixNodeValueList(const QList<NodeMatrixInfo *> jbInfoList)
  92. {
  93. QSqlDatabase db = SqlDBHelper::getDatabase();
  94. QSqlQuery query(db);
  95. bool ret = false;
  96. for (int i = 0; i < jbInfoList.length(); i++) {
  97. NodeMatrixInfo *nodeMatrixInfo = jbInfoList.at(i);
  98. QString updateSql = QString("UPDATE t_node_matrix_info SET NODE_VALUE ='%1' WHERE "
  99. "ENGINEER_ID = %2 AND expert_name = '%3'"
  100. " AND abscissa = '%4' AND ordinate = '%5' and table_msg = '%6' "
  101. "and mark = '%7' and str_uuid = '%8'")
  102. .arg(nodeMatrixInfo->nodeValue)
  103. .arg(nodeMatrixInfo->engineerId)
  104. .arg(nodeMatrixInfo->expertName)
  105. .arg(nodeMatrixInfo->abscissa)
  106. .arg(nodeMatrixInfo->ordinate)
  107. .arg(nodeMatrixInfo->tableMsg)
  108. .arg(nodeMatrixInfo->mark)
  109. .arg(nodeMatrixInfo->strUuid);
  110. // qDebug() << updateSql;
  111. query.exec(updateSql);
  112. ret = true;
  113. }
  114. return ret;
  115. }
  116. bool NodeMatrixService::UpdateNodeMatrixNodeValueList2(const QList<NodeMatrixInfo *> jbInfoList)
  117. {
  118. QSqlDatabase db = SqlDBHelper::getDatabase2();
  119. QSqlQuery query(db);
  120. bool ret = false;
  121. for (int i = 0; i < jbInfoList.length(); i++) {
  122. NodeMatrixInfo *nodeMatrixInfo = jbInfoList.at(i);
  123. QString updateSql = QString("UPDATE t_node_matrix_info SET NODE_VALUE ='%1' WHERE "
  124. "ENGINEER_ID = %2 AND expert_name = '%3'"
  125. " AND abscissa = '%4' AND ordinate = '%5' and table_msg = '%6' "
  126. "and mark = '%7' and tab_index = '%8'")
  127. .arg(nodeMatrixInfo->nodeValue)
  128. .arg(nodeMatrixInfo->engineerId)
  129. .arg(nodeMatrixInfo->expertName)
  130. .arg(nodeMatrixInfo->abscissa)
  131. .arg(nodeMatrixInfo->ordinate)
  132. .arg(nodeMatrixInfo->tableMsg)
  133. .arg(nodeMatrixInfo->mark)
  134. .arg(nodeMatrixInfo->tabIndex);
  135. // qDebug() << updateSql;
  136. query.exec(updateSql);
  137. ret = true;
  138. }
  139. return ret;
  140. }
  141. /*根据专家姓名和工程id获取节点信息*/
  142. bool NodeMatrixService::QueryNodeMatrixListByExpertNameAndEngineerId(QString expertName, int engineerId,
  143. QString tableMsg, QString mark)
  144. {
  145. QSqlDatabase db = SqlDBHelper::getDatabase();
  146. QSqlQuery query(db);
  147. bool ret = false;
  148. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  149. "node_value, expert_id,mind_id,write_date from "
  150. "t_node_matrix_info where expert_name "
  151. "= '%1' and engineer_id ='%2' and table_msg='%3' and mark = '%4'")
  152. .arg(expertName)
  153. .arg(QString::number(engineerId))
  154. .arg(tableMsg)
  155. .arg(mark);
  156. if (query.exec(selectSql)) {
  157. if (query.next()) {
  158. ret = true;
  159. }
  160. } else {
  161. qDebug() << query.lastError();
  162. }
  163. qDebug() << ret;
  164. return ret;
  165. }
  166. /*根据专家姓名和工程id获取节点信息*/
  167. bool NodeMatrixService::QueryNodeMatrixListByExpertIdAndEngineerId(QString expertId, int engineerId, QString tableMsg)
  168. {
  169. QSqlDatabase db = SqlDBHelper::getDatabase();
  170. QSqlQuery query(db);
  171. bool ret = false;
  172. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  173. "node_value, expert_id,mind_id,write_date from "
  174. "t_node_matrix_info where expert_id "
  175. "= '%1' and engineer_id ='%2' and table_msg='%3'")
  176. .arg(expertId)
  177. .arg(QString::number(engineerId))
  178. .arg(tableMsg);
  179. // qDebug() << selectSql;
  180. if (query.exec(selectSql)) {
  181. if (query.next()) {
  182. ret = true;
  183. }
  184. } else {
  185. qDebug() << query.lastError();
  186. }
  187. // qDebug() << ret;
  188. return ret;
  189. }
  190. bool NodeMatrixService::QueryNodeMatrixListByExpertNameAndEngineerId(QList<NodeMatrixInfo *> *nodeMatrixInfoList,
  191. QString expertName, int engineerId)
  192. {
  193. QSqlDatabase db = SqlDBHelper::getDatabase();
  194. QSqlQuery query(db);
  195. bool ret = false;
  196. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  197. "node_value, expert_id,mind_id,write_date,mark,str_uuid from "
  198. "t_node_matrix_info where expert_name "
  199. "= '%1' and engineer_id ='%2'")
  200. .arg(expertName)
  201. .arg(QString::number(engineerId));
  202. if (query.exec(selectSql)) {
  203. while (query.next()) {
  204. if (query.isNull(0) == false) {
  205. NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo();
  206. nodeMatrixInfo->id = query.value(0).toInt();
  207. nodeMatrixInfo->expertName = query.value(1).toString();
  208. nodeMatrixInfo->engineerId = query.value(2).toInt();
  209. nodeMatrixInfo->node = query.value(3).toString();
  210. nodeMatrixInfo->abscissa = query.value(4).toString();
  211. nodeMatrixInfo->ordinate = query.value(5).toString();
  212. nodeMatrixInfo->nodeValue = query.value(6).toString();
  213. nodeMatrixInfo->expertId = query.value(7).toInt();
  214. nodeMatrixInfo->mindId = query.value(8).toInt();
  215. nodeMatrixInfo->writeDate = query.value(9).toDateTime();
  216. nodeMatrixInfo->mark = query.value(10).toString();
  217. nodeMatrixInfo->strUuid = query.value(11).toString();
  218. nodeMatrixInfoList->append(nodeMatrixInfo);
  219. }
  220. ret = true;
  221. }
  222. } else {
  223. qDebug() << query.lastError();
  224. }
  225. return ret;
  226. }
  227. bool NodeMatrixService::QueryNodeMatrixListByExpertNameAndEngineerId2(QString expertName, int engineerId,
  228. QString tableMsg, QString mark, int tabIndex)
  229. {
  230. QSqlDatabase db = SqlDBHelper::getDatabase2();
  231. QSqlQuery query(db);
  232. bool ret = false;
  233. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  234. "node_value, expert_id,mind_id,write_date from "
  235. "t_node_matrix_info where expert_name "
  236. "= '%1' and engineer_id ='%2' and table_msg='%3' and mark = '%4' and tab_index = '%5'")
  237. .arg(expertName)
  238. .arg(QString::number(engineerId))
  239. .arg(tableMsg)
  240. .arg(mark)
  241. .arg(tabIndex);
  242. if (query.exec(selectSql)) {
  243. if (query.next()) {
  244. ret = true;
  245. }
  246. } else {
  247. qDebug() << query.lastError();
  248. }
  249. qDebug() << ret;
  250. return ret;
  251. }
  252. bool NodeMatrixService::QueryNodesByExpertNameAndEngineerId2(QList<NodeMatrixInfo *> *nodeMatrixInfoList,
  253. QString expertName, int engineerId, QString tableMsg,
  254. QString mark, int tabIndex)
  255. {
  256. QSqlDatabase db = SqlDBHelper::getDatabase2();
  257. QSqlQuery query(db);
  258. bool ret = false;
  259. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  260. "node_value, expert_id,mind_id,write_date,str_uuid from "
  261. "t_node_matrix_info where expert_name "
  262. "= '%1' and engineer_id ='%2' and table_msg='%3' and mark = '%4' and tab_index = '%5'")
  263. .arg(expertName)
  264. .arg(QString::number(engineerId))
  265. .arg(tableMsg)
  266. .arg(mark)
  267. .arg(tabIndex);
  268. // qDebug() << "----" << selectSql;
  269. if (query.exec(selectSql)) {
  270. while (query.next()) {
  271. if (query.isNull(0) == false) {
  272. NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo();
  273. nodeMatrixInfo->id = query.value(0).toInt();
  274. nodeMatrixInfo->expertName = query.value(1).toString();
  275. nodeMatrixInfo->node = query.value(2).toString();
  276. nodeMatrixInfo->engineerId = query.value(3).toInt();
  277. nodeMatrixInfo->abscissa = query.value(4).toString();
  278. nodeMatrixInfo->ordinate = query.value(5).toString();
  279. nodeMatrixInfo->nodeValue = query.value(6).toString();
  280. nodeMatrixInfo->expertId = query.value(7).toInt();
  281. nodeMatrixInfo->mindId = query.value(8).toInt();
  282. nodeMatrixInfo->writeDate = query.value(9).toDateTime();
  283. nodeMatrixInfo->mark = query.value(10).toString();
  284. nodeMatrixInfo->strUuid = query.value(11).toString();
  285. nodeMatrixInfoList->append(nodeMatrixInfo);
  286. }
  287. ret = true;
  288. }
  289. } else {
  290. qDebug() << query.lastError();
  291. }
  292. qDebug() << ret;
  293. return ret;
  294. }
  295. bool NodeMatrixService::QueryNodeValueByUserIdAndEngineerId(int experId, int engineerId)
  296. {
  297. QSqlDatabase db = SqlDBHelper::getDatabase();
  298. QSqlQuery query(db);
  299. bool ret = false;
  300. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  301. "node_value, expert_id,mind_id,write_date from "
  302. "t_node_matrix_info where expert_id "
  303. "= '%1' and engineer_id ='%2'")
  304. .arg(QString::number(experId))
  305. .arg(QString::number(engineerId));
  306. // qDebug() << "selectSql=" << selectSql;
  307. if (query.exec(selectSql)) {
  308. if (query.next()) {
  309. ret = true;
  310. }
  311. } else {
  312. qDebug() << query.lastError();
  313. }
  314. return ret;
  315. }
  316. bool NodeMatrixService::QueryNodeMatrixListByExpertIdAndEngineerId(QList<NodeMatrixInfo *> *nodeMatrixInfoList,
  317. int expertId, int engineerId, QString tableMsg)
  318. {
  319. QSqlDatabase db = SqlDBHelper::getDatabase();
  320. QSqlQuery query(db);
  321. bool ret = false;
  322. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  323. "node_value, expert_id,mind_id,write_date,mark,str_uuid from "
  324. "t_node_matrix_info where expert_id "
  325. "= '%1' and engineer_id ='%2' and table_msg ='%3'")
  326. .arg(QString::number(expertId))
  327. .arg(QString::number(engineerId))
  328. .arg(tableMsg);
  329. // qDebug() << "selectSql=" << selectSql;
  330. if (query.exec(selectSql)) {
  331. while (query.next()) {
  332. if (query.isNull(0) == false) {
  333. NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo();
  334. nodeMatrixInfo->id = query.value(0).toInt();
  335. nodeMatrixInfo->expertName = query.value(1).toString();
  336. nodeMatrixInfo->engineerId = query.value(2).toInt();
  337. nodeMatrixInfo->node = query.value(3).toString();
  338. nodeMatrixInfo->abscissa = query.value(4).toString();
  339. nodeMatrixInfo->ordinate = query.value(5).toString();
  340. nodeMatrixInfo->nodeValue = query.value(6).toString();
  341. nodeMatrixInfo->expertId = query.value(7).toInt();
  342. nodeMatrixInfo->mindId = query.value(8).toInt();
  343. nodeMatrixInfo->writeDate = query.value(9).toDateTime();
  344. nodeMatrixInfo->mark = query.value(10).toString();
  345. nodeMatrixInfo->strUuid = query.value(11).toString();
  346. nodeMatrixInfoList->append(nodeMatrixInfo);
  347. }
  348. }
  349. ret = true;
  350. } else {
  351. qDebug() << query.lastError();
  352. }
  353. return ret;
  354. }
  355. bool NodeMatrixService::QueryNodeMatrixListByExpertIdAndEngineerId2(QList<NodeMatrixInfo *> *nodeMatrixInfoList,
  356. int expertId, int engineerId, QString tableMsg)
  357. {
  358. QSqlDatabase db = SqlDBHelper::getDatabase2();
  359. QSqlQuery query(db);
  360. bool ret = false;
  361. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  362. "node_value, expert_id,mind_id,write_date,mark,str_uuid from "
  363. "t_node_matrix_info where expert_id "
  364. "= '%1' and engineer_id ='%2' and table_msg ='%3'")
  365. .arg(QString::number(expertId))
  366. .arg(QString::number(engineerId))
  367. .arg(tableMsg);
  368. // qDebug() << "selectSql=" << selectSql;
  369. if (query.exec(selectSql)) {
  370. while (query.next()) {
  371. if (query.isNull(0) == false) {
  372. NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo();
  373. nodeMatrixInfo->id = query.value(0).toInt();
  374. nodeMatrixInfo->expertName = query.value(1).toString();
  375. nodeMatrixInfo->engineerId = query.value(2).toInt();
  376. nodeMatrixInfo->node = query.value(3).toString();
  377. nodeMatrixInfo->abscissa = query.value(4).toString();
  378. nodeMatrixInfo->ordinate = query.value(5).toString();
  379. nodeMatrixInfo->nodeValue = query.value(6).toString();
  380. nodeMatrixInfo->expertId = query.value(7).toInt();
  381. nodeMatrixInfo->mindId = query.value(8).toInt();
  382. nodeMatrixInfo->writeDate = query.value(9).toDateTime();
  383. nodeMatrixInfo->mark = query.value(10).toString();
  384. nodeMatrixInfo->strUuid = query.value(11).toString();
  385. nodeMatrixInfoList->append(nodeMatrixInfo);
  386. }
  387. ret = true;
  388. }
  389. } else {
  390. qDebug() << query.lastError();
  391. }
  392. return ret;
  393. }
  394. /*根据专家姓名查询对应的节点信息*/
  395. bool NodeMatrixService::QueryNodeMatrixListByExpertName(QList<NodeMatrixInfo *> *nodeMatrixInfoList, QString expertName)
  396. {
  397. QSqlDatabase db = SqlDBHelper::getDatabase();
  398. QSqlQuery query(db);
  399. bool ret = false;
  400. QString selectSql = QString("select id,expert_name, node,engineer_id, abscissa, ordinate, "
  401. "node_value, expert_id,mind_name,write_date,mark ,str_uuid from "
  402. "t_node_matrix_info where expert_name = '%1'")
  403. .arg(expertName);
  404. if (query.exec(selectSql)) {
  405. while (query.next()) {
  406. if (query.isNull(0) == false) {
  407. NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo();
  408. nodeMatrixInfo->id = query.value(0).toInt();
  409. nodeMatrixInfo->expertName = query.value(1).toString();
  410. nodeMatrixInfo->node = query.value(2).toString();
  411. nodeMatrixInfo->engineerId = query.value(3).toInt();
  412. nodeMatrixInfo->abscissa = query.value(4).toString();
  413. nodeMatrixInfo->ordinate = query.value(5).toString();
  414. nodeMatrixInfo->nodeValue = query.value(6).toString();
  415. nodeMatrixInfo->expertId = query.value(7).toInt();
  416. nodeMatrixInfo->mindId = query.value(8).toInt();
  417. nodeMatrixInfo->writeDate = query.value(9).toDateTime();
  418. nodeMatrixInfo->mark = query.value(10).toString();
  419. nodeMatrixInfo->strUuid = query.value(11).toString();
  420. nodeMatrixInfoList->append(nodeMatrixInfo);
  421. }
  422. ret = true;
  423. }
  424. } else {
  425. qDebug() << query.lastError();
  426. }
  427. return ret;
  428. }
  429. /*根据专家姓名编号对应的节点信息*/
  430. bool NodeMatrixService::QueryNodeMatrixListByExpertId(QList<NodeMatrixInfo *> *nodeMatrixInfoList, int expertId)
  431. {
  432. QSqlDatabase db = SqlDBHelper::getDatabase();
  433. QSqlQuery query(db);
  434. bool ret = false;
  435. QString selectSql = QString("select id,expert_name, node,engineer_id, abscissa, ordinate, "
  436. "node_value, expert_id,mind_name,write_date,mark,str_uuid from "
  437. "t_node_matrix_info where expert_id = '%1'")
  438. .arg(expertId);
  439. if (query.exec(selectSql)) {
  440. while (query.next()) {
  441. if (query.isNull(0) == false) {
  442. NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo();
  443. nodeMatrixInfo->id = query.value(0).toInt();
  444. nodeMatrixInfo->expertName = query.value(1).toString();
  445. nodeMatrixInfo->node = query.value(2).toString();
  446. nodeMatrixInfo->engineerId = query.value(3).toInt();
  447. nodeMatrixInfo->abscissa = query.value(4).toString();
  448. nodeMatrixInfo->ordinate = query.value(5).toString();
  449. nodeMatrixInfo->nodeValue = query.value(6).toString();
  450. nodeMatrixInfo->expertId = query.value(7).toInt();
  451. nodeMatrixInfo->mindId = query.value(8).toInt();
  452. nodeMatrixInfo->writeDate = query.value(9).toDateTime();
  453. nodeMatrixInfo->mark = query.value(10).toString();
  454. nodeMatrixInfo->strUuid = query.value(11).toString();
  455. nodeMatrixInfoList->append(nodeMatrixInfo);
  456. }
  457. ret = true;
  458. }
  459. } else {
  460. qDebug() << query.lastError();
  461. }
  462. return ret;
  463. }
  464. /*根据工程编号查询对应的节点信息*/
  465. bool NodeMatrixService::QueryNodeMatrixListByEngineerId(QList<NodeMatrixInfo *> *nodeMatrixInfoList, int engineerId)
  466. {
  467. QSqlDatabase db = SqlDBHelper::getDatabase();
  468. QSqlQuery query(db);
  469. bool ret = false;
  470. QString selectSql = QString("select id,expert_name, node, engineer_id, abscissa, ordinate, "
  471. "node_value, expert_id ,mind_name,write_date,mark,str_uuid from "
  472. "t_node_matrix_info where engineer_id = '%1'")
  473. .arg(engineerId);
  474. if (query.exec(selectSql)) {
  475. while (query.next()) {
  476. if (query.isNull(0) == false) {
  477. NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo();
  478. nodeMatrixInfo->id = query.value(0).toInt();
  479. nodeMatrixInfo->expertName = query.value(1).toString();
  480. nodeMatrixInfo->node = query.value(2).toString();
  481. nodeMatrixInfo->engineerId = query.value(3).toInt();
  482. nodeMatrixInfo->abscissa = query.value(4).toString();
  483. nodeMatrixInfo->ordinate = query.value(5).toString();
  484. nodeMatrixInfo->nodeValue = query.value(6).toString();
  485. nodeMatrixInfo->expertId = query.value(7).toInt();
  486. nodeMatrixInfo->mindId = query.value(8).toInt();
  487. nodeMatrixInfo->writeDate = query.value(9).toDateTime();
  488. nodeMatrixInfo->mark = query.value(10).toString();
  489. nodeMatrixInfo->strUuid = query.value(11).toString();
  490. nodeMatrixInfoList->append(nodeMatrixInfo);
  491. }
  492. ret = true;
  493. }
  494. } else {
  495. qDebug() << query.lastError();
  496. }
  497. return ret;
  498. }
  499. /*根据工程编号删除对应的节点信息*/
  500. bool NodeMatrixService::DeleteNodeMatrixListByEngineerId(int engineerId)
  501. {
  502. bool ret = false;
  503. try {
  504. Transaction t(SqlDBHelper::getDatabase());
  505. t.deleteFrom("t_node_matrix_info").where("engineer_id = ?", engineerId);
  506. t.commit();
  507. ret = true;
  508. } catch (const DBException &ex) {
  509. qDebug() << ex.lastError.text();
  510. }
  511. return ret;
  512. }
  513. /*根据专家名称删除对应的节点信息*/
  514. bool NodeMatrixService::DeleteNodeMatrixListByExpertName(QString expertName)
  515. {
  516. bool ret = false;
  517. try {
  518. Transaction t(SqlDBHelper::getDatabase());
  519. t.deleteFrom("t_node_matrix_info").where("expert_name = ?", expertName);
  520. t.commit();
  521. ret = true;
  522. } catch (const DBException &ex) {
  523. qDebug() << ex.lastError.text();
  524. }
  525. return ret;
  526. }
  527. /*根据专家编号删除对应的节点信息*/
  528. bool NodeMatrixService::DeleteNodeMatrixListByExpertId(int expertId)
  529. {
  530. bool ret = false;
  531. try {
  532. Transaction t(SqlDBHelper::getDatabase());
  533. t.deleteFrom("t_node_matrix_info").where("expert_id = ?", expertId);
  534. t.commit();
  535. ret = true;
  536. } catch (const DBException &ex) {
  537. qDebug() << ex.lastError.text();
  538. }
  539. return ret;
  540. }
  541. bool NodeMatrixService::QueryMeaureDataByProjectAndIndex(QList<NodeMatrixInfo *> *dataList, QString index, int projId)
  542. {
  543. return QueryDataByProjectAndIndex(dataList, index, projId, 1);
  544. }
  545. bool NodeMatrixService::QueryExpertDataByProjectAndIndex(QList<NodeMatrixInfo *> *dataList, QString index, int projId)
  546. {
  547. return QueryDataByProjectAndIndex(dataList, index, projId, 0);
  548. }
  549. bool NodeMatrixService::QueryDataByProjectAndIndex(QList<NodeMatrixInfo *> *dataList, QString index, int projId,
  550. int dataSource)
  551. {
  552. QSqlDatabase db = SqlDBHelper::getDatabase();
  553. QSqlQuery query(db);
  554. bool ret = false;
  555. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  556. "node_value, expert_id,mind_id,write_date,mark,str_uuid,table_msg from "
  557. "t_node_matrix_info where mind_id = '%1' and engineer_id ='%2' and table_msg ='%3'")
  558. .arg(dataSource)
  559. .arg(QString::number(projId))
  560. .arg(index);
  561. // qDebug() << "selectSql=" << selectSql;
  562. if (query.exec(selectSql)) {
  563. while (query.next()) {
  564. if (query.isNull(0) == false) {
  565. NodeMatrixInfo *nodeMatrixInfo = new NodeMatrixInfo();
  566. nodeMatrixInfo->id = query.value(0).toInt();
  567. nodeMatrixInfo->expertName = query.value(1).toString();
  568. nodeMatrixInfo->engineerId = query.value(2).toInt();
  569. nodeMatrixInfo->node = query.value(3).toString();
  570. nodeMatrixInfo->abscissa = query.value(4).toString();
  571. nodeMatrixInfo->ordinate = query.value(5).toString();
  572. nodeMatrixInfo->nodeValue = query.value(6).toString();
  573. nodeMatrixInfo->expertId = query.value(7).toString();
  574. nodeMatrixInfo->mindId = query.value(8).toInt();
  575. nodeMatrixInfo->writeDate = query.value(9).toDateTime();
  576. nodeMatrixInfo->mark = query.value(10).toString();
  577. nodeMatrixInfo->strUuid = query.value(11).toString();
  578. nodeMatrixInfo->tableMsg = query.value(12).toString();
  579. dataList->append(nodeMatrixInfo);
  580. }
  581. }
  582. ret = true;
  583. } else {
  584. qDebug() << query.lastError();
  585. }
  586. return ret;
  587. }
  588. bool NodeMatrixService::UpdateMeasureData(const NodeMatrixInfo &info)
  589. {
  590. bool ret = false;
  591. try {
  592. Transaction t(SqlDBHelper::getDatabase());
  593. if (info.ordinate.length() > 0) {
  594. t.update("t_node_matrix_info")
  595. .set("node_value", info.nodeValue)
  596. .where("mind_id = 1 and engineer_id = ? and table_msg = ? and str_uuid = ? and abscissa = ? and "
  597. "ordinate = ?",
  598. info.engineerId, info.tableMsg, info.strUuid, info.abscissa, info.ordinate);
  599. } else {
  600. t.update("t_node_matrix_info")
  601. .set("node_value", info.nodeValue)
  602. .where("engineer_id = ? and table_msg = ? and str_uuid = ? and abscissa = ?", info.engineerId,
  603. info.tableMsg, info.strUuid, info.abscissa);
  604. }
  605. t.commit();
  606. ret = true;
  607. } catch (const DBException &ex) {
  608. qDebug() << ex.lastError.text();
  609. }
  610. return ret;
  611. }
  612. bool NodeMatrixService::deleteMeasureData(int projId, QString index, QString uuid)
  613. {
  614. bool ret = false;
  615. try {
  616. Transaction t(SqlDBHelper::getDatabase());
  617. t.deleteFrom("t_node_matrix_info")
  618. .where("engineer_id = ? and table_msg = ? and str_uuid = ?", projId, index, uuid);
  619. t.commit();
  620. ret = true;
  621. } catch (const DBException &ex) {
  622. qDebug() << ex.lastError.text();
  623. }
  624. return ret;
  625. }
  626. bool NodeMatrixService::deleteExpertData(int projId, int expertId)
  627. {
  628. bool ret = false;
  629. try {
  630. Transaction t(SqlDBHelper::getDatabase());
  631. t.deleteFrom("t_node_matrix_info").where("engineer_id = ? and expert_id = ?", projId, expertId);
  632. t.commit();
  633. ret = true;
  634. } catch (const DBException &ex) {
  635. qDebug() << ex.lastError.text();
  636. }
  637. return ret;
  638. }
  639. bool NodeMatrixService::hasMeasureData(int projId, QString index)
  640. {
  641. QSqlDatabase db = SqlDBHelper::getDatabase();
  642. QSqlQuery query(db);
  643. bool ret = false;
  644. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  645. "node_value, expert_id,mind_id,write_date,mark,str_uuid,table_msg from "
  646. "t_node_matrix_info where mind_id = 1 and engineer_id ='%1' and table_msg ='%2'")
  647. .arg(QString::number(projId))
  648. .arg(index);
  649. // qDebug() << "selectSql=" << selectSql;
  650. if (query.exec(selectSql)) {
  651. if (query.next()) {
  652. ret = true;
  653. }
  654. } else {
  655. qDebug() << query.lastError();
  656. }
  657. return ret;
  658. }
  659. bool NodeMatrixService::hasExpertData(int projId, QString index, int expertId)
  660. {
  661. QSqlDatabase db = SqlDBHelper::getDatabase();
  662. QSqlQuery query(db);
  663. bool ret = false;
  664. QString selectSql = QString("select id,expert_name, engineer_id, node, abscissa, ordinate, "
  665. "node_value, expert_id,mind_id,write_date,mark,str_uuid,table_msg from "
  666. "t_node_matrix_info where expert_id = '%1' and engineer_id ='%2' and table_msg ='%3'")
  667. .arg(QString::number(expertId))
  668. .arg(QString::number(projId))
  669. .arg(index);
  670. // qDebug() << "selectSql=" << selectSql;
  671. if (query.exec(selectSql)) {
  672. if (query.next()) {
  673. ret = true;
  674. }
  675. } else {
  676. qDebug() << query.lastError();
  677. }
  678. return ret;
  679. }