| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241 | 
							- #include "stdafx.h"
 
- #include "HttpPrcess.h"
 
- #include <yyjson.h>
 
- #include <Simplelog.h>
 
- #include "MonitorObject.h"
 
- #include "AlarmDefine.h"
 
- #include <crc32.h>
 
- #include "AppService.h"
 
- #include <gbk2utf8.h>
 
- #include "Device.h"
 
- #include "ResistAlarm.h"
 
- //处理get请求总入口
 
- void DealHttpGet(const httplib::Request& req, httplib::Response& res)
 
- {
 
- 	int code = 500;
 
- 	auto start = chrono::steady_clock::now();
 
- 	auto token = req.get_header_value("token");
 
- 	if (token.length() == 0 || token.empty())
 
- 		token = req.get_header_value("Authorization");
 
- 	char* json = nullptr;
 
- 	string body;
 
- 	size_t json_len = 0;
 
- 	SPDLOG_INFO("[HTTP][GET][START] {}:{} {}", req.remote_addr, req.remote_port, req.target);
 
- 	try
 
- 	{
 
- 		if (token.empty())
 
- 		{
 
- 			code = 401;
 
- 		}
 
- 		if (req.path.find("option_svg") != -1)
 
- 			code = DealOptionSvgData(req, token, res);
 
- 		else if (req.path.find("get_svg") != -1)
 
- 			code = DealGetSvgData(req, token, res);
 
- 		else if (req.path.find("get_mp_stat") != -1)
 
- 			code = DealGetMpStat(req, token, res);
 
- 		else if (req.path.find("conf_read/mitie_lock") != -1)
 
- 			code = DealGetMitieLock(req, token, &json, &json_len);
 
- 		else if (req.path.find("conf_read/convert_resist") != -1)
 
- 			code = DealGetConvertResist(req, token, &json, &json_len);
 
- 		else if (req.path.find("resistance_curve") != -1)
 
- 			code = DealGetResistCurve(req, token, &json, &json_len);
 
- 		else if (req.path.find("resistance_report") != -1)
 
- 			code = DealGetResistReport(req, token, &json, &json_len);
 
- 		else if (req.path.find("move_info") != -1)
 
- 			code = DealGetMoveInfo(req, token, &json, &json_len);
 
- 		else if (req.path.find("operation_log") != -1)
 
- 			code = DealGetOptLog(req, token, &json, &json_len);
 
- 		else if (req.path.find("refer_curve") != -1)
 
- 			code = DealGetrefer_curve(req, token, &json, &json_len);
 
- 		else if (req.path.find("refer_option") != -1)
 
- 			code = DealGetrefer_option(req, token, &json, &json_len);
 
- 		else if (req.path.find("get_temp") != -1)
 
- 			code = DealGetTemp(req, token, &json, &json_len);
 
- 		else if (req.path.find("get_humitemp") != -1)
 
- 			code = DealGetTempHumi(req, token, &json, &json_len);
 
- 		else if (req.path.find("backend_type") != -1)
 
- 		{
 
- 			body = R"({"type":2})"; code = 200;
 
- 		}
 
- 		else
 
- 			code = 405;
 
- 	}
 
- 	catch (...)
 
- 	{
 
- 		code = 500;
 
- 	}
 
- 	if (json)
 
- 		res.set_content(json, "application/json");
 
- 	if (!body.empty())
 
- 		res.set_content(body.c_str(), "application/json");
 
- 	auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
 
- 	SPDLOG_INFO("[HTTP][GET][END] code:{} COST:{} {}:{} {} {}", code, cost, req.remote_addr, req.remote_port, req.target, json ? json : "");
 
- 	res.set_header("cost", to_string(cost) + " ms");
 
- 	res.status = code;
 
- 	if (json) free(json);
 
- }
 
- //处理post请求总入口
 
- void DealHttpPost(const httplib::Request& req, httplib::Response& res)
 
- {
 
- 	int code = 500;
 
- 	auto start = chrono::steady_clock::now();
 
- 	auto token = req.get_header_value("token");
 
- 	if (token.length() == 0 || token.empty()) 
 
- 		token = req.get_header_value("Authorization");
 
- 	char* json = nullptr;
 
- 	size_t json_len = 0;
 
- 	SPDLOG_INFO("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body);
 
- 	try
 
- 	{
 
- 		if (token.empty())
 
- 		{
 
- 			code = 401;
 
- 		}
 
- 		if (req.path.find("post_svg") != -1)
 
- 			code = DealPostSvgData(req, token, res);
 
- 		else if (req.path.find("option_svg") != -1)
 
- 			code = DealOptionSvgData(req, token, res);
 
- 		else if (req.path.find("commit_record") != -1)
 
- 			code = DealPostCommitRecord(req.body.c_str(), req.body.length(), token, &json, &json_len);
 
- 		else if (req.path.find("get_svg") != -1)
 
- 			code = DealGetSvgData(req, token, res);
 
- 		//else if (req.path.find("post_soft") != -1)
 
- 		//	code = DealPostBinData(req, token, res);
 
- 		else if (req.path.find("conf_write/convert_resist") != -1)
 
- 			code = DealPostConvertResist(req.body.c_str(), req.body.length(), token, &json, &json_len);
 
- 		else if (req.path.find("conf_write/mitie_lock") != -1)
 
- 			code = DealPostMitieLock(req.body.c_str(), req.body.length(), token, &json, &json_len);
 
- 		else if (req.path.find("refer_curve") != -1)
 
- 			code = DealPostrefer_curve(req.body.c_str(), req.body.length(), token, &json, &json_len);
 
- 		else
 
- 			code = 405;
 
- 	}
 
- 	catch (...)
 
- 	{
 
- 		code = 500;
 
- 	}
 
- 	if (json)
 
- 		res.set_content(json, "application/json");
 
- 	auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
 
- 	SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{} json:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body, json ? json : "");
 
- 	res.set_header("cost", to_string(cost) + " ms");
 
- 	res.status = code;
 
- 	if (json) free(json);
 
- }
 
- int DealPostSvgData(const httplib::Request& req, const string token, httplib::Response& res)
 
- {
 
- 	if (token.find("AAAAAAAA") == -1) return 403;
 
- 	auto id = req.get_header_value("id");
 
- 	if (id.empty()) return 400;//参数错误
 
- 	char szID[200] = { 0 };
 
- 	utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
 
- 	if (req.body.empty()) return 400;
 
- 	CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
 
- 	CFile file;
 
- 	if (file.Open(strPath, CFile::modeWrite | CFile::typeBinary | CFile::modeCreate))
 
- 	{
 
- 		file.Write(req.body.c_str(), req.body.length());
 
- 		file.Close();
 
- 		return 200;
 
- 	}
 
- 	else
 
- 	{
 
- 		return 500;
 
- 	}
 
- 	return 405;
 
- }
 
- int DealGetSvgData(const httplib::Request& req, const string token, httplib::Response& res)
 
- {
 
- 	auto id = req.get_param_value("id");
 
- 	if (id.empty()) return 400;//参数错误
 
- 	char szID[200] = { 0 };
 
- 	utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
 
- 	CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
 
- 	auto bExist = CSimpleLog::PathFileExists(strPath);
 
- 	if (bExist == false) return 404;
 
- 	CFile file;
 
- 	if (file.Open(strPath, CFile::modeRead | CFile::typeBinary))
 
- 	{
 
- 		int len = file.GetLength();
 
- 		auto pData = new uint8_t[len];
 
- 		file.Read(pData, len);
 
- 		file.Close();
 
- 		res.set_content((char*)pData, len, "image/svg+xml");
 
- 	}
 
- 	else
 
- 	{
 
- 		return 500;
 
- 	}
 
- 	return 200;
 
- }
 
- int DealOptionSvgData(const httplib::Request& req, const string token, httplib::Response& res)
 
- {
 
- 	auto id = req.get_param_value("id");
 
- 	if (id.empty()) return 400;//参数错误
 
- 	char szID[200] = { 0 };
 
- 	utf82gbk(szID, 200, id.c_str(), id.length()); //处理中文
 
- 	CString strPath = CSimpleLog::GetAppDir() + "svg\\" + szID + ".svg";
 
- 	auto bExist = CSimpleLog::PathFileExists(strPath);
 
- 	string strResult;
 
- 	if (bExist)
 
- 		strResult = R"({"result":true})";
 
- 	else
 
- 		strResult = R"({"result":false})";
 
- 	res.set_content(strResult, "application/json");
 
- 	return 200;
 
- }
 
- int DealGetMpStat(const httplib::Request& req, const string token, httplib::Response& res)
 
- {
 
- 	auto id = req.get_param_value("id");//杭南杭甬场
 
- 	if (id.empty()) return 400;//参数错误
 
- 	char station[200];
 
- 	int id_len = utf82gbk(station, 200, id.c_str(), id.length());
 
- 	auto pStation = CMonitorObjectMng::Instance()->GetTreeByID(string(station));
 
- 	if (nullptr == pStation) return 404;
 
- 	if (pStation->type.compare("station") != 0) return 400;
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_arr(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	for (const auto& it : pStation->m_lstMo)
 
- 	{
 
- 		auto arr = yyjson_mut_arr(doc);
 
- 		yyjson_mut_arr_add_val(root, arr);
 
- 		yyjson_mut_arr_add_strcpy(doc, arr, it->id.c_str());
 
- 		yyjson_mut_arr_add_strcpy(doc, arr, it->name.c_str());
 
- 		CDevice* pDevice = CDeviceMng::Instance()->Find(it->id);
 
- 		if (pDevice)
 
- 		{
 
- 			string mo, mp;
 
- 			if (CMonitorObjectMng::spiltByPoint(it->id, mo, mp))
 
- 			{
 
- 				SYSTEMTIME stAlarm = { 0 };
 
- 				auto ty = CResistAlarmMng::Instance()->GetAlarmStat(mo, mp, stAlarm);
 
- 				if (ty == eZL_MP_STAT::MP_STAT_OFFLINE_GRAY)
 
- 				{
 
- 					if (pDevice->IsDeviceOnline())
 
- 						yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_NORMAL_GREEN);
 
- 					else
 
- 						yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_OFFLINE_GRAY);
 
- 				}
 
- 				else
 
- 				{
 
- 					yyjson_mut_arr_add_int(doc, arr, (int)ty);
 
- 					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);
 
- 					yyjson_mut_arr_add_strcpy(doc, arr, station);
 
- 				}
 
- 			}
 
- 			else
 
- 			{
 
- 				yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_UNINSTALL_WHITE);
 
- 			}
 
- 		}
 
- 		else
 
- 		{
 
- 			yyjson_mut_arr_add_int(doc, arr, (int)eZL_MP_STAT::MP_STAT_UNINSTALL_WHITE);
 
- 		}
 
- 	}
 
- 	size_t len;
 
- 	auto json = yyjson_mut_write(doc, 0, &len);
 
- 	res.set_content(json, len, "application/json");
 
- 	if (json)
 
- 	{
 
- 		free((void*)json);
 
- 		json = nullptr;
 
- 	}
 
- 	yyjson_mut_doc_free(doc);
 
- 	return 200;
 
- }
 
