HttpPrcess.cpp 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241
  1. #include "stdafx.h"
  2. #include "HttpPrcess.h"
  3. #include <yyjson.h>
  4. #include <Simplelog.h>
  5. #include "MonitorObject.h"
  6. #include "AlarmDefine.h"
  7. #include <crc32.h>
  8. #include "AppService.h"
  9. #include <gbk2utf8.h>
  10. #include "Device.h"
  11. #include "ResistAlarm.h"
  12. //处理get请求总入口
  13. void DealHttpGet(const httplib::Request& req, httplib::Response& res)
  14. {
  15. int code = 500;
  16. auto start = chrono::steady_clock::now();
  17. auto token = req.get_header_value("token");
  18. if (token.length() == 0 || token.empty())
  19. token = req.get_header_value("Authorization");
  20. char* json = nullptr;
  21. string body;
  22. size_t json_len = 0;
  23. SPDLOG_INFO("[HTTP][GET][START] {}:{} {}", req.remote_addr, req.remote_port, req.target);
  24. try
  25. {
  26. if (token.empty())
  27. {
  28. code = 401;
  29. }
  30. if (req.path.find("option_svg") != -1)
  31. code = DealOptionSvgData(req, token, res);
  32. else if (req.path.find("get_svg") != -1)
  33. code = DealGetSvgData(req, token, res);
  34. else if (req.path.find("get_mp_stat") != -1)
  35. code = DealGetMpStat(req, token, res);
  36. else if (req.path.find("conf_read/mitie_lock") != -1)
  37. code = DealGetMitieLock(req, token, &json, &json_len);
  38. else if (req.path.find("conf_read/convert_resist") != -1)
  39. code = DealGetConvertResist(req, token, &json, &json_len);
  40. else if (req.path.find("resistance_curve") != -1)
  41. code = DealGetResistCurve(req, token, &json, &json_len);
  42. else if (req.path.find("resistance_report") != -1)
  43. code = DealGetResistReport(req, token, &json, &json_len);
  44. else if (req.path.find("move_info") != -1)
  45. code = DealGetMoveInfo(req, token, &json, &json_len);
  46. else if (req.path.find("operation_log") != -1)
  47. code = DealGetOptLog(req, token, &json, &json_len);
  48. else if (req.path.find("refer_curve") != -1)
  49. code = DealGetrefer_curve(req, token, &json, &json_len);
  50. else if (req.path.find("refer_option") != -1)
  51. code = DealGetrefer_option(req, token, &json, &json_len);
  52. else if (req.path.find("get_temp") != -1)
  53. code = DealGetTemp(req, token, &json, &json_len);
  54. else if (req.path.find("get_humitemp") != -1)
  55. code = DealGetTempHumi(req, token, &json, &json_len);
  56. else if (req.path.find("backend_type") != -1)
  57. {
  58. body = R"({"type":2})"; code = 200;
  59. }
  60. else
  61. code = 405;
  62. }
  63. catch (...)
  64. {
  65. code = 500;
  66. }
  67. if (json)
  68. res.set_content(json, "application/json");
  69. if (!body.empty())
  70. res.set_content(body.c_str(), "application/json");
  71. auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
  72. SPDLOG_INFO("[HTTP][GET][END] code:{} COST:{} {}:{} {} {}", code, cost, req.remote_addr, req.remote_port, req.target, json ? json : "");
  73. res.set_header("cost", to_string(cost) + " ms");
  74. res.status = code;
  75. if (json) free(json);
  76. }
  77. //处理post请求总入口
  78. void DealHttpPost(const httplib::Request& req, httplib::Response& res)
  79. {
  80. int code = 500;
  81. auto start = chrono::steady_clock::now();
  82. auto token = req.get_header_value("token");
  83. if (token.length() == 0 || token.empty())
  84. token = req.get_header_value("Authorization");
  85. char* json = nullptr;
  86. size_t json_len = 0;
  87. SPDLOG_INFO("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body);
  88. try
  89. {
  90. if (token.empty())
  91. {
  92. code = 401;
  93. }
  94. if (req.path.find("post_svg") != -1)
  95. code = DealPostSvgData(req, token, res);
  96. else if (req.path.find("option_svg") != -1)
  97. code = DealOptionSvgData(req, token, res);
  98. else if (req.path.find("commit_record") != -1)
  99. code = DealPostCommitRecord(req.body.c_str(), req.body.length(), token, &json, &json_len);
  100. else if (req.path.find("get_svg") != -1)
  101. code = DealGetSvgData(req, token, res);
  102. //else if (req.path.find("post_soft") != -1)
  103. // code = DealPostBinData(req, token, res);
  104. else if (req.path.find("conf_write/convert_resist") != -1)
  105. code = DealPostConvertResist(req.body.c_str(), req.body.length(), token, &json, &json_len);
  106. else if (req.path.find("conf_write/mitie_lock") != -1)
  107. code = DealPostMitieLock(req.body.c_str(), req.body.length(), token, &json, &json_len);
  108. else if (req.path.find("refer_curve") != -1)
  109. code = DealPostrefer_curve(req.body.c_str(), req.body.length(), token, &json, &json_len);
  110. else
  111. code = 405;
  112. }
  113. catch (...)
  114. {
  115. code = 500;
  116. }
  117. if (json)
  118. res.set_content(json, "application/json");
  119. auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
  120. SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{} json:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body, json ? json : "");
  121. res.set_header("cost", to_string(cost) + " ms");
  122. res.status = code;
  123. if (json) free(json);
  124. }
  125. int DealPostSvgData(const httplib::Request& req, const string token, httplib::Response& res)
  126. {
  127. if (token.find("AAAAAAAA") == -1) return 403;
  128. auto id = req.get_header_value("id");
  129. if (id.empty()) return 400;//参数错误
  130. char szID[200] = { 0 };
  131. utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
  132. if (req.body.empty()) return 400;
  133. CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
  134. CFile file;
  135. if (file.Open(strPath, CFile::modeWrite | CFile::typeBinary | CFile::modeCreate))
  136. {
  137. file.Write(req.body.c_str(), req.body.length());
  138. file.Close();
  139. return 200;
  140. }
  141. else
  142. {
  143. return 500;
  144. }
  145. return 405;
  146. }
  147. int DealGetSvgData(const httplib::Request& req, const string token, httplib::Response& res)
  148. {
  149. auto id = req.get_param_value("id");
  150. if (id.empty()) return 400;//参数错误
  151. char szID[200] = { 0 };
  152. utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
  153. CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
  154. auto bExist = CSimpleLog::PathFileExists(strPath);
  155. if (bExist == false) return 404;
  156. CFile file;
  157. if (file.Open(strPath, CFile::modeRead | CFile::typeBinary))
  158. {
  159. int len = file.GetLength();
  160. auto pData = new uint8_t[len];
  161. file.Read(pData, len);
  162. file.Close();
  163. res.set_content((char*)pData, len, "image/svg+xml");
  164. }
  165. else
  166. {
  167. return 500;
  168. }
  169. return 200;
  170. }
  171. int DealOptionSvgData(const httplib::Request& req, const string token, httplib::Response& res)
  172. {
  173. auto id = req.get_param_value("id");
  174. if (id.empty()) return 400;//参数错误
  175. char szID[200] = { 0 };
  176. utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
  177. CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
  178. auto bExist = CSimpleLog::PathFileExists(strPath);
  179. string strResult;
  180. if (bExist)
  181. strResult = R"({"result":true})";
  182. else
  183. strResult = R"({"result":false})";
  184. res.set_content(strResult, "application/json");
  185. return 200;
  186. }
  187. int DealGetMpStat(const httplib::Request& req, const string token, httplib::Response& res)
  188. {
  189. auto id = req.get_param_value("id");//杭南杭甬场
  190. if (id.empty()) return 400;//参数错误
  191. char station[200];
  192. int id_len = utf82gbk(station, 200, id.c_str(), id.length());
  193. auto pStation = CMonitorObjectMng::Instance()->GetTreeByID(string(station));
  194. if (nullptr == pStation) return 404;
  195. if (pStation->type.compare("station") != 0) return 400;
  196. auto doc = yyjson_mut_doc_new(nullptr);
  197. auto root = yyjson_mut_arr(doc);
  198. yyjson_mut_doc_set_root(doc, root);
  199. for (const auto& it : pStation->m_lstMo)
  200. {
  201. auto arr = yyjson_mut_arr(doc);
  202. yyjson_mut_arr_add_val(root, arr);
  203. yyjson_mut_arr_add_strcpy(doc, arr, it->id.c_str());
  204. yyjson_mut_arr_add_strcpy(doc, arr, it->name.c_str());
  205. CDevice* pDevice = CDeviceMng::Instance()->Find(it->id);
  206. if (pDevice)
  207. {
  208. string mo, mp;
  209. if (CMonitorObjectMng::spiltByPoint(it->id, mo, mp))
  210. {
  211. SYSTEMTIME stAlarm = { 0 };
  212. auto ty = CResistAlarmMng::Instance()->GetAlarmStat(mo, mp, stAlarm);
  213. if (ty == eZL_MP_STAT::MP_STAT_OFFLINE_GRAY)
  214. {
  215. if (pDevice->IsDeviceOnline())
  216. yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_NORMAL_GREEN);
  217. else
  218. yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_OFFLINE_GRAY);
  219. }
  220. else
  221. {
  222. yyjson_mut_arr_add_int(doc, arr, (int)ty);
  223. sprintf_s(station, 200, "%04d-%02d-%02d %02d:%02d:%02d.%03d", stAlarm.wYear, stAlarm.wMonth, stAlarm.wDay, stAlarm.wHour, stAlarm.wMinute, stAlarm.wSecond, stAlarm.wMilliseconds);
  224. yyjson_mut_arr_add_strcpy(doc, arr, station);
  225. }
  226. }
  227. else
  228. {
  229. yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_UNINSTALL_WHITE);
  230. }
  231. }
  232. else
  233. {
  234. yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_UNINSTALL_WHITE);
  235. }
  236. }
  237. size_t len;
  238. auto json = yyjson_mut_write(doc, 0, &len);
  239. res.set_content(json, len, "application/json");
  240. if (json)
  241. {
  242. free((void*)json);
  243. json = nullptr;
  244. }
  245. yyjson_mut_doc_free(doc);
  246. return 200;
  247. }
  248. int DealGetMitieLock(const httplib::Request& req, const string token, char** json, size_t* json_len)
  249. {
  250. string mo = req.get_param_value("mo");
  251. string mp = req.get_param_value("mp");
  252. eSuoBiPosi posi = (eSuoBiPosi)atoi(req.get_param_value("posi").c_str());
  253. if (posi == eSuoBiPosi::SB_ZERO) posi = eSuoBiPosi::SB_UNKNOWN;
  254. if (mo.length() == 0 || mp.length() == 0)
  255. return 400;
  256. auto doc = yyjson_mut_doc_new(nullptr);
  257. auto root = yyjson_mut_obj(doc);
  258. yyjson_mut_doc_set_root(doc, root);
  259. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  260. if (pInfo)
  261. {
  262. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  263. if (pInfo->alarm_low_limit > INT_MIN)
  264. yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
  265. else
  266. yyjson_mut_obj_add_null(doc, root, "alarm_low_limit");
  267. if (pInfo->warn_low_limit > INT_MIN)
  268. yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
  269. else
  270. yyjson_mut_obj_add_null(doc, root, "warn_low_limit");
  271. if (pInfo->alarm_high_limit < INT_MAX)
  272. yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
  273. else
  274. yyjson_mut_obj_add_null(doc, root, "alarm_high_limit");
  275. if (pInfo->warn_high_limit < INT_MAX)
  276. yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
  277. else
  278. yyjson_mut_obj_add_null(doc, root, "warn_high_limit");
  279. }
  280. else
  281. {
  282. yyjson_mut_obj_add_bool(doc, root, "enable", false);
  283. yyjson_mut_obj_add_null(doc, root, "alarm_low_limit");
  284. yyjson_mut_obj_add_null(doc, root, "warn_low_limit");
  285. yyjson_mut_obj_add_null(doc, root, "alarm_high_limit");
  286. yyjson_mut_obj_add_null(doc, root, "warn_high_limit");
  287. }
  288. *json = yyjson_mut_write(doc, 0, json_len);
  289. yyjson_mut_doc_free(doc);
  290. return 200;
  291. }
  292. int DealPostMitieLock(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  293. {
  294. return 403; //关闭设置
  295. int code = 400;
  296. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  297. if (req_doc == nullptr) return 400;
  298. auto req_root = yyjson_doc_get_root(req_doc);
  299. do
  300. {
  301. auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
  302. auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
  303. eSuoBiPosi posi = (eSuoBiPosi)yyjson_get_int(yyjson_obj_get(req_root, "posi"));;//预留
  304. if (posi == eSuoBiPosi::SB_ZERO) posi = eSuoBiPosi::SB_UNKNOWN;
  305. auto conf = yyjson_obj_get(req_root, "conf");
  306. if (mo == nullptr || mp == nullptr || conf == nullptr)
  307. break;
  308. auto doc = yyjson_mut_doc_new(nullptr);
  309. auto root = yyjson_mut_obj(doc);
  310. yyjson_mut_doc_set_root(doc, root);
  311. size_t len;
  312. char* str_conf = nullptr;
  313. //更新内存里
  314. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  315. CString sql;
  316. if (pInfo == nullptr)
  317. {
  318. SUOBI_OVER_LIMIT_INFO* pInfo = new SUOBI_OVER_LIMIT_INFO;
  319. pInfo->type = eZL_ALARMTYPE::SUOBI_LOCK_LIMIT;
  320. pInfo->no = (uint8_t)posi;
  321. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  322. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  323. {
  324. auto val = yyjson_obj_get(conf, "alarm_low_limit");
  325. if (val && yyjson_is_int(val))
  326. pInfo->alarm_low_limit = yyjson_get_int(val);
  327. yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
  328. }
  329. {
  330. auto val = yyjson_obj_get(conf, "warn_low_limit");
  331. if (val && yyjson_is_int(val))
  332. pInfo->warn_low_limit = yyjson_get_int(val);
  333. yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
  334. }
  335. {
  336. auto val = yyjson_obj_get(conf, "alarm_high_limit");
  337. if (val && yyjson_is_int(val))
  338. pInfo->alarm_high_limit = yyjson_get_int(val);
  339. yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
  340. }
  341. {
  342. auto val = yyjson_obj_get(conf, "warn_high_limit");
  343. if (val && yyjson_is_int(val))
  344. pInfo->warn_high_limit = yyjson_get_int(val);
  345. yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
  346. }
  347. str_conf = yyjson_mut_write(doc, 0, &len);
  348. yyjson_mut_doc_free(doc);
  349. CResistAlarmMng::Instance()->Insert(mo, mp, (uint8_t)posi, (uint8_t)eZL_ALARMTYPE::SUOBI_LOCK_LIMIT, pInfo);
  350. time_t tt;
  351. time(&tt);
  352. sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d, %d,'%s','%I64u')",
  353. mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT, str_conf, tt);
  354. }
  355. else
  356. {
  357. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  358. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  359. {
  360. auto val = yyjson_obj_get(conf, "alarm_low_limit");
  361. if (val && yyjson_is_int(val))
  362. pInfo->alarm_low_limit = yyjson_get_int(val);
  363. else
  364. pInfo->alarm_low_limit = INT_MIN;
  365. yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
  366. }
  367. {
  368. auto val = yyjson_obj_get(conf, "warn_low_limit");
  369. if (val && yyjson_is_int(val))
  370. pInfo->warn_low_limit = yyjson_get_int(val);
  371. else
  372. pInfo->warn_low_limit = INT_MIN;
  373. yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
  374. }
  375. {
  376. auto val = yyjson_obj_get(conf, "alarm_high_limit");
  377. if (val && yyjson_is_int(val))
  378. pInfo->alarm_high_limit = yyjson_get_int(val);
  379. else
  380. pInfo->alarm_high_limit = INT_MAX;
  381. yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
  382. }
  383. {
  384. auto val = yyjson_obj_get(conf, "warn_high_limit");
  385. if (val && yyjson_is_int(val))
  386. pInfo->warn_high_limit = yyjson_get_int(val);
  387. else
  388. pInfo->warn_high_limit = INT_MAX;
  389. yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
  390. }
  391. str_conf = yyjson_mut_write(doc, 0, &len);
  392. yyjson_mut_doc_free(doc);
  393. sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
  394. str_conf, mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  395. }
  396. if (str_conf) free(str_conf);
  397. if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  398. {
  399. ASSERT(FALSE);
  400. CSimpleLog::Error("语句执行失败" + sql);
  401. code = 500;
  402. break;
  403. }
  404. code = 200;
  405. } while (false);
  406. yyjson_doc_free(req_doc);
  407. return code;
  408. }
  409. int DealGetConvertResist(const httplib::Request& req, const string token, char** json, size_t* json_len)
  410. {
  411. string mo = req.get_param_value("mo");
  412. string mp = req.get_param_value("mp");
  413. if (mo.length() == 0 || mp.length() == 0)
  414. return 400;
  415. auto doc = yyjson_mut_doc_new(nullptr);
  416. auto root = yyjson_mut_obj(doc);
  417. yyjson_mut_doc_set_root(doc, root);
  418. CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  419. if (pInfo)
  420. {
  421. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  422. if (pInfo->dw_alarm_low_limit > INT_MIN)
  423. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
  424. else
  425. yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_limit");
  426. if (pInfo->dw_warn_low_limit > INT_MIN)
  427. yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
  428. else
  429. yyjson_mut_obj_add_null(doc, root, "dw_warn_low_limit");
  430. if (pInfo->up_alarm_high_limit < INT_MAX)
  431. yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
  432. else
  433. yyjson_mut_obj_add_null(doc, root, "up_alarm_high_limit");
  434. if (pInfo->up_warn_high_limit < INT_MAX)
  435. yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
  436. else
  437. yyjson_mut_obj_add_null(doc, root, "up_warn_high_limit");
  438. }
  439. else
  440. {
  441. yyjson_mut_obj_add_bool(doc, root, "enable", false);
  442. yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_limit");
  443. yyjson_mut_obj_add_null(doc, root, "dw_warn_low_limit");
  444. yyjson_mut_obj_add_null(doc, root, "up_alarm_high_limit");
  445. yyjson_mut_obj_add_null(doc, root, "up_warn_high_limit");
  446. }
  447. *json = yyjson_mut_write(doc, 0, json_len);
  448. yyjson_mut_doc_free(doc);
  449. return 200;
  450. }
  451. int DealPostConvertResist(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  452. {
  453. return 403;
  454. int code = 400;
  455. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  456. if (req_doc == nullptr) return 400;
  457. auto req_root = yyjson_doc_get_root(req_doc);
  458. do
  459. {
  460. auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
  461. auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
  462. auto conf = yyjson_obj_get(req_root, "conf");
  463. if (mo == nullptr || mp == nullptr || conf == nullptr)
  464. break;
  465. auto doc = yyjson_mut_doc_new(nullptr);
  466. auto root = yyjson_mut_obj(doc);
  467. yyjson_mut_doc_set_root(doc, root);
  468. size_t len;
  469. char* str_conf = nullptr;
  470. //更新内存里
  471. CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  472. CString sql;
  473. if (pInfo == nullptr)
  474. {
  475. CONVERT_RESIST_OVER_LIMIT* pInfo = new CONVERT_RESIST_OVER_LIMIT;
  476. pInfo->type = eZL_ALARMTYPE::CONVERT_LIMIT;
  477. pInfo->no = 2;
  478. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  479. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  480. {
  481. auto val = yyjson_obj_get(conf, "dw_alarm_low_limit");
  482. if (val && yyjson_is_int(val))
  483. pInfo->dw_alarm_low_limit = yyjson_get_int(val);
  484. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
  485. }
  486. {
  487. auto val = yyjson_obj_get(conf, "dw_warn_low_limit");
  488. if (val && yyjson_is_int(val))
  489. pInfo->dw_warn_low_limit = yyjson_get_int(val);
  490. yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
  491. }
  492. {
  493. auto val = yyjson_obj_get(conf, "up_alarm_high_limit");
  494. if (val && yyjson_is_int(val))
  495. pInfo->up_alarm_high_limit = yyjson_get_int(val);
  496. yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
  497. }
  498. {
  499. auto val = yyjson_obj_get(conf, "up_warn_high_limit");
  500. if (val && yyjson_is_int(val))
  501. pInfo->up_warn_high_limit = yyjson_get_int(val);
  502. yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
  503. }
  504. str_conf = yyjson_mut_write(doc, 0, &len);
  505. yyjson_mut_doc_free(doc);
  506. CResistAlarmMng::Instance()->Insert(mo, mp, 2, (uint8_t)eZL_ALARMTYPE::CONVERT_LIMIT, pInfo);
  507. sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d,%d,'%s','%I64u')",
  508. mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT, str_conf, 0);
  509. }
  510. else
  511. {
  512. pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
  513. yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
  514. {
  515. auto val = yyjson_obj_get(conf, "dw_alarm_low_limit");
  516. if (val && yyjson_is_int(val))
  517. pInfo->dw_alarm_low_limit = yyjson_get_int(val);
  518. else
  519. pInfo->dw_alarm_low_limit = INT_MIN;
  520. yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
  521. }
  522. {
  523. auto val = yyjson_obj_get(conf, "dw_warn_low_limit");
  524. if (val && yyjson_is_int(val))
  525. pInfo->dw_warn_low_limit = yyjson_get_int(val);
  526. else
  527. pInfo->dw_warn_low_limit = INT_MIN;
  528. yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
  529. }
  530. {
  531. auto val = yyjson_obj_get(conf, "up_alarm_high_limit");
  532. if (val && yyjson_is_int(val))
  533. pInfo->up_alarm_high_limit = yyjson_get_int(val);
  534. else
  535. pInfo->up_alarm_high_limit = INT_MAX;
  536. yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
  537. }
  538. {
  539. auto val = yyjson_obj_get(conf, "up_warn_high_limit");
  540. if (val && yyjson_is_int(val))
  541. pInfo->up_warn_high_limit = yyjson_get_int(val);
  542. else
  543. pInfo->up_warn_high_limit = INT_MAX;
  544. yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
  545. }
  546. str_conf = yyjson_mut_write(doc, 0, &len);
  547. yyjson_mut_doc_free(doc);
  548. sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
  549. str_conf, mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  550. }
  551. if (str_conf) free(str_conf);
  552. if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  553. {
  554. ASSERT(FALSE);
  555. CSimpleLog::Error("语句执行失败" + sql);
  556. code = 500;
  557. break;
  558. }
  559. code = 200;
  560. } while (false);
  561. yyjson_doc_free(req_doc);
  562. return code;
  563. }
  564. int DealPostCommitRecord(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  565. {
  566. int code = 400;
  567. string msg;
  568. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  569. if (req_doc == nullptr) return 400;
  570. auto req_root = yyjson_doc_get_root(req_doc);
  571. do
  572. {
  573. if (yyjson_is_arr(req_root) == false) break;
  574. auto doc = yyjson_mut_doc_new(nullptr);
  575. auto root = yyjson_mut_obj(doc);
  576. yyjson_mut_doc_set_root(doc, root);
  577. size_t n = yyjson_arr_size(req_root);
  578. auto req_obj = yyjson_arr_get_first(req_root);
  579. for (size_t i = 0; i < n; i++)
  580. {
  581. auto module = yyjson_get_int(yyjson_obj_get(req_obj, "module"));
  582. auto dura = yyjson_get_int(yyjson_obj_get(req_obj, "dura"));
  583. auto analyze_type = yyjson_get_int(yyjson_obj_get(req_obj, "analyze_type"));
  584. auto station = yyjson_get_str(yyjson_obj_get(req_obj, "station"));
  585. auto station_name = yyjson_get_str(yyjson_obj_get(req_obj, "station_name"));
  586. auto mo = yyjson_get_str(yyjson_obj_get(req_obj, "mo"));
  587. auto mo_name = yyjson_get_str(yyjson_obj_get(req_obj, "mo_name"));
  588. auto mp = yyjson_get_str(yyjson_obj_get(req_obj, "mp"));
  589. auto mp_name = yyjson_get_str(yyjson_obj_get(req_obj, "mp_name"));
  590. auto start_time = yyjson_get_uint(yyjson_obj_get(req_obj, "start_time"));
  591. auto end_time = yyjson_get_uint(yyjson_obj_get(req_obj, "end_time"));
  592. time_t tt;
  593. time(&tt);
  594. auto name = yyjson_get_str(yyjson_obj_get(req_obj, "name"));
  595. auto username = yyjson_get_str(yyjson_obj_get(req_obj, "username"));
  596. if (module == 0 || dura == 0 || station == nullptr ||
  597. station_name == nullptr || start_time == 0 || name == nullptr)
  598. break;
  599. auto strStation = UTF8toANSI(station);
  600. auto strStationName = UTF8toANSI(station_name);
  601. auto strName = UTF8toANSI(name);
  602. CString strDuraTime;
  603. dura = dura / 1000.0 + 0.5;
  604. if (dura / 60)
  605. strDuraTime.Format(" 时长:%d分%d秒", dura / 60, dura % 60);
  606. else if (dura)
  607. strDuraTime.Format(" 时长:%d秒", dura);
  608. CString sql = fmt::format("INSERT INTO [dbo].[rm_record]\
  609. (module, dura, analyze_type, station\
  610. , station_name, mo, mo_name, mp, mp_name, start_time\
  611. , end_time, time, name,username,opt,mark) VALUES\
  612. ({}, {}, {}, '{}', '{}'\
  613. , '{}', '{}', '{}', '{}', {}\
  614. , {}, {}, '{}', '{}',{}, '{}')",
  615. module, dura, analyze_type, strStation, strStationName,
  616. IS_NULL(mo), IS_NULL(mo_name), IS_NULL(mp), IS_NULL(mp_name), start_time,
  617. end_time, tt, strName, IS_NULL(username), 1, strDuraTime).c_str();
  618. if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  619. {
  620. ASSERT(FALSE);
  621. msg = "语句执行失败:" + sql;
  622. CSimpleLog::Error(msg.c_str());
  623. code = 500;
  624. break;
  625. }
  626. else
  627. {
  628. code = 200;
  629. }
  630. code = ExecSqlForRecord((eRecord_Module)module, dura, analyze_type, strStation, strStationName, mo, mo_name, mp, mp_name, start_time, end_time, tt, strName, username, eRocord_Opt::RO_RECORD, string(strDuraTime));
  631. req_obj = unsafe_yyjson_get_next(req_obj);
  632. }
  633. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  634. yyjson_mut_obj_add_int(doc, root, "code", code);
  635. if (json) *json = yyjson_mut_write(doc, 0, json_len);
  636. } while (false);
  637. yyjson_doc_free(req_doc);
  638. return code;
  639. }
  640. int DealGetOptLog(const httplib::Request& req, const string token, char** json, size_t* json_len)
  641. {
  642. string station_name = req.get_param_value("station_name");
  643. string time = req.get_param_value("time");
  644. string end_time = req.get_param_value("end_time");
  645. if (time.length() == 0 )
  646. return 400;
  647. time_t uTime = atoll(time.c_str());
  648. time_t uEndTime = atoll(end_time.c_str());
  649. if (uEndTime == 0) uEndTime = uTime + 86400;
  650. COleDateTime odt(uTime);
  651. if (odt.GetStatus() == COleDateTime::invalid)
  652. return 400;
  653. string str_station_name = UTF8toANSI(station_name);
  654. int code = 400;
  655. string msg;
  656. auto doc = yyjson_mut_doc_new(nullptr);
  657. auto root = yyjson_mut_obj(doc);
  658. yyjson_mut_doc_set_root(doc, root);
  659. auto yy_data = yyjson_mut_arr(doc);
  660. auto yy_name = yyjson_mut_arr(doc);
  661. auto yy_mo = yyjson_mut_arr(doc);
  662. auto yy_mp = yyjson_mut_arr(doc);
  663. yyjson_mut_obj_add_val(doc, root, "data", yy_data);
  664. yyjson_mut_obj_add_val(doc, root, "name", yy_name);
  665. yyjson_mut_obj_add_val(doc, root, "mo_name", yy_mo);
  666. yyjson_mut_obj_add_val(doc, root, "mp_name", yy_mp);
  667. //query
  668. //查询数据库
  669. std::map<string, uint16_t> map_name;
  670. std::map<string, uint16_t> map_mo_name;
  671. std::map<string, uint16_t> map_mp_name;
  672. {
  673. //station,station_name,
  674. CString sql;
  675. if (str_station_name.length() == 0)
  676. sql = fmt::format("SELECT module,dura,analyze_type, mo, mo_name, mp, mp_name, start_time, end_time, [time], name, username, opt, mark,station_name\
  677. FROM rm_record WHERE time between {} AND {}",
  678. uTime, uEndTime).c_str();
  679. else
  680. sql = fmt::format("SELECT module,dura,analyze_type, mo, mo_name, mp, mp_name, start_time, end_time, [time], name, username, opt, mark,station_name\
  681. FROM rm_record WHERE station_name = '{}' AND time between {} AND {}",
  682. str_station_name, uTime, uEndTime).c_str();
  683. COdbcStatement stmt;
  684. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  685. {
  686. uint8_t umodule, analyze_type;
  687. int16_t opt = 0;
  688. int dura;
  689. char /*station[100], char station_name[100], */mo[50], mo_name[50], mp[50], mp_name[50], name[100], username[50], mark[200], station_name[100];
  690. uint64_t start_time, end_time, tt;
  691. int nCol = 1;
  692. stmt.BindTinyIntCol(nCol++, &umodule);
  693. stmt.BindIntCol(nCol++, &dura);
  694. stmt.BindTinyIntCol(nCol++, &analyze_type);
  695. //stmt.BindCharCol(nCol++, station, sizeof(station));
  696. //stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
  697. stmt.BindCharCol(nCol++, mo, sizeof(mo));
  698. stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
  699. stmt.BindCharCol(nCol++, mp, sizeof(mp));
  700. stmt.BindCharCol(nCol++, mp_name, sizeof(mp_name));
  701. stmt.BindBigIntCol(nCol++, (__int64*)&start_time);
  702. stmt.BindBigIntCol(nCol++, (__int64*)&end_time);
  703. stmt.BindBigIntCol(nCol++, (__int64*)&tt);
  704. stmt.BindCharCol(nCol++, name, sizeof(name));
  705. stmt.BindCharCol(nCol++, username, sizeof(username));
  706. stmt.BindSmallIntCol(nCol++, &opt);
  707. stmt.BindCharCol(nCol++, mark, sizeof(mark));
  708. stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
  709. do
  710. {
  711. //ZeroMemory(station, 100);
  712. //ZeroMemory(station_name, 100);
  713. ZeroMemory(mo, 50);
  714. ZeroMemory(mo_name, 50);
  715. ZeroMemory(mp, 50);
  716. ZeroMemory(mp_name, 50);
  717. ZeroMemory(name, 100);
  718. ZeroMemory(username, 50);
  719. ZeroMemory(mark, 200);
  720. ZeroMemory(station_name, 100);
  721. if (stmt.FetchNext() != 0)
  722. break;
  723. map_name[name]++;
  724. map_mo_name[mo_name]++;
  725. map_mp_name[mp_name]++;
  726. auto o = yyjson_mut_obj(doc);
  727. yyjson_mut_arr_add_val(yy_data, o);
  728. yyjson_mut_obj_add_int(doc, o, "module", umodule);
  729. yyjson_mut_obj_add_int(doc, o, "opt", opt);
  730. yyjson_mut_obj_add_int(doc, o, "analyze_type", analyze_type);
  731. yyjson_mut_obj_add_strcpy(doc, o, "mo_name", mo_name);
  732. yyjson_mut_obj_add_strcpy(doc, o, "mp_name", mp_name);
  733. yyjson_mut_obj_add_int(doc, o, "time", tt);
  734. yyjson_mut_obj_add_strcpy(doc, o, "name", ANSItoUTF8(name).c_str());
  735. yyjson_mut_obj_add_strcpy(doc, o, "mark", ANSItoUTF8(mark).c_str());
  736. yyjson_mut_obj_add_strcpy(doc, o, "station_name", ANSItoUTF8(station_name).c_str());
  737. } while (TRUE);
  738. }
  739. stmt.Close();
  740. }
  741. for (auto& it : map_name)
  742. yyjson_mut_arr_add_strcpy(doc, yy_name, ANSItoUTF8(it.first).c_str());
  743. for (auto& it : map_mo_name)
  744. yyjson_mut_arr_add_strcpy(doc, yy_mo, it.first.c_str());
  745. for (auto& it : map_mp_name)
  746. yyjson_mut_arr_add_strcpy(doc, yy_mp, it.first.c_str());
  747. code = 200;
  748. yyjson_mut_obj_add_int(doc, root, "code", code);
  749. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  750. if (json)
  751. {
  752. *json = yyjson_mut_write(doc, 0, json_len);
  753. /*
  754. *json = (char*)malloc(1024);
  755. strcpy_s(*json, 1024, R"({
  756. "code": 200,
  757. "msg": "",
  758. "data": [{
  759. "mo_name": "21#",
  760. "mp_name": "J1",
  761. "name": "张三",
  762. "opt":1,
  763. "time": 1693808336,
  764. "mark": ""
  765. }, {
  766. "mo_name": "22#",
  767. "mp_name": "J1",
  768. "name": "李四",
  769. "opt":1,
  770. "time": 1693808336,
  771. "mark": ""
  772. }],
  773. "name": ["张三", "李四", "王五"],
  774. "mo_name": ["21#", "22#", "23#"],
  775. "mp_name": ["J1", "J2", "J3"]
  776. }
  777. )");
  778. */
  779. }
  780. yyjson_mut_doc_free(doc);
  781. return code;
  782. }
  783. int ExecSqlForRecord(eRecord_Module module, int dura, uint8_t analyze_type, string& strStation, string& strStationName, const char* mo, const char* mo_name, const char* mp, const char* mp_name,
  784. uint64_t start_time, uint64_t end_time, time_t tt, string& strName, const char* username, eRocord_Opt opt, string& mark)
  785. {
  786. CString sql = fmt::format("INSERT INTO rm_record\
  787. (module, dura, analyze_type, station\
  788. , station_name, mo, mo_name, mp, mp_name, start_time\
  789. , end_time, time, name,username,opt,mark) VALUES\
  790. ({}, {}, {}, '{}', '{}'\
  791. , '{}', '{}', '{}', '{}', {}\
  792. , {}, {}, '{}', '{}',{}, '{}')",
  793. int(module), dura, analyze_type, strStation, strStationName,
  794. IS_NULL(mo), IS_NULL(mo_name), IS_NULL(mp), IS_NULL(mp_name), start_time,
  795. end_time, tt, strName, IS_NULL(username), int(opt), mark).c_str();
  796. if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
  797. {
  798. ASSERT(FALSE);
  799. CSimpleLog::Error("语句执行失败:" + sql);
  800. return 500;
  801. }
  802. else
  803. {
  804. return 200;
  805. }
  806. }
  807. int DealGetrefer_option(const httplib::Request& req, const string token, char** json, size_t* json_len)
  808. {
  809. string station = req.get_param_value("station");
  810. string mo = req.get_param_value("mo");
  811. string mp = req.get_param_value("mp");
  812. string str_direct = req.get_param_value("direct");
  813. if (station.length() == 0 || mo.length() == 0 || mp.length() == 0 || str_direct.length() == 0)
  814. return 400;
  815. auto direct = atoi(str_direct.c_str());
  816. if (direct != 3 && direct != 4)
  817. return 400;
  818. string str_station = UTF8toANSI(station);
  819. if (CSimpleLog::PathFileExistsA(CSimpleLog::GetAppDir() + "refer\\" +
  820. fmt::format("{}.{}.{}.{}.json", str_station, mo, mp, direct).c_str()))
  821. return 200;
  822. else
  823. return 404;
  824. }
  825. //获取参考曲线
  826. int DealGetrefer_curve(const httplib::Request& req, const string token, char** json, size_t* json_len)
  827. {
  828. string station = req.get_param_value("station");
  829. string mo = req.get_param_value("mo");
  830. string mp = req.get_param_value("mp");
  831. string str_direct = req.get_param_value("direct");
  832. string str_show_time = req.get_param_value("show_time");
  833. if (station.length() == 0 || mo.length() == 0 || mp.length() == 0 || str_direct.length() == 0 || str_show_time.length() == 0)
  834. return 400;
  835. auto direct = atoi(str_direct.c_str());
  836. if (direct != 3 && direct != 4)
  837. return 400;
  838. int yy, mm, dd, hh, MM, SS, micromm;
  839. auto ret_num = sscanf_s(str_show_time.c_str(), "%d-%d-%d %d:%d:%d.%d", &yy, &mm, &dd, &hh, &MM, &SS, &micromm);
  840. if (ret_num != 7)
  841. return 400;
  842. string str_station = UTF8toANSI(station);
  843. time_t show_time = CTime(yy, mm, dd, hh, MM, SS).GetTime() * 1000 + micromm;
  844. int code = 400;
  845. string msg;
  846. auto doc = yyjson_mut_doc_new(nullptr);
  847. auto root = yyjson_mut_obj(doc);
  848. yyjson_mut_doc_set_root(doc, root);
  849. auto data = yyjson_mut_arr(doc);
  850. yyjson_mut_obj_add_val(doc, root, "data", data);
  851. yyjson_mut_obj_add_strcpy(doc, root, "station", station.c_str());
  852. yyjson_mut_obj_add_strcpy(doc, root, "mo", mo.c_str());
  853. yyjson_mut_obj_add_strcpy(doc, root, "mp", mp.c_str());
  854. yyjson_mut_obj_add_int(doc, root, "direct", direct);
  855. code = ReadReferFile(str_station, mo, mp, direct, show_time, doc, data, msg);
  856. yyjson_mut_obj_add_int(doc, root, "code", code);
  857. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  858. if (json)
  859. {
  860. *json = yyjson_mut_write(doc, 0, json_len);
  861. }
  862. yyjson_mut_doc_free(doc);
  863. return code;
  864. }
  865. int ReadReferFile(const string& station, const string& mo, const string& mp, uint8_t posi, time_t show_time, yyjson_mut_doc* mut_doc,
  866. yyjson_mut_val* arr, OUT string& msg)
  867. {
  868. string strJsonPath = fmt::format("{}refer\\{}.{}.{}.{}.json", CSimpleLog::GetAppDir(), station, mo, mp, posi);
  869. if (CSimpleLog::PathFileExistsA(strJsonPath.c_str()) == false)
  870. {
  871. msg = fmt::format("未设置参考曲线");
  872. return 404;
  873. }
  874. yyjson_read_err err;
  875. auto doc = yyjson_read_file(strJsonPath.c_str(), strJsonPath.length(), nullptr, &err);
  876. if (doc == nullptr)
  877. {
  878. msg = err.msg;
  879. return 500;
  880. }
  881. auto root = yyjson_doc_get_root(doc);
  882. auto t = yyjson_obj_get(root, "t");
  883. auto d0 = yyjson_obj_get(root, "d0");
  884. auto d1 = yyjson_obj_get(root, "d1");
  885. auto d2 = yyjson_obj_get(root, "d2");
  886. if (yyjson_is_arr(t) == false || yyjson_is_arr(d0) == false || yyjson_is_arr(d1) == false || yyjson_is_arr(d2) == false)
  887. {
  888. msg = "参考曲线存储格式错误";
  889. yyjson_doc_free(doc);
  890. doc = nullptr;
  891. return 500;
  892. }
  893. auto obj1 = yyjson_mut_obj(mut_doc);
  894. auto obj2 = yyjson_mut_obj(mut_doc);
  895. auto obj3 = yyjson_mut_obj(mut_doc);
  896. yyjson_mut_arr_add_val(arr, obj1);
  897. yyjson_mut_arr_add_val(arr, obj2);
  898. yyjson_mut_arr_add_val(arr, obj3);
  899. auto data1 = yyjson_mut_arr(mut_doc);
  900. auto data2 = yyjson_mut_arr(mut_doc);
  901. auto data3 = yyjson_mut_arr(mut_doc);
  902. yyjson_mut_obj_add_val(mut_doc, obj1, "data", data1);
  903. yyjson_mut_obj_add_val(mut_doc, obj2, "data", data2);
  904. yyjson_mut_obj_add_val(mut_doc, obj3, "data", data3);
  905. yyjson_mut_obj_add_val(mut_doc, obj1, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name0")));
  906. yyjson_mut_obj_add_val(mut_doc, obj2, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name1")));
  907. yyjson_mut_obj_add_val(mut_doc, obj3, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name2")));
  908. int n = yyjson_arr_size(t);
  909. auto it_t = yyjson_arr_get_first(t);
  910. auto it_d0 = yyjson_arr_get_first(d0);
  911. auto it_d1 = yyjson_arr_get_first(d1);
  912. auto it_d2 = yyjson_arr_get_first(d2);
  913. for (int i = 0; i < n; i++)
  914. {
  915. //按双数组的形式添加
  916. auto o1 = yyjson_mut_arr(mut_doc);
  917. yyjson_mut_arr_add_val(data1, o1);
  918. auto o2 = yyjson_mut_arr(mut_doc);
  919. yyjson_mut_arr_add_val(data2, o2);
  920. auto o3 = yyjson_mut_arr(mut_doc);
  921. yyjson_mut_arr_add_val(data3, o3);
  922. auto t = yyjson_get_int(it_t) + show_time;
  923. yyjson_mut_arr_add_int(mut_doc, o1, t);
  924. yyjson_mut_arr_add_int(mut_doc, o2, t);
  925. yyjson_mut_arr_add_int(mut_doc, o3, t);
  926. yyjson_mut_arr_add_int(mut_doc, o1, yyjson_get_int(it_d0));
  927. yyjson_mut_arr_add_int(mut_doc, o2, yyjson_get_int(it_d1));
  928. yyjson_mut_arr_add_int(mut_doc, o3, yyjson_get_int(it_d2));
  929. it_t = unsafe_yyjson_get_next(it_t);
  930. it_d0 = unsafe_yyjson_get_next(it_d0);
  931. it_d1 = unsafe_yyjson_get_next(it_d1);
  932. it_d2 = unsafe_yyjson_get_next(it_d2);
  933. }
  934. yyjson_doc_free(doc);
  935. doc = nullptr;
  936. msg = "读取成功";
  937. return 200;
  938. }
  939. int DealGetTemp(const httplib::Request& req, const string token, char** json, size_t* json_len)
  940. {
  941. string starttime = req.get_param_value("starttime");
  942. string mo = req.get_param_value("mo");
  943. string mp = req.get_param_value("mp");
  944. string endtime = req.get_param_value("endtime");
  945. if (starttime.length() == 0 || mo.length() == 0 || endtime.length() == 0 || mp.length() == 0)
  946. return 400;
  947. int code = 500;
  948. static auto sz_temp = ANSItoUTF8("温度");
  949. static auto sz_unit = ANSItoUTF8("℃");
  950. auto doc = yyjson_mut_doc_new(nullptr);
  951. auto root = yyjson_mut_obj(doc);
  952. yyjson_mut_doc_set_root(doc, root);
  953. yyjson_mut_obj_add_str(doc, root, "name", sz_temp.c_str());
  954. yyjson_mut_obj_add_str(doc, root, "ValueSuffix", sz_unit.c_str());
  955. auto data = yyjson_mut_arr(doc);
  956. yyjson_mut_obj_add_val(doc, root, "data", data);
  957. do
  958. {
  959. int year, month, day;
  960. auto num = sscanf_s(starttime.c_str(), "%d-%d-%d ", &year, &month, &day);
  961. if (num != 3) break;
  962. CString sql = fmt::format(" SELECT TOP 100000 [acquisitiontime],[temperature] FROM rm_temphumidity_{}{:0>2} \
  963. WHERE mo='{}' AND mp='{}' AND acquisitiontime >= '{}' AND acquisitiontime < '{}' ORDER BY acquisitiontime ", year, month, mo, mp, starttime, endtime).c_str();
  964. COdbcStatement stmt;
  965. if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
  966. break;
  967. TIMESTAMP_STRUCT ts;
  968. int temp;
  969. stmt.BindTimeStampCol(1, &ts);
  970. stmt.BindIntCol(2, &temp);
  971. while (true)
  972. {
  973. if (stmt.FetchNext() != 0)
  974. break;
  975. auto arr = yyjson_mut_arr(doc);
  976. yyjson_mut_arr_add_val(data, arr);
  977. yyjson_mut_arr_add_uint(doc, arr, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction);
  978. yyjson_mut_arr_add_strcpy(doc, arr, fmt::format("{:.1f}", temp / 100.0).c_str());
  979. }
  980. code = 200;
  981. } while (false);
  982. *json = yyjson_mut_write(doc, 0, json_len);
  983. yyjson_mut_doc_free(doc);
  984. return code;
  985. }
  986. int DealGetTempHumi(const httplib::Request& req, const string token, char** json, size_t* json_len)
  987. {
  988. string starttime = req.get_param_value("starttime");
  989. string mo = req.get_param_value("mo");
  990. string mp = req.get_param_value("mp");
  991. string endtime = req.get_param_value("endtime");
  992. if (starttime.length() == 0 || mo.length() == 0 || endtime.length() == 0 || mp.length() == 0)
  993. return 400;
  994. int code = 500;
  995. static auto sz_temp = ANSItoUTF8("温度");
  996. static auto sz_humi = ANSItoUTF8("湿度");
  997. static auto sz_unit = ANSItoUTF8("℃");
  998. auto doc = yyjson_mut_doc_new(nullptr);
  999. auto root = yyjson_mut_obj(doc);
  1000. yyjson_mut_doc_set_root(doc, root);
  1001. yyjson_mut_obj_add_int(doc, root, "total", 2);
  1002. auto rows = yyjson_mut_arr(doc);
  1003. yyjson_mut_obj_add_val(doc, root, "rows", rows);
  1004. auto temp_curve = yyjson_mut_obj(doc);
  1005. auto humi_curve = yyjson_mut_obj(doc);
  1006. yyjson_mut_arr_add_val(rows, temp_curve);
  1007. yyjson_mut_arr_add_val(rows, humi_curve);
  1008. yyjson_mut_obj_add_int(doc, temp_curve, "yAxis", 0);
  1009. yyjson_mut_obj_add_int(doc, humi_curve, "yAxis", 1);
  1010. yyjson_mut_obj_add_str(doc, temp_curve, "name", sz_temp.c_str());
  1011. yyjson_mut_obj_add_str(doc, humi_curve, "name", sz_humi.c_str());
  1012. yyjson_mut_obj_add_str(doc, temp_curve, "ValueSuffix", sz_unit.c_str());
  1013. yyjson_mut_obj_add_str(doc, humi_curve, "ValueSuffix", "%");
  1014. auto temp_data = yyjson_mut_arr(doc);
  1015. yyjson_mut_obj_add_val(doc, temp_curve, "data", temp_data);
  1016. auto humi_data = yyjson_mut_arr(doc);
  1017. yyjson_mut_obj_add_val(doc, humi_curve, "data", humi_data);
  1018. do
  1019. {
  1020. int year, month, day;
  1021. auto num = sscanf_s(starttime.c_str(), "%d-%d-%d ", &year, &month, &day);
  1022. if (num != 3) break;
  1023. CString sql = fmt::format(" SELECT TOP 100000 [acquisitiontime],[temperature],[humidity] FROM rm_temphumidity_{}{:0>2} \
  1024. WHERE mo='{}' AND mp='{}' AND acquisitiontime >= '{}' AND acquisitiontime < '{}' ORDER BY acquisitiontime ", year, month, mo, mp, starttime, endtime).c_str();
  1025. COdbcStatement stmt;
  1026. if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
  1027. break;
  1028. TIMESTAMP_STRUCT ts;
  1029. int temp, humi;
  1030. stmt.BindTimeStampCol(1, &ts);
  1031. stmt.BindIntCol(2, &temp);
  1032. stmt.BindIntCol(3, &humi);
  1033. while (true)
  1034. {
  1035. if (stmt.FetchNext() != 0)
  1036. break;
  1037. uint64_t t = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction;
  1038. {
  1039. auto arr = yyjson_mut_arr(doc);
  1040. yyjson_mut_arr_add_val(temp_data, arr);
  1041. yyjson_mut_arr_add_uint(doc, arr, t);
  1042. yyjson_mut_arr_add_strcpy(doc, arr, fmt::format("{:.1f}", temp / 100.0).c_str());
  1043. }
  1044. {
  1045. auto arr = yyjson_mut_arr(doc);
  1046. yyjson_mut_arr_add_val(humi_data, arr);
  1047. yyjson_mut_arr_add_uint(doc, arr, t);
  1048. yyjson_mut_arr_add_int(doc, arr, humi / 100);
  1049. }
  1050. }
  1051. code = 200;
  1052. } while (false);
  1053. *json = yyjson_mut_write(doc, 0, json_len);
  1054. yyjson_mut_doc_free(doc);
  1055. return code;
  1056. }
  1057. //设置参考曲线
  1058. int DealPostrefer_curve(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
  1059. {
  1060. return 403; //暂时屏蔽
  1061. /*
  1062. int code = 400;
  1063. string msg;
  1064. auto req_doc = yyjson_read(body_ptr, body_len, 0);
  1065. if (req_doc == nullptr) return 400;
  1066. auto req_root = yyjson_doc_get_root(req_doc);
  1067. auto doc = yyjson_mut_doc_new(nullptr);
  1068. auto root = yyjson_mut_obj(doc);
  1069. yyjson_mut_doc_set_root(doc, root);
  1070. do
  1071. {
  1072. auto station = yyjson_get_str(yyjson_obj_get(req_root, "station"));
  1073. auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
  1074. auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
  1075. auto mo_name = yyjson_get_str(yyjson_obj_get(req_root, "mo_name"));
  1076. auto mp_name = yyjson_get_str(yyjson_obj_get(req_root, "mp_name"));
  1077. auto direct = yyjson_get_int(yyjson_obj_get(req_root, "direct"));
  1078. auto show_time = yyjson_get_str(yyjson_obj_get(req_root, "show_time"));
  1079. auto full_name = yyjson_get_str(yyjson_obj_get(req_root, "full_name"));
  1080. if (station == nullptr || show_time == 0 || mo == nullptr || mp == nullptr || (direct != 3 && direct != 4) || full_name == nullptr
  1081. || mo_name == nullptr || mp_name == nullptr)
  1082. {
  1083. msg = "参数错误";
  1084. break;
  1085. }
  1086. auto strStation = UTF8toANSI(station);
  1087. auto strName = UTF8toANSI(full_name);
  1088. time_t tt;
  1089. time(&tt);
  1090. auto len = strlen(show_time);
  1091. if (len == 0) //取消参考曲线
  1092. {
  1093. auto strPath = CSimpleLog::GetAppDir() + "refer\\" +
  1094. fmt::format("{}.{}.{}.{}.json", strStation, mo, mp, direct).c_str();
  1095. if (CSimpleLog::PathFileExistsA(strPath))
  1096. DeleteFile(strPath);
  1097. ExecSqlForRecord(eRecord_Module::RM_REFER, 0, 0, strStation, strStation, mo, mo_name, mp, mp_name, 0, 0, tt, strName, "", eRocord_Opt::RO_CONFIG,
  1098. fmt::format("用户[{}]取消了[{}.{}][{}]的参考曲线", strName, mo_name, mp_name, direct == 3 ? "定扳反" : "反扳定"));
  1099. msg = "操作成功.";
  1100. code = 200;
  1101. break;
  1102. }
  1103. int yy, mm, dd, hh, MM, SS, micromm;
  1104. auto ret_num = sscanf_s(show_time, "%d-%d-%d %d:%d:%d.%d", &yy, &mm, &dd, &hh, &MM, &SS, &micromm);
  1105. if (ret_num != 7)
  1106. {
  1107. msg = "show_time参数错误";
  1108. break;
  1109. }
  1110. CString sql = fmt::format("SELECT start_time,idx FROM rm_move_{:0>4}{:0>2} WHERE mo = '{}' and mp = '{}' and show_time = '{}'",
  1111. yy, mm, mo, mp, show_time).c_str();
  1112. COdbcStatement stmt;
  1113. if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
  1114. {
  1115. ASSERT(FALSE);
  1116. msg = "语句执行失败:" + sql;
  1117. code = 500;
  1118. break;
  1119. }
  1120. TIMESTAMP_STRUCT ts = { 0 };
  1121. uint8_t idx = -1;
  1122. stmt.BindTimeStampCol(1, &ts);
  1123. stmt.BindTinyIntCol(2, &idx);
  1124. if (stmt.FetchNext() != 0)
  1125. {
  1126. msg = "查询转换记录失败";
  1127. code = 500;
  1128. break;
  1129. }
  1130. stmt.Close();
  1131. string imei; int idx_2;
  1132. if (CMonitorObjectMng::Instance()->MOMP2IMEI(string(mo), string(mp), imei, idx_2) == FALSE)
  1133. {
  1134. msg = "查询imei失败";
  1135. code = 500;
  1136. break;
  1137. }
  1138. ASSERT(idx == idx_2);
  1139. CTime ctStart(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  1140. CTime ctEnd = ctStart + CTimeSpan(0, 0, 0, 30);
  1141. sql = fmt::format(" SELECT acquisitiontime,data0,data1,data2 FROM rm_resistance_{:0>4}{:0>2}{:0>2}\
  1142. WHERE IMEI = '{}' AND acquisitiontime between '{}' and '{}' AND idx = {}",
  1143. ts.year, ts.month, ts.day, imei, ctStart.Format("%Y-%m-%d %H:%M:%S"), ctEnd.Format("%Y-%m-%d %H:%M:%S"),idx
  1144. ).c_str();
  1145. int sdata0, sdata1, sdata2;
  1146. if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
  1147. {
  1148. ASSERT(FALSE);
  1149. msg = "语句执行失败:" + sql;
  1150. code = 500;
  1151. break;
  1152. }
  1153. int nCol = 1;
  1154. stmt.BindTimeStampCol(nCol++, &ts);
  1155. stmt.BindIntCol(nCol++, &sdata0);
  1156. stmt.BindIntCol(nCol++, &sdata1);
  1157. stmt.BindIntCol(nCol++, &sdata2);
  1158. int no = 0;
  1159. std::map<time_t, int> data0, data1, data2;
  1160. //time_t tmStart = ctStart.GetTime() * 1000; //存储数据时, 以起始时间为0
  1161. time_t tmShowTime = CTime(yy, mm, dd, hh, MM, SS).GetTime() * 1000 + micromm;
  1162. do
  1163. {
  1164. if (stmt.FetchNext() != 0)
  1165. break;
  1166. no++;
  1167. CTime ctTime;
  1168. try
  1169. {
  1170. ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  1171. }
  1172. catch (...)
  1173. {
  1174. continue;
  1175. }
  1176. time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000 - tmShowTime;
  1177. data0[tm] = sdata0;
  1178. data1[tm] = sdata1;
  1179. data2[tm] = sdata2;
  1180. } while (true);
  1181. stmt.Close();
  1182. if (no == 0)
  1183. {
  1184. msg = "数据为空";
  1185. code = 500;
  1186. break;
  1187. }
  1188. //存储数据
  1189. code = WriteReferFile(strStation, mo, mp, direct, data0, data1, data2, msg);
  1190. ExecSqlForRecord(eRecord_Module::RM_REFER, 0, 0, strStation, strStation, mo, mo_name, mp, mp_name, 0, 0, tt, strName, "", eRocord_Opt::RO_CONFIG,
  1191. fmt::format("用户[{}]设置了[{}.{}][{}]的参考曲线", strName, mo_name, mp_name, direct == 3 ? "定扳反" : "反扳定"));
  1192. } while (false);
  1193. yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
  1194. yyjson_mut_obj_add_int(doc, root, "code", code);
  1195. if (json) *json = yyjson_mut_write(doc, 0, json_len);
  1196. yyjson_doc_free(req_doc);
  1197. yyjson_mut_doc_free(doc);
  1198. return code;*/
  1199. }
  1200. int WriteReferFile(const string& station, const string& mo, const string& mp, uint8_t posi,
  1201. const std::map<time_t, int>& data0, const std::map<time_t, int>& data1, const std::map<time_t, int>& data2, OUT string& msg)
  1202. {
  1203. string strJsonPath = fmt::format("{}refer\\{}.{}.{}.{}.json", CSimpleLog::GetAppDir(), station, mo, mp, posi);
  1204. string name1, name2, name3, out_name, in_name;
  1205. CMonitorObjectMng::Instance()->GetNameByMoMp(mo + "." + mp, name1, name2, name3, out_name, in_name);
  1206. auto doc = yyjson_mut_doc_new(nullptr);
  1207. auto root = yyjson_mut_obj(doc);
  1208. yyjson_mut_doc_set_root(doc, root);
  1209. yyjson_mut_obj_add_strcpy(doc, root, "station", ANSItoUTF8(station).c_str());
  1210. yyjson_mut_obj_add_strcpy(doc, root, "mo", mo.c_str());
  1211. yyjson_mut_obj_add_strcpy(doc, root, "mp", mp.c_str());
  1212. yyjson_mut_obj_add_int(doc, root, "posi", posi);
  1213. auto t = yyjson_mut_arr(doc);
  1214. yyjson_mut_obj_add_val(doc, root, "t", t);
  1215. auto d0 = yyjson_mut_arr(doc);
  1216. yyjson_mut_obj_add_val(doc, root, "d0", d0);
  1217. auto d1 = yyjson_mut_arr(doc);
  1218. yyjson_mut_obj_add_val(doc, root, "d1", d1);
  1219. auto d2 = yyjson_mut_arr(doc);
  1220. yyjson_mut_obj_add_val(doc, root, "d2", d2);
  1221. if (name1.find("定位") != -1)
  1222. {
  1223. yyjson_mut_obj_add_strcpy(doc, root, "name0", ANSItoUTF8("定位参考曲线").c_str());
  1224. yyjson_mut_obj_add_strcpy(doc, root, "name1", ANSItoUTF8("反位参考曲线").c_str());
  1225. yyjson_mut_obj_add_strcpy(doc, root, "name2", ANSItoUTF8("转换参考曲线").c_str());
  1226. }
  1227. else
  1228. {
  1229. yyjson_mut_obj_add_strcpy(doc, root, "name0", ANSItoUTF8("反位参考曲线").c_str());
  1230. yyjson_mut_obj_add_strcpy(doc, root, "name1", ANSItoUTF8("定位参考曲线").c_str());
  1231. yyjson_mut_obj_add_strcpy(doc, root, "name2", ANSItoUTF8("转换参考曲线").c_str());
  1232. }
  1233. for (auto& it : data0)
  1234. {
  1235. yyjson_mut_arr_add_int(doc, t, it.first);
  1236. yyjson_mut_arr_add_int(doc, d0, it.second);
  1237. }
  1238. for (auto& it : data1)
  1239. yyjson_mut_arr_add_int(doc, d1, it.second);
  1240. for (auto& it : data2)
  1241. yyjson_mut_arr_add_int(doc, d2, it.second);
  1242. yyjson_write_err err;
  1243. auto ret = yyjson_mut_write_file(strJsonPath.c_str(), doc, 0, nullptr, &err);
  1244. if (ret == false)
  1245. {
  1246. msg = fmt::format("写入文件错误:{} 错误码:{}", strJsonPath, err.msg);
  1247. CSimpleLog::Error(msg.c_str());
  1248. return 500;
  1249. }
  1250. msg = "处理成功.";
  1251. return 200;
  1252. }
  1253. int DealGetResistCurve(const httplib::Request& req, const string token, char** json, size_t* json_len)
  1254. {
  1255. string mo = req.get_param_value("mo");
  1256. string mp = req.get_param_value("mp");
  1257. string time = req.get_param_value("time");
  1258. string name = req.get_param_value("name");
  1259. if (mo.length() == 0 || mp.length() == 0 || time.length() == 0 || name.length() == 0)
  1260. return 400;
  1261. time_t uTime = atoll(time.c_str());
  1262. COleDateTime odt(uTime);
  1263. if (odt.GetStatus() == COleDateTime::invalid)
  1264. return 400;
  1265. auto doc = yyjson_mut_doc_new(nullptr);
  1266. auto root = yyjson_mut_obj(doc);
  1267. yyjson_mut_doc_set_root(doc, root);
  1268. auto convert_resist = yyjson_mut_obj(doc);
  1269. yyjson_mut_obj_add_val(doc, root, "convert_resist", convert_resist);//转换阻力
  1270. auto suobi_lock = yyjson_mut_obj(doc);
  1271. yyjson_mut_obj_add_val(doc, root, "suobi_lock", suobi_lock);//锁闭力数据
  1272. yyjson_mut_obj_add_str(doc, root, "name", name.c_str());
  1273. yyjson_mut_obj_add_str(doc, root, "unit", "N");
  1274. yyjson_mut_obj_add_uint(doc, root, "time", uTime);
  1275. //title
  1276. yyjson_mut_obj_add_strcpy(doc, convert_resist, "title", ANSItoUTF8("转换阻力峰值统计图").c_str());
  1277. yyjson_mut_obj_add_strcpy(doc, suobi_lock, "title", ANSItoUTF8("定反位锁闭力值统计图").c_str());
  1278. //curve_data and line
  1279. auto convert_curve_data = yyjson_mut_arr(doc);
  1280. yyjson_mut_obj_add_val(doc, convert_resist, "curve_data", convert_curve_data);
  1281. auto suobi_curve_data = yyjson_mut_arr(doc);
  1282. yyjson_mut_obj_add_val(doc, suobi_lock, "curve_data", suobi_curve_data);
  1283. auto convert_line = yyjson_mut_arr(doc);
  1284. yyjson_mut_obj_add_val(doc, convert_resist, "line", convert_line);
  1285. auto suobi_line = yyjson_mut_arr(doc);
  1286. yyjson_mut_obj_add_val(doc, suobi_lock, "line", suobi_line);
  1287. //curve_obj
  1288. auto d_convert_obj = yyjson_mut_obj(doc);
  1289. yyjson_mut_obj_add_strcpy(doc, d_convert_obj, "name", ANSItoUTF8("定扳反转换阻力峰值").c_str());
  1290. yyjson_mut_obj_add_str(doc, d_convert_obj, "color", "#a8ff78");// 苹果绿
  1291. yyjson_mut_arr_add_val(convert_curve_data, d_convert_obj);
  1292. auto f_convert_obj = yyjson_mut_obj(doc);
  1293. yyjson_mut_obj_add_strcpy(doc, f_convert_obj, "name", ANSItoUTF8("反扳定转换阻力峰值").c_str());
  1294. yyjson_mut_obj_add_str(doc, f_convert_obj, "color", "#FFE000");// 芒果黄
  1295. yyjson_mut_arr_add_val(convert_curve_data, f_convert_obj);
  1296. auto d_suobi_obj = yyjson_mut_obj(doc);
  1297. yyjson_mut_obj_add_strcpy(doc, d_suobi_obj, "name", ANSItoUTF8("定位锁闭力值").c_str());
  1298. yyjson_mut_obj_add_str(doc, d_suobi_obj, "color", "#a8ff78");// 苹果绿
  1299. yyjson_mut_arr_add_val(suobi_curve_data, d_suobi_obj);
  1300. auto f_suobi_obj = yyjson_mut_obj(doc);
  1301. yyjson_mut_obj_add_strcpy(doc, f_suobi_obj, "name", ANSItoUTF8("反位锁闭力值").c_str());
  1302. yyjson_mut_obj_add_str(doc, f_suobi_obj, "color", "#FFE000");// 芒果黄
  1303. yyjson_mut_arr_add_val(suobi_curve_data, f_suobi_obj);
  1304. //curve_data
  1305. auto d_convert_data = yyjson_mut_arr(doc);
  1306. yyjson_mut_obj_add_val(doc, d_convert_obj, "data", d_convert_data);
  1307. auto f_convert_data = yyjson_mut_arr(doc);
  1308. yyjson_mut_obj_add_val(doc, f_convert_obj, "data", f_convert_data);
  1309. auto d_suobi_data = yyjson_mut_arr(doc);
  1310. yyjson_mut_obj_add_val(doc, d_suobi_obj, "data", d_suobi_data);
  1311. auto f_suobi_data = yyjson_mut_arr(doc);
  1312. yyjson_mut_obj_add_val(doc, f_suobi_obj, "data", f_suobi_data);
  1313. //query
  1314. //查询数据库 填充 d_convert_data f_convert_data d_suobi_data f_suobi_data
  1315. {
  1316. string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
  1317. CString sql = fmt::format("SELECT show_time,show_val,posi FROM {} WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}'",
  1318. table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), odt.Format("%Y-%m-%d 23:59:59.999")).c_str();
  1319. COdbcStatement stmt;
  1320. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  1321. {
  1322. int nCol = 1;
  1323. TIMESTAMP_STRUCT ts;
  1324. int show_val;
  1325. eDaoChaPosi posi;
  1326. stmt.BindTimeStampCol(nCol++, &ts);
  1327. stmt.BindIntCol(nCol++, &show_val);
  1328. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  1329. do
  1330. {
  1331. if (stmt.FetchNext() != 0)
  1332. break;
  1333. CTime ctTime;
  1334. try
  1335. {
  1336. ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
  1337. }
  1338. catch (...)
  1339. {
  1340. continue;
  1341. }
  1342. time_t tt = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
  1343. auto o = yyjson_mut_arr(doc);
  1344. yyjson_mut_arr_add_int(doc, o, tt);
  1345. yyjson_mut_arr_add_int(doc, o, show_val);
  1346. switch (posi)
  1347. {
  1348. case eDaoChaPosi::DCP_FIX:
  1349. yyjson_mut_arr_add_val(d_suobi_data, o);
  1350. break;
  1351. case eDaoChaPosi::DCP_INVERT:
  1352. yyjson_mut_arr_add_val(f_suobi_data, o);
  1353. break;
  1354. case eDaoChaPosi::DCP_FIX2INVERT:
  1355. yyjson_mut_arr_add_val(d_convert_data, o);
  1356. break;
  1357. case eDaoChaPosi::DCP_INVERT2FIX:
  1358. yyjson_mut_arr_add_val(f_convert_data, o);
  1359. break;
  1360. default:
  1361. ASSERT(FALSE);
  1362. break;
  1363. }
  1364. } while (TRUE);
  1365. }
  1366. stmt.Close();
  1367. }
  1368. //line
  1369. {
  1370. //转换阻力报警线
  1371. CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  1372. if (pInfo && pInfo->enable)
  1373. {
  1374. if (pInfo->dw_warn_low_limit > INT_MIN)
  1375. {
  1376. auto obj = yyjson_mut_obj(doc);
  1377. yyjson_mut_arr_add_val(convert_line, obj);
  1378. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
  1379. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_warn_low_limit);
  1380. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1381. }
  1382. if (pInfo->up_warn_high_limit < INT_MAX)
  1383. {
  1384. auto obj = yyjson_mut_obj(doc);
  1385. yyjson_mut_arr_add_val(convert_line, obj);
  1386. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
  1387. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->up_warn_high_limit);
  1388. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1389. }
  1390. if (pInfo->dw_alarm_low_limit > INT_MIN)
  1391. {
  1392. auto obj = yyjson_mut_obj(doc);
  1393. yyjson_mut_arr_add_val(convert_line, obj);
  1394. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
  1395. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_alarm_low_limit);
  1396. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1397. }
  1398. if (pInfo->up_alarm_high_limit < INT_MAX)
  1399. {
  1400. auto obj = yyjson_mut_obj(doc);
  1401. yyjson_mut_arr_add_val(convert_line, obj);
  1402. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
  1403. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->up_alarm_high_limit);
  1404. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1405. }
  1406. }
  1407. }
  1408. {
  1409. //锁闭力报警线
  1410. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, -1, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  1411. if (pInfo && pInfo->enable)
  1412. {
  1413. if (pInfo->warn_low_limit > INT_MIN)
  1414. {
  1415. auto obj = yyjson_mut_obj(doc);
  1416. yyjson_mut_arr_add_val(suobi_line, obj);
  1417. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
  1418. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
  1419. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1420. }
  1421. if (pInfo->warn_high_limit < INT_MAX)
  1422. {
  1423. auto obj = yyjson_mut_obj(doc);
  1424. yyjson_mut_arr_add_val(suobi_line, obj);
  1425. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
  1426. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
  1427. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1428. }
  1429. if (pInfo->alarm_low_limit > INT_MIN)
  1430. {
  1431. auto obj = yyjson_mut_obj(doc);
  1432. yyjson_mut_arr_add_val(suobi_line, obj);
  1433. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
  1434. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
  1435. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1436. }
  1437. if (pInfo->alarm_high_limit < INT_MAX)
  1438. {
  1439. auto obj = yyjson_mut_obj(doc);
  1440. yyjson_mut_arr_add_val(suobi_line, obj);
  1441. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
  1442. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
  1443. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1444. }
  1445. }
  1446. }
  1447. {
  1448. //定位锁闭力报警线
  1449. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  1450. if (pInfo && pInfo->enable)
  1451. {
  1452. if (pInfo->warn_low_limit > INT_MIN)
  1453. {
  1454. auto obj = yyjson_mut_obj(doc);
  1455. yyjson_mut_arr_add_val(suobi_line, obj);
  1456. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位预警线").c_str());
  1457. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
  1458. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1459. }
  1460. if (pInfo->warn_high_limit < INT_MAX)
  1461. {
  1462. auto obj = yyjson_mut_obj(doc);
  1463. yyjson_mut_arr_add_val(suobi_line, obj);
  1464. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位预警线").c_str());
  1465. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
  1466. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1467. }
  1468. if (pInfo->alarm_low_limit > INT_MIN)
  1469. {
  1470. auto obj = yyjson_mut_obj(doc);
  1471. yyjson_mut_arr_add_val(suobi_line, obj);
  1472. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
  1473. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
  1474. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1475. }
  1476. if (pInfo->alarm_high_limit < INT_MAX)
  1477. {
  1478. auto obj = yyjson_mut_obj(doc);
  1479. yyjson_mut_arr_add_val(suobi_line, obj);
  1480. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
  1481. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
  1482. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1483. }
  1484. }
  1485. }
  1486. {
  1487. //反位锁闭力报警线
  1488. SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  1489. if (pInfo && pInfo->enable)
  1490. {
  1491. if (pInfo->warn_low_limit > INT_MIN)
  1492. {
  1493. auto obj = yyjson_mut_obj(doc);
  1494. yyjson_mut_arr_add_val(suobi_line, obj);
  1495. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位预警线").c_str());
  1496. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
  1497. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1498. }
  1499. if (pInfo->warn_high_limit < INT_MAX)
  1500. {
  1501. auto obj = yyjson_mut_obj(doc);
  1502. yyjson_mut_arr_add_val(suobi_line, obj);
  1503. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位预警线").c_str());
  1504. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
  1505. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1506. }
  1507. if (pInfo->alarm_low_limit > INT_MIN)
  1508. {
  1509. auto obj = yyjson_mut_obj(doc);
  1510. yyjson_mut_arr_add_val(suobi_line, obj);
  1511. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
  1512. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
  1513. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1514. }
  1515. if (pInfo->alarm_high_limit < INT_MAX)
  1516. {
  1517. auto obj = yyjson_mut_obj(doc);
  1518. yyjson_mut_arr_add_val(suobi_line, obj);
  1519. yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
  1520. yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
  1521. yyjson_mut_obj_add_str(doc, obj, "color", "Red");
  1522. }
  1523. }
  1524. }
  1525. *json = yyjson_mut_write(doc, 0, json_len);
  1526. yyjson_mut_doc_free(doc);
  1527. return 200;
  1528. }
  1529. int DealGetResistReport(const httplib::Request& req, const string token, char** json, size_t* json_len)
  1530. {
  1531. string station = req.get_param_value("station");
  1532. string time = req.get_param_value("time");
  1533. if (time.length() == 0 || station.length() == 0)
  1534. return 400;
  1535. time_t uTime = atoll(time.c_str());
  1536. COleDateTime odt(uTime);
  1537. if (odt.GetStatus() == COleDateTime::invalid)
  1538. return 400;
  1539. auto doc = yyjson_mut_doc_new(nullptr);
  1540. auto root = yyjson_mut_arr(doc);
  1541. yyjson_mut_doc_set_root(doc, root);
  1542. {
  1543. string strStation = UTF8toANSI(station);
  1544. string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
  1545. CString sql = fmt::format("SELECT A.*,B.name FROM (SELECT mo, mp, posi, count(*) as num, max(show_val) as l, min(show_val) as s, sum(show_val) as sum FROM {} WHERE mo in (SELECT id FROM rm_mo WHERE up = '{}') AND show_time >= '{}' AND show_time <= '{}' GROUP BY mo, mp, posi) AS A \
  1546. LEFT JOIN rm_mo AS B ON A.mo = B.id",
  1547. table_name, strStation, odt.Format("%Y-%m-%d 00:00:00"), odt.Format("%Y-%m-%d 23:59:59.999")).c_str();
  1548. //SELECT A.*,B.name FROM (SELECT mo, mp, posi, count(*) as num, max(show_val) as l, min(show_val) as s FROM rm_move_202301 WHERE mo in (SELECT id FROM rm_mo WHERE up = '温州南站') AND show_time >= '2023-01-10 00:00:00' AND show_time <= '2023-01-10 23:59:59.999' GROUP BY mo, mp, posi) AS A LEFT JOIN rm_mo AS B ON A.mo = B.id
  1549. COdbcStatement stmt;
  1550. struct tagData
  1551. {
  1552. string mo_name;
  1553. string mo;
  1554. string mp;
  1555. int d_convert_resist = INT_MAX;
  1556. int d_convert_resist_max = INT_MAX;
  1557. int d_convert_resist_min = INT_MAX;
  1558. int d_convert_resist_avg = INT_MAX;
  1559. uint8_t d_convert_resist_max_color = 0; //0 为正常 1 为预警 2 为报警
  1560. uint8_t d_convert_resist_min_color = 0;
  1561. uint8_t d_convert_resist_avg_color = 0;
  1562. int f_convert_resist = INT_MAX;
  1563. int f_convert_resist_max = INT_MAX;
  1564. int f_convert_resist_min = INT_MAX;
  1565. int f_convert_resist_avg = INT_MAX;
  1566. uint8_t f_convert_resist_max_color = 0;
  1567. uint8_t f_convert_resist_min_color = 0;
  1568. uint8_t f_convert_resist_avg_color = 0;
  1569. int d_suobi_lock = INT_MAX;
  1570. int d_suobi_lock_max = INT_MAX;
  1571. int d_suobi_lock_min = INT_MAX;
  1572. int d_suobi_lock_avg = INT_MAX;
  1573. uint8_t d_suobi_lock_max_color = 0;
  1574. uint8_t d_suobi_lock_min_color = 0;
  1575. uint8_t d_suobi_lock_avg_color = 0;
  1576. int f_suobi_lock = INT_MAX;
  1577. int f_suobi_lock_max = INT_MAX;
  1578. int f_suobi_lock_min = INT_MAX;
  1579. int f_suobi_lock_avg = INT_MAX;
  1580. uint8_t f_suobi_lock_max_color = 0;
  1581. uint8_t f_suobi_lock_min_color = 0;
  1582. uint8_t f_suobi_lock_avg_color = 0;
  1583. };
  1584. std::map<string, tagData> mapData;
  1585. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  1586. {
  1587. int nCol = 1;
  1588. char mo[50], mp[50], mo_name[50];
  1589. int num;
  1590. int max;
  1591. int min;
  1592. int64_t sum;
  1593. eDaoChaPosi posi;
  1594. stmt.BindCharCol(nCol++, mo, sizeof(mo));
  1595. stmt.BindCharCol(nCol++, mp, sizeof(mp));
  1596. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  1597. stmt.BindIntCol(nCol++, &num);
  1598. stmt.BindIntCol(nCol++, &max);
  1599. stmt.BindIntCol(nCol++, &min);
  1600. stmt.BindBigIntCol(nCol++, &sum);
  1601. stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
  1602. do
  1603. {
  1604. if (stmt.FetchNext() != 0)
  1605. break;
  1606. SUOBI_OVER_LIMIT_INFO* pInfo = nullptr;
  1607. CONVERT_RESIST_OVER_LIMIT* pInfo2 = nullptr;
  1608. auto& it = mapData[fmt::format("{}.{}", mo, mp)];
  1609. it.mo_name = mo_name;
  1610. it.mo = mo;
  1611. it.mp = mp;
  1612. eSuoBiPosi idx;
  1613. switch (posi)
  1614. {
  1615. case eDaoChaPosi::DCP_FIX:
  1616. it.d_suobi_lock = num;
  1617. it.d_suobi_lock_max = max;
  1618. it.d_suobi_lock_min = min;
  1619. if (num) it.d_suobi_lock_avg = sum / num;
  1620. idx = eSuoBiPosi::SB_FIX;
  1621. pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)idx, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  1622. if (pInfo && pInfo->enable)
  1623. {
  1624. if (max > pInfo->alarm_high_limit)
  1625. it.d_suobi_lock_max_color = UINT8_ALARM;
  1626. else if (max > pInfo->warn_high_limit)
  1627. it.d_suobi_lock_max_color = UINT8_WARN;
  1628. if (min < pInfo->alarm_low_limit)
  1629. it.d_suobi_lock_min_color = UINT8_ALARM;
  1630. else if (min < pInfo->warn_low_limit)
  1631. it.d_suobi_lock_min_color = UINT8_WARN;
  1632. if (num && (it.d_suobi_lock_avg > pInfo->alarm_high_limit || it.d_suobi_lock_avg < pInfo->alarm_low_limit))
  1633. it.d_suobi_lock_avg_color = UINT8_ALARM;
  1634. else if (num && (it.d_suobi_lock_avg > pInfo->warn_high_limit || it.d_suobi_lock_avg < pInfo->warn_low_limit))
  1635. it.d_suobi_lock_avg_color = UINT8_WARN;
  1636. }
  1637. break;
  1638. case eDaoChaPosi::DCP_INVERT:
  1639. it.f_suobi_lock = num;
  1640. it.f_suobi_lock_max = max;
  1641. it.f_suobi_lock_min = min;
  1642. if (num) it.f_suobi_lock_avg = sum / num;
  1643. idx = eSuoBiPosi::SB_INVERT;
  1644. pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)idx, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
  1645. if (pInfo && pInfo->enable)
  1646. {
  1647. if (max > pInfo->alarm_high_limit)
  1648. it.f_suobi_lock_max_color = UINT8_ALARM;
  1649. else if (max > pInfo->warn_high_limit)
  1650. it.f_suobi_lock_max_color = UINT8_WARN;
  1651. if (min < pInfo->alarm_low_limit)
  1652. it.f_suobi_lock_min_color = UINT8_ALARM;
  1653. else if (min < pInfo->warn_low_limit)
  1654. it.f_suobi_lock_min_color = UINT8_WARN;
  1655. if (num && (it.f_suobi_lock_avg > pInfo->alarm_high_limit || it.f_suobi_lock_avg < pInfo->alarm_low_limit))
  1656. it.f_suobi_lock_avg_color = UINT8_ALARM;
  1657. else if (num && (it.f_suobi_lock_avg > pInfo->warn_high_limit || it.f_suobi_lock_avg < pInfo->warn_low_limit))
  1658. it.f_suobi_lock_avg_color = UINT8_WARN;
  1659. }
  1660. break;
  1661. case eDaoChaPosi::DCP_FIX2INVERT:
  1662. it.d_convert_resist = num;
  1663. it.d_convert_resist_max = max;
  1664. it.d_convert_resist_min = min;
  1665. if (num) it.d_convert_resist_avg = sum / num;
  1666. pInfo2 = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  1667. if (pInfo2 && pInfo2->enable)
  1668. {
  1669. string name1, name2, name3, out_name, in_name;
  1670. CMonitorObjectMng::Instance()->GetNameByMoMp(fmt::format("{}.{}", mo, mp), name1, name2, name3, out_name, in_name);
  1671. if (in_name.find("定扳反") == -1) //如果缩进不是定扳反, 那就是伸出
  1672. {
  1673. if (max > pInfo2->dw_alarm_low_limit)
  1674. it.d_convert_resist_max_color = UINT8_ALARM;
  1675. else if (max > pInfo2->dw_warn_low_limit)
  1676. it.d_convert_resist_max_color = UINT8_WARN;
  1677. if (num && it.d_convert_resist_avg > pInfo2->dw_alarm_low_limit)
  1678. it.d_convert_resist_avg_color = UINT8_ALARM;
  1679. else if (num && it.d_convert_resist_avg > pInfo2->dw_warn_low_limit)
  1680. it.d_convert_resist_avg_color = UINT8_WARN;
  1681. }
  1682. else
  1683. {
  1684. if (max > pInfo2->up_alarm_high_limit)
  1685. it.d_convert_resist_max_color = UINT8_ALARM;
  1686. else if (max > pInfo2->up_warn_high_limit)
  1687. it.d_convert_resist_max_color = UINT8_WARN;
  1688. if (num && it.d_convert_resist_avg > pInfo2->up_alarm_high_limit)
  1689. it.d_convert_resist_avg_color = UINT8_ALARM;
  1690. else if (num && it.d_convert_resist_avg > pInfo2->up_warn_high_limit)
  1691. it.d_convert_resist_avg_color = UINT8_WARN;
  1692. }
  1693. }
  1694. break;
  1695. case eDaoChaPosi::DCP_INVERT2FIX:
  1696. it.f_convert_resist = num;
  1697. it.f_convert_resist_max = max;
  1698. it.f_convert_resist_min = min;
  1699. if (num) it.f_convert_resist_avg = sum / num;
  1700. pInfo2 = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
  1701. if (pInfo2 && pInfo2->enable)
  1702. {
  1703. string name1, name2, name3, out_name, in_name;
  1704. CMonitorObjectMng::Instance()->GetNameByMoMp(fmt::format("{}.{}", mo, mp), name1, name2, name3, out_name, in_name);
  1705. if (in_name.find("反扳定") != -1) //如果反扳定是缩进
  1706. {
  1707. if (max > pInfo2->up_alarm_high_limit)
  1708. it.f_convert_resist_max_color = UINT8_ALARM;
  1709. else if (max > pInfo2->up_warn_high_limit)
  1710. it.f_convert_resist_max_color = UINT8_WARN;
  1711. if (num && it.f_convert_resist_avg > pInfo2->up_alarm_high_limit)
  1712. it.f_convert_resist_avg_color = UINT8_ALARM;
  1713. else if (num && it.f_convert_resist_avg > pInfo2->up_warn_high_limit)
  1714. it.f_convert_resist_avg_color = UINT8_WARN;
  1715. }
  1716. else
  1717. {
  1718. if (max > pInfo2->dw_alarm_low_limit)
  1719. it.f_convert_resist_max_color = UINT8_ALARM;
  1720. else if (max > pInfo2->dw_warn_low_limit)
  1721. it.f_convert_resist_max_color = UINT8_WARN;
  1722. if (num && it.f_convert_resist_avg > pInfo2->dw_alarm_low_limit)
  1723. it.f_convert_resist_avg_color = UINT8_ALARM;
  1724. else if (num && it.f_convert_resist_avg > pInfo2->dw_warn_low_limit)
  1725. it.f_convert_resist_avg_color = UINT8_WARN;
  1726. }
  1727. }
  1728. break;
  1729. default:
  1730. ASSERT(FALSE);
  1731. break;
  1732. }
  1733. } while (TRUE);
  1734. }
  1735. stmt.Close();
  1736. for (auto& it : mapData)
  1737. {
  1738. auto obj = yyjson_mut_obj(doc);
  1739. yyjson_mut_arr_add_val(root, obj);
  1740. yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", ANSItoUTF8(it.second.mo_name).c_str());
  1741. yyjson_mut_obj_add_strcpy(doc, obj, "mo", it.second.mo.c_str());
  1742. yyjson_mut_obj_add_strcpy(doc, obj, "mp", it.second.mp.c_str());
  1743. if (it.second.d_convert_resist != INT_MAX)
  1744. yyjson_mut_obj_add_int(doc, obj, "d_convert_resist", it.second.d_convert_resist);
  1745. else
  1746. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist", "-");
  1747. if (it.second.d_convert_resist_max != INT_MAX)
  1748. yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_max", it.second.d_convert_resist_max);
  1749. else
  1750. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max", "-");
  1751. if (it.second.d_convert_resist_min != INT_MAX)
  1752. yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_min", it.second.d_convert_resist_min);
  1753. else
  1754. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min", "-");
  1755. if (it.second.d_convert_resist_avg != INT_MAX)
  1756. yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_avg", it.second.d_convert_resist_avg);
  1757. else
  1758. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg", "-");
  1759. //颜色
  1760. if (it.second.d_convert_resist_max_color == UINT8_ALARM)
  1761. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max_color", "red");
  1762. else if (it.second.d_convert_resist_max_color == UINT8_WARN)
  1763. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max_color", "orange");
  1764. if (it.second.d_convert_resist_min_color == UINT8_ALARM)
  1765. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min_color", "red");
  1766. else if (it.second.d_convert_resist_min_color == UINT8_WARN)
  1767. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min_color", "orange");
  1768. if (it.second.d_convert_resist_avg_color == UINT8_ALARM)
  1769. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg_color", "red");
  1770. else if (it.second.d_convert_resist_avg_color == UINT8_WARN)
  1771. yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg_color", "orange");
  1772. if (it.second.f_convert_resist != INT_MAX)
  1773. yyjson_mut_obj_add_int(doc, obj, "f_convert_resist", it.second.f_convert_resist);
  1774. else
  1775. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist", "-");
  1776. if (it.second.f_convert_resist_max != INT_MAX)
  1777. yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_max", it.second.f_convert_resist_max);
  1778. else
  1779. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max", "-");
  1780. if (it.second.f_convert_resist_min != INT_MAX)
  1781. yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_min", it.second.f_convert_resist_min);
  1782. else
  1783. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min", "-");
  1784. if (it.second.f_convert_resist_avg != INT_MAX)
  1785. yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_avg", it.second.f_convert_resist_avg);
  1786. else
  1787. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg", "-");
  1788. //颜色
  1789. if (it.second.f_convert_resist_max_color == UINT8_ALARM)
  1790. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max_color", "red");
  1791. else if (it.second.f_convert_resist_max_color == UINT8_WARN)
  1792. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max_color", "orange");
  1793. if (it.second.f_convert_resist_min_color == UINT8_ALARM)
  1794. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min_color", "red");
  1795. else if (it.second.f_convert_resist_min_color == UINT8_WARN)
  1796. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min_color", "orange");
  1797. if (it.second.f_convert_resist_avg_color == UINT8_ALARM)
  1798. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg_color", "red");
  1799. else if (it.second.f_convert_resist_avg_color == UINT8_WARN)
  1800. yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg_color", "orange");
  1801. if (it.second.d_suobi_lock != INT_MAX)
  1802. yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock", it.second.d_suobi_lock);
  1803. else
  1804. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock", "-");
  1805. if (it.second.d_suobi_lock_max != INT_MAX)
  1806. yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_max", it.second.d_suobi_lock_max);
  1807. else
  1808. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max", "-");
  1809. if (it.second.d_suobi_lock_min != INT_MAX)
  1810. yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_min", it.second.d_suobi_lock_min);
  1811. else
  1812. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min", "-");
  1813. if (it.second.d_suobi_lock_avg != INT_MAX)
  1814. yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_avg", it.second.d_suobi_lock_avg);
  1815. else
  1816. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg", "-");
  1817. //颜色
  1818. if (it.second.d_suobi_lock_max_color == UINT8_ALARM)
  1819. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max_color", "red");
  1820. else if (it.second.d_suobi_lock_max_color == UINT8_WARN)
  1821. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max_color", "orange");
  1822. if (it.second.d_suobi_lock_min_color == UINT8_ALARM)
  1823. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min_color", "red");
  1824. else if (it.second.d_suobi_lock_min_color == UINT8_WARN)
  1825. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min_color", "orange");
  1826. if (it.second.d_suobi_lock_avg_color == UINT8_ALARM)
  1827. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg_color", "red");
  1828. else if (it.second.d_suobi_lock_avg_color == UINT8_WARN)
  1829. yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg_color", "orange");
  1830. if (it.second.f_suobi_lock != INT_MAX)
  1831. yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock", it.second.f_suobi_lock);
  1832. else
  1833. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock", "-");
  1834. if (it.second.f_suobi_lock_max != INT_MAX)
  1835. yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_max", it.second.f_suobi_lock_max);
  1836. else
  1837. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max", "-");
  1838. if (it.second.f_suobi_lock_min!= INT_MAX)
  1839. yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_min", it.second.f_suobi_lock_min);
  1840. else
  1841. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min", "-");
  1842. if (it.second.f_suobi_lock_avg != INT_MAX)
  1843. yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_avg", it.second.f_suobi_lock_avg);
  1844. else
  1845. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg", "-");
  1846. //颜色
  1847. if (it.second.f_suobi_lock_max_color == UINT8_ALARM)
  1848. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max_color", "red");
  1849. else if (it.second.f_suobi_lock_max_color == UINT8_WARN)
  1850. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max_color", "orange");
  1851. if (it.second.f_suobi_lock_min_color == UINT8_ALARM)
  1852. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min_color", "red");
  1853. else if (it.second.f_suobi_lock_min_color == UINT8_WARN)
  1854. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min_color", "orange");
  1855. if (it.second.f_suobi_lock_avg_color == UINT8_ALARM)
  1856. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg_color", "red");
  1857. else if (it.second.f_suobi_lock_avg_color == UINT8_WARN)
  1858. yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg_color", "orange");
  1859. }
  1860. }
  1861. *json = yyjson_mut_write(doc, 0, json_len);
  1862. yyjson_mut_doc_free(doc);
  1863. return 200;
  1864. }
  1865. int DealGetMoveInfo(const httplib::Request& req, const string token, char** json, size_t* json_len)
  1866. {
  1867. string mo = req.get_param_value("mo");
  1868. string mp = req.get_param_value("mp");
  1869. string start_time = req.get_param_value("start_time");
  1870. string end_time = req.get_param_value("end_time");
  1871. if (mo.length() == 0 || mp.length() == 0 || start_time.length() == 0 || end_time.length() == 0)
  1872. return 400;
  1873. auto doc = yyjson_mut_doc_new(nullptr);
  1874. auto root = yyjson_mut_obj(doc);
  1875. yyjson_mut_doc_set_root(doc, root);
  1876. auto data = yyjson_mut_arr(doc);
  1877. yyjson_mut_obj_add_val(doc, root, "data", data);
  1878. COleDateTime odtStart, odtEnd;
  1879. do {
  1880. auto ret_time = odtEnd.ParseDateTime(end_time.c_str());
  1881. if (ret_time == FALSE)
  1882. break;
  1883. ret_time = odtStart.ParseDateTime(start_time.c_str());
  1884. if (ret_time == FALSE)
  1885. break;
  1886. if (odtEnd <= odtStart)
  1887. break;
  1888. auto fix_object = yyjson_mut_obj(doc);
  1889. yyjson_mut_arr_add_val(data, fix_object);
  1890. auto invert_object = yyjson_mut_obj(doc);
  1891. yyjson_mut_arr_add_val(data, invert_object);
  1892. auto convert_object = yyjson_mut_obj(doc);
  1893. yyjson_mut_arr_add_val(data, convert_object);
  1894. static string fix_name = ANSItoUTF8("定位测力曲线");
  1895. yyjson_mut_obj_add_str(doc, fix_object, "name", fix_name.c_str());
  1896. static string invert_name = ANSItoUTF8("反位测力曲线");
  1897. yyjson_mut_obj_add_str(doc, invert_object, "name", invert_name.c_str());
  1898. static string convert_name = ANSItoUTF8("转换阻力曲线");
  1899. yyjson_mut_obj_add_str(doc, convert_object, "name", convert_name.c_str());
  1900. static string lock_low = ANSItoUTF8("锁闭力过低");
  1901. auto fix_points = yyjson_mut_arr(doc);
  1902. yyjson_mut_obj_add_val(doc, fix_object, "mark_points", fix_points);
  1903. auto invert_points = yyjson_mut_arr(doc);
  1904. yyjson_mut_obj_add_val(doc, invert_object, "mark_points", invert_points);
  1905. auto convert_points = yyjson_mut_arr(doc);
  1906. yyjson_mut_obj_add_val(doc, convert_object, "mark_points", convert_points);
  1907. string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odtStart.GetYear(), odtStart.GetMonth());
  1908. CString sql = fmt::format("SELECT show_time, curr_val, show_val, posi, mark FROM {} \
  1909. WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' order by posi, show_time",
  1910. table_name, mo, mp, start_time, end_time).c_str();
  1911. COdbcStatement stmt;
  1912. if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
  1913. {
  1914. TIMESTAMP_STRUCT ts;
  1915. int curr_val;
  1916. int show_val;
  1917. eDaoChaPosi posi;
  1918. char mark[200];
  1919. int nCol = 1;
  1920. stmt.BindTimeStampCol(nCol++, &ts);
  1921. stmt.BindIntCol(nCol++, &curr_val);
  1922. stmt.BindIntCol(nCol++, &show_val);
  1923. stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
  1924. stmt.BindCharCol(nCol++, mark, sizeof(mark));
  1925. do
  1926. {
  1927. if (stmt.FetchNext() != 0)
  1928. break;
  1929. auto obj = yyjson_mut_obj(doc);
  1930. switch (posi)
  1931. {
  1932. case eDaoChaPosi::DCP_FIX:
  1933. {
  1934. yyjson_mut_arr_add_val(fix_points, obj);
  1935. auto coord = yyjson_mut_arr(doc);
  1936. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  1937. yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
  1938. yyjson_mut_arr_add_int(doc, coord, curr_val);
  1939. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  1940. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  1941. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  1942. if (show_val < 500)
  1943. {
  1944. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1945. yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
  1946. }
  1947. else
  1948. {
  1949. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  1950. }
  1951. }
  1952. break;
  1953. case eDaoChaPosi::DCP_INVERT:
  1954. {
  1955. yyjson_mut_arr_add_val(invert_points, obj);
  1956. auto coord = yyjson_mut_arr(doc);
  1957. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  1958. yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
  1959. yyjson_mut_arr_add_int(doc, coord, curr_val);
  1960. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  1961. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  1962. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  1963. if (show_val < 500)
  1964. {
  1965. yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
  1966. yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
  1967. }
  1968. else
  1969. {
  1970. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
  1971. }
  1972. }
  1973. break;
  1974. case eDaoChaPosi::DCP_FIX2INVERT:
  1975. {
  1976. yyjson_mut_arr_add_val(convert_points, obj);
  1977. auto coord = yyjson_mut_arr(doc);
  1978. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  1979. yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
  1980. yyjson_mut_arr_add_int(doc, coord, curr_val);
  1981. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  1982. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  1983. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  1984. if (curr_val < 0)
  1985. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  1986. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", show_val)).c_str());
  1987. }
  1988. break;
  1989. case eDaoChaPosi::DCP_INVERT2FIX:
  1990. {
  1991. yyjson_mut_arr_add_val(convert_points, obj);
  1992. auto coord = yyjson_mut_arr(doc);
  1993. yyjson_mut_obj_add_val(doc, obj, "coord", coord);
  1994. yyjson_mut_arr_add_int(doc, coord, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction / 1000000);
  1995. yyjson_mut_arr_add_int(doc, coord, curr_val);
  1996. yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
  1997. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
  1998. yyjson_mut_obj_add_int(doc, obj, "val", show_val);
  1999. if (curr_val < 0)
  2000. yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
  2001. yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", show_val)).c_str());
  2002. }
  2003. break;
  2004. default:
  2005. ASSERT(FALSE);
  2006. break;
  2007. }
  2008. } while (TRUE);
  2009. }
  2010. stmt.Close();
  2011. }while (false);
  2012. *json = yyjson_mut_write(doc, 0, json_len);
  2013. yyjson_mut_doc_free(doc);
  2014. return 200;
  2015. }