gtdgnsdao.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  1. //
  2. // Created by anna on 2020/10/14.
  3. //
  4. #include <iostream>
  5. #include "cstdlib"
  6. #include <map>
  7. #include "dgns_gtmloutcode.h"
  8. #include "dgns_gtcvrparam.h"
  9. #include "dgns_gtbaseparam.h"
  10. #include "dgns_gtcvrresult.h"
  11. #include "dgns_gtserverrunlog.h"
  12. #include "dgns_gtstandard.h"
  13. #include "gtpgcnn.h"
  14. #include <vector>
  15. #include <string>
  16. #include <list>
  17. #include "algorithm"
  18. #include "../gtrunconf.h"
  19. #include "dgns_gtgktype.h"
  20. #include "../Jsonxx/json.hpp"
  21. #include "gtdgnsdao.h"
  22. #include "aoid_daily_yield.h"
  23. #include "aoid_singlegt_yield.h"
  24. /*
  25. * search
  26. * dgns_gtcvrparam
  27. */
  28. std::vector<dgns_gtcvrparam> gtdgnsdao::getDgns_gtcvrparamContent(int paramid = -1, std::string paramitemname = NULL) {
  29. gtpgcnn _gtpgcnn;
  30. _gtpgcnn.openCnn();
  31. std::string key = postgresql_aes_secretkey;
  32. std::string encryptF = postgresql_field_encryptfunc;
  33. std::string sql =
  34. "select paramid,paramitemname,convert_from((decrypt(paramcontent::bytea,'" + key + "','" + encryptF
  35. + "')),'SQL_ASCII') paramcontent from dgns_gtcvrparam where 1=1";
  36. bool r;
  37. if (paramid > 0) {
  38. sql += " and paramid=" + std::to_string(paramid) + " ";
  39. }
  40. if (!paramitemname.empty()) {
  41. sql += " and paramitemname='" + paramitemname + "' ";
  42. }
  43. r = _gtpgcnn.readContent(sql);
  44. if (!r) return std::vector<dgns_gtcvrparam>();
  45. int rows = _gtpgcnn.getRowsNumFromResult();
  46. std::vector<dgns_gtcvrparam> lis;
  47. for (int i = 0; i < rows; ++i) {
  48. dgns_gtcvrparam d;
  49. d.paramid = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
  50. d.paramitemname = _gtpgcnn.getValueFromResult(i, 1);
  51. d.paramcontent = _gtpgcnn.getValueFromResult(i, 2);
  52. lis.push_back(d);
  53. }
  54. _gtpgcnn.clearRes();
  55. _gtpgcnn.closeCnn();
  56. return lis;
  57. }
  58. /*
  59. * add
  60. * dgns_gtcvrparam
  61. */
  62. bool gtdgnsdao::addDgns_gtcvrparamContent(dgns_gtcvrparam d) {
  63. gtpgcnn _gtpgcnn;
  64. _gtpgcnn.openCnn();
  65. // char *addsql_Str;
  66. bool r = false;
  67. if (d.paramid > 0) {
  68. std::string addsql =
  69. "insert into dgns_gtcvrparam(paramid, paramitemname, paramcontent) values (" +
  70. std::to_string(d.paramid) +
  71. ",'" + d.paramitemname +
  72. "',encrypt(replace('" + d.paramcontent + "','\','')::bytea,'" + postgresql_aes_secretkey + "','" +
  73. postgresql_field_encryptfunc + "'))";
  74. /*std::string addsql =
  75. "insert into dgns_gtcvrparam(paramid, paramitemname, paramcontent) values (" +
  76. std::to_string(d.paramid) +
  77. ",'" + d.paramitemname +
  78. "','" + d.paramcontent + "')";*/
  79. //sprintf(addsql_Str, addsql.c_str(), d.paramid);
  80. r = _gtpgcnn.writeContent(addsql);
  81. }
  82. _gtpgcnn.clearRes();
  83. _gtpgcnn.closeCnn();
  84. return r;
  85. }
  86. /*
  87. * alter
  88. * dgns_gtcvrparam
  89. */
  90. bool gtdgnsdao::alterDgns_gtcvrparamContent(dgns_gtcvrparam d) {
  91. gtpgcnn _gtpgcnn;
  92. _gtpgcnn.openCnn();
  93. //char *altersql_Str;
  94. bool r = false;
  95. if (d.paramid > 0) {
  96. std::string altersql =
  97. "update dgns_gtcvrparam set paramitemname='" + d.paramitemname + "', paramcontent='" + d.paramcontent +
  98. "' where paramid=" + std::to_string(d.paramid);
  99. //sprintf(altersql_Str, altersql.c_str(), d.paramid);
  100. r = _gtpgcnn.writeContent(altersql);
  101. _gtpgcnn.clearRes();
  102. _gtpgcnn.closeCnn();
  103. return r;
  104. }
  105. return r;
  106. }
  107. /*
  108. * delete
  109. * dgns_gtcvrparam
  110. */
  111. bool gtdgnsdao::deleteDgns_gtcvrparamContent(int paramid) {
  112. gtpgcnn _gtpgcnn;
  113. _gtpgcnn.openCnn();
  114. //char *deletesql_Str;
  115. bool r = false;
  116. if (paramid > 0) {
  117. std::string deletesql = "delete from dgns_gtcvrparam where paramid=" + std::to_string(paramid);
  118. //sprintf(deletesql_Str, deletesql.c_str(), paramid);
  119. r = _gtpgcnn.writeContent(deletesql);
  120. }
  121. _gtpgcnn.clearRes();
  122. _gtpgcnn.closeCnn();
  123. return r;
  124. }
  125. /*
  126. * search
  127. * dgns_gtbaseparam
  128. */
  129. bool gtdgnsdao::get_dgns_gtbaseparam_single(dgns_gtbaseparam &d, std::string _id, std::string _recivetime) {
  130. std::string sql = "select id,createtime,recivetime,wellname,sgt,s_max,s_min,l_max,l_min,l_mid,l_fistdownturnpoint,s,s_pre,n,l,s_effect,area,upload,download,islegal,remark,sgtpointnum,s_max_point_location,s_min_point_location,l_max_point_location,l_min_point_location from dgns_gtbaseparam where 1=1";
  131. bool r = false;
  132. std::vector<std::string> wheresql;
  133. if (!_id.empty())
  134. wheresql.push_back(" and id ='" + _id + "' ");
  135. if (!_recivetime.empty())
  136. wheresql.push_back(" and recivetime='" + _recivetime + "' ");
  137. if (wheresql.size() == 0) return r;
  138. for (int i = 0; i < wheresql.size(); ++i) {
  139. sql += wheresql[i];
  140. }
  141. gtpgcnn _gtpgcnn;
  142. _gtpgcnn.openCnn();
  143. r = _gtpgcnn.readContent(sql);
  144. if (r) {
  145. int rows = _gtpgcnn.getRowsNumFromResult();
  146. for (int i = 0; i < rows; ++i) {
  147. d.id = _gtpgcnn.getValueFromResult(i, 0);
  148. d.createtime = _gtpgcnn.getValueFromResult(i, 1);
  149. d.recivetime = _gtpgcnn.getValueFromResult(i, 2);
  150. d.wellname = _gtpgcnn.getValueFromResult(i, 3);
  151. d.sgt.clear();
  152. std::string sgt_str = _gtpgcnn.getValueFromResult(i, 4);
  153. if (!sgt_str.empty()) {
  154. d.sgt = d.gt_trans_strtoarray(sgt_str);
  155. }
  156. //下面的必须不是空值
  157. d.s_max = std::atof(_gtpgcnn.getValueFromResult(i, 5).c_str());
  158. d.s_min = std::atof(_gtpgcnn.getValueFromResult(i, 6).c_str());
  159. d.l_max = std::atof(_gtpgcnn.getValueFromResult(i, 7).c_str());
  160. d.l_min = std::atof(_gtpgcnn.getValueFromResult(i, 8).c_str());
  161. d.l_mid = std::atof(_gtpgcnn.getValueFromResult(i, 9).c_str());
  162. d.l_fistdownturnpoint = std::atof(_gtpgcnn.getValueFromResult(i, 10).c_str());
  163. d.s = std::atof(_gtpgcnn.getValueFromResult(i, 11).c_str());
  164. d.s_pre = std::atof(_gtpgcnn.getValueFromResult(i, 12).c_str());
  165. d.n = std::atof(_gtpgcnn.getValueFromResult(i, 13).c_str());
  166. d.l = std::atof(_gtpgcnn.getValueFromResult(i, 14).c_str());
  167. d.s_effect = std::atof(_gtpgcnn.getValueFromResult(i, 15).c_str());
  168. d.area = std::atof(_gtpgcnn.getValueFromResult(i, 16).c_str());
  169. //d.upload =std::atof(_gtpgcnn.getValueFromResult(i, 17).c_str());
  170. //d.download =std::atof(_gtpgcnn.getValueFromResult(i, 18).c_str());
  171. d.islegal = std::atoi(_gtpgcnn.getValueFromResultChar(i, 19));
  172. d.remark = _gtpgcnn.getValueFromResult(i, 20);
  173. d.sgtpointnum = std::atoi(_gtpgcnn.getValueFromResult(i, 21).c_str());
  174. d.s_max_point_location = std::atoi(_gtpgcnn.getValueFromResult(i, 22).c_str());
  175. d.s_min_point_location = std::atoi(_gtpgcnn.getValueFromResult(i, 23).c_str());
  176. d.l_max_point_location = std::atoi(_gtpgcnn.getValueFromResult(i, 24).c_str());
  177. d.l_min_point_location = std::atoi(_gtpgcnn.getValueFromResult(i, 25).c_str());
  178. }
  179. }
  180. _gtpgcnn.clearRes();
  181. _gtpgcnn.closeCnn();
  182. return r;
  183. }
  184. /*
  185. * add
  186. * dgns_gtbaseparam
  187. */
  188. bool gtdgnsdao::add_dgns_gtbaseparam_single(dgns_gtbaseparam d) {
  189. bool r = false;
  190. std::vector<std::string> insertsql_fields_name;
  191. std::vector<std::string> insertsql_fields_value;
  192. if (!d.recivetime.empty()) {
  193. insertsql_fields_name.push_back("recivetime");
  194. insertsql_fields_value.push_back("'" + d.recivetime + "'");
  195. } else {
  196. std::cout << "Warning:必须指定功图的接收时间【唯一标识】" << std::endl;
  197. return r;
  198. }
  199. if (!d.sgt.empty() && d.sgt.size() > 0) {
  200. std::string sgt_str = d.gt_trans_arraytostr(d.sgt);
  201. if (!sgt_str.empty()) {
  202. insertsql_fields_value.push_back("'" + sgt_str + "'");
  203. insertsql_fields_name.push_back("sgt");
  204. }
  205. }
  206. {
  207. insertsql_fields_name.push_back("s_max");
  208. insertsql_fields_value.push_back(std::to_string(d.s_max));
  209. insertsql_fields_name.push_back("s_min");
  210. insertsql_fields_value.push_back(std::to_string(d.s_min));
  211. insertsql_fields_name.push_back("l_max");
  212. insertsql_fields_value.push_back(std::to_string(d.l_max));
  213. insertsql_fields_name.push_back("l_min");
  214. insertsql_fields_value.push_back(std::to_string(d.l_min));
  215. insertsql_fields_name.push_back("l_mid");
  216. insertsql_fields_value.push_back(std::to_string(d.l_mid));
  217. insertsql_fields_name.push_back("l_fistdownturnpoint");
  218. insertsql_fields_value.push_back(std::to_string(d.l_fistdownturnpoint));
  219. insertsql_fields_name.push_back("s");
  220. insertsql_fields_value.push_back(std::to_string(d.s));
  221. insertsql_fields_name.push_back("s_pre");
  222. insertsql_fields_value.push_back(std::to_string(d.s_pre));
  223. insertsql_fields_name.push_back("n");
  224. insertsql_fields_value.push_back(std::to_string(d.n));
  225. insertsql_fields_name.push_back("l");
  226. insertsql_fields_value.push_back(std::to_string(d.l));
  227. insertsql_fields_name.push_back("s_effect");
  228. insertsql_fields_value.push_back(std::to_string(d.s_effect));
  229. insertsql_fields_name.push_back("area");
  230. insertsql_fields_value.push_back(std::to_string(d.area));
  231. /*insertsql_fields_name.push_back("upload");
  232. insertsql_fields_value.push_back(std::to_string(d.upload));
  233. insertsql_fields_name.push_back("download");
  234. insertsql_fields_value.push_back(std::to_string(d.download));*/
  235. insertsql_fields_name.push_back("islegal");
  236. insertsql_fields_value.push_back(std::to_string(d.islegal));
  237. insertsql_fields_name.push_back("remark");
  238. insertsql_fields_value.push_back("'" + d.remark + "'");
  239. insertsql_fields_name.push_back("sgtpointnum");
  240. insertsql_fields_value.push_back(std::to_string(d.sgtpointnum));
  241. insertsql_fields_name.push_back("s_max_point_location");
  242. insertsql_fields_value.push_back(std::to_string(d.s_max_point_location));
  243. insertsql_fields_name.push_back("s_min_point_location");
  244. insertsql_fields_value.push_back(std::to_string(d.s_min_point_location));
  245. insertsql_fields_name.push_back("l_max_point_location");
  246. insertsql_fields_value.push_back(std::to_string(d.l_max_point_location));
  247. insertsql_fields_name.push_back("l_min_point_location");
  248. insertsql_fields_value.push_back(std::to_string(d.l_min_point_location));
  249. }
  250. if (insertsql_fields_name.size() == 0)return r;
  251. std::string addsql =
  252. "insert into dgns_gtbaseparam(";
  253. std::string valuessql = "values(";
  254. for (int i = 0; i < insertsql_fields_name.size(); ++i) {
  255. if (i > 0) {
  256. addsql += ",";
  257. valuessql += ",";
  258. }
  259. addsql += insertsql_fields_name[i];
  260. valuessql += insertsql_fields_value[i];
  261. }
  262. addsql = addsql + ")" + valuessql + ")";
  263. gtpgcnn _gtpgcnn;
  264. _gtpgcnn.openCnn();
  265. r = _gtpgcnn.writeContent(addsql);
  266. _gtpgcnn.clearRes();
  267. _gtpgcnn.closeCnn();
  268. return r;
  269. }
  270. /*
  271. * alter
  272. * dgns_gtbaseparam
  273. */
  274. bool gtdgnsdao::alterDgns_gtbaseparamContent(dgns_gtbaseparam d) {
  275. bool r = false;
  276. /* char *altersql_Str;
  277. gtpgcnn _gtpgcnn;
  278. _gtpgcnn.openCnn();
  279. d.id.erase(std::remove(d.id.begin(), d.id.end(), '-'), d.id.end());
  280. if (d.id.length() == 32) {
  281. std::string altersql =
  282. "update dgns_gtbaseparam set createtime=to_timestamp('" + d.createtime +
  283. "','YYYY-MM-DD HH24:MI:SS'), recivetime=to_timestamp('" +
  284. d.recivetime + "','YYYY-MM-DD HH24:MI:SS'), wellname='" + d.wellname + "', sgt='" + d.sgt +
  285. "',s_max=%f,s_min=%f,l_max=%f,l_min=%f,s=%f,n=%f,l=%f,s_effect=%f,area=%f,upload=%f,download=%f,islegal=%d,remark='" +
  286. d.remark +
  287. "' where id='" + d.id + "'";
  288. sprintf(altersql_Str, altersql.c_str(), d.s_max, d.s_min, d.l_max, d.l_min, d.s, d.n, d.l, d.s_effect, d.area,
  289. d.upload, d.download,
  290. d.islegal);
  291. r = _gtpgcnn.writeContent(altersql_Str);
  292. }
  293. _gtpgcnn.clearRes();
  294. _gtpgcnn.closeCnn();*/
  295. return r;
  296. }
  297. /*
  298. * delete
  299. * dgns_gtbaseparam
  300. */
  301. bool gtdgnsdao::deleteDgns_gtbaseparamContent(std::string paramid) {
  302. gtpgcnn _gtpgcnn;
  303. _gtpgcnn.openCnn();
  304. bool r = false;
  305. paramid.erase(std::remove(paramid.begin(), paramid.end(), '-'), paramid.end());
  306. if (paramid.length() == 32) {
  307. std::string deletesql = "delete from dgns_gtbaseparam where id='" + paramid + "'";
  308. r = _gtpgcnn.writeContent(deletesql);
  309. }
  310. _gtpgcnn.clearRes();
  311. _gtpgcnn.closeCnn();
  312. return r;
  313. }
  314. /*
  315. * search
  316. * dgns_gtcvrresult
  317. */
  318. std::vector<dgns_gtcvrresult>
  319. gtdgnsdao::getDgns_gtcvrresultContent(std::string id, std::string sgt_recivetime) {
  320. if (id.empty() && sgt_recivetime.empty()) {
  321. std::cout << "Warning:没有足够的参数传入";
  322. return std::vector<dgns_gtcvrresult>();
  323. }
  324. std::string sql = "select id,result1,result2,wellname,sgt,processparam,remark,createtime,userconfirmtime,userconfirmcontent,isproblem,isexpected from dgns_gtcvrresult where 1=1";
  325. bool r = false;
  326. if (!id.empty())
  327. sql += " and id='" + id + "' ";
  328. if (!sgt_recivetime.empty()) {
  329. sql += " and processparam->>'sgt_recivetime'::text='" + sgt_recivetime + "' ";
  330. }
  331. gtpgcnn _gtpgcnn;
  332. _gtpgcnn.openCnn();
  333. r = _gtpgcnn.readContent(sql);
  334. if (!r) return std::vector<dgns_gtcvrresult>();
  335. int rows = _gtpgcnn.getRowsNumFromResult();
  336. std::vector<dgns_gtcvrresult> lis;
  337. for (int i = 0; i < rows; ++i) {
  338. dgns_gtcvrresult d;
  339. d.id = _gtpgcnn.getValueFromResultChar(i, 0);
  340. d.result1 = _gtpgcnn.getValueFromResult(i, 1);
  341. d.result2 = _gtpgcnn.getValueFromResult(i, 2);
  342. d.wellname = _gtpgcnn.getValueFromResult(i, 3);
  343. d.sgt =d.gt_trans_strtoarray(_gtpgcnn.getValueFromResult(i, 4));
  344. d.processparam = _gtpgcnn.getValueFromResult(i, 5);
  345. d.remark = _gtpgcnn.getValueFromResult(i, 6);
  346. d.createtime = _gtpgcnn.getValueFromResult(i, 7);
  347. d.userconfirmtime = _gtpgcnn.getValueFromResult(i, 8);
  348. d.userconfirmcontent = _gtpgcnn.getValueFromResult(i, 9);
  349. d.isproblem = _gtpgcnn.getValueFromResult(i, 10);
  350. d.isexpected = std::atoi(_gtpgcnn.getValueFromResultChar(i, 11));
  351. lis.push_back(d);
  352. }
  353. _gtpgcnn.clearRes();
  354. _gtpgcnn.closeCnn();
  355. return lis;
  356. }
  357. /*
  358. * add
  359. * dgns_gtcvrresult
  360. */
  361. bool gtdgnsdao::addDgns_gtcvrresultContent(dgns_gtcvrresult d) {
  362. bool r = false;
  363. std::vector<std::string> insertsql_fields_name;
  364. std::vector<std::string> insertsql_fields_value;
  365. /* if (!d.id.empty()) {
  366. insertsql_fields_name.push_back("id");
  367. insertsql_fields_value.push_back("'" + d.id + "'");
  368. } else {
  369. std::cout << "Warning:必须指定的id【唯一标识】" << std::endl;
  370. return r;
  371. }*/
  372. if (!d.sgt.empty() && d.sgt.size() > 0) {
  373. std::string sgt_str = d.gt_trans_arraytostr(d.sgt);
  374. if (!sgt_str.empty()) {
  375. insertsql_fields_value.push_back("'" + sgt_str + "'");
  376. insertsql_fields_name.push_back("sgt");
  377. }
  378. }
  379. {
  380. insertsql_fields_name.push_back("result1");
  381. insertsql_fields_value.push_back("'" + d.result1 + "'");
  382. insertsql_fields_name.push_back("result2");
  383. insertsql_fields_value.push_back("'" + d.result2 + "'");
  384. /*insertsql_fields_name.push_back("wellname");
  385. insertsql_fields_value.push_back("'"+d.wellname+"'");*/
  386. insertsql_fields_name.push_back("processparam");
  387. insertsql_fields_value.push_back("'"+d.processparam+"'");
  388. insertsql_fields_name.push_back("remark");
  389. insertsql_fields_value.push_back("'" + d.remark + "'");
  390. /*insertsql_fields_name.push_back("createtime");
  391. insertsql_fields_value.push_back("'"+d.createtime+"'");*/
  392. /*insertsql_fields_name.push_back("userconfirmtime");
  393. insertsql_fields_value.push_back("'"+d.userconfirmtime+"'");
  394. insertsql_fields_name.push_back("userconfirmcontent");
  395. insertsql_fields_value.push_back("'"+d.userconfirmcontent+"'");*/
  396. insertsql_fields_name.push_back("isproblem");
  397. insertsql_fields_value.push_back("'" + d.isproblem + "'");
  398. insertsql_fields_name.push_back("isexpected");
  399. insertsql_fields_value.push_back(std::to_string(d.isexpected));
  400. }
  401. if (insertsql_fields_name.size() == 0)return r;
  402. std::string addsql =
  403. "insert into dgns_gtcvrresult(";
  404. std::string valuessql = "values(";
  405. for (int i = 0; i < insertsql_fields_name.size(); ++i) {
  406. if (i > 0) {
  407. addsql += ",";
  408. valuessql += ",";
  409. }
  410. addsql += insertsql_fields_name[i];
  411. valuessql += insertsql_fields_value[i];
  412. }
  413. addsql = addsql + ")" + valuessql + ")";
  414. gtpgcnn _gtpgcnn;
  415. _gtpgcnn.openCnn();
  416. r = _gtpgcnn.writeContent(addsql);
  417. _gtpgcnn.clearRes();
  418. _gtpgcnn.closeCnn();
  419. return r;
  420. }
  421. /*
  422. * alter
  423. * dgns_gtcvrresult
  424. */
  425. bool gtdgnsdao::alterDgns_gtcvrresultContent(dgns_gtcvrresult d) {
  426. gtpgcnn _gtpgcnn;
  427. _gtpgcnn.openCnn();
  428. //char *altersql_Str;
  429. bool r = false;
  430. /*if (!d.id.empty()) {
  431. std::string altersql =
  432. "update dgns_gtcvrresult set result1='" + d.result1 + "', result2='" + d.result2 + "',wellname='" +
  433. d.wellname + "',sgt='" + d.sgt +
  434. "',processparam='" + d.processparam + "',remark='" + d.remark + "',createtime=to_timestamp('" +
  435. d.createtime +
  436. "','YYYY-MM-DD HH24:MI:SS'),userconfirmtime=to_timestamp('" + d.userconfirmtime +
  437. "','YYYY-MM-DD HH24:MI:SS'),userconfirmcontent='" +
  438. d.userconfirmcontent + "',isproblem='" + d.isproblem + "',isexpected=" + std::to_string(d.isexpected) + " where id='" + d.id + "'";
  439. //sprintf(altersql_Str, altersql.c_str(), d.isexpected);
  440. r = _gtpgcnn.writeContent(altersql);
  441. }*/
  442. _gtpgcnn.clearRes();
  443. _gtpgcnn.closeCnn();
  444. return r;
  445. }
  446. /*
  447. * delete
  448. * dgns_gtcvrresult
  449. */
  450. bool gtdgnsdao::deleteDgns_gtcvrresultContent(int paramid) {
  451. gtpgcnn _gtpgcnn;
  452. _gtpgcnn.openCnn();
  453. //char *deletesql_Str;
  454. bool r = false;
  455. if (paramid > 0) {
  456. std::string deletesql = "delete from dgns_gtcvrresult where paramid=" + std::to_string(paramid);
  457. //sprintf(deletesql_Str, deletesql.c_str(), paramid);
  458. r = _gtpgcnn.writeContent(deletesql);
  459. }
  460. _gtpgcnn.clearRes();
  461. _gtpgcnn.closeCnn();
  462. return r;
  463. }
  464. /*
  465. * search
  466. * dgns_gtserverrunlog
  467. */
  468. std::vector<dgns_gtserverrunlog>
  469. gtdgnsdao::getDgns_gtserverrunlogContent(int paramid = -1, std::string paramitemname = NULL) {
  470. gtpgcnn _gtpgcnn;
  471. _gtpgcnn.openCnn();
  472. std::string sql = "select * from dgns_gtserverrunlog where 1=1";
  473. bool r;
  474. if (paramid > 0 && (!paramitemname.empty() || paramitemname != "")) {
  475. std::string a = " and code=" + std::to_string(paramid) + " and contents='" + paramitemname + "'";
  476. //char *astr;
  477. //sprintf(astr, a.c_str(), paramid);
  478. std::string sqlto = sql + a;
  479. r = _gtpgcnn.readContent(sqlto);
  480. } else {
  481. r = _gtpgcnn.readContent(sql);
  482. }
  483. if (!r) return std::vector<dgns_gtserverrunlog>();
  484. int rows = _gtpgcnn.getRowsNumFromResult();
  485. std::vector<dgns_gtserverrunlog> lis;
  486. for (int i = 0; i < rows; ++i) {
  487. dgns_gtserverrunlog d;
  488. d.time = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
  489. d.contents = _gtpgcnn.getValueFromResult(i, 1);
  490. d.item = _gtpgcnn.getValueFromResult(i, 2);
  491. d.code = atoi(_gtpgcnn.getValueFromResultChar(i, 3));
  492. lis.push_back(d);
  493. }
  494. _gtpgcnn.clearRes();
  495. _gtpgcnn.closeCnn();
  496. return lis;
  497. }
  498. /*
  499. * add
  500. * dgns_gtserverrunlog
  501. */
  502. bool gtdgnsdao::addDgns_gtserverrunlogContent(dgns_gtserverrunlog d) {
  503. gtpgcnn _gtpgcnn;
  504. _gtpgcnn.openCnn();
  505. //char *addsql_Str;
  506. bool r = false;
  507. if (d.code > 0) {
  508. std::string addsql =
  509. "insert into dgns_gtserverrunlog(time, contents, item,code) values ('" + d.time + "','" + d.contents +
  510. "','" + d.item + "'," + std::to_string(d.code) + ")";
  511. //sprintf(addsql_Str, addsql.c_str(), d.code);
  512. r = _gtpgcnn.writeContent(addsql);
  513. }
  514. _gtpgcnn.clearRes();
  515. _gtpgcnn.closeCnn();
  516. return r;
  517. }
  518. /*
  519. * alter
  520. * dgns_gtserverrunlog
  521. */
  522. bool gtdgnsdao::alterDgns_gtserverrunlogContent(dgns_gtserverrunlog d) {
  523. gtpgcnn _gtpgcnn;
  524. _gtpgcnn.openCnn();
  525. //char *altersql_Str;
  526. bool r = false;
  527. if (d.code > 0) {
  528. std::string altersql =
  529. "update dgns_gtserverrunlog set time='" + d.time + "', contents='" + d.contents + "', item='" + d.item +
  530. "' where code=" + std::to_string(d.code);
  531. //sprintf(altersql_Str, altersql.c_str(), d.code);
  532. r = _gtpgcnn.writeContent(altersql);
  533. }
  534. _gtpgcnn.clearRes();
  535. _gtpgcnn.closeCnn();
  536. return r;
  537. }
  538. /*
  539. * delete
  540. * dgns_gtserverrunlog
  541. */
  542. bool gtdgnsdao::deleteDgns_gtserverrunlogContent(int paramid) {
  543. gtpgcnn _gtpgcnn;
  544. _gtpgcnn.openCnn();
  545. //char *deletesql_Str;
  546. bool r = false;
  547. if (paramid > 0) {
  548. std::string deletesql = "delete from dgns_gtserverrunlog where code=" + std::to_string(paramid);
  549. //sprintf(deletesql_Str, deletesql.c_str(), paramid);
  550. r = _gtpgcnn.writeContent(deletesql);
  551. }
  552. _gtpgcnn.clearRes();
  553. _gtpgcnn.closeCnn();
  554. return r;
  555. }
  556. /*
  557. * search
  558. * dgns_gtstandard
  559. */
  560. std::vector<dgns_gtstandard>
  561. gtdgnsdao::get_dgns_gtstandard_list(std::string conditionsql) {
  562. gtpgcnn _gtpgcnn;
  563. _gtpgcnn.openCnn();
  564. std::string key = postgresql_aes_secretkey;
  565. std::string encryptF = postgresql_field_encryptfunc;
  566. std::string sql =
  567. "select sgtprodate,createtime,id,convert_from((decrypt(sgtcharacters::bytea,'" + key + "','" + encryptF
  568. +
  569. "')),'SQL_ASCII') sgtcharacters,appearcounter,graphicfeatureinterpretation,maxsemblance,minsemblance,wellname,latestupdatedtime from dgns_gtstandard ";
  570. bool r;
  571. /* if (maxcounterbzt) {
  572. sql += " where appearcounter=(select max(appearcounter) from dgns_gtstandard) ";
  573. }*/
  574. if (!conditionsql.empty())
  575. sql += conditionsql;
  576. r = _gtpgcnn.readContent(sql);
  577. if (!r) return std::vector<dgns_gtstandard>();
  578. int rows = _gtpgcnn.getRowsNumFromResult();
  579. std::vector<dgns_gtstandard> lis;
  580. for (int i = 0; i < rows; ++i) {
  581. dgns_gtstandard d;
  582. d.sgtprodate = _gtpgcnn.getValueFromResult(i, 0);
  583. d.createtime = _gtpgcnn.getValueFromResult(i, 1);
  584. d.id = _gtpgcnn.getValueFromResult(i, 2);
  585. if (!_gtpgcnn.getValueFromResult(i, 3).empty()) {
  586. jsonxx::json jobj = jsonxx::json::parse(_gtpgcnn.getValueFromResult(i, 3));
  587. d.sgtcharacters = new double[cardgray_characters_num];
  588. for (int jindex = 0; jindex < cardgray_characters_num; jindex++) {
  589. d.sgtcharacters[jindex] = jobj[jindex].as_float_anynum();
  590. }
  591. }
  592. d.appearcounter = std::atol(_gtpgcnn.getValueFromResult(i, 4).c_str());
  593. d.graphicfeatureinterpretation = _gtpgcnn.getValueFromResult(i, 5);
  594. if (!_gtpgcnn.getValueFromResult(i, 6).empty())
  595. d.maxsemblance = std::atof(_gtpgcnn.getValueFromResult(i, 6).c_str());
  596. if (!_gtpgcnn.getValueFromResult(i, 7).empty())
  597. d.minsemblance = std::atof(_gtpgcnn.getValueFromResult(i, 7).c_str());
  598. d.wellname = _gtpgcnn.getValueFromResult(i, 8);
  599. d.latestupdatedtime = _gtpgcnn.getValueFromResult(i, 9);
  600. lis.push_back(d);
  601. }
  602. _gtpgcnn.clearRes();
  603. _gtpgcnn.closeCnn();
  604. return lis;
  605. }
  606. /*
  607. * add
  608. * dgns_gtstandard
  609. */
  610. bool gtdgnsdao::addDgns_gtstandardContent(dgns_gtstandard d) {
  611. bool r = false;
  612. //sgtprodate,createtime,id,sgtcharacters,appearcounter,graphicfeatureinterpretation,maxsemblance,minsemblance,wellname
  613. std::string addsql = "insert into dgns_gtstandard(";
  614. std::string valuesql = "values(";
  615. std::vector<std::string> field_name;
  616. std::vector<std::string> field_value;
  617. if (!d.sgtprodate.empty()) {
  618. field_name.push_back("sgtprodate");
  619. field_value.push_back("'" + d.sgtprodate + "'");
  620. }
  621. if (d.sgtcharacters != NULL) {
  622. jsonxx::json jobj;
  623. for (int i = 0; i < cardgray_characters_num; ++i) {
  624. jobj[i] = d.sgtcharacters[i];
  625. }
  626. std::string j_str = jobj.dump();
  627. field_name.push_back("sgtcharacters");
  628. field_value.push_back(
  629. "encrypt(replace('" + j_str + "','\','')::bytea,'" + postgresql_aes_secretkey + "','" +
  630. postgresql_field_encryptfunc + "')");
  631. }
  632. if (d.appearcounter > 0) {
  633. field_name.push_back("appearcounter");
  634. field_value.push_back(std::to_string(d.appearcounter));
  635. }
  636. if (!d.graphicfeatureinterpretation.empty()) {
  637. field_name.push_back("graphicfeatureinterpretation");
  638. field_value.push_back("'" + d.graphicfeatureinterpretation + "'");
  639. }
  640. if (d.maxsemblance > 0) {
  641. field_name.push_back("maxsemblance");
  642. field_value.push_back(std::to_string(d.maxsemblance));
  643. }
  644. if (d.minsemblance > 0) {
  645. field_name.push_back("minsemblance");
  646. field_value.push_back(std::to_string(d.minsemblance));
  647. }
  648. {
  649. field_name.push_back("latestupdatedtime");
  650. field_value.push_back("'" + d.latestupdatedtime + "'");
  651. }
  652. if (field_name.size() == 0) return r;
  653. for (int i = 0; i < field_name.size(); ++i) {
  654. if (i > 0) {
  655. addsql += ",";
  656. valuesql += ",";
  657. }
  658. valuesql += field_value[i];
  659. addsql += field_name[i];
  660. }
  661. addsql += ")" + valuesql + ")";
  662. gtpgcnn _gtpgcnn;
  663. _gtpgcnn.openCnn();
  664. r = _gtpgcnn.writeContent(addsql);
  665. _gtpgcnn.clearRes();
  666. _gtpgcnn.closeCnn();
  667. return r;
  668. }
  669. /*
  670. * alter
  671. * dgns_gtstandard
  672. */
  673. bool gtdgnsdao::alterDgns_gtstandardContent(dgns_gtstandard d) {
  674. bool r = false;
  675. if (d.id.empty()) return r;
  676. std::string altersql =
  677. "update dgns_gtstandard set ";
  678. std::string wheresql = " where id='" + d.id + "' ";
  679. std::vector<std::string> setcontentsql;
  680. if (!d.sgtprodate.empty())
  681. setcontentsql.push_back(" sgtprodate='" + d.sgtprodate + "' ");
  682. if (d.sgtcharacters != NULL) {
  683. jsonxx::json jobj;
  684. for (int i = 0; i < cardgray_characters_num; ++i) {
  685. jobj[i] = d.sgtcharacters[i];
  686. }
  687. std::string j_str = jobj.dump();
  688. setcontentsql.push_back(
  689. " sgtcharacters=encrypt(replace('" + j_str + "','\','')::bytea,'" + postgresql_aes_secretkey +
  690. "','" +
  691. postgresql_field_encryptfunc + "') ");
  692. }
  693. if (d.appearcounter > 0)
  694. setcontentsql.push_back(" appearcounter=" + std::to_string(d.appearcounter) + " ");
  695. if (!d.graphicfeatureinterpretation.empty())
  696. setcontentsql.push_back(" graphicfeatureinterpretation='" + d.graphicfeatureinterpretation + "' ");
  697. if (d.maxsemblance > 0)
  698. setcontentsql.push_back(" maxsemblance=" + std::to_string(d.maxsemblance) + " ");
  699. if (d.minsemblance > 0)
  700. setcontentsql.push_back(" minsemblance=" + std::to_string(d.minsemblance) + " ");
  701. if (!d.latestupdatedtime.empty())
  702. setcontentsql.push_back(" latestupdatedtime='" + d.latestupdatedtime + "' ");
  703. if (setcontentsql.size() <= 0) return r;
  704. for (int i = 0; i < setcontentsql.size(); ++i) {
  705. if (i > 0)
  706. altersql += ",";
  707. altersql += setcontentsql[i];
  708. }
  709. altersql += wheresql;
  710. gtpgcnn _gtpgcnn;
  711. _gtpgcnn.openCnn();
  712. r = _gtpgcnn.writeContent(altersql);
  713. _gtpgcnn.clearRes();
  714. _gtpgcnn.closeCnn();
  715. return r;
  716. }
  717. /*
  718. * delete
  719. * dgns_gtstandard
  720. */
  721. bool gtdgnsdao::deleteDgns_gtstandardContent(std::string id) {
  722. bool r = false;
  723. if (id.empty()) return r;
  724. std::string deletesql = "delete from dgns_gtstandard where id='" + id + "'";
  725. gtpgcnn _gtpgcnn;
  726. _gtpgcnn.openCnn();
  727. r = _gtpgcnn.writeContent(deletesql);
  728. _gtpgcnn.clearRes();
  729. _gtpgcnn.closeCnn();
  730. return r;
  731. }
  732. std::map<int, dgns_gtmloutcode> gtdgnsdao::get_dgns_gtmloutcode_map() {
  733. gtpgcnn _gtpgcnn;
  734. _gtpgcnn.openCnn();
  735. std::string key = postgresql_aes_secretkey;
  736. std::string encryptF = postgresql_field_encryptfunc;
  737. std::string sql =
  738. "select gkcode,gkdec from dgns_gtmloutcode order by gkcode";
  739. bool r;
  740. std::map<int, dgns_gtmloutcode> res;
  741. r = _gtpgcnn.readContent(sql);
  742. if (!r) return res;
  743. int rows = _gtpgcnn.getRowsNumFromResult();
  744. for (int i = 0; i < rows; ++i) {
  745. dgns_gtmloutcode d;
  746. d.gkcode = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
  747. d.gkdec = _gtpgcnn.getValueFromResult(i, 1);
  748. if (res.find(d.gkcode) != res.end()) {
  749. std::cout << "gtcode:" << d.gkcode << " exited ;warning: repeat gkcode!" << std::endl;
  750. res[d.gkcode] = d;
  751. } else {
  752. res.insert(std::pair<int, dgns_gtmloutcode>(d.gkcode, d));
  753. }
  754. }
  755. _gtpgcnn.clearRes();
  756. _gtpgcnn.closeCnn();
  757. return res;
  758. }
  759. /*
  760. * search
  761. * dgns_gtgktype
  762. */
  763. std::map<std::string, dgns_gtgktype> gtdgnsdao::get_dgns_gtgktype_all_map_indexofgkname() {
  764. bool r = false;
  765. std::string sql = "select id,gkname,dec,modbustranscode,remark from dgns_gtgktype where 1=1";
  766. gtpgcnn _gtpgcnn;
  767. _gtpgcnn.openCnn();
  768. r = _gtpgcnn.readContent(sql);
  769. std::map<std::string, dgns_gtgktype> ls;
  770. if (r) {
  771. int rows = _gtpgcnn.getRowsNumFromResult();
  772. for (int i = 0; i < rows; ++i) {
  773. dgns_gtgktype d;
  774. d.id = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
  775. d.gkname = _gtpgcnn.getValueFromResult(i, 1);
  776. d.dec = _gtpgcnn.getValueFromResult(i, 2);
  777. d.modbustranscode = _gtpgcnn.getValueFromResult(i, 3);
  778. d.remark = _gtpgcnn.getValueFromResult(i, 4);
  779. ls.insert(std::pair<std::string, dgns_gtgktype>(d.gkname, d));
  780. }
  781. }
  782. _gtpgcnn.clearRes();
  783. _gtpgcnn.closeCnn();
  784. return ls;
  785. }
  786. std::map<int, dgns_gtgktype> gtdgnsdao::get_dgns_gtgktype_all_map_indexofid() {
  787. bool r = false;
  788. std::string sql = "select id,gkname,dec,modbustranscode,remark from dgns_gtgktype where 1=1";
  789. gtpgcnn _gtpgcnn;
  790. _gtpgcnn.openCnn();
  791. r = _gtpgcnn.readContent(sql);
  792. std::map<int, dgns_gtgktype> ls;
  793. if (r) {
  794. int rows = _gtpgcnn.getRowsNumFromResult();
  795. for (int i = 0; i < rows; ++i) {
  796. dgns_gtgktype d;
  797. d.id = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
  798. d.gkname = _gtpgcnn.getValueFromResult(i, 1);
  799. d.dec = _gtpgcnn.getValueFromResult(i, 2);
  800. d.modbustranscode = _gtpgcnn.getValueFromResult(i, 3);
  801. d.remark = _gtpgcnn.getValueFromResult(i, 4);
  802. ls.insert(std::pair<int, dgns_gtgktype>(d.id, d));
  803. }
  804. }
  805. _gtpgcnn.clearRes();
  806. _gtpgcnn.closeCnn();
  807. return ls;
  808. }
  809. bool gtdgnsdao::get_dgns_gtgktype_single(dgns_gtgktype &d, int _id = -1, std::string _gkname = NULL) {
  810. bool r = false;
  811. std::string sql = "select * from dgns_gtgktype where 1=1";
  812. std::vector<std::string> wheresql;
  813. if (_id > 0) wheresql.push_back(" and id ='" + std::to_string(_id) + "' ");
  814. if (!_gkname.empty()) wheresql.push_back(" and gkname ='" + _gkname + "' ");
  815. if (wheresql.size() == 0) return r;
  816. for (int i = 0; i < wheresql.size(); ++i) {
  817. sql += wheresql[i];
  818. }
  819. gtpgcnn _gtpgcnn;
  820. _gtpgcnn.openCnn();
  821. r = _gtpgcnn.readContent(sql);
  822. if (r) {
  823. int rows = _gtpgcnn.getRowsNumFromResult();
  824. for (int i = 0; i < rows; ++i) {
  825. d.id = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
  826. d.gkname = _gtpgcnn.getValueFromResult(i, 1);
  827. d.dec = _gtpgcnn.getValueFromResult(i, 2);
  828. d.modbustranscode = _gtpgcnn.getValueFromResult(i, 3);
  829. d.remark = _gtpgcnn.getValueFromResult(i, 4);
  830. }
  831. }
  832. _gtpgcnn.clearRes();
  833. _gtpgcnn.closeCnn();
  834. return r;
  835. }
  836. /*
  837. * add
  838. * dgns_gtgktype
  839. */
  840. bool gtdgnsdao::addDgns_gtgktypeContent(dgns_gtgktype d) {
  841. gtpgcnn _gtpgcnn;
  842. _gtpgcnn.openCnn();
  843. //char *addsql_Str;
  844. bool r = false;
  845. if (d.id > 0) {
  846. std::string addsql =
  847. "insert into dgns_gtcvrresult(id, gkname, result2,wellname,sgt,processparam,remark,createtime,userconfirmtime,userconfirmtime,"
  848. "userconfirmcontent,isproblem,%d) values (" + std::to_string(d.id) + ",'" +
  849. d.gkname + "','" + d.dec + "','" + d.modbustranscode + "')";
  850. //sprintf(addsql_Str, addsql.c_str(), d.id);
  851. r = _gtpgcnn.writeContent(addsql);
  852. }
  853. _gtpgcnn.clearRes();
  854. _gtpgcnn.closeCnn();
  855. return r;
  856. }
  857. /*
  858. * alter
  859. * dgns_gtgktype
  860. */
  861. bool gtdgnsdao::alterDgns_gtgktypeContent(dgns_gtgktype d) {
  862. gtpgcnn _gtpgcnn;
  863. _gtpgcnn.openCnn();
  864. //char *altersql_Str;
  865. bool r = false;
  866. if (d.id > 0) {
  867. std::string altersql =
  868. "update dgns_gtgktype set gkname='" + d.gkname + "',dec='" + d.dec + "', modbustranscode='" +
  869. d.modbustranscode +
  870. "',remark='" + d.remark + "' where id=" + std::to_string(d.id);
  871. //sprintf(altersql_Str, altersql.c_str(), d.id);
  872. r = _gtpgcnn.writeContent(altersql);
  873. }
  874. _gtpgcnn.clearRes();
  875. _gtpgcnn.closeCnn();
  876. return r;
  877. }
  878. /*
  879. * delete
  880. * dgns_gtgktype
  881. */
  882. bool gtdgnsdao::deleteDgns_gtgktypeContent(int paramid) {
  883. gtpgcnn _gtpgcnn;
  884. _gtpgcnn.openCnn();
  885. //char *deletesql_Str;
  886. bool r = false;
  887. if (paramid > 0) {
  888. std::string deletesql = "delete from dgns_gtgktype where id=" + std::to_string(paramid);
  889. //sprintf(deletesql_Str, deletesql.c_str(), paramid);
  890. r = _gtpgcnn.writeContent(deletesql);
  891. }
  892. _gtpgcnn.clearRes();
  893. _gtpgcnn.closeCnn();
  894. return r;
  895. }