- int DealGetMitieLock(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string mo = req.get_param_value("mo");
 
- 	string mp = req.get_param_value("mp");
 
- 	eSuoBiPosi posi = (eSuoBiPosi)atoi(req.get_param_value("posi").c_str());
 
- 	if (posi == eSuoBiPosi::SB_ZERO) posi = eSuoBiPosi::SB_UNKNOWN;
 
- 	if (mo.length() == 0 || mp.length() == 0)
 
- 		return 400;
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
 
- 	if (pInfo)
 
- 	{
 
- 		yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
 
- 		if (pInfo->alarm_low_limit > INT_MIN)
 
- 			yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
 
- 		else 
 
- 			yyjson_mut_obj_add_null(doc, root, "alarm_low_limit");
 
- 		if (pInfo->warn_low_limit > INT_MIN)
 
- 			yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
 
- 		else 
 
- 			yyjson_mut_obj_add_null(doc, root, "warn_low_limit");
 
- 		if (pInfo->alarm_high_limit < INT_MAX)
 
- 			yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
 
- 		else
 
- 			yyjson_mut_obj_add_null(doc, root, "alarm_high_limit");
 
- 		if (pInfo->warn_high_limit < INT_MAX)
 
- 			yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
 
- 		else
 
- 			yyjson_mut_obj_add_null(doc, root, "warn_high_limit");
 
- 	}
 
- 	else
 
- 	{
 
- 		yyjson_mut_obj_add_bool(doc, root, "enable", false);
 
- 		yyjson_mut_obj_add_null(doc, root, "alarm_low_limit");
 
- 		yyjson_mut_obj_add_null(doc, root, "warn_low_limit");
 
- 		yyjson_mut_obj_add_null(doc, root, "alarm_high_limit");
 
- 		yyjson_mut_obj_add_null(doc, root, "warn_high_limit");
 
- 	}
 
- 	*json = yyjson_mut_write(doc, 0, json_len);
 
- 	yyjson_mut_doc_free(doc);
 
- 	return 200;
 
- }
 
- int DealPostMitieLock(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
 
- {
 
- 	return 403; //关闭设置
 
- 	int code = 400;
 
- 	auto req_doc = yyjson_read(body_ptr, body_len, 0);
 
- 	if (req_doc == nullptr) return 400;
 
- 	auto req_root = yyjson_doc_get_root(req_doc);
 
- 	do 
 
- 	{
 
- 		auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
 
- 		auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
 
- 		eSuoBiPosi posi = (eSuoBiPosi)yyjson_get_int(yyjson_obj_get(req_root, "posi"));;//预留
 
- 		if (posi == eSuoBiPosi::SB_ZERO) posi = eSuoBiPosi::SB_UNKNOWN;
 
- 		auto conf = yyjson_obj_get(req_root, "conf");
 
- 		if (mo == nullptr || mp == nullptr || conf == nullptr)
 
- 			break;
 
- 		auto doc = yyjson_mut_doc_new(nullptr);
 
- 		auto root = yyjson_mut_obj(doc);
 
- 		yyjson_mut_doc_set_root(doc, root);
 
- 		size_t len;
 
- 		char* str_conf = nullptr;
 
- 		//更新内存里
 
- 		SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
 
- 		CString sql;
 
- 		if (pInfo == nullptr)
 
- 		{
 
- 			SUOBI_OVER_LIMIT_INFO* pInfo = new SUOBI_OVER_LIMIT_INFO;
 
- 			pInfo->type = eZL_ALARMTYPE::SUOBI_LOCK_LIMIT;
 
- 			pInfo->no = (uint8_t)posi;
 
- 			pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
 
- 			yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "alarm_low_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->alarm_low_limit = yyjson_get_int(val);
 
- 				yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "warn_low_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->warn_low_limit = yyjson_get_int(val);
 
- 				yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "alarm_high_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->alarm_high_limit = yyjson_get_int(val);
 
- 				yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "warn_high_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->warn_high_limit = yyjson_get_int(val);
 
- 				yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
 
- 			}
 
- 			str_conf = yyjson_mut_write(doc, 0, &len);
 
- 			yyjson_mut_doc_free(doc);
 
- 			CResistAlarmMng::Instance()->Insert(mo, mp, (uint8_t)posi, (uint8_t)eZL_ALARMTYPE::SUOBI_LOCK_LIMIT, pInfo);
 
- 			time_t tt;
 
- 			time(&tt);
 
- 			sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d, %d,'%s','%I64u')",
 
- 				mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT, str_conf, tt);
 
- 		}
 
- 		else
 
- 		{
 
- 			pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
 
- 			yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "alarm_low_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->alarm_low_limit = yyjson_get_int(val);
 
- 				else
 
- 					pInfo->alarm_low_limit = INT_MIN;
 
- 				yyjson_mut_obj_add_int(doc, root, "alarm_low_limit", pInfo->alarm_low_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "warn_low_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->warn_low_limit = yyjson_get_int(val);
 
- 				else
 
- 					pInfo->warn_low_limit = INT_MIN;
 
- 				yyjson_mut_obj_add_int(doc, root, "warn_low_limit", pInfo->warn_low_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "alarm_high_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->alarm_high_limit = yyjson_get_int(val);
 
- 				else
 
- 					pInfo->alarm_high_limit = INT_MAX;
 
- 				yyjson_mut_obj_add_int(doc, root, "alarm_high_limit", pInfo->alarm_high_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "warn_high_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->warn_high_limit = yyjson_get_int(val);
 
- 				else
 
- 					pInfo->warn_high_limit = INT_MAX;
 
- 				yyjson_mut_obj_add_int(doc, root, "warn_high_limit", pInfo->warn_high_limit);
 
- 			}
 
- 			str_conf = yyjson_mut_write(doc, 0, &len);
 
- 			yyjson_mut_doc_free(doc);
 
- 			sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
 
- 				str_conf, mo, mp, (uint8_t)posi, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
 
- 		}
 
- 	
 
- 		if (str_conf) free(str_conf);
 
- 		if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
 
- 		{
 
- 			ASSERT(FALSE);
 
- 			CSimpleLog::Error("语句执行失败" + sql);
 
- 			code = 500;
 
- 			break;
 
- 		}
 
- 		code = 200;
 
- 	} while (false);
 
- 	yyjson_doc_free(req_doc);
 
- 	return code;
 
- }
 
- int DealGetConvertResist(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string mo = req.get_param_value("mo");
 
- 	string mp = req.get_param_value("mp");
 
- 	if (mo.length() == 0 || mp.length() == 0)
 
- 		return 400;
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
 
- 	if (pInfo)
 
- 	{
 
- 		yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
 
- 		if (pInfo->dw_alarm_low_limit > INT_MIN)
 
- 			yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
 
- 		else
 
- 			yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_limit");
 
- 		if (pInfo->dw_warn_low_limit > INT_MIN)
 
- 			yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
 
- 		else
 
- 			yyjson_mut_obj_add_null(doc, root, "dw_warn_low_limit");
 
- 		if (pInfo->up_alarm_high_limit < INT_MAX)
 
- 			yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
 
- 		else
 
- 			yyjson_mut_obj_add_null(doc, root, "up_alarm_high_limit");
 
- 		if (pInfo->up_warn_high_limit < INT_MAX)
 
- 			yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
 
- 		else
 
- 			yyjson_mut_obj_add_null(doc, root, "up_warn_high_limit");
 
- 	}
 
- 	else
 
- 	{
 
- 		yyjson_mut_obj_add_bool(doc, root, "enable", false);
 
- 		yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_limit");
 
- 		yyjson_mut_obj_add_null(doc, root, "dw_warn_low_limit");
 
- 		yyjson_mut_obj_add_null(doc, root, "up_alarm_high_limit");
 
- 		yyjson_mut_obj_add_null(doc, root, "up_warn_high_limit");
 
- 	}
 
- 	*json = yyjson_mut_write(doc, 0, json_len);
 
- 	yyjson_mut_doc_free(doc);
 
- 	return 200;
 
- }
 
- int DealPostConvertResist(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
 
- {
 
- 	return 403;
 
- 	int code = 400;
 
- 	auto req_doc = yyjson_read(body_ptr, body_len, 0);
 
- 	if (req_doc == nullptr) return 400;
 
- 	auto req_root = yyjson_doc_get_root(req_doc);
 
- 	do
 
- 	{
 
- 		auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
 
- 		auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
 
- 		auto conf = yyjson_obj_get(req_root, "conf");
 
- 		if (mo == nullptr || mp == nullptr || conf == nullptr)
 
- 			break;
 
- 		auto doc = yyjson_mut_doc_new(nullptr);
 
- 		auto root = yyjson_mut_obj(doc);
 
- 		yyjson_mut_doc_set_root(doc, root);
 
- 		size_t len;
 
- 		char* str_conf = nullptr;
 
- 		//更新内存里
 
- 		CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
 
- 		CString sql;
 
- 		if (pInfo == nullptr)
 
- 		{
 
- 			CONVERT_RESIST_OVER_LIMIT* pInfo = new CONVERT_RESIST_OVER_LIMIT;
 
- 			pInfo->type = eZL_ALARMTYPE::CONVERT_LIMIT;
 
- 			pInfo->no = 2;
 
- 			pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
 
- 			yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "dw_alarm_low_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->dw_alarm_low_limit = yyjson_get_int(val);
 
- 				yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "dw_warn_low_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->dw_warn_low_limit = yyjson_get_int(val);
 
- 				yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "up_alarm_high_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->up_alarm_high_limit = yyjson_get_int(val);
 
- 				yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "up_warn_high_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->up_warn_high_limit = yyjson_get_int(val);
 
- 				yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
 
- 			}
 
- 			str_conf = yyjson_mut_write(doc, 0, &len);
 
- 			yyjson_mut_doc_free(doc);
 
- 			CResistAlarmMng::Instance()->Insert(mo, mp, 2, (uint8_t)eZL_ALARMTYPE::CONVERT_LIMIT, pInfo);
 
- 			sql.Format("INSERT INTO [rm_alarm_set]([mo],[mp],[no],[type],[conf],[time]) VALUES ('%s','%s',%d,%d,'%s','%I64u')",
 
- 				mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT, str_conf, 0);
 
- 		}
 
- 		else
 
- 		{
 
- 			pInfo->enable = yyjson_get_bool(yyjson_obj_get(conf, "enable"));
 
- 			yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable);
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "dw_alarm_low_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->dw_alarm_low_limit = yyjson_get_int(val);
 
- 				else
 
- 					pInfo->dw_alarm_low_limit = INT_MIN;
 
- 				yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_limit", pInfo->dw_alarm_low_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "dw_warn_low_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->dw_warn_low_limit = yyjson_get_int(val);
 
- 				else
 
- 					pInfo->dw_warn_low_limit = INT_MIN;
 
- 				yyjson_mut_obj_add_int(doc, root, "dw_warn_low_limit", pInfo->dw_warn_low_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "up_alarm_high_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->up_alarm_high_limit = yyjson_get_int(val);
 
- 				else
 
- 					pInfo->up_alarm_high_limit = INT_MAX;
 
- 				yyjson_mut_obj_add_int(doc, root, "up_alarm_high_limit", pInfo->up_alarm_high_limit);
 
- 			}
 
- 			{
 
- 				auto val = yyjson_obj_get(conf, "up_warn_high_limit");
 
- 				if (val && yyjson_is_int(val))
 
- 					pInfo->up_warn_high_limit = yyjson_get_int(val);
 
- 				else
 
- 					pInfo->up_warn_high_limit = INT_MAX;
 
- 				yyjson_mut_obj_add_int(doc, root, "up_warn_high_limit", pInfo->up_warn_high_limit);
 
- 			}
 
- 			str_conf = yyjson_mut_write(doc, 0, &len);
 
- 			yyjson_mut_doc_free(doc);
 
- 			sql.Format("update rm_alarm_set SET conf = '%s' WHERE mo = '%s' and mp = '%s' and no = %d and type = %d",
 
- 				str_conf, mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
 
- 		}
 
- 		if (str_conf) free(str_conf);
 
- 		if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
 
- 		{
 
- 			ASSERT(FALSE);
 
- 			CSimpleLog::Error("语句执行失败" + sql);
 
- 			code = 500;
 
- 			break;
 
- 		}
 
- 		code = 200;
 
- 	} while (false);
 
- 	yyjson_doc_free(req_doc);
 
- 	return code;
 
- }
 
