123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017 |
- //
- // Created by anna on 2020/10/14.
- //
- #include <iostream>
- #include "cstdlib"
- #include <map>
- #include "dgns_gtmloutcode.h"
- #include "dgns_gtcvrparam.h"
- #include "dgns_gtbaseparam.h"
- #include "dgns_gtcvrresult.h"
- #include "dgns_gtserverrunlog.h"
- #include "dgns_gtstandard.h"
- #include "gtpgcnn.h"
- #include <vector>
- #include <string>
- #include <list>
- #include "algorithm"
- #include "../gtrunconf.h"
- #include "dgns_gtgktype.h"
- #include "../Jsonxx/json.hpp"
- #include "gtdgnsdao.h"
- #include "aoid_daily_yield.h"
- #include "aoid_singlegt_yield.h"
- /*
- * search
- * dgns_gtcvrparam
- */
- std::vector<dgns_gtcvrparam> gtdgnsdao::getDgns_gtcvrparamContent(int paramid = -1, std::string paramitemname = NULL) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- std::string key = postgresql_aes_secretkey;
- std::string encryptF = postgresql_field_encryptfunc;
- std::string sql =
- "select paramid,paramitemname,convert_from((decrypt(paramcontent::bytea,'" + key + "','" + encryptF
- + "')),'SQL_ASCII') paramcontent from dgns_gtcvrparam where 1=1";
- bool r;
- if (paramid > 0) {
- sql += " and paramid=" + std::to_string(paramid) + " ";
- }
- if (!paramitemname.empty()) {
- sql += " and paramitemname='" + paramitemname + "' ";
- }
- r = _gtpgcnn.readContent(sql);
- if (!r) return std::vector<dgns_gtcvrparam>();
- int rows = _gtpgcnn.getRowsNumFromResult();
- std::vector<dgns_gtcvrparam> lis;
- for (int i = 0; i < rows; ++i) {
- dgns_gtcvrparam d;
- d.paramid = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
- d.paramitemname = _gtpgcnn.getValueFromResult(i, 1);
- d.paramcontent = _gtpgcnn.getValueFromResult(i, 2);
- lis.push_back(d);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return lis;
- }
- /*
- * add
- * dgns_gtcvrparam
- */
- bool gtdgnsdao::addDgns_gtcvrparamContent(dgns_gtcvrparam d) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- // char *addsql_Str;
- bool r = false;
- if (d.paramid > 0) {
- std::string addsql =
- "insert into dgns_gtcvrparam(paramid, paramitemname, paramcontent) values (" +
- std::to_string(d.paramid) +
- ",'" + d.paramitemname +
- "',encrypt(replace('" + d.paramcontent + "','\','')::bytea,'" + postgresql_aes_secretkey + "','" +
- postgresql_field_encryptfunc + "'))";
- /*std::string addsql =
- "insert into dgns_gtcvrparam(paramid, paramitemname, paramcontent) values (" +
- std::to_string(d.paramid) +
- ",'" + d.paramitemname +
- "','" + d.paramcontent + "')";*/
- //sprintf(addsql_Str, addsql.c_str(), d.paramid);
- r = _gtpgcnn.writeContent(addsql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * alter
- * dgns_gtcvrparam
- */
- bool gtdgnsdao::alterDgns_gtcvrparamContent(dgns_gtcvrparam d) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *altersql_Str;
- bool r = false;
- if (d.paramid > 0) {
- std::string altersql =
- "update dgns_gtcvrparam set paramitemname='" + d.paramitemname + "', paramcontent='" + d.paramcontent +
- "' where paramid=" + std::to_string(d.paramid);
- //sprintf(altersql_Str, altersql.c_str(), d.paramid);
- r = _gtpgcnn.writeContent(altersql);
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- return r;
- }
- /*
- * delete
- * dgns_gtcvrparam
- */
- bool gtdgnsdao::deleteDgns_gtcvrparamContent(int paramid) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *deletesql_Str;
- bool r = false;
- if (paramid > 0) {
- std::string deletesql = "delete from dgns_gtcvrparam where paramid=" + std::to_string(paramid);
- //sprintf(deletesql_Str, deletesql.c_str(), paramid);
- r = _gtpgcnn.writeContent(deletesql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * search
- * dgns_gtbaseparam
- */
- bool gtdgnsdao::get_dgns_gtbaseparam_single(dgns_gtbaseparam &d, std::string _id, std::string _recivetime) {
- 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";
- bool r = false;
- std::vector<std::string> wheresql;
- if (!_id.empty())
- wheresql.push_back(" and id ='" + _id + "' ");
- if (!_recivetime.empty())
- wheresql.push_back(" and recivetime='" + _recivetime + "' ");
- if (wheresql.size() == 0) return r;
- for (int i = 0; i < wheresql.size(); ++i) {
- sql += wheresql[i];
- }
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.readContent(sql);
- if (r) {
- int rows = _gtpgcnn.getRowsNumFromResult();
- for (int i = 0; i < rows; ++i) {
- d.id = _gtpgcnn.getValueFromResult(i, 0);
- d.createtime = _gtpgcnn.getValueFromResult(i, 1);
- d.recivetime = _gtpgcnn.getValueFromResult(i, 2);
- d.wellname = _gtpgcnn.getValueFromResult(i, 3);
- d.sgt.clear();
- std::string sgt_str = _gtpgcnn.getValueFromResult(i, 4);
- if (!sgt_str.empty()) {
- d.sgt = d.gt_trans_strtoarray(sgt_str);
- }
- //下面的必须不是空值
- d.s_max = std::atof(_gtpgcnn.getValueFromResult(i, 5).c_str());
- d.s_min = std::atof(_gtpgcnn.getValueFromResult(i, 6).c_str());
- d.l_max = std::atof(_gtpgcnn.getValueFromResult(i, 7).c_str());
- d.l_min = std::atof(_gtpgcnn.getValueFromResult(i, 8).c_str());
- d.l_mid = std::atof(_gtpgcnn.getValueFromResult(i, 9).c_str());
- d.l_fistdownturnpoint = std::atof(_gtpgcnn.getValueFromResult(i, 10).c_str());
- d.s = std::atof(_gtpgcnn.getValueFromResult(i, 11).c_str());
- d.s_pre = std::atof(_gtpgcnn.getValueFromResult(i, 12).c_str());
- d.n = std::atof(_gtpgcnn.getValueFromResult(i, 13).c_str());
- d.l = std::atof(_gtpgcnn.getValueFromResult(i, 14).c_str());
- d.s_effect = std::atof(_gtpgcnn.getValueFromResult(i, 15).c_str());
- d.area = std::atof(_gtpgcnn.getValueFromResult(i, 16).c_str());
- //d.upload =std::atof(_gtpgcnn.getValueFromResult(i, 17).c_str());
- //d.download =std::atof(_gtpgcnn.getValueFromResult(i, 18).c_str());
- d.islegal = std::atoi(_gtpgcnn.getValueFromResultChar(i, 19));
- d.remark = _gtpgcnn.getValueFromResult(i, 20);
- d.sgtpointnum = std::atoi(_gtpgcnn.getValueFromResult(i, 21).c_str());
- d.s_max_point_location = std::atoi(_gtpgcnn.getValueFromResult(i, 22).c_str());
- d.s_min_point_location = std::atoi(_gtpgcnn.getValueFromResult(i, 23).c_str());
- d.l_max_point_location = std::atoi(_gtpgcnn.getValueFromResult(i, 24).c_str());
- d.l_min_point_location = std::atoi(_gtpgcnn.getValueFromResult(i, 25).c_str());
- }
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * add
- * dgns_gtbaseparam
- */
- bool gtdgnsdao::add_dgns_gtbaseparam_single(dgns_gtbaseparam d) {
- bool r = false;
- std::vector<std::string> insertsql_fields_name;
- std::vector<std::string> insertsql_fields_value;
- if (!d.recivetime.empty()) {
- insertsql_fields_name.push_back("recivetime");
- insertsql_fields_value.push_back("'" + d.recivetime + "'");
- } else {
- std::cout << "Warning:必须指定功图的接收时间【唯一标识】" << std::endl;
- return r;
- }
- if (!d.sgt.empty() && d.sgt.size() > 0) {
- std::string sgt_str = d.gt_trans_arraytostr(d.sgt);
- if (!sgt_str.empty()) {
- insertsql_fields_value.push_back("'" + sgt_str + "'");
- insertsql_fields_name.push_back("sgt");
- }
- }
- {
- insertsql_fields_name.push_back("s_max");
- insertsql_fields_value.push_back(std::to_string(d.s_max));
- insertsql_fields_name.push_back("s_min");
- insertsql_fields_value.push_back(std::to_string(d.s_min));
- insertsql_fields_name.push_back("l_max");
- insertsql_fields_value.push_back(std::to_string(d.l_max));
- insertsql_fields_name.push_back("l_min");
- insertsql_fields_value.push_back(std::to_string(d.l_min));
- insertsql_fields_name.push_back("l_mid");
- insertsql_fields_value.push_back(std::to_string(d.l_mid));
- insertsql_fields_name.push_back("l_fistdownturnpoint");
- insertsql_fields_value.push_back(std::to_string(d.l_fistdownturnpoint));
- insertsql_fields_name.push_back("s");
- insertsql_fields_value.push_back(std::to_string(d.s));
- insertsql_fields_name.push_back("s_pre");
- insertsql_fields_value.push_back(std::to_string(d.s_pre));
- insertsql_fields_name.push_back("n");
- insertsql_fields_value.push_back(std::to_string(d.n));
- insertsql_fields_name.push_back("l");
- insertsql_fields_value.push_back(std::to_string(d.l));
- insertsql_fields_name.push_back("s_effect");
- insertsql_fields_value.push_back(std::to_string(d.s_effect));
- insertsql_fields_name.push_back("area");
- insertsql_fields_value.push_back(std::to_string(d.area));
- /*insertsql_fields_name.push_back("upload");
- insertsql_fields_value.push_back(std::to_string(d.upload));
- insertsql_fields_name.push_back("download");
- insertsql_fields_value.push_back(std::to_string(d.download));*/
- insertsql_fields_name.push_back("islegal");
- insertsql_fields_value.push_back(std::to_string(d.islegal));
- insertsql_fields_name.push_back("remark");
- insertsql_fields_value.push_back("'" + d.remark + "'");
- insertsql_fields_name.push_back("sgtpointnum");
- insertsql_fields_value.push_back(std::to_string(d.sgtpointnum));
- insertsql_fields_name.push_back("s_max_point_location");
- insertsql_fields_value.push_back(std::to_string(d.s_max_point_location));
- insertsql_fields_name.push_back("s_min_point_location");
- insertsql_fields_value.push_back(std::to_string(d.s_min_point_location));
- insertsql_fields_name.push_back("l_max_point_location");
- insertsql_fields_value.push_back(std::to_string(d.l_max_point_location));
- insertsql_fields_name.push_back("l_min_point_location");
- insertsql_fields_value.push_back(std::to_string(d.l_min_point_location));
- }
- if (insertsql_fields_name.size() == 0)return r;
- std::string addsql =
- "insert into dgns_gtbaseparam(";
- std::string valuessql = "values(";
- for (int i = 0; i < insertsql_fields_name.size(); ++i) {
- if (i > 0) {
- addsql += ",";
- valuessql += ",";
- }
- addsql += insertsql_fields_name[i];
- valuessql += insertsql_fields_value[i];
- }
- addsql = addsql + ")" + valuessql + ")";
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.writeContent(addsql);
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * alter
- * dgns_gtbaseparam
- */
- bool gtdgnsdao::alterDgns_gtbaseparamContent(dgns_gtbaseparam d) {
- bool r = false;
- /* char *altersql_Str;
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- d.id.erase(std::remove(d.id.begin(), d.id.end(), '-'), d.id.end());
- if (d.id.length() == 32) {
- std::string altersql =
- "update dgns_gtbaseparam set createtime=to_timestamp('" + d.createtime +
- "','YYYY-MM-DD HH24:MI:SS'), recivetime=to_timestamp('" +
- d.recivetime + "','YYYY-MM-DD HH24:MI:SS'), wellname='" + d.wellname + "', sgt='" + d.sgt +
- "',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='" +
- d.remark +
- "' where id='" + d.id + "'";
- 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,
- d.upload, d.download,
- d.islegal);
- r = _gtpgcnn.writeContent(altersql_Str);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();*/
- return r;
- }
- /*
- * delete
- * dgns_gtbaseparam
- */
- bool gtdgnsdao::deleteDgns_gtbaseparamContent(std::string paramid) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- bool r = false;
- paramid.erase(std::remove(paramid.begin(), paramid.end(), '-'), paramid.end());
- if (paramid.length() == 32) {
- std::string deletesql = "delete from dgns_gtbaseparam where id='" + paramid + "'";
- r = _gtpgcnn.writeContent(deletesql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * search
- * dgns_gtcvrresult
- */
- std::vector<dgns_gtcvrresult>
- gtdgnsdao::getDgns_gtcvrresultContent(std::string id, std::string sgt_recivetime) {
- if (id.empty() && sgt_recivetime.empty()) {
- std::cout << "Warning:没有足够的参数传入";
- return std::vector<dgns_gtcvrresult>();
- }
- std::string sql = "select id,result1,result2,wellname,sgt,processparam,remark,createtime,userconfirmtime,userconfirmcontent,isproblem,isexpected from dgns_gtcvrresult where 1=1";
- bool r = false;
- if (!id.empty())
- sql += " and id='" + id + "' ";
- if (!sgt_recivetime.empty()) {
- sql += " and processparam->>'sgt_recivetime'::text='" + sgt_recivetime + "' ";
- }
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.readContent(sql);
- if (!r) return std::vector<dgns_gtcvrresult>();
- int rows = _gtpgcnn.getRowsNumFromResult();
- std::vector<dgns_gtcvrresult> lis;
- for (int i = 0; i < rows; ++i) {
- dgns_gtcvrresult d;
- d.id = _gtpgcnn.getValueFromResultChar(i, 0);
- d.result1 = _gtpgcnn.getValueFromResult(i, 1);
- d.result2 = _gtpgcnn.getValueFromResult(i, 2);
- d.wellname = _gtpgcnn.getValueFromResult(i, 3);
- d.sgt =d.gt_trans_strtoarray(_gtpgcnn.getValueFromResult(i, 4));
- d.processparam = _gtpgcnn.getValueFromResult(i, 5);
- d.remark = _gtpgcnn.getValueFromResult(i, 6);
- d.createtime = _gtpgcnn.getValueFromResult(i, 7);
- d.userconfirmtime = _gtpgcnn.getValueFromResult(i, 8);
- d.userconfirmcontent = _gtpgcnn.getValueFromResult(i, 9);
- d.isproblem = _gtpgcnn.getValueFromResult(i, 10);
- d.isexpected = std::atoi(_gtpgcnn.getValueFromResultChar(i, 11));
- lis.push_back(d);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return lis;
- }
- /*
- * add
- * dgns_gtcvrresult
- */
- bool gtdgnsdao::addDgns_gtcvrresultContent(dgns_gtcvrresult d) {
- bool r = false;
- std::vector<std::string> insertsql_fields_name;
- std::vector<std::string> insertsql_fields_value;
- /* if (!d.id.empty()) {
- insertsql_fields_name.push_back("id");
- insertsql_fields_value.push_back("'" + d.id + "'");
- } else {
- std::cout << "Warning:必须指定的id【唯一标识】" << std::endl;
- return r;
- }*/
- if (!d.sgt.empty() && d.sgt.size() > 0) {
- std::string sgt_str = d.gt_trans_arraytostr(d.sgt);
- if (!sgt_str.empty()) {
- insertsql_fields_value.push_back("'" + sgt_str + "'");
- insertsql_fields_name.push_back("sgt");
- }
- }
- {
- insertsql_fields_name.push_back("result1");
- insertsql_fields_value.push_back("'" + d.result1 + "'");
- insertsql_fields_name.push_back("result2");
- insertsql_fields_value.push_back("'" + d.result2 + "'");
- /*insertsql_fields_name.push_back("wellname");
- insertsql_fields_value.push_back("'"+d.wellname+"'");*/
- insertsql_fields_name.push_back("processparam");
- insertsql_fields_value.push_back("'"+d.processparam+"'");
- insertsql_fields_name.push_back("remark");
- insertsql_fields_value.push_back("'" + d.remark + "'");
- /*insertsql_fields_name.push_back("createtime");
- insertsql_fields_value.push_back("'"+d.createtime+"'");*/
- /*insertsql_fields_name.push_back("userconfirmtime");
- insertsql_fields_value.push_back("'"+d.userconfirmtime+"'");
- insertsql_fields_name.push_back("userconfirmcontent");
- insertsql_fields_value.push_back("'"+d.userconfirmcontent+"'");*/
- insertsql_fields_name.push_back("isproblem");
- insertsql_fields_value.push_back("'" + d.isproblem + "'");
- insertsql_fields_name.push_back("isexpected");
- insertsql_fields_value.push_back(std::to_string(d.isexpected));
- }
- if (insertsql_fields_name.size() == 0)return r;
- std::string addsql =
- "insert into dgns_gtcvrresult(";
- std::string valuessql = "values(";
- for (int i = 0; i < insertsql_fields_name.size(); ++i) {
- if (i > 0) {
- addsql += ",";
- valuessql += ",";
- }
- addsql += insertsql_fields_name[i];
- valuessql += insertsql_fields_value[i];
- }
- addsql = addsql + ")" + valuessql + ")";
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.writeContent(addsql);
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * alter
- * dgns_gtcvrresult
- */
- bool gtdgnsdao::alterDgns_gtcvrresultContent(dgns_gtcvrresult d) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *altersql_Str;
- bool r = false;
- /*if (!d.id.empty()) {
- std::string altersql =
- "update dgns_gtcvrresult set result1='" + d.result1 + "', result2='" + d.result2 + "',wellname='" +
- d.wellname + "',sgt='" + d.sgt +
- "',processparam='" + d.processparam + "',remark='" + d.remark + "',createtime=to_timestamp('" +
- d.createtime +
- "','YYYY-MM-DD HH24:MI:SS'),userconfirmtime=to_timestamp('" + d.userconfirmtime +
- "','YYYY-MM-DD HH24:MI:SS'),userconfirmcontent='" +
- d.userconfirmcontent + "',isproblem='" + d.isproblem + "',isexpected=" + std::to_string(d.isexpected) + " where id='" + d.id + "'";
- //sprintf(altersql_Str, altersql.c_str(), d.isexpected);
- r = _gtpgcnn.writeContent(altersql);
- }*/
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * delete
- * dgns_gtcvrresult
- */
- bool gtdgnsdao::deleteDgns_gtcvrresultContent(int paramid) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *deletesql_Str;
- bool r = false;
- if (paramid > 0) {
- std::string deletesql = "delete from dgns_gtcvrresult where paramid=" + std::to_string(paramid);
- //sprintf(deletesql_Str, deletesql.c_str(), paramid);
- r = _gtpgcnn.writeContent(deletesql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * search
- * dgns_gtserverrunlog
- */
- std::vector<dgns_gtserverrunlog>
- gtdgnsdao::getDgns_gtserverrunlogContent(int paramid = -1, std::string paramitemname = NULL) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- std::string sql = "select * from dgns_gtserverrunlog where 1=1";
- bool r;
- if (paramid > 0 && (!paramitemname.empty() || paramitemname != "")) {
- std::string a = " and code=" + std::to_string(paramid) + " and contents='" + paramitemname + "'";
- //char *astr;
- //sprintf(astr, a.c_str(), paramid);
- std::string sqlto = sql + a;
- r = _gtpgcnn.readContent(sqlto);
- } else {
- r = _gtpgcnn.readContent(sql);
- }
- if (!r) return std::vector<dgns_gtserverrunlog>();
- int rows = _gtpgcnn.getRowsNumFromResult();
- std::vector<dgns_gtserverrunlog> lis;
- for (int i = 0; i < rows; ++i) {
- dgns_gtserverrunlog d;
- d.time = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
- d.contents = _gtpgcnn.getValueFromResult(i, 1);
- d.item = _gtpgcnn.getValueFromResult(i, 2);
- d.code = atoi(_gtpgcnn.getValueFromResultChar(i, 3));
- lis.push_back(d);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return lis;
- }
- /*
- * add
- * dgns_gtserverrunlog
- */
- bool gtdgnsdao::addDgns_gtserverrunlogContent(dgns_gtserverrunlog d) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *addsql_Str;
- bool r = false;
- if (d.code > 0) {
- std::string addsql =
- "insert into dgns_gtserverrunlog(time, contents, item,code) values ('" + d.time + "','" + d.contents +
- "','" + d.item + "'," + std::to_string(d.code) + ")";
- //sprintf(addsql_Str, addsql.c_str(), d.code);
- r = _gtpgcnn.writeContent(addsql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * alter
- * dgns_gtserverrunlog
- */
- bool gtdgnsdao::alterDgns_gtserverrunlogContent(dgns_gtserverrunlog d) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *altersql_Str;
- bool r = false;
- if (d.code > 0) {
- std::string altersql =
- "update dgns_gtserverrunlog set time='" + d.time + "', contents='" + d.contents + "', item='" + d.item +
- "' where code=" + std::to_string(d.code);
- //sprintf(altersql_Str, altersql.c_str(), d.code);
- r = _gtpgcnn.writeContent(altersql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * delete
- * dgns_gtserverrunlog
- */
- bool gtdgnsdao::deleteDgns_gtserverrunlogContent(int paramid) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *deletesql_Str;
- bool r = false;
- if (paramid > 0) {
- std::string deletesql = "delete from dgns_gtserverrunlog where code=" + std::to_string(paramid);
- //sprintf(deletesql_Str, deletesql.c_str(), paramid);
- r = _gtpgcnn.writeContent(deletesql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * search
- * dgns_gtstandard
- */
- std::vector<dgns_gtstandard>
- gtdgnsdao::get_dgns_gtstandard_list(std::string conditionsql) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- std::string key = postgresql_aes_secretkey;
- std::string encryptF = postgresql_field_encryptfunc;
- std::string sql =
- "select sgtprodate,createtime,id,convert_from((decrypt(sgtcharacters::bytea,'" + key + "','" + encryptF
- +
- "')),'SQL_ASCII') sgtcharacters,appearcounter,graphicfeatureinterpretation,maxsemblance,minsemblance,wellname,latestupdatedtime from dgns_gtstandard ";
- bool r;
- /* if (maxcounterbzt) {
- sql += " where appearcounter=(select max(appearcounter) from dgns_gtstandard) ";
- }*/
- if (!conditionsql.empty())
- sql += conditionsql;
- r = _gtpgcnn.readContent(sql);
- if (!r) return std::vector<dgns_gtstandard>();
- int rows = _gtpgcnn.getRowsNumFromResult();
- std::vector<dgns_gtstandard> lis;
- for (int i = 0; i < rows; ++i) {
- dgns_gtstandard d;
- d.sgtprodate = _gtpgcnn.getValueFromResult(i, 0);
- d.createtime = _gtpgcnn.getValueFromResult(i, 1);
- d.id = _gtpgcnn.getValueFromResult(i, 2);
- if (!_gtpgcnn.getValueFromResult(i, 3).empty()) {
- jsonxx::json jobj = jsonxx::json::parse(_gtpgcnn.getValueFromResult(i, 3));
- d.sgtcharacters = new double[cardgray_characters_num];
- for (int jindex = 0; jindex < cardgray_characters_num; jindex++) {
- d.sgtcharacters[jindex] = jobj[jindex].as_float_anynum();
- }
- }
- d.appearcounter = std::atol(_gtpgcnn.getValueFromResult(i, 4).c_str());
- d.graphicfeatureinterpretation = _gtpgcnn.getValueFromResult(i, 5);
- if (!_gtpgcnn.getValueFromResult(i, 6).empty())
- d.maxsemblance = std::atof(_gtpgcnn.getValueFromResult(i, 6).c_str());
- if (!_gtpgcnn.getValueFromResult(i, 7).empty())
- d.minsemblance = std::atof(_gtpgcnn.getValueFromResult(i, 7).c_str());
- d.wellname = _gtpgcnn.getValueFromResult(i, 8);
- d.latestupdatedtime = _gtpgcnn.getValueFromResult(i, 9);
- lis.push_back(d);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return lis;
- }
- /*
- * add
- * dgns_gtstandard
- */
- bool gtdgnsdao::addDgns_gtstandardContent(dgns_gtstandard d) {
- bool r = false;
- //sgtprodate,createtime,id,sgtcharacters,appearcounter,graphicfeatureinterpretation,maxsemblance,minsemblance,wellname
- std::string addsql = "insert into dgns_gtstandard(";
- std::string valuesql = "values(";
- std::vector<std::string> field_name;
- std::vector<std::string> field_value;
- if (!d.sgtprodate.empty()) {
- field_name.push_back("sgtprodate");
- field_value.push_back("'" + d.sgtprodate + "'");
- }
- if (d.sgtcharacters != NULL) {
- jsonxx::json jobj;
- for (int i = 0; i < cardgray_characters_num; ++i) {
- jobj[i] = d.sgtcharacters[i];
- }
- std::string j_str = jobj.dump();
- field_name.push_back("sgtcharacters");
- field_value.push_back(
- "encrypt(replace('" + j_str + "','\','')::bytea,'" + postgresql_aes_secretkey + "','" +
- postgresql_field_encryptfunc + "')");
- }
- if (d.appearcounter > 0) {
- field_name.push_back("appearcounter");
- field_value.push_back(std::to_string(d.appearcounter));
- }
- if (!d.graphicfeatureinterpretation.empty()) {
- field_name.push_back("graphicfeatureinterpretation");
- field_value.push_back("'" + d.graphicfeatureinterpretation + "'");
- }
- if (d.maxsemblance > 0) {
- field_name.push_back("maxsemblance");
- field_value.push_back(std::to_string(d.maxsemblance));
- }
- if (d.minsemblance > 0) {
- field_name.push_back("minsemblance");
- field_value.push_back(std::to_string(d.minsemblance));
- }
- {
- field_name.push_back("latestupdatedtime");
- field_value.push_back("'" + d.latestupdatedtime + "'");
- }
- if (field_name.size() == 0) return r;
- for (int i = 0; i < field_name.size(); ++i) {
- if (i > 0) {
- addsql += ",";
- valuesql += ",";
- }
- valuesql += field_value[i];
- addsql += field_name[i];
- }
- addsql += ")" + valuesql + ")";
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.writeContent(addsql);
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * alter
- * dgns_gtstandard
- */
- bool gtdgnsdao::alterDgns_gtstandardContent(dgns_gtstandard d) {
- bool r = false;
- if (d.id.empty()) return r;
- std::string altersql =
- "update dgns_gtstandard set ";
- std::string wheresql = " where id='" + d.id + "' ";
- std::vector<std::string> setcontentsql;
- if (!d.sgtprodate.empty())
- setcontentsql.push_back(" sgtprodate='" + d.sgtprodate + "' ");
- if (d.sgtcharacters != NULL) {
- jsonxx::json jobj;
- for (int i = 0; i < cardgray_characters_num; ++i) {
- jobj[i] = d.sgtcharacters[i];
- }
- std::string j_str = jobj.dump();
- setcontentsql.push_back(
- " sgtcharacters=encrypt(replace('" + j_str + "','\','')::bytea,'" + postgresql_aes_secretkey +
- "','" +
- postgresql_field_encryptfunc + "') ");
- }
- if (d.appearcounter > 0)
- setcontentsql.push_back(" appearcounter=" + std::to_string(d.appearcounter) + " ");
- if (!d.graphicfeatureinterpretation.empty())
- setcontentsql.push_back(" graphicfeatureinterpretation='" + d.graphicfeatureinterpretation + "' ");
- if (d.maxsemblance > 0)
- setcontentsql.push_back(" maxsemblance=" + std::to_string(d.maxsemblance) + " ");
- if (d.minsemblance > 0)
- setcontentsql.push_back(" minsemblance=" + std::to_string(d.minsemblance) + " ");
- if (!d.latestupdatedtime.empty())
- setcontentsql.push_back(" latestupdatedtime='" + d.latestupdatedtime + "' ");
- if (setcontentsql.size() <= 0) return r;
- for (int i = 0; i < setcontentsql.size(); ++i) {
- if (i > 0)
- altersql += ",";
- altersql += setcontentsql[i];
- }
- altersql += wheresql;
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.writeContent(altersql);
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * delete
- * dgns_gtstandard
- */
- bool gtdgnsdao::deleteDgns_gtstandardContent(std::string id) {
- bool r = false;
- if (id.empty()) return r;
- std::string deletesql = "delete from dgns_gtstandard where id='" + id + "'";
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.writeContent(deletesql);
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- std::map<int, dgns_gtmloutcode> gtdgnsdao::get_dgns_gtmloutcode_map() {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- std::string key = postgresql_aes_secretkey;
- std::string encryptF = postgresql_field_encryptfunc;
- std::string sql =
- "select gkcode,gkdec from dgns_gtmloutcode order by gkcode";
- bool r;
- std::map<int, dgns_gtmloutcode> res;
- r = _gtpgcnn.readContent(sql);
- if (!r) return res;
- int rows = _gtpgcnn.getRowsNumFromResult();
- for (int i = 0; i < rows; ++i) {
- dgns_gtmloutcode d;
- d.gkcode = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
- d.gkdec = _gtpgcnn.getValueFromResult(i, 1);
- if (res.find(d.gkcode) != res.end()) {
- std::cout << "gtcode:" << d.gkcode << " exited ;warning: repeat gkcode!" << std::endl;
- res[d.gkcode] = d;
- } else {
- res.insert(std::pair<int, dgns_gtmloutcode>(d.gkcode, d));
- }
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return res;
- }
- /*
- * search
- * dgns_gtgktype
- */
- std::map<std::string, dgns_gtgktype> gtdgnsdao::get_dgns_gtgktype_all_map_indexofgkname() {
- bool r = false;
- std::string sql = "select id,gkname,dec,modbustranscode,remark from dgns_gtgktype where 1=1";
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.readContent(sql);
- std::map<std::string, dgns_gtgktype> ls;
- if (r) {
- int rows = _gtpgcnn.getRowsNumFromResult();
- for (int i = 0; i < rows; ++i) {
- dgns_gtgktype d;
- d.id = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
- d.gkname = _gtpgcnn.getValueFromResult(i, 1);
- d.dec = _gtpgcnn.getValueFromResult(i, 2);
- d.modbustranscode = _gtpgcnn.getValueFromResult(i, 3);
- d.remark = _gtpgcnn.getValueFromResult(i, 4);
- ls.insert(std::pair<std::string, dgns_gtgktype>(d.gkname, d));
- }
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return ls;
- }
- std::map<int, dgns_gtgktype> gtdgnsdao::get_dgns_gtgktype_all_map_indexofid() {
- bool r = false;
- std::string sql = "select id,gkname,dec,modbustranscode,remark from dgns_gtgktype where 1=1";
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.readContent(sql);
- std::map<int, dgns_gtgktype> ls;
- if (r) {
- int rows = _gtpgcnn.getRowsNumFromResult();
- for (int i = 0; i < rows; ++i) {
- dgns_gtgktype d;
- d.id = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
- d.gkname = _gtpgcnn.getValueFromResult(i, 1);
- d.dec = _gtpgcnn.getValueFromResult(i, 2);
- d.modbustranscode = _gtpgcnn.getValueFromResult(i, 3);
- d.remark = _gtpgcnn.getValueFromResult(i, 4);
- ls.insert(std::pair<int, dgns_gtgktype>(d.id, d));
- }
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return ls;
- }
- bool gtdgnsdao::get_dgns_gtgktype_single(dgns_gtgktype &d, int _id = -1, std::string _gkname = NULL) {
- bool r = false;
- std::string sql = "select * from dgns_gtgktype where 1=1";
- std::vector<std::string> wheresql;
- if (_id > 0) wheresql.push_back(" and id ='" + std::to_string(_id) + "' ");
- if (!_gkname.empty()) wheresql.push_back(" and gkname ='" + _gkname + "' ");
- if (wheresql.size() == 0) return r;
- for (int i = 0; i < wheresql.size(); ++i) {
- sql += wheresql[i];
- }
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- r = _gtpgcnn.readContent(sql);
- if (r) {
- int rows = _gtpgcnn.getRowsNumFromResult();
- for (int i = 0; i < rows; ++i) {
- d.id = atoi(_gtpgcnn.getValueFromResultChar(i, 0));
- d.gkname = _gtpgcnn.getValueFromResult(i, 1);
- d.dec = _gtpgcnn.getValueFromResult(i, 2);
- d.modbustranscode = _gtpgcnn.getValueFromResult(i, 3);
- d.remark = _gtpgcnn.getValueFromResult(i, 4);
- }
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * add
- * dgns_gtgktype
- */
- bool gtdgnsdao::addDgns_gtgktypeContent(dgns_gtgktype d) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *addsql_Str;
- bool r = false;
- if (d.id > 0) {
- std::string addsql =
- "insert into dgns_gtcvrresult(id, gkname, result2,wellname,sgt,processparam,remark,createtime,userconfirmtime,userconfirmtime,"
- "userconfirmcontent,isproblem,%d) values (" + std::to_string(d.id) + ",'" +
- d.gkname + "','" + d.dec + "','" + d.modbustranscode + "')";
- //sprintf(addsql_Str, addsql.c_str(), d.id);
- r = _gtpgcnn.writeContent(addsql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * alter
- * dgns_gtgktype
- */
- bool gtdgnsdao::alterDgns_gtgktypeContent(dgns_gtgktype d) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *altersql_Str;
- bool r = false;
- if (d.id > 0) {
- std::string altersql =
- "update dgns_gtgktype set gkname='" + d.gkname + "',dec='" + d.dec + "', modbustranscode='" +
- d.modbustranscode +
- "',remark='" + d.remark + "' where id=" + std::to_string(d.id);
- //sprintf(altersql_Str, altersql.c_str(), d.id);
- r = _gtpgcnn.writeContent(altersql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
- /*
- * delete
- * dgns_gtgktype
- */
- bool gtdgnsdao::deleteDgns_gtgktypeContent(int paramid) {
- gtpgcnn _gtpgcnn;
- _gtpgcnn.openCnn();
- //char *deletesql_Str;
- bool r = false;
- if (paramid > 0) {
- std::string deletesql = "delete from dgns_gtgktype where id=" + std::to_string(paramid);
- //sprintf(deletesql_Str, deletesql.c_str(), paramid);
- r = _gtpgcnn.writeContent(deletesql);
- }
- _gtpgcnn.clearRes();
- _gtpgcnn.closeCnn();
- return r;
- }
|