- int DealPostCommitRecord(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
 
- {
 
- 	int code = 400;
 
- 	string msg;
 
- 	auto req_doc = yyjson_read(body_ptr, body_len, 0);
 
- 	if (req_doc == nullptr) return 400;
 
- 	auto req_root = yyjson_doc_get_root(req_doc);
 
- 	do
 
- 	{
 
- 		if (yyjson_is_arr(req_root) == false) break;
 
- 		auto doc = yyjson_mut_doc_new(nullptr);
 
- 		auto root = yyjson_mut_obj(doc);
 
- 		yyjson_mut_doc_set_root(doc, root);
 
- 		size_t n = yyjson_arr_size(req_root);
 
- 		auto req_obj = yyjson_arr_get_first(req_root);
 
- 		for (size_t i = 0; i < n; i++)
 
- 		{
 
- 			auto module = yyjson_get_int(yyjson_obj_get(req_obj, "module"));
 
- 			auto dura = yyjson_get_int(yyjson_obj_get(req_obj, "dura"));
 
- 			auto analyze_type = yyjson_get_int(yyjson_obj_get(req_obj, "analyze_type"));
 
- 			auto station = yyjson_get_str(yyjson_obj_get(req_obj, "station"));
 
- 			auto station_name = yyjson_get_str(yyjson_obj_get(req_obj, "station_name"));
 
- 			auto mo = yyjson_get_str(yyjson_obj_get(req_obj, "mo"));
 
- 			auto mo_name = yyjson_get_str(yyjson_obj_get(req_obj, "mo_name"));
 
- 			auto mp = yyjson_get_str(yyjson_obj_get(req_obj, "mp"));
 
- 			auto mp_name = yyjson_get_str(yyjson_obj_get(req_obj, "mp_name"));
 
- 			auto start_time = yyjson_get_uint(yyjson_obj_get(req_obj, "start_time"));
 
- 			auto end_time = yyjson_get_uint(yyjson_obj_get(req_obj, "end_time"));
 
- 			time_t tt;
 
- 			time(&tt);
 
- 			auto name = yyjson_get_str(yyjson_obj_get(req_obj, "name"));
 
- 			auto username = yyjson_get_str(yyjson_obj_get(req_obj, "username"));
 
- 			if (module == 0 || dura == 0 || station == nullptr ||
 
- 				station_name == nullptr || start_time == 0 || name == nullptr)
 
- 				break;
 
- 			auto strStation = UTF8toANSI(station);
 
- 			auto strStationName = UTF8toANSI(station_name);
 
- 			auto strName = UTF8toANSI(name);
 
- 			CString strDuraTime;
 
- 			dura = dura / 1000.0 + 0.5;
 
- 			if (dura / 60)
 
- 				strDuraTime.Format(" 时长:%d分%d秒", dura / 60, dura % 60);
 
- 			else  if (dura)
 
- 				strDuraTime.Format(" 时长:%d秒", dura);
 
- 			CString sql = fmt::format("INSERT INTO [dbo].[rm_record]\
 
- 			(module, dura, analyze_type, station\
 
- 				, station_name, mo, mo_name, mp, mp_name, start_time\
 
- 				, end_time, time, name,username,opt,mark)	VALUES\
 
- 			({}, {}, {}, '{}', '{}'\
 
- 			, '{}', '{}', '{}', '{}', {}\
 
- 			, {}, {}, '{}', '{}',{}, '{}')",
 
- 				module, dura, analyze_type, strStation, strStationName,
 
- 				IS_NULL(mo), IS_NULL(mo_name), IS_NULL(mp), IS_NULL(mp_name), start_time,
 
- 				end_time, tt, strName, IS_NULL(username), 1, strDuraTime).c_str();
 
- 			if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
 
- 			{
 
- 				ASSERT(FALSE);
 
- 				msg = "语句执行失败:" + sql;
 
- 				CSimpleLog::Error(msg.c_str());
 
- 				code = 500;
 
- 				break;
 
- 			}
 
- 			else
 
- 			{
 
- 				code = 200;
 
- 			}
 
- 			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));
 
- 			req_obj = unsafe_yyjson_get_next(req_obj);
 
- 		}
 
- 		yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
 
- 		yyjson_mut_obj_add_int(doc, root, "code", code);
 
- 		if (json) *json = yyjson_mut_write(doc, 0, json_len);
 
- 	} while (false);
 
- 	yyjson_doc_free(req_doc);
 
- 	return code;
 
- }
 
- int DealGetOptLog(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string station_name = req.get_param_value("station_name");
 
- 	string time = req.get_param_value("time");
 
- 	string end_time = req.get_param_value("end_time");
 
- 	if (time.length() == 0 )
 
- 		return 400;
 
- 	time_t uTime = atoll(time.c_str());
 
- 	time_t uEndTime = atoll(end_time.c_str());
 
- 	if (uEndTime == 0) uEndTime = uTime + 86400;
 
- 	COleDateTime odt(uTime);
 
- 	if (odt.GetStatus() == COleDateTime::invalid)
 
- 		return 400;
 
- 	string str_station_name = UTF8toANSI(station_name);
 
- 	int code = 400;
 
- 	string msg;
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	auto yy_data = yyjson_mut_arr(doc);
 
- 	auto yy_name = yyjson_mut_arr(doc);
 
- 	auto yy_mo = yyjson_mut_arr(doc);
 
- 	auto yy_mp = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "data", yy_data);
 
- 	yyjson_mut_obj_add_val(doc, root, "name", yy_name);
 
- 	yyjson_mut_obj_add_val(doc, root, "mo_name", yy_mo);
 
- 	yyjson_mut_obj_add_val(doc, root, "mp_name", yy_mp);
 
- 	//query
 
- 	//查询数据库
 
- 	std::map<string, uint16_t> map_name;
 
- 	std::map<string, uint16_t> map_mo_name;
 
- 	std::map<string, uint16_t> map_mp_name;
 
- 	{
 
- 		//station,station_name,
 
- 		CString sql;
 
- 		if (str_station_name.length() == 0)
 
- 			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\
 
- 			FROM rm_record WHERE time between {} AND {}",
 
- 				uTime, uEndTime).c_str();
 
- 		else
 
- 			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\
 
- 			FROM rm_record WHERE station_name = '{}' AND time between {} AND {}",
 
- 			str_station_name, uTime, uEndTime).c_str();
 
- 		COdbcStatement stmt;
 
- 		if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
 
- 		{
 
- 			uint8_t umodule, analyze_type;
 
- 			int16_t opt = 0;
 
- 			int dura;
 
- 			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];
 
- 			uint64_t start_time, end_time, tt;
 
- 			int nCol = 1;
 
- 			stmt.BindTinyIntCol(nCol++, &umodule);
 
- 			stmt.BindIntCol(nCol++, &dura);
 
- 			stmt.BindTinyIntCol(nCol++, &analyze_type);
 
- 			//stmt.BindCharCol(nCol++, station, sizeof(station));
 
- 			//stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
 
- 			stmt.BindCharCol(nCol++, mo, sizeof(mo));
 
- 			stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
 
- 			stmt.BindCharCol(nCol++, mp, sizeof(mp));
 
- 			stmt.BindCharCol(nCol++, mp_name, sizeof(mp_name));
 
- 			stmt.BindBigIntCol(nCol++, (__int64*)&start_time);
 
- 			stmt.BindBigIntCol(nCol++, (__int64*)&end_time);
 
- 			stmt.BindBigIntCol(nCol++, (__int64*)&tt);
 
- 			stmt.BindCharCol(nCol++, name, sizeof(name));
 
- 			stmt.BindCharCol(nCol++, username, sizeof(username));
 
- 			stmt.BindSmallIntCol(nCol++, &opt);
 
- 			stmt.BindCharCol(nCol++, mark, sizeof(mark));
 
- 			stmt.BindCharCol(nCol++, station_name, sizeof(station_name));
 
- 			do
 
- 			{
 
- 				//ZeroMemory(station, 100);
 
- 				//ZeroMemory(station_name, 100);
 
- 				ZeroMemory(mo, 50);
 
- 				ZeroMemory(mo_name, 50);
 
- 				ZeroMemory(mp, 50);
 
- 				ZeroMemory(mp_name, 50);
 
- 				ZeroMemory(name, 100);
 
- 				ZeroMemory(username, 50);
 
- 				ZeroMemory(mark, 200);
 
- 				ZeroMemory(station_name, 100);
 
- 				if (stmt.FetchNext() != 0)
 
- 					break;
 
- 				map_name[name]++;
 
- 				map_mo_name[mo_name]++;
 
- 				map_mp_name[mp_name]++;
 
- 				auto o = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(yy_data, o);
 
- 				yyjson_mut_obj_add_int(doc, o, "module", umodule);
 
- 				yyjson_mut_obj_add_int(doc, o, "opt", opt);
 
- 				yyjson_mut_obj_add_int(doc, o, "analyze_type", analyze_type);
 
- 				yyjson_mut_obj_add_strcpy(doc, o, "mo_name", mo_name);
 
- 				yyjson_mut_obj_add_strcpy(doc, o, "mp_name", mp_name);
 
- 				yyjson_mut_obj_add_int(doc, o, "time", tt);
 
- 				yyjson_mut_obj_add_strcpy(doc, o, "name", ANSItoUTF8(name).c_str());
 
- 				yyjson_mut_obj_add_strcpy(doc, o, "mark", ANSItoUTF8(mark).c_str());
 
- 				yyjson_mut_obj_add_strcpy(doc, o, "station_name", ANSItoUTF8(station_name).c_str());
 
- 			} while (TRUE);
 
- 		}
 
- 		stmt.Close();
 
- 	}
 
- 	for (auto& it : map_name)
 
- 		yyjson_mut_arr_add_strcpy(doc, yy_name, ANSItoUTF8(it.first).c_str());
 
- 	for (auto& it : map_mo_name)
 
- 		yyjson_mut_arr_add_strcpy(doc, yy_mo, it.first.c_str());
 
- 	for (auto& it : map_mp_name)
 
- 		yyjson_mut_arr_add_strcpy(doc, yy_mp, it.first.c_str());
 
- 	code = 200;
 
- 	yyjson_mut_obj_add_int(doc, root, "code", code);
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
 
- 	if (json)
 
- 	{
 
- 		*json = yyjson_mut_write(doc, 0, json_len);
 
- 		/*
 
- 		*json = (char*)malloc(1024);
 
- 		strcpy_s(*json, 1024, R"({
 
-     "code": 200,
 
-     "msg": "",
 
-     "data": [{
 
-         "mo_name": "21#",
 
-         "mp_name": "J1",
 
-         "name": "张三",
 
-         "opt":1,
 
-         "time": 1693808336,
 
-         "mark": ""
 
-     }, {
 
-         "mo_name": "22#",
 
-         "mp_name": "J1",
 
-         "name": "李四",
 
-         "opt":1,
 
-         "time": 1693808336,
 
-         "mark": ""
 
-     }],
 
-     "name": ["张三", "李四", "王五"],
 
-     "mo_name": ["21#", "22#", "23#"],
 
-     "mp_name": ["J1", "J2", "J3"]
 
- }
 
- )");
 
- */
 
- 	}
 
- 	yyjson_mut_doc_free(doc);
 
- 	return code;
 
- }
 
- 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,
 
- 	uint64_t start_time, uint64_t end_time, time_t tt, string& strName, const char* username, eRocord_Opt opt, string& mark)
 
- {
 
- 	CString sql = fmt::format("INSERT INTO rm_record\
 
- 			(module, dura, analyze_type, station\
 
- 				, station_name, mo, mo_name, mp, mp_name, start_time\
 
- 				, end_time, time, name,username,opt,mark)	VALUES\
 
- 			({}, {}, {}, '{}', '{}'\
 
- 			, '{}', '{}', '{}', '{}', {}\
 
- 			, {}, {}, '{}', '{}',{}, '{}')",
 
- 		int(module), dura, analyze_type, strStation, strStationName,
 
- 		IS_NULL(mo), IS_NULL(mo_name), IS_NULL(mp), IS_NULL(mp_name), start_time,
 
- 		end_time, tt, strName, IS_NULL(username), int(opt), mark).c_str();
 
- 	if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE)
 
- 	{
 
- 		ASSERT(FALSE);
 
- 		CSimpleLog::Error("语句执行失败:" + sql);
 
- 		return 500;
 
- 	}
 
- 	else
 
- 	{
 
- 		return 200;
 
- 	}
 
- }
 
- int DealGetrefer_option(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string station = req.get_param_value("station");
 
- 	string mo = req.get_param_value("mo");
 
- 	string mp = req.get_param_value("mp");
 
- 	string str_direct = req.get_param_value("direct");
 
- 	if (station.length() == 0 || mo.length() == 0 || mp.length() == 0 || str_direct.length() == 0)
 
- 		return 400;
 
- 	auto direct = atoi(str_direct.c_str());
 
- 	if (direct != 3 && direct != 4)
 
- 		return 400;
 
- 	string str_station = UTF8toANSI(station);
 
- 	if (CSimpleLog::PathFileExistsA(CSimpleLog::GetAppDir() + "refer\\" + 
 
- 		fmt::format("{}.{}.{}.{}.json", str_station, mo, mp, direct).c_str()))
 
- 		return 200;
 
- 	else
 
- 		return 404;
 
- }
 
- //获取参考曲线
 
- int DealGetrefer_curve(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string station = req.get_param_value("station");
 
- 	string mo = req.get_param_value("mo");
 
- 	string mp = req.get_param_value("mp");
 
- 	string str_direct = req.get_param_value("direct");
 
- 	string str_show_time = req.get_param_value("show_time");
 
- 	if (station.length() == 0 || mo.length() == 0 || mp.length() == 0 || str_direct.length() == 0 || str_show_time.length() == 0)
 
- 		return 400;
 
- 	auto direct = atoi(str_direct.c_str());
 
- 	if (direct != 3 && direct != 4)
 
- 		return 400;
 
- 	int yy, mm, dd, hh, MM, SS, micromm;
 
- 	auto ret_num = sscanf_s(str_show_time.c_str(), "%d-%d-%d %d:%d:%d.%d", &yy, &mm, &dd, &hh, &MM, &SS, µmm);
 
- 	if (ret_num != 7)
 
- 		return 400;
 
- 	string str_station = UTF8toANSI(station);
 
- 	time_t show_time = CTime(yy, mm, dd, hh, MM, SS).GetTime() * 1000 + micromm;
 
- 	int code = 400;
 
- 	string msg;
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	auto data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "data", data);
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "station", station.c_str());
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "mo", mo.c_str());
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "mp", mp.c_str());
 
- 	yyjson_mut_obj_add_int(doc, root, "direct", direct);
 
- 	code = ReadReferFile(str_station, mo, mp, direct, show_time, doc, data, msg);
 
- 	yyjson_mut_obj_add_int(doc, root, "code", code);
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
 
- 	if (json)
 
- 	{
 
- 		*json = yyjson_mut_write(doc, 0, json_len);
 
- 	}
 
- 	yyjson_mut_doc_free(doc);
 
- 	return code;
 
- }
 
- int ReadReferFile(const string& station, const string& mo, const string& mp, uint8_t posi, time_t show_time, yyjson_mut_doc* mut_doc,
 
- 	yyjson_mut_val* arr, OUT string& msg)
 
- {
 
- 	string strJsonPath = fmt::format("{}refer\\{}.{}.{}.{}.json", CSimpleLog::GetAppDir(), station, mo, mp, posi);
 
- 	if (CSimpleLog::PathFileExistsA(strJsonPath.c_str()) == false)
 
- 	{
 
- 		msg = fmt::format("未设置参考曲线");
 
- 		return 404;
 
- 	}
 
- 	yyjson_read_err err;
 
- 	auto doc = yyjson_read_file(strJsonPath.c_str(), strJsonPath.length(), nullptr, &err);
 
- 	if (doc == nullptr)
 
- 	{
 
- 		msg = err.msg;
 
- 		return 500;
 
- 	}
 
- 	auto root = yyjson_doc_get_root(doc);
 
- 	auto t = yyjson_obj_get(root, "t");
 
- 	auto d0 = yyjson_obj_get(root, "d0");
 
- 	auto d1 = yyjson_obj_get(root, "d1");
 
- 	auto d2 = yyjson_obj_get(root, "d2");
 
- 	if (yyjson_is_arr(t) == false || yyjson_is_arr(d0) == false || yyjson_is_arr(d1) == false || yyjson_is_arr(d2) == false)
 
- 	{
 
- 		msg = "参考曲线存储格式错误";
 
- 		yyjson_doc_free(doc);
 
- 		doc = nullptr;
 
- 		return 500;
 
- 	}
 
- 	auto obj1 = yyjson_mut_obj(mut_doc);
 
- 	auto obj2 = yyjson_mut_obj(mut_doc);
 
- 	auto obj3 = yyjson_mut_obj(mut_doc);
 
- 	yyjson_mut_arr_add_val(arr, obj1);
 
- 	yyjson_mut_arr_add_val(arr, obj2);
 
- 	yyjson_mut_arr_add_val(arr, obj3);
 
- 	auto data1 = yyjson_mut_arr(mut_doc);
 
- 	auto data2 = yyjson_mut_arr(mut_doc);
 
- 	auto data3 = yyjson_mut_arr(mut_doc);
 
- 	yyjson_mut_obj_add_val(mut_doc, obj1, "data", data1);
 
- 	yyjson_mut_obj_add_val(mut_doc, obj2, "data", data2);
 
- 	yyjson_mut_obj_add_val(mut_doc, obj3, "data", data3);
 
- 	yyjson_mut_obj_add_val(mut_doc, obj1, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name0")));
 
- 	yyjson_mut_obj_add_val(mut_doc, obj2, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name1")));
 
- 	yyjson_mut_obj_add_val(mut_doc, obj3, "name", yyjson_val_mut_copy(mut_doc, yyjson_obj_get(root, "name2")));
 
- 	int n = yyjson_arr_size(t);
 
- 	auto it_t = yyjson_arr_get_first(t);
 
- 	auto it_d0 = yyjson_arr_get_first(d0);
 
- 	auto it_d1 = yyjson_arr_get_first(d1);
 
- 	auto it_d2 = yyjson_arr_get_first(d2);
 
- 	for (int i = 0; i < n; i++)
 
- 	{
 
- 		//按双数组的形式添加
 
- 		auto o1 = yyjson_mut_arr(mut_doc);
 
- 		yyjson_mut_arr_add_val(data1, o1);
 
- 		auto o2 = yyjson_mut_arr(mut_doc);
 
- 		yyjson_mut_arr_add_val(data2, o2);
 
- 		auto o3 = yyjson_mut_arr(mut_doc);
 
- 		yyjson_mut_arr_add_val(data3, o3);
 
- 		auto t = yyjson_get_int(it_t) + show_time;
 
- 		yyjson_mut_arr_add_int(mut_doc, o1, t);
 
- 		yyjson_mut_arr_add_int(mut_doc, o2, t);
 
- 		yyjson_mut_arr_add_int(mut_doc, o3, t);
 
- 		yyjson_mut_arr_add_int(mut_doc, o1, yyjson_get_int(it_d0));
 
- 		yyjson_mut_arr_add_int(mut_doc, o2, yyjson_get_int(it_d1));
 
- 		yyjson_mut_arr_add_int(mut_doc, o3, yyjson_get_int(it_d2));
 
- 		it_t = unsafe_yyjson_get_next(it_t);
 
- 		it_d0 = unsafe_yyjson_get_next(it_d0);
 
- 		it_d1 = unsafe_yyjson_get_next(it_d1);
 
- 		it_d2 = unsafe_yyjson_get_next(it_d2);
 
- 	}
 
- 	yyjson_doc_free(doc);
 
- 	doc = nullptr;
 
- 	msg = "读取成功";
 
- 	return 200;
 
- }
 
- int DealGetTemp(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string starttime = req.get_param_value("starttime");
 
- 	string mo = req.get_param_value("mo");
 
- 	string mp = req.get_param_value("mp");
 
- 	string endtime = req.get_param_value("endtime");
 
- 	if (starttime.length() == 0 || mo.length() == 0 || endtime.length() == 0 || mp.length() == 0)
 
- 		return 400;
 
- 	int code = 500;
 
- 	static auto sz_temp = ANSItoUTF8("温度");
 
- 	static auto sz_unit = ANSItoUTF8("℃");
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	yyjson_mut_obj_add_str(doc, root, "name", sz_temp.c_str());
 
- 	yyjson_mut_obj_add_str(doc, root, "ValueSuffix", sz_unit.c_str());
 
- 	auto data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "data", data);
 
- 	do
 
- 	{
 
- 		int year, month, day;
 
- 		auto num = sscanf_s(starttime.c_str(), "%d-%d-%d ", &year, &month, &day);
 
- 		if (num != 3) break;
 
- 		CString sql = fmt::format(" SELECT TOP 100000 [acquisitiontime],[temperature] FROM rm_temphumidity_{}{:0>2} \
 
- 			WHERE mo='{}' AND mp='{}' AND acquisitiontime >= '{}' AND acquisitiontime < '{}' ORDER BY acquisitiontime ", year, month, mo, mp, starttime, endtime).c_str();
 
- 		COdbcStatement stmt;
 
- 		if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
 
- 			break;
 
- 		TIMESTAMP_STRUCT ts;
 
- 		int temp;
 
- 		stmt.BindTimeStampCol(1, &ts);
 
- 		stmt.BindIntCol(2, &temp);
 
- 		while (true)
 
- 		{
 
- 			if (stmt.FetchNext() != 0)
 
- 				break;
 
- 			auto arr = yyjson_mut_arr(doc);
 
- 			yyjson_mut_arr_add_val(data, arr);
 
- 			yyjson_mut_arr_add_uint(doc, arr, CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction);
 
- 			yyjson_mut_arr_add_strcpy(doc, arr, fmt::format("{:.1f}", temp / 100.0).c_str());
 
- 		}
 
- 		code = 200;
 
- 	} while (false);
 
- 	*json = yyjson_mut_write(doc, 0, json_len);
 
- 	yyjson_mut_doc_free(doc);
 
- 	return code;
 
- }
 
- int DealGetTempHumi(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string starttime = req.get_param_value("starttime");
 
- 	string mo = req.get_param_value("mo");
 
- 	string mp = req.get_param_value("mp");
 
- 	string endtime = req.get_param_value("endtime");
 
- 	if (starttime.length() == 0 || mo.length() == 0 || endtime.length() == 0 || mp.length() == 0)
 
- 		return 400;
 
- 	int code = 500;
 
- 	static auto sz_temp = ANSItoUTF8("温度");
 
- 	static auto sz_humi = ANSItoUTF8("湿度");
 
- 	static auto sz_unit = ANSItoUTF8("℃");
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	yyjson_mut_obj_add_int(doc, root, "total", 2);
 
- 	auto rows = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "rows", rows);
 
- 	auto temp_curve = yyjson_mut_obj(doc);
 
- 	auto humi_curve = yyjson_mut_obj(doc);
 
- 	yyjson_mut_arr_add_val(rows, temp_curve);
 
- 	yyjson_mut_arr_add_val(rows, humi_curve);
 
- 	yyjson_mut_obj_add_int(doc, temp_curve, "yAxis", 0);
 
- 	yyjson_mut_obj_add_int(doc, humi_curve, "yAxis", 1);
 
- 	yyjson_mut_obj_add_str(doc, temp_curve, "name", sz_temp.c_str());
 
- 	yyjson_mut_obj_add_str(doc, humi_curve, "name", sz_humi.c_str());
 
- 	yyjson_mut_obj_add_str(doc, temp_curve, "ValueSuffix", sz_unit.c_str());
 
- 	yyjson_mut_obj_add_str(doc, humi_curve, "ValueSuffix", "%");
 
- 	auto temp_data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, temp_curve, "data", temp_data);
 
- 	auto humi_data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, humi_curve, "data", humi_data);
 
- 	do
 
- 	{
 
- 		int year, month, day;
 
- 		auto num = sscanf_s(starttime.c_str(), "%d-%d-%d ", &year, &month, &day);
 
- 		if (num != 3) break;
 
- 		CString sql = fmt::format(" SELECT TOP 100000 [acquisitiontime],[temperature],[humidity] FROM rm_temphumidity_{}{:0>2} \
 
- 			WHERE mo='{}' AND mp='{}' AND acquisitiontime >= '{}' AND acquisitiontime < '{}' ORDER BY acquisitiontime ", year, month, mo, mp, starttime, endtime).c_str();
 
- 		COdbcStatement stmt;
 
- 		if (!CDBConnectPool::Instance()->DBQuery(stmt, sql))
 
- 			break;
 
- 		TIMESTAMP_STRUCT ts;
 
- 		int temp, humi;
 
- 		stmt.BindTimeStampCol(1, &ts);
 
- 		stmt.BindIntCol(2, &temp);
 
- 		stmt.BindIntCol(3, &humi);
 
- 		while (true)
 
- 		{
 
- 			if (stmt.FetchNext() != 0)
 
- 				break;
 
- 			uint64_t t = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second).GetTime() * 1000 + ts.fraction;
 
- 			{
 
- 				auto arr = yyjson_mut_arr(doc);
 
- 				yyjson_mut_arr_add_val(temp_data, arr);
 
- 				yyjson_mut_arr_add_uint(doc, arr, t);
 
- 				yyjson_mut_arr_add_strcpy(doc, arr, fmt::format("{:.1f}", temp / 100.0).c_str());
 
- 			}
 
- 			{
 
- 				auto arr = yyjson_mut_arr(doc);
 
- 				yyjson_mut_arr_add_val(humi_data, arr);
 
- 				yyjson_mut_arr_add_uint(doc, arr, t);
 
- 				yyjson_mut_arr_add_int(doc, arr, humi / 100);
 
- 			}
 
- 		}
 
- 		code = 200;
 
- 	} while (false);
 
- 	*json = yyjson_mut_write(doc, 0, json_len);
 
- 	yyjson_mut_doc_free(doc);
 
- 	return code;
 
- }
 
- //设置参考曲线
 
- int DealPostrefer_curve(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
 
- {
 
- 	return 403; //暂时屏蔽
 
- 	/*
 
- 	int code = 400;
 
- 	string msg;
 
- 	auto req_doc = yyjson_read(body_ptr, body_len, 0);
 
- 	if (req_doc == nullptr) return 400;
 
- 	auto req_root = yyjson_doc_get_root(req_doc);
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	do
 
- 	{
 
- 		auto station = yyjson_get_str(yyjson_obj_get(req_root, "station"));
 
- 		auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
 
- 		auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
 
- 		auto mo_name = yyjson_get_str(yyjson_obj_get(req_root, "mo_name"));
 
- 		auto mp_name = yyjson_get_str(yyjson_obj_get(req_root, "mp_name"));
 
- 		auto direct = yyjson_get_int(yyjson_obj_get(req_root, "direct"));
 
- 		auto show_time = yyjson_get_str(yyjson_obj_get(req_root, "show_time"));
 
- 		auto full_name = yyjson_get_str(yyjson_obj_get(req_root, "full_name"));
 
- 		if (station == nullptr || show_time == 0 || mo == nullptr || mp == nullptr || (direct != 3 && direct != 4) || full_name == nullptr
 
- 			|| mo_name == nullptr || mp_name == nullptr)
 
- 		{
 
- 			msg = "参数错误";
 
- 			break;
 
- 		}
 
- 		auto strStation = UTF8toANSI(station);
 
- 		auto strName = UTF8toANSI(full_name);
 
- 		time_t tt;
 
- 		time(&tt);
 
- 		auto len = strlen(show_time);
 
- 		if (len == 0) //取消参考曲线
 
- 		{
 
- 			auto strPath = CSimpleLog::GetAppDir() + "refer\\" +
 
- 				fmt::format("{}.{}.{}.{}.json", strStation, mo, mp, direct).c_str();
 
- 			if (CSimpleLog::PathFileExistsA(strPath))
 
- 				DeleteFile(strPath);
 
- 			ExecSqlForRecord(eRecord_Module::RM_REFER, 0, 0, strStation, strStation, mo, mo_name, mp, mp_name, 0, 0, tt, strName, "", eRocord_Opt::RO_CONFIG,
 
- 				fmt::format("用户[{}]取消了[{}.{}][{}]的参考曲线",  strName, mo_name, mp_name, direct == 3 ? "定扳反" : "反扳定"));
 
- 			msg = "操作成功.";
 
- 			code = 200;
 
- 			break;
 
- 		}
 
- 		int yy, mm, dd, hh, MM, SS, micromm;
 
- 		auto ret_num = sscanf_s(show_time, "%d-%d-%d %d:%d:%d.%d", &yy, &mm, &dd, &hh, &MM, &SS, µmm);
 
- 		if (ret_num != 7)
 
- 		{
 
- 			msg = "show_time参数错误";
 
- 			break;
 
- 		}
 
- 		CString sql = fmt::format("SELECT start_time,idx FROM rm_move_{:0>4}{:0>2}  WHERE mo = '{}' and mp = '{}' and show_time = '{}'",
 
- 			yy, mm, mo, mp, show_time).c_str();
 
- 		COdbcStatement stmt;
 
- 		if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
 
- 		{
 
- 			ASSERT(FALSE);
 
- 			msg = "语句执行失败:" + sql;
 
- 			code = 500;
 
- 			break;
 
- 		}
 
- 		TIMESTAMP_STRUCT ts = { 0 };
 
- 		uint8_t idx = -1;
 
- 		stmt.BindTimeStampCol(1, &ts);
 
- 		stmt.BindTinyIntCol(2, &idx);
 
- 		if (stmt.FetchNext() != 0)
 
- 		{
 
- 			msg = "查询转换记录失败";
 
- 			code = 500;
 
- 			break;
 
- 		}
 
- 		stmt.Close();
 
- 		string imei; int idx_2;
 
- 		if (CMonitorObjectMng::Instance()->MOMP2IMEI(string(mo), string(mp), imei, idx_2) == FALSE) 
 
- 		{
 
- 			msg = "查询imei失败";
 
- 			code = 500;
 
- 			break;
 
- 		}
 
- 		ASSERT(idx == idx_2);
 
- 		CTime ctStart(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
 
- 		CTime ctEnd = ctStart + CTimeSpan(0, 0, 0, 30);
 
- 		sql = fmt::format("  SELECT acquisitiontime,data0,data1,data2 FROM rm_resistance_{:0>4}{:0>2}{:0>2}\
 
- 			WHERE IMEI = '{}' AND acquisitiontime between '{}' and '{}' AND idx = {}",
 
- 			ts.year, ts.month, ts.day, imei, ctStart.Format("%Y-%m-%d %H:%M:%S"), ctEnd.Format("%Y-%m-%d %H:%M:%S"),idx
 
- 		).c_str();
 
- 		int sdata0, sdata1, sdata2;
 
- 		if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE)
 
- 		{
 
- 			ASSERT(FALSE);
 
- 			msg = "语句执行失败:" + sql;
 
- 			code = 500;
 
- 			break;
 
- 		}
 
- 		int nCol = 1;
 
- 		stmt.BindTimeStampCol(nCol++, &ts);
 
- 		stmt.BindIntCol(nCol++, &sdata0);
 
- 		stmt.BindIntCol(nCol++, &sdata1);
 
- 		stmt.BindIntCol(nCol++, &sdata2);
 
- 		int no = 0;
 
- 		std::map<time_t, int> data0, data1, data2;
 
- 		//time_t tmStart = ctStart.GetTime() * 1000; //存储数据时, 以起始时间为0
 
- 		time_t tmShowTime = CTime(yy, mm, dd, hh, MM, SS).GetTime() * 1000 + micromm;
 
- 		do
 
- 		{
 
- 			if (stmt.FetchNext() != 0)
 
- 				break;
 
- 			no++;
 
- 			CTime ctTime;
 
- 			try
 
- 			{
 
- 				ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
 
- 			}
 
- 			catch (...)
 
- 			{
 
- 				continue;
 
- 			}
 
- 			time_t tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000 - tmShowTime;
 
- 			data0[tm] = sdata0;
 
- 			data1[tm] = sdata1;
 
- 			data2[tm] = sdata2;
 
- 		} while (true);
 
- 		stmt.Close();
 
- 		if (no == 0)
 
- 		{
 
- 			msg = "数据为空";
 
- 			code = 500;
 
- 			break;
 
- 		}
 
- 		//存储数据
 
- 		code = WriteReferFile(strStation, mo, mp, direct, data0, data1, data2, msg);
 
- 		ExecSqlForRecord(eRecord_Module::RM_REFER, 0, 0, strStation, strStation, mo, mo_name, mp, mp_name, 0, 0, tt, strName, "", eRocord_Opt::RO_CONFIG,
 
- 			fmt::format("用户[{}]设置了[{}.{}][{}]的参考曲线", strName, mo_name, mp_name, direct == 3 ? "定扳反" : "反扳定"));
 
- 	} while (false);
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str());
 
- 	yyjson_mut_obj_add_int(doc, root, "code", code);
 
- 	if (json) *json = yyjson_mut_write(doc, 0, json_len);
 
- 	yyjson_doc_free(req_doc);
 
- 	yyjson_mut_doc_free(doc);
 
- 	return code;*/
 
- }
 
- int WriteReferFile(const string& station, const string& mo, const string& mp, uint8_t posi, 
 
- 	const std::map<time_t, int>& data0, const std::map<time_t, int>& data1, const std::map<time_t, int>& data2, OUT string& msg)
 
- {
 
- 	string strJsonPath = fmt::format("{}refer\\{}.{}.{}.{}.json", CSimpleLog::GetAppDir(), station, mo, mp, posi);
 
- 	string name1, name2, name3, out_name, in_name;
 
- 	CMonitorObjectMng::Instance()->GetNameByMoMp(mo + "." + mp, name1, name2, name3, out_name, in_name);
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "station", ANSItoUTF8(station).c_str());
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "mo", mo.c_str());
 
- 	yyjson_mut_obj_add_strcpy(doc, root, "mp", mp.c_str());
 
- 	yyjson_mut_obj_add_int(doc, root, "posi", posi);
 
- 	auto t = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "t", t);
 
- 	auto d0 = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "d0", d0);
 
- 	auto d1 = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "d1", d1);
 
- 	auto d2 = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "d2", d2);
 
- 	if (name1.find("定位") != -1)
 
- 	{
 
- 		yyjson_mut_obj_add_strcpy(doc, root, "name0", ANSItoUTF8("定位参考曲线").c_str());
 
- 		yyjson_mut_obj_add_strcpy(doc, root, "name1", ANSItoUTF8("反位参考曲线").c_str());
 
- 		yyjson_mut_obj_add_strcpy(doc, root, "name2", ANSItoUTF8("转换参考曲线").c_str());
 
- 	}
 
- 	else
 
- 	{
 
- 		yyjson_mut_obj_add_strcpy(doc, root, "name0", ANSItoUTF8("反位参考曲线").c_str());
 
- 		yyjson_mut_obj_add_strcpy(doc, root, "name1", ANSItoUTF8("定位参考曲线").c_str());
 
- 		yyjson_mut_obj_add_strcpy(doc, root, "name2", ANSItoUTF8("转换参考曲线").c_str());
 
- 	}
 
- 	for (auto& it : data0)
 
- 	{
 
- 		yyjson_mut_arr_add_int(doc, t, it.first);
 
- 		yyjson_mut_arr_add_int(doc, d0, it.second);
 
- 	}
 
- 	for (auto& it : data1)
 
- 		yyjson_mut_arr_add_int(doc, d1, it.second);
 
- 	for (auto& it : data2)
 
- 		yyjson_mut_arr_add_int(doc, d2, it.second);
 
- 	yyjson_write_err err;
 
- 	auto ret = yyjson_mut_write_file(strJsonPath.c_str(), doc, 0, nullptr, &err);
 
- 	if (ret == false)
 
- 	{
 
- 		msg = fmt::format("写入文件错误:{} 错误码:{}", strJsonPath, err.msg);
 
- 		CSimpleLog::Error(msg.c_str());
 
- 		return 500;
 
- 	}
 
- 	msg = "处理成功.";
 
- 	return 200;
 
- }
 
- int DealGetResistCurve(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string mo = req.get_param_value("mo");
 
- 	string mp = req.get_param_value("mp");
 
- 	string time = req.get_param_value("time");
 
- 	string name = req.get_param_value("name");
 
- 	if (mo.length() == 0 || mp.length() == 0 || time.length() == 0 || name.length() == 0)
 
- 		return 400;
 
- 	time_t uTime = atoll(time.c_str());
 
- 	COleDateTime odt(uTime);
 
- 	if (odt.GetStatus() == COleDateTime::invalid)
 
- 		return 400;
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	auto convert_resist = yyjson_mut_obj(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "convert_resist", convert_resist);//转换阻力
 
- 	auto suobi_lock = yyjson_mut_obj(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "suobi_lock", suobi_lock);//锁闭力数据
 
- 	yyjson_mut_obj_add_str(doc, root, "name", name.c_str());
 
- 	yyjson_mut_obj_add_str(doc, root, "unit", "N");
 
- 	yyjson_mut_obj_add_uint(doc, root, "time", uTime);
 
- 	//title
 
- 	yyjson_mut_obj_add_strcpy(doc, convert_resist, "title", ANSItoUTF8("转换阻力峰值统计图").c_str());
 
- 	yyjson_mut_obj_add_strcpy(doc, suobi_lock, "title", ANSItoUTF8("定反位锁闭力值统计图").c_str());
 
- 	//curve_data and line
 
- 	auto convert_curve_data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, convert_resist, "curve_data", convert_curve_data);
 
- 	auto suobi_curve_data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, suobi_lock, "curve_data", suobi_curve_data);
 
- 	auto convert_line = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, convert_resist, "line", convert_line);
 
- 	auto suobi_line = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, suobi_lock, "line", suobi_line);
 
- 	//curve_obj
 
- 	auto d_convert_obj = yyjson_mut_obj(doc);
 
- 	yyjson_mut_obj_add_strcpy(doc, d_convert_obj, "name", ANSItoUTF8("定扳反转换阻力峰值").c_str());
 
- 	yyjson_mut_obj_add_str(doc, d_convert_obj, "color", "#a8ff78");// 苹果绿
 
- 	yyjson_mut_arr_add_val(convert_curve_data, d_convert_obj);
 
- 	auto f_convert_obj = yyjson_mut_obj(doc);
 
- 	yyjson_mut_obj_add_strcpy(doc, f_convert_obj, "name", ANSItoUTF8("反扳定转换阻力峰值").c_str());
 
- 	yyjson_mut_obj_add_str(doc, f_convert_obj, "color", "#FFE000");// 芒果黄
 
- 	yyjson_mut_arr_add_val(convert_curve_data, f_convert_obj);
 
- 	auto d_suobi_obj = yyjson_mut_obj(doc);
 
- 	yyjson_mut_obj_add_strcpy(doc, d_suobi_obj, "name", ANSItoUTF8("定位锁闭力值").c_str());
 
- 	yyjson_mut_obj_add_str(doc, d_suobi_obj, "color", "#a8ff78");// 苹果绿
 
- 	yyjson_mut_arr_add_val(suobi_curve_data, d_suobi_obj);
 
- 	auto f_suobi_obj = yyjson_mut_obj(doc);
 
- 	yyjson_mut_obj_add_strcpy(doc, f_suobi_obj, "name", ANSItoUTF8("反位锁闭力值").c_str());
 
- 	yyjson_mut_obj_add_str(doc, f_suobi_obj, "color", "#FFE000");// 芒果黄
 
- 	yyjson_mut_arr_add_val(suobi_curve_data, f_suobi_obj);
 
- 	//curve_data
 
- 	auto d_convert_data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, d_convert_obj, "data", d_convert_data);
 
- 	auto f_convert_data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, f_convert_obj, "data", f_convert_data);
 
- 	auto d_suobi_data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, d_suobi_obj, "data", d_suobi_data);
 
- 	auto f_suobi_data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, f_suobi_obj, "data", f_suobi_data);
 
- 	//query
 
- 	//查询数据库 填充 d_convert_data f_convert_data d_suobi_data f_suobi_data
 
- 	{
 
- 		string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
 
- 		CString sql = fmt::format("SELECT show_time,show_val,posi FROM {} WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}'", 
 
- 			table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), odt.Format("%Y-%m-%d 23:59:59.999")).c_str();
 
- 		COdbcStatement stmt;
 
- 		if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
 
- 		{
 
- 			int nCol = 1;
 
- 			TIMESTAMP_STRUCT ts;
 
- 			int show_val;
 
- 			eDaoChaPosi posi;
 
- 			stmt.BindTimeStampCol(nCol++, &ts);
 
- 			stmt.BindIntCol(nCol++, &show_val);
 
- 			stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
 
- 			do 
 
- 			{
 
- 				if (stmt.FetchNext() != 0)
 
- 					break;
 
- 				CTime ctTime;
 
- 				try
 
- 				{
 
- 					ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
 
- 				}
 
- 				catch (...)
 
- 				{
 
- 					continue;
 
- 				}
 
- 				time_t tt = ctTime.GetTime() * 1000 + ts.fraction / 1000000;
 
- 				auto o = yyjson_mut_arr(doc);
 
- 				yyjson_mut_arr_add_int(doc, o, tt);
 
- 				yyjson_mut_arr_add_int(doc, o, show_val);
 
- 				switch (posi)
 
- 				{
 
- 				case eDaoChaPosi::DCP_FIX:
 
- 					yyjson_mut_arr_add_val(d_suobi_data, o);
 
- 					break;
 
- 				case eDaoChaPosi::DCP_INVERT:
 
- 					yyjson_mut_arr_add_val(f_suobi_data, o);
 
- 					break;
 
- 				case eDaoChaPosi::DCP_FIX2INVERT:
 
- 					yyjson_mut_arr_add_val(d_convert_data, o);
 
- 					break;
 
- 				case eDaoChaPosi::DCP_INVERT2FIX:
 
- 					yyjson_mut_arr_add_val(f_convert_data, o);
 
- 					break;
 
- 				default:
 
- 					ASSERT(FALSE);
 
- 					break;
 
- 				}
 
- 			} while (TRUE);
 
- 		}
 
- 		stmt.Close();
 
- 	}
 
- 	//line 
 
- 	{
 
- 		//转换阻力报警线
 
- 		CONVERT_RESIST_OVER_LIMIT* pInfo = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
 
- 		if (pInfo && pInfo->enable)
 
- 		{
 
- 			if (pInfo->dw_warn_low_limit > INT_MIN)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(convert_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_warn_low_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 			}
 
- 			if (pInfo->up_warn_high_limit < INT_MAX)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(convert_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->up_warn_high_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 			}
 
- 			if (pInfo->dw_alarm_low_limit > INT_MIN)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(convert_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->dw_alarm_low_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Red");
 
- 			}
 
- 			if (pInfo->up_alarm_high_limit < INT_MAX)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(convert_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->up_alarm_high_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Red");
 
- 			}
 
- 		}
 
- 	}
 
- 	{
 
- 		//锁闭力报警线
 
- 		SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, -1, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
 
- 		if (pInfo && pInfo->enable)
 
- 		{
 
- 			if (pInfo->warn_low_limit > INT_MIN)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 			}
 
- 			if (pInfo->warn_high_limit < INT_MAX)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("预警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 			}
 
- 			if (pInfo->alarm_low_limit > INT_MIN)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Red");
 
- 			}
 
- 			if (pInfo->alarm_high_limit < INT_MAX)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("告警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Red");
 
- 			}
 
- 		}
 
- 	}
 
- 	{
 
- 		//定位锁闭力报警线
 
- 		SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
 
- 		if (pInfo && pInfo->enable)
 
- 		{
 
- 			if (pInfo->warn_low_limit > INT_MIN)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位预警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 			}
 
- 			if (pInfo->warn_high_limit < INT_MAX)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位预警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 			}
 
- 			if (pInfo->alarm_low_limit > INT_MIN)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Red");
 
- 			}
 
- 			if (pInfo->alarm_high_limit < INT_MAX)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("定位告警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Red");
 
- 			}
 
- 		}
 
- 	}
 
- 	{
 
- 		//反位锁闭力报警线
 
- 		SUOBI_OVER_LIMIT_INFO* pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
 
- 		if (pInfo && pInfo->enable)
 
- 		{
 
- 			if (pInfo->warn_low_limit > INT_MIN)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位预警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_low_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 			}
 
- 			if (pInfo->warn_high_limit < INT_MAX)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位预警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->warn_high_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 			}
 
- 			if (pInfo->alarm_low_limit > INT_MIN)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_low_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Red");
 
- 			}
 
- 			if (pInfo->alarm_high_limit < INT_MAX)
 
- 			{
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				yyjson_mut_arr_add_val(suobi_line, obj);
 
- 				yyjson_mut_obj_add_strcpy(doc, obj, "name", ANSItoUTF8("反位告警线").c_str());
 
- 				yyjson_mut_obj_add_int(doc, obj, "value", pInfo->alarm_high_limit);
 
- 				yyjson_mut_obj_add_str(doc, obj, "color", "Red");
 
- 			}
 
- 		}
 
- 	}
 
- 	*json = yyjson_mut_write(doc, 0, json_len);
 
- 	yyjson_mut_doc_free(doc);
 
- 	return 200;
 
- }
 
- int DealGetResistReport(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string station = req.get_param_value("station");
 
- 	string time = req.get_param_value("time");
 
- 	if (time.length() == 0 || station.length() == 0)
 
- 		return 400;
 
- 	time_t uTime = atoll(time.c_str());
 
- 	COleDateTime odt(uTime);
 
- 	if (odt.GetStatus() == COleDateTime::invalid)
 
- 		return 400;
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_arr(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	{
 
- 		string strStation = UTF8toANSI(station);
 
- 		string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth());
 
- 		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 \
 
- 			LEFT JOIN rm_mo AS B ON A.mo = B.id",
 
- 			table_name, strStation, odt.Format("%Y-%m-%d 00:00:00"), odt.Format("%Y-%m-%d 23:59:59.999")).c_str();
 
- 		//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
 
- 		COdbcStatement stmt;
 
- 		struct tagData
 
- 		{
 
- 			string mo_name;
 
- 			string mo;
 
- 			string mp;
 
- 			int d_convert_resist = INT_MAX;
 
- 			int d_convert_resist_max = INT_MAX;
 
- 			int d_convert_resist_min = INT_MAX;
 
- 			int d_convert_resist_avg = INT_MAX;
 
- 			uint8_t d_convert_resist_max_color = 0;   //0 为正常   1 为预警    2 为报警
 
- 			uint8_t d_convert_resist_min_color = 0;
 
- 			uint8_t d_convert_resist_avg_color = 0;
 
- 			int f_convert_resist = INT_MAX;
 
- 			int f_convert_resist_max = INT_MAX;
 
- 			int f_convert_resist_min = INT_MAX;
 
- 			int f_convert_resist_avg = INT_MAX;
 
- 			uint8_t f_convert_resist_max_color = 0;
 
- 			uint8_t f_convert_resist_min_color = 0;
 
- 			uint8_t f_convert_resist_avg_color = 0;
 
- 			int d_suobi_lock = INT_MAX;
 
- 			int d_suobi_lock_max = INT_MAX;
 
- 			int d_suobi_lock_min = INT_MAX;
 
- 			int d_suobi_lock_avg = INT_MAX;
 
- 			uint8_t d_suobi_lock_max_color = 0;
 
- 			uint8_t d_suobi_lock_min_color = 0;
 
- 			uint8_t d_suobi_lock_avg_color = 0;
 
- 			int f_suobi_lock = INT_MAX;
 
- 			int f_suobi_lock_max = INT_MAX;
 
- 			int f_suobi_lock_min = INT_MAX;
 
- 			int f_suobi_lock_avg = INT_MAX;
 
- 			uint8_t f_suobi_lock_max_color = 0;
 
- 			uint8_t f_suobi_lock_min_color = 0;
 
- 			uint8_t f_suobi_lock_avg_color = 0;
 
- 		};
 
- 		std::map<string, tagData> mapData;
 
- 		if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
 
- 		{
 
- 			int nCol = 1;
 
- 			char mo[50], mp[50], mo_name[50];
 
- 			int num;
 
- 			int max;
 
- 			int min;
 
- 			int64_t sum;
 
- 			eDaoChaPosi posi;
 
- 			stmt.BindCharCol(nCol++, mo, sizeof(mo));
 
- 			stmt.BindCharCol(nCol++, mp, sizeof(mp));
 
- 			stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
 
- 			stmt.BindIntCol(nCol++, &num);
 
- 			stmt.BindIntCol(nCol++, &max);
 
- 			stmt.BindIntCol(nCol++, &min);
 
- 			stmt.BindBigIntCol(nCol++, &sum);
 
- 			stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name));
 
- 			do
 
- 			{
 
- 				if (stmt.FetchNext() != 0)
 
- 					break;
 
- 				SUOBI_OVER_LIMIT_INFO* pInfo = nullptr;
 
- 				CONVERT_RESIST_OVER_LIMIT* pInfo2 = nullptr;
 
- 				auto& it = mapData[fmt::format("{}.{}", mo, mp)];
 
- 				it.mo_name = mo_name;
 
- 				it.mo = mo;
 
- 				it.mp = mp;
 
- 				eSuoBiPosi idx;
 
- 				switch (posi)
 
- 				{
 
- 				case eDaoChaPosi::DCP_FIX:
 
- 					it.d_suobi_lock = num;
 
- 					it.d_suobi_lock_max = max;
 
- 					it.d_suobi_lock_min = min;
 
- 					if (num) it.d_suobi_lock_avg = sum / num;
 
- 					idx = eSuoBiPosi::SB_FIX;
 
- 					pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)idx, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
 
- 					if (pInfo && pInfo->enable)
 
- 					{
 
- 						if (max > pInfo->alarm_high_limit)
 
- 							it.d_suobi_lock_max_color = UINT8_ALARM;
 
- 						else if (max > pInfo->warn_high_limit)
 
- 							it.d_suobi_lock_max_color = UINT8_WARN;
 
- 						if (min < pInfo->alarm_low_limit)
 
- 							it.d_suobi_lock_min_color = UINT8_ALARM;
 
- 						else if (min < pInfo->warn_low_limit)
 
- 							it.d_suobi_lock_min_color = UINT8_WARN;
 
- 						if (num && (it.d_suobi_lock_avg > pInfo->alarm_high_limit || it.d_suobi_lock_avg < pInfo->alarm_low_limit))
 
- 							it.d_suobi_lock_avg_color = UINT8_ALARM;
 
- 						else if (num && (it.d_suobi_lock_avg > pInfo->warn_high_limit || it.d_suobi_lock_avg < pInfo->warn_low_limit))
 
- 							it.d_suobi_lock_avg_color = UINT8_WARN;
 
- 					}
 
- 					break;
 
- 				case eDaoChaPosi::DCP_INVERT:
 
- 					it.f_suobi_lock = num;
 
- 					it.f_suobi_lock_max = max;
 
- 					it.f_suobi_lock_min = min;
 
- 					if (num) it.f_suobi_lock_avg = sum / num;
 
- 					idx = eSuoBiPosi::SB_INVERT;
 
- 					pInfo = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)idx, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT);
 
- 					if (pInfo && pInfo->enable)
 
- 					{
 
- 						if (max > pInfo->alarm_high_limit)
 
- 							it.f_suobi_lock_max_color = UINT8_ALARM;
 
- 						else if (max > pInfo->warn_high_limit)
 
- 							it.f_suobi_lock_max_color = UINT8_WARN;
 
- 						if (min < pInfo->alarm_low_limit)
 
- 							it.f_suobi_lock_min_color = UINT8_ALARM;
 
- 						else if (min < pInfo->warn_low_limit)
 
- 							it.f_suobi_lock_min_color = UINT8_WARN;
 
- 						if (num && (it.f_suobi_lock_avg > pInfo->alarm_high_limit || it.f_suobi_lock_avg < pInfo->alarm_low_limit))
 
- 							it.f_suobi_lock_avg_color = UINT8_ALARM;
 
- 						else if (num && (it.f_suobi_lock_avg > pInfo->warn_high_limit || it.f_suobi_lock_avg < pInfo->warn_low_limit))
 
- 							it.f_suobi_lock_avg_color = UINT8_WARN;
 
- 					}
 
- 					break;
 
- 				case eDaoChaPosi::DCP_FIX2INVERT:
 
- 					it.d_convert_resist = num;
 
- 					it.d_convert_resist_max = max;
 
- 					it.d_convert_resist_min = min;
 
- 					if (num) it.d_convert_resist_avg = sum / num;
 
- 					pInfo2 = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
 
- 					if (pInfo2 && pInfo2->enable)
 
- 					{
 
- 						string name1, name2, name3, out_name, in_name;
 
- 						CMonitorObjectMng::Instance()->GetNameByMoMp(fmt::format("{}.{}", mo, mp), name1, name2, name3, out_name, in_name);
 
- 						if (in_name.find("定扳反") == -1) //如果缩进不是定扳反, 那就是伸出
 
- 						{
 
- 							if (max > pInfo2->dw_alarm_low_limit)
 
- 								it.d_convert_resist_max_color = UINT8_ALARM;
 
- 							else if (max > pInfo2->dw_warn_low_limit)
 
- 								it.d_convert_resist_max_color = UINT8_WARN;
 
- 							if (num && it.d_convert_resist_avg > pInfo2->dw_alarm_low_limit)
 
- 								it.d_convert_resist_avg_color = UINT8_ALARM;
 
- 							else if (num && it.d_convert_resist_avg > pInfo2->dw_warn_low_limit)
 
- 								it.d_convert_resist_avg_color = UINT8_WARN;
 
- 						}
 
- 						else
 
- 						{
 
- 							if (max > pInfo2->up_alarm_high_limit)
 
- 								it.d_convert_resist_max_color = UINT8_ALARM;
 
- 							else if (max > pInfo2->up_warn_high_limit)
 
- 								it.d_convert_resist_max_color = UINT8_WARN;
 
- 							if (num && it.d_convert_resist_avg > pInfo2->up_alarm_high_limit)
 
- 								it.d_convert_resist_avg_color = UINT8_ALARM;
 
- 							else if (num && it.d_convert_resist_avg > pInfo2->up_warn_high_limit)
 
- 								it.d_convert_resist_avg_color = UINT8_WARN;
 
- 						}
 
- 					}
 
- 					break;
 
- 				case eDaoChaPosi::DCP_INVERT2FIX:
 
- 					it.f_convert_resist = num;
 
- 					it.f_convert_resist_max = max;
 
- 					it.f_convert_resist_min = min;
 
- 					if (num) it.f_convert_resist_avg = sum / num;
 
- 					pInfo2 = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT);
 
- 					if (pInfo2 && pInfo2->enable)
 
- 					{
 
- 						string name1, name2, name3, out_name, in_name;
 
- 						CMonitorObjectMng::Instance()->GetNameByMoMp(fmt::format("{}.{}", mo, mp), name1, name2, name3, out_name, in_name);
 
- 						if (in_name.find("反扳定") != -1) //如果反扳定是缩进
 
- 						{
 
- 							if (max > pInfo2->up_alarm_high_limit)
 
- 								it.f_convert_resist_max_color = UINT8_ALARM;
 
- 							else if (max > pInfo2->up_warn_high_limit)
 
- 								it.f_convert_resist_max_color = UINT8_WARN;
 
- 							if (num && it.f_convert_resist_avg > pInfo2->up_alarm_high_limit)
 
- 								it.f_convert_resist_avg_color = UINT8_ALARM;
 
- 							else if (num && it.f_convert_resist_avg > pInfo2->up_warn_high_limit)
 
- 								it.f_convert_resist_avg_color = UINT8_WARN;
 
- 						}
 
- 						else
 
- 						{
 
- 							if (max > pInfo2->dw_alarm_low_limit)
 
- 								it.f_convert_resist_max_color = UINT8_ALARM;
 
- 							else if (max > pInfo2->dw_warn_low_limit)
 
- 								it.f_convert_resist_max_color = UINT8_WARN;
 
- 							if (num && it.f_convert_resist_avg > pInfo2->dw_alarm_low_limit)
 
- 								it.f_convert_resist_avg_color = UINT8_ALARM;
 
- 							else if (num && it.f_convert_resist_avg > pInfo2->dw_warn_low_limit)
 
- 								it.f_convert_resist_avg_color = UINT8_WARN;
 
- 						}
 
- 					}
 
- 					break;
 
- 				default:
 
- 					ASSERT(FALSE);
 
- 					break;
 
- 				}
 
- 			} while (TRUE);
 
- 		}
 
- 		stmt.Close();
 
- 		for (auto& it : mapData)
 
- 		{
 
- 			auto obj = yyjson_mut_obj(doc);
 
- 			yyjson_mut_arr_add_val(root, obj);
 
- 			yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", ANSItoUTF8(it.second.mo_name).c_str());
 
- 			yyjson_mut_obj_add_strcpy(doc, obj, "mo", it.second.mo.c_str());
 
- 			yyjson_mut_obj_add_strcpy(doc, obj, "mp", it.second.mp.c_str());
 
- 			if (it.second.d_convert_resist != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "d_convert_resist", it.second.d_convert_resist);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist", "-");
 
- 			if (it.second.d_convert_resist_max != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_max", it.second.d_convert_resist_max);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max", "-");
 
- 			if (it.second.d_convert_resist_min != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_min", it.second.d_convert_resist_min);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min", "-");
 
- 			if (it.second.d_convert_resist_avg != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "d_convert_resist_avg", it.second.d_convert_resist_avg);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg", "-");
 
- 			//颜色
 
- 			if (it.second.d_convert_resist_max_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max_color", "red");
 
- 			else if (it.second.d_convert_resist_max_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_max_color", "orange");
 
- 			if (it.second.d_convert_resist_min_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min_color", "red");
 
- 			else if (it.second.d_convert_resist_min_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_min_color", "orange");
 
- 			if (it.second.d_convert_resist_avg_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg_color", "red");
 
- 			else if (it.second.d_convert_resist_avg_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_convert_resist_avg_color", "orange");
 
- 			if (it.second.f_convert_resist != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "f_convert_resist", it.second.f_convert_resist);
 
- 			else 
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist", "-");
 
- 			if (it.second.f_convert_resist_max != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_max", it.second.f_convert_resist_max);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max", "-");
 
- 			if (it.second.f_convert_resist_min != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_min", it.second.f_convert_resist_min);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min", "-");
 
- 			if (it.second.f_convert_resist_avg != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "f_convert_resist_avg", it.second.f_convert_resist_avg);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg", "-");
 
- 			//颜色
 
- 			if (it.second.f_convert_resist_max_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max_color", "red");
 
- 			else if (it.second.f_convert_resist_max_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_max_color", "orange");
 
- 			if (it.second.f_convert_resist_min_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min_color", "red");
 
- 			else if (it.second.f_convert_resist_min_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_min_color", "orange");
 
- 			if (it.second.f_convert_resist_avg_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg_color", "red");
 
- 			else if (it.second.f_convert_resist_avg_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_convert_resist_avg_color", "orange");
 
- 			if (it.second.d_suobi_lock != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock", it.second.d_suobi_lock);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock", "-");
 
- 			if (it.second.d_suobi_lock_max != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_max", it.second.d_suobi_lock_max);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max", "-");
 
- 			if (it.second.d_suobi_lock_min != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_min", it.second.d_suobi_lock_min);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min", "-");
 
- 			if (it.second.d_suobi_lock_avg != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "d_suobi_lock_avg", it.second.d_suobi_lock_avg);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg", "-");
 
- 			//颜色
 
- 			if (it.second.d_suobi_lock_max_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max_color", "red");
 
- 			else if (it.second.d_suobi_lock_max_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_max_color", "orange");
 
- 			if (it.second.d_suobi_lock_min_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min_color", "red");
 
- 			else if (it.second.d_suobi_lock_min_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_min_color", "orange");
 
- 			if (it.second.d_suobi_lock_avg_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg_color", "red");
 
- 			else if (it.second.d_suobi_lock_avg_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "d_suobi_lock_avg_color", "orange");
 
- 			if (it.second.f_suobi_lock != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock", it.second.f_suobi_lock);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock", "-");
 
- 			if (it.second.f_suobi_lock_max != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_max", it.second.f_suobi_lock_max);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max", "-");
 
- 			if (it.second.f_suobi_lock_min!= INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_min", it.second.f_suobi_lock_min);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min", "-");
 
- 			if (it.second.f_suobi_lock_avg != INT_MAX)
 
- 				yyjson_mut_obj_add_int(doc, obj, "f_suobi_lock_avg", it.second.f_suobi_lock_avg);
 
- 			else
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg", "-");
 
- 			//颜色
 
- 			if (it.second.f_suobi_lock_max_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max_color", "red");
 
- 			else if (it.second.f_suobi_lock_max_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_max_color", "orange");
 
- 			if (it.second.f_suobi_lock_min_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min_color", "red");
 
- 			else if (it.second.f_suobi_lock_min_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_min_color", "orange");
 
- 			if (it.second.f_suobi_lock_avg_color == UINT8_ALARM)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg_color", "red");
 
- 			else if (it.second.f_suobi_lock_avg_color == UINT8_WARN)
 
- 				yyjson_mut_obj_add_str(doc, obj, "f_suobi_lock_avg_color", "orange");
 
- 		}
 
- 	}
 
- 	*json = yyjson_mut_write(doc, 0, json_len);
 
- 	yyjson_mut_doc_free(doc);
 
- 	return 200;
 
- }
 
- int DealGetMoveInfo(const httplib::Request& req, const string token, char** json, size_t* json_len)
 
- {
 
- 	string mo = req.get_param_value("mo");
 
- 	string mp = req.get_param_value("mp");
 
- 	string start_time = req.get_param_value("start_time");
 
- 	string end_time = req.get_param_value("end_time");
 
- 	if (mo.length() == 0 || mp.length() == 0 || start_time.length() == 0 || end_time.length() == 0)
 
- 		return 400;
 
- 	auto doc = yyjson_mut_doc_new(nullptr);
 
- 	auto root = yyjson_mut_obj(doc);
 
- 	yyjson_mut_doc_set_root(doc, root);
 
- 	auto data = yyjson_mut_arr(doc);
 
- 	yyjson_mut_obj_add_val(doc, root, "data", data);
 
- 	COleDateTime odtStart, odtEnd;
 
- 	do {
 
- 		auto ret_time = odtEnd.ParseDateTime(end_time.c_str());
 
- 		if (ret_time == FALSE)
 
- 			break;
 
- 		ret_time = odtStart.ParseDateTime(start_time.c_str());
 
- 		if (ret_time == FALSE)
 
- 			break;
 
- 		if (odtEnd <= odtStart)
 
- 			break;
 
- 		auto fix_object = yyjson_mut_obj(doc);
 
- 		yyjson_mut_arr_add_val(data, fix_object);
 
- 		auto invert_object = yyjson_mut_obj(doc);
 
- 		yyjson_mut_arr_add_val(data, invert_object);
 
- 		auto convert_object = yyjson_mut_obj(doc);
 
- 		yyjson_mut_arr_add_val(data, convert_object);
 
- 		static string fix_name = ANSItoUTF8("定位测力曲线");
 
- 		yyjson_mut_obj_add_str(doc, fix_object, "name", fix_name.c_str());
 
- 		static string invert_name = ANSItoUTF8("反位测力曲线");
 
- 		yyjson_mut_obj_add_str(doc, invert_object, "name", invert_name.c_str());
 
- 		static string convert_name = ANSItoUTF8("转换阻力曲线");
 
- 		yyjson_mut_obj_add_str(doc, convert_object, "name", convert_name.c_str());
 
- 		static string lock_low = ANSItoUTF8("锁闭力过低");
 
- 		auto fix_points = yyjson_mut_arr(doc);
 
- 		yyjson_mut_obj_add_val(doc, fix_object, "mark_points", fix_points);
 
- 		auto invert_points = yyjson_mut_arr(doc);
 
- 		yyjson_mut_obj_add_val(doc, invert_object, "mark_points", invert_points);
 
- 		auto convert_points = yyjson_mut_arr(doc);
 
- 		yyjson_mut_obj_add_val(doc, convert_object, "mark_points", convert_points);
 
- 		string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odtStart.GetYear(), odtStart.GetMonth());
 
- 		CString sql = fmt::format("SELECT show_time, curr_val, show_val, posi, mark FROM {} \
 
- 			WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' order by posi, show_time", 
 
- 			table_name, mo, mp, start_time, end_time).c_str();
 
- 		COdbcStatement stmt;
 
- 		if (CDBConnectPool::Instance()->DBQuery(stmt, sql))
 
- 		{
 
- 			TIMESTAMP_STRUCT ts;
 
- 			int curr_val;
 
- 			int show_val;
 
- 			eDaoChaPosi posi;
 
- 			char mark[200];
 
- 			int nCol = 1;
 
- 			stmt.BindTimeStampCol(nCol++, &ts);
 
- 			stmt.BindIntCol(nCol++, &curr_val);
 
- 			stmt.BindIntCol(nCol++, &show_val);
 
- 			stmt.BindTinyIntCol(nCol++, (BYTE*)&posi);
 
- 			stmt.BindCharCol(nCol++, mark, sizeof(mark));
 
- 			do
 
- 			{
 
- 				if (stmt.FetchNext() != 0)
 
- 					break;
 
- 				auto obj = yyjson_mut_obj(doc);
 
- 				switch (posi)
 
- 				{
 
- 				case eDaoChaPosi::DCP_FIX:
 
- 				{
 
- 					yyjson_mut_arr_add_val(fix_points, obj);
 
- 					auto coord = yyjson_mut_arr(doc);
 
- 					yyjson_mut_obj_add_val(doc, obj, "coord", coord);
 
- 					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);
 
- 					yyjson_mut_arr_add_int(doc, coord, curr_val);
 
- 					yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
 
- 						ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
 
- 					yyjson_mut_obj_add_int(doc, obj, "val", show_val);
 
- 					if (show_val < 500)
 
- 					{
 
- 						yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 						yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
 
- 					}
 
- 					else
 
- 					{
 
- 						yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
 
- 					}
 
- 				}
 
- 					break;
 
- 				case eDaoChaPosi::DCP_INVERT:
 
- 				{
 
- 					yyjson_mut_arr_add_val(invert_points, obj);
 
- 					auto coord = yyjson_mut_arr(doc);
 
- 					yyjson_mut_obj_add_val(doc, obj, "coord", coord);
 
- 					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);
 
- 					yyjson_mut_arr_add_int(doc, coord, curr_val);
 
- 					yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
 
- 						ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
 
- 					yyjson_mut_obj_add_int(doc, obj, "val", show_val);
 
- 					if (show_val < 500)
 
- 					{
 
- 						yyjson_mut_obj_add_str(doc, obj, "color", "Orange");
 
- 						yyjson_mut_obj_add_str(doc, obj, "label", lock_low.c_str());
 
- 					}
 
- 					else
 
- 					{
 
- 						yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str());
 
- 					}
 
- 				}
 
- 					break;
 
- 				case eDaoChaPosi::DCP_FIX2INVERT:
 
- 				{
 
- 					yyjson_mut_arr_add_val(convert_points, obj);
 
- 					auto coord = yyjson_mut_arr(doc);
 
- 					yyjson_mut_obj_add_val(doc, obj, "coord", coord);
 
- 					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);
 
- 					yyjson_mut_arr_add_int(doc, coord, curr_val);
 
- 					yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
 
- 						ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
 
- 					yyjson_mut_obj_add_int(doc, obj, "val", show_val);
 
- 					if (curr_val < 0)
 
- 						yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
 
- 					yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("定扳反:{}", show_val)).c_str());
 
- 				}
 
- 					break;
 
- 				case eDaoChaPosi::DCP_INVERT2FIX:
 
- 				{
 
- 					yyjson_mut_arr_add_val(convert_points, obj);
 
- 					auto coord = yyjson_mut_arr(doc);
 
- 					yyjson_mut_obj_add_val(doc, obj, "coord", coord);
 
- 					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);
 
- 					yyjson_mut_arr_add_int(doc, coord, curr_val);
 
- 					yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}.{:0>3}",
 
- 						ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second, ts.fraction / 1000000).c_str());
 
- 					yyjson_mut_obj_add_int(doc, obj, "val", show_val);
 
- 					if (curr_val < 0)
 
- 						yyjson_mut_obj_add_str(doc, obj, "position", "bottom");
 
- 					yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("反扳定:{}", show_val)).c_str());
 
- 				}
 
- 				break;
 
- 				default:
 
- 					ASSERT(FALSE);
 
- 					break;
 
- 				}
 
- 			} while (TRUE);
 
- 		}
 
- 		stmt.Close();
 
- 		
 
- 	}while (false);
 
- 	*json = yyjson_mut_write(doc, 0, json_len);
 
- 	yyjson_mut_doc_free(doc);
 
- 	return 200;
 
- }
 
 
  |