#include "stdafx.h" #include "HttpPrcess.h" #include #include #include "MonitorObject.h" #include "AlarmDefine.h" #include "ResistAlarm.h" #include #include "AppService.h" #include #include "Device.h" #include "SkylightMng.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; //CSimpleLog::Info(fmt::format("[HTTP][GET][START] {}:{} {}", req.remote_addr, req.remote_port, req.target).c_str()); 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("conf_read/retension_force") != -1) code = DealGetRetesionForce(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("retension_curve") != -1) code = DealGetRetentionCurve(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("Retention_report") != -1) code = DealGetRetentionReport(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("reminder_interval") != -1) code = deal_get_reminder_interval(req, token, &json, &json_len); else if (req.path.find("resist_data") != -1) code = DealGetResistData(req, token, &json, &json_len); //else if (req.path.find("retention_data") != -1) // code = DealGetRetentionData(req, token, &json, &json_len); else if (req.path.find("resist_move") != -1) code = DealResistMove(req, token, &json, &json_len); else if (req.path.find("alarm_list") != -1) code = deal_get_alarm_list(req, body, &json, &json_len); else if (req.path.find("backend_type") != -1) { body = R"({"type":1})"; 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::steady_clock::now() - start).count(); //CSimpleLog::Info(fmt::format("[HTTP][GET][END] code:{} COST:{} {}:{} {} {}", code, cost, req.remote_addr, req.remote_port, req.target, json ? json : "").c_str()); SPDLOG_INFO("[HTTP][GET][END] code:{} COST:{} {}:{} {}", code, cost, req.remote_addr, req.remote_port, req.target); res.set_header("cost", to_string(cost) + " ms"); res.status = code; if (json) free(json); } //处理get请求总入口 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; //CSimpleLog::Info(fmt::format("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body).c_str()); 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("conf_write/retension_force") != -1) code = DealPosttRetesionForce(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 if (req.path.find("reminder_interval") != -1) code = deal_post_reminder_interval(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::steady_clock::now() - start).count(); //CSimpleLog::Info(fmt::format("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{} json:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body, json ? json : "").c_str()); SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body); res.set_header("cost", to_string(cost) + " ms"); res.status = code; if (json) free(json); } void DealHttpPut(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("/data/zzjno") != -1) code = DealPutChangeZzjno(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::steady_clock::now() - start).count(); SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body); 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 DealPostBinData(const httplib::Request& req, const string token, httplib::Response& res) { auto doc = yyjson_mut_doc_new(nullptr); auto root = yyjson_mut_obj(doc); yyjson_mut_doc_set_root(doc, root); char msg[100] = { 0 }; int code = 500; string type; do { if (token.find("AAAAAAAA") == -1) { code = 403; gbk2utf8(msg, 100, "无权限"); break; } auto IMEI = req.get_header_value("IMEI"); if (IMEI.empty()) { code = 400; gbk2utf8(msg, 100, "IMEI不能为空"); break; } type = req.get_header_value("type"); if (type.empty()) { code = 400; gbk2utf8(msg, 100, "type不能为空"); break; } if (req.body.empty()) { code = 400; gbk2utf8(msg, 100, "body数据不能为空"); break; } time_t tNow; time(&tNow); if (CAppService::Instance()->m_bHaveDeviceUpgrade && tNow - CAppService::Instance()->m_tDeviceUpgrade < 60) { code = 400; gbk2utf8(msg, 100, "目前有设备在升级中, 请等待."); break; } auto filesize = req.body.length(); yyjson_mut_obj_add_int(doc, root, "filesize", filesize); auto filecrc = crc32buf(req.body.c_str(), filesize); yyjson_mut_obj_add_int(doc, root, "filecrc", filecrc); auto pData = new char[filesize * 2 + 2]; CAppService::FileDataConvertCharData((uint8_t*)req.body.c_str(), filesize, pData); { auto& mapTypeData = CAppService::Instance()->m_mapTypeData; auto it = mapTypeData.find(type.c_str()); int datalen = filesize * 2; if (it != mapTypeData.end()) { it->second->Join(); it->second = nullptr; } auto pInfo = new UPGRADE_FILE_DATA; mapTypeData[type.c_str()] = pInfo; pInfo->data = pData; pInfo->len = filesize * 2; pInfo->crc = filecrc; pData[datalen] = 0x00; pData[datalen + 1] = 0x00; } gbk2utf8(msg, 100, "数据接收成功"); //通知设备 auto notify_ret = CLNHandle::SendUpdateToDevice(IMEI.c_str(), req.remote_addr, type); if (notify_ret == 0) { code = 200; gbk2utf8(msg, 100, "数据接收成功, 且下发数据成功!"); } else if (notify_ret == 1) { code = 400; gbk2utf8(msg, 100, "未找到设备或者设备未在线!"); } else if (notify_ret == 2) { code = 500; gbk2utf8(msg, 100, "数据接收成功, 但下发数据失败!"); } } while (false); yyjson_mut_obj_add_strcpy(doc, root, "type", type.c_str()); yyjson_mut_obj_add_int(doc, root, "code", code); yyjson_mut_obj_add_str(doc, root, "msg", msg); size_t len; auto json = yyjson_mut_write(doc, 0, &len); if (json) { res.set_content(json, len, "application/json"); free((void*)json); } yyjson_mut_doc_free(doc); return code; } 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()); //处理中文 //auto doc = yyjson_mut_doc_new(nullptr); //auto root = yyjson_mut_obj(doc); //yyjson_mut_doc_set_root(doc, root); //yyjson_mut_obj_add_bool(doc, root, "result", CSimpleLog::PathFileExists(CSimpleLog::GetAppDir() + id.c_str())); //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); 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 gbk[200]; int id_len = utf82gbk(gbk, 200, id.c_str(), id.length()); auto pObject = CMonitorObjectMng::Instance()->GetTreeByID(string(gbk)); if (nullptr == pObject) return 404; if (pObject->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 : pObject->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()); string imei; int idx; CMonitorObjectMng::Instance()->MOMP2IMEI(it->id, imei, idx); if (imei.length()) { 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 || ty == eZL_MP_STAT::MP_STAT_UNKNOW) { if (CDeviceMng::Instance()->IsDeviceOnline(imei, idx)) 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(gbk, 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, gbk); } } 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) { 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 DealGetRetesionForce(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 posi = req.get_param_value("posi"); if (mo.length() == 0 || mp.length() == 0 || posi.length() == 0) return 400; eSuoBiPosi no = (eSuoBiPosi)atoi(posi.c_str()); auto doc = yyjson_mut_doc_new(nullptr); auto root = yyjson_mut_obj(doc); yyjson_mut_doc_set_root(doc, root); RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)no, eZL_ALARMTYPE::RETENSION_FORCE); if (pInfo) { yyjson_mut_obj_add_bool(doc, root, "enable", pInfo->enable); if (pInfo->dw_alarm_low_drop > INT_MIN) yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop); else yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_drop"); if (pInfo->alarm_low_percent > INT_MIN) yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent); else yyjson_mut_obj_add_null(doc, root, "alarm_low_percent"); if (pInfo->alarm_high_percent > INT_MIN) yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent); else yyjson_mut_obj_add_null(doc, root, "alarm_high_percent"); } else { yyjson_mut_obj_add_bool(doc, root, "enable", false); yyjson_mut_obj_add_null(doc, root, "dw_alarm_low_drop"); yyjson_mut_obj_add_null(doc, root, "alarm_low_percent"); yyjson_mut_obj_add_null(doc, root, "alarm_high_percent"); } *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) { 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 DealPosttRetesionForce(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len) { int code = 400; auto req_doc = yyjson_read(body_ptr, body_len, 0); if (req_doc == nullptr) return 400; string msg; 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 posi= yyjson_get_int(yyjson_obj_get(req_root, "posi")); auto conf = yyjson_obj_get(req_root, "conf"); if (mo == nullptr || mp == nullptr || conf == nullptr || posi == 0) 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; //更新内存里 RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, posi, eZL_ALARMTYPE::RETENSION_FORCE); CString sql; if (pInfo == nullptr/* && pInfo->dw_alarm_low_drop == INT_MIN*/) { RETENSION_FORCE_DROP* pInfo = new RETENSION_FORCE_DROP; pInfo->type = eZL_ALARMTYPE::RETENSION_FORCE; pInfo->no = 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, "dw_alarm_low_drop"); if (val && yyjson_is_int(val)) pInfo->dw_alarm_low_drop = yyjson_get_int(val); else pInfo->dw_alarm_low_drop = INT_MIN; yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop); } { auto val = yyjson_obj_get(conf, "alarm_high_percent"); if (val && yyjson_is_int(val)) pInfo->alarm_high_percent = yyjson_get_int(val); else pInfo->alarm_high_percent = INT_MIN; yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent); } { auto val = yyjson_obj_get(conf, "alarm_low_percent"); if (val && yyjson_is_int(val)) pInfo->alarm_low_percent = yyjson_get_int(val); else pInfo->alarm_low_percent = INT_MIN; yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent); } str_conf = yyjson_mut_write(doc, 0, &len); yyjson_mut_doc_free(doc); CResistAlarmMng::Instance()->Insert(mo, mp, posi, (uint8_t)eZL_ALARMTYPE::RETENSION_FORCE, 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, posi, eZL_ALARMTYPE::RETENSION_FORCE, 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, "dw_alarm_low_drop"); if (val && yyjson_is_int(val)) pInfo->dw_alarm_low_drop = yyjson_get_int(val); else pInfo->dw_alarm_low_drop = INT_MIN; yyjson_mut_obj_add_int(doc, root, "dw_alarm_low_drop", pInfo->dw_alarm_low_drop); } { auto val = yyjson_obj_get(conf, "alarm_high_percent"); if (val && yyjson_is_int(val)) pInfo->alarm_high_percent = yyjson_get_int(val); else pInfo->alarm_high_percent = INT_MIN; yyjson_mut_obj_add_int(doc, root, "alarm_high_percent", pInfo->alarm_high_percent); } { auto val = yyjson_obj_get(conf, "alarm_low_percent"); if (val && yyjson_is_int(val)) pInfo->alarm_low_percent = yyjson_get_int(val); else pInfo->alarm_low_percent = INT_MIN; yyjson_mut_obj_add_int(doc, root, "alarm_low_percent", pInfo->alarm_low_percent); } 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, posi, eZL_ALARMTYPE::RETENSION_FORCE); } if (str_conf) free(str_conf); if (CDBConnectPool::Instance()->DBExecuteSQL(sql) == FALSE) { ASSERT(FALSE); msg = "语句执行失败" + sql; CSimpleLog::Error(msg.c_str()); 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 map_name; std::map map_mo_name; std::map 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_strcpy(doc, o, "station_name", ANSItoUTF8(station_name).c_str()); 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()); } 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 deal_get_reminder_interval(const httplib::Request& req, const string token, char** json, size_t* json_len) { 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, "code", 200); yyjson_mut_obj_add_int(doc, root, "interval", g_tReminderInterval); *json = yyjson_mut_write(doc, 0, json_len); yyjson_mut_doc_free(doc); return 200; } int deal_post_reminder_interval(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 { auto interval = yyjson_get_int(yyjson_obj_get(req_root, "interval")); if (interval == 0) break; g_tReminderInterval = interval; auto strIniPath = CSimpleLog::GetAppDir() + "DataServices.ini"; ::WritePrivateProfileString("SET", "reminder_interval", (to_string(g_tReminderInterval) + " #报警提醒间隔").c_str(), strIniPath); code = 200; } while (false); return code; } string convertWhere(string mo, string mp, string starttime, string endtime, string type, string no, string level, string ack_result, string handle_result, string sunroof, string recovery) { string wh = " "; if (!starttime.empty()) { wh += fmt::format(" AND occur_time >= '{}'", starttime); } if (!endtime.empty()) { wh += fmt::format(" AND occur_time <= '{}'", endtime); } if (!mo.empty()) { wh += fmt::format(" AND mo = '{}'", mo); } if (!mp.empty()) { wh += fmt::format(" AND mp = '{}'", mp); } if (!type.empty()) { wh += fmt::format(" AND a.type = {}", type); } if (!no.empty()) { wh += fmt::format(" AND no = {}", no); } if (!level.empty()) { wh += fmt::format(" AND level = {}", level); } if (!ack_result.empty()) { wh += fmt::format(" AND ack_result = {}", ack_result); } if (!handle_result.empty()) { wh += fmt::format(" AND handle_result = {}", handle_result); } if (!sunroof.empty()) { if (sunroof.compare("0") == 0) wh += " AND [sunroof]=0"; else if (sunroof.compare("1") == 0) wh += " AND [sunroof]=1"; } if (!handle_result.empty()) { wh += fmt::format(" AND handle_result = {}", handle_result); } if (!recovery.empty()) { if (recovery.compare("0") == 0) wh += " AND [recovery_time] < '1901'"; else if (recovery.compare("1") == 0) wh += " AND [recovery_time] > '1901'"; } wh += " AND rel_id = ''"; int nPos = wh.find("AND"); if (nPos != -1) wh.replace(nPos, 3, "WHERE"); return wh; } int deal_get_alarm_list(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 starttime = req.get_param_value("starttime"); string endtime = req.get_param_value("endtime"); string type = req.get_param_value("type"); string no = req.get_param_value("no"); string sort = req.get_param_value("sort"); string order = req.get_param_value("order"); string offset = req.get_param_value("offset"); string limit = req.get_param_value("limit"); string level = req.get_param_value("level"); string ack_result = req.get_param_value("ack_result"); string handle_result = req.get_param_value("handle_result"); string sunroof = req.get_param_value("sunroof"); string recovery = req.get_param_value("recovery"); if (sort.empty()) sort = "occur_time"; if (order.empty()) order = "desc"; if (offset.empty()) offset = "0"; if (limit.empty()) limit = "10"; auto doc = yyjson_mut_doc_new(nullptr); auto root = yyjson_mut_obj(doc); yyjson_mut_doc_set_root(doc, root); auto rows = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, root, "rows", rows); int total = -1; int code = 200; string msg; string wh = convertWhere(mo, mp, starttime, endtime, type, no, level, ack_result, handle_result, sunroof, recovery); string or = " ORDER BY " + sort + " " + order + " OFFSET " + offset + " ROWS FETCH NEXT " + limit + " ROWS ONLY "; do { CString sql = ("select count(*) from rm_alarm as a " + wh).c_str(); COdbcStatement stmt; if (!CDBConnectPool::Instance()->DBQuery(stmt, sql)) { msg = fmt::format("语句执行错误:{}", sql); code = 500; break; } stmt.BindIntCol(1, &total); if (stmt.FetchNext() == 0) yyjson_mut_obj_add_int(doc, root, "total", total); } while (false); std::map mapList; do { if (total == -1) break; CString sql = fmt::format("select a.[id],[mo],[mp],[no],a.[type] ,[occur_time],[level],[desc],[suggest],[val],[referval],"\ " [ack_result],ISNULL([ack_name], ''),ISNULL([ack_time], 0),[handle_result],ISNULL([handle_name],''),ISNULL([handle_time], 0),ISNULL([handle_info], '') ,b.name,c.id,c.name,"\ " recovery_time,sunroof,[event_id] from [rm_alarm] as a left join rm_mo as b on b.id = a.mo left join rm_mo as c on b.up = c.id {} {}", wh, or ).c_str(); COdbcStatement stmt; if (!CDBConnectPool::Instance()->DBQuery(stmt, sql)) { msg = fmt::format("语句执行错误:{}", sql); code = 500; break; } int id, val, refer; char smo[20]; char smp[10]; char desc[200]; char suggest[200]; char ack_name[50]; char handle_name[50]; char hanele_info[50]; char mo_name[20]; char station_name[50]; char station_id[50]; char event_id[37] = { 0 }; char rel_id[37] = { 0 }; uint8_t no, utype , level, ack_result, h_result, skylight ; TIMESTAMP_STRUCT tsOcccur, tsHandle, tsAck, tsRecovery; int nCol = 1; stmt.BindIntCol(nCol++, &id); stmt.BindCharCol(nCol++, smo, sizeof(smo)); stmt.BindCharCol(nCol++, smp, sizeof(smp)); stmt.BindTinyIntCol(nCol++, &no); stmt.BindTinyIntCol(nCol++, &utype); stmt.BindTimeStampCol(nCol++, &tsOcccur); stmt.BindTinyIntCol(nCol++, &level); stmt.BindCharCol(nCol++, desc, sizeof(desc)); stmt.BindCharCol(nCol++, suggest, sizeof(suggest)); stmt.BindIntCol(nCol++, &val); stmt.BindIntCol(nCol++, &refer); stmt.BindTinyIntCol(nCol++, &ack_result); stmt.BindCharCol(nCol++, ack_name, sizeof(ack_name)); stmt.BindTimeStampCol(nCol++, &tsAck); stmt.BindTinyIntCol(nCol++, &h_result); stmt.BindCharCol(nCol++, handle_name, sizeof(handle_name)); stmt.BindTimeStampCol(nCol++, &tsHandle); stmt.BindCharCol(nCol++, hanele_info, sizeof(hanele_info)); stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name)); stmt.BindCharCol(nCol++, station_id, sizeof(station_id)); stmt.BindCharCol(nCol++, station_name, sizeof(station_name)); stmt.BindTimeStampCol(nCol++, &tsRecovery); stmt.BindTinyIntCol(nCol++, &skylight); stmt.BindCharCol(nCol++, event_id, sizeof(event_id)); while (true) { if (stmt.FetchNext() != 0) break; auto obj = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(rows, obj); auto child = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, obj, "child", child); mapList[event_id] = child; //临时记录后面统一添加 if (ack_name[0]) yyjson_mut_obj_add_strcpy(doc, obj, "ack_name", ANSItoUTF8(ack_name).c_str()); else yyjson_mut_obj_add_str(doc, obj, "ack_name", ""); if (tsAck.year != 1900) yyjson_mut_obj_add_strcpy(doc, obj, "ack_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tsAck.year, tsAck.month, tsAck.day, tsAck.hour, tsAck.minute, tsAck.second).c_str()); else yyjson_mut_obj_add_str(doc, obj, "ack_time", ""); yyjson_mut_obj_add_int(doc, obj, "ack_result", ack_result); if (handle_name[0]) yyjson_mut_obj_add_strcpy(doc, obj, "handle_name", ANSItoUTF8(handle_name).c_str()); else yyjson_mut_obj_add_str(doc, obj, "handle_name", ""); if (tsHandle.year != 1900) yyjson_mut_obj_add_strcpy(doc, obj, "handle_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tsHandle.year, tsHandle.month, tsHandle.day, tsHandle.hour, tsHandle.minute, tsHandle.second).c_str()); else yyjson_mut_obj_add_str(doc, obj, "handle_time", ""); yyjson_mut_obj_add_int(doc, obj, "handle_result", h_result); yyjson_mut_obj_add_int(doc, obj, "id", id); yyjson_mut_obj_add_int(doc, obj, "level", level); yyjson_mut_obj_add_strcpy(doc, obj, "mo", smo); yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name); yyjson_mut_obj_add_strcpy(doc, obj, "mp", smp); yyjson_mut_obj_add_int(doc, obj, "no", no); yyjson_mut_obj_add_strcpy(doc, obj, "type_name", ANSItoUTF8(GetAlarmName((eZL_ALARMTYPE)utype)).c_str()); yyjson_mut_obj_add_strcpy(doc, obj, "occur_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tsOcccur.year, tsOcccur.month, tsOcccur.day, tsOcccur.hour, tsOcccur.minute, tsOcccur.second).c_str()); if (tsRecovery.year != 1900) yyjson_mut_obj_add_strcpy(doc, obj, "recovery_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tsRecovery.year, tsRecovery.month, tsRecovery.day, tsRecovery.hour, tsRecovery.minute, tsRecovery.second).c_str()); else yyjson_mut_obj_add_str(doc, obj, "recovery_time", ""); if (suggest[0]) yyjson_mut_obj_add_strcpy(doc, obj, "suggest", ANSItoUTF8(suggest).c_str()); else yyjson_mut_obj_add_str(doc, obj, "suggest", ""); if (desc[0]) yyjson_mut_obj_add_strcpy(doc, obj, "desc", ANSItoUTF8(desc).c_str()); else yyjson_mut_obj_add_str(doc, obj, "desc", ""); yyjson_mut_obj_add_int(doc, obj, "sunroof", skylight); yyjson_mut_obj_add_int(doc, obj, "type", utype); //yyjson_mut_obj_add_strcpy(doc, obj, "type_name", ) yyjson_mut_obj_add_strcpy(doc, obj, "up", ANSItoUTF8(station_id).c_str()); yyjson_mut_obj_add_strcpy(doc, obj, "up_name", ANSItoUTF8(station_name).c_str()); yyjson_mut_obj_add_int(doc, obj, "val", val); yyjson_mut_obj_add_int(doc, obj, "referval", refer); yyjson_mut_obj_add_strcpy(doc, obj, "event_id", event_id); } } while (false); do { if (mapList.size() == 0) break; stringstream ss; ss << " where rel_id in ("; int index = 0; for (const auto& it : mapList) { if (index == 0) ss << '\'' << it.first << '\''; else ss << ",'" << it.first << '\''; index++; } ss << ')'; CString sql = fmt::format("select a.[id],[mo],[mp],[no],a.[type] ,[occur_time],[level],[desc],[suggest],[val],[referval],"\ " [ack_result],ISNULL([ack_name], ''),ISNULL([ack_time], 0),[handle_result],ISNULL([handle_name],''),ISNULL([handle_time], 0),ISNULL([handle_info], '') ,b.name,c.id,c.name,"\ " recovery_time,sunroof,[event_id],[rel_id] from [rm_alarm] as a left join rm_mo as b on b.id = a.mo left join rm_mo as c on b.up = c.id {}", ss.str()).c_str(); COdbcStatement stmt; if (!CDBConnectPool::Instance()->DBQuery(stmt, sql)) { msg = fmt::format("语句执行错误:{}", sql); code = 500; break; } int id, val, refer; char smo[20]; char smp[10]; char desc[200]; char suggest[200]; char ack_name[50]; char handle_name[50]; char hanele_info[50]; char mo_name[20]; char station_name[50]; char station_id[50]; char event_id[37] = { 0 }; char rel_id[37] = { 0 }; uint8_t no, utype, level, ack_result, h_result, skylight; TIMESTAMP_STRUCT tsOcccur, tsHandle, tsAck, tsRecovery; int nCol = 1; stmt.BindIntCol(nCol++, &id); stmt.BindCharCol(nCol++, smo, sizeof(smo)); stmt.BindCharCol(nCol++, smp, sizeof(smp)); stmt.BindTinyIntCol(nCol++, &no); stmt.BindTinyIntCol(nCol++, &utype); stmt.BindTimeStampCol(nCol++, &tsOcccur); stmt.BindTinyIntCol(nCol++, &level); stmt.BindCharCol(nCol++, desc, sizeof(desc)); stmt.BindCharCol(nCol++, suggest, sizeof(suggest)); stmt.BindIntCol(nCol++, &val); stmt.BindIntCol(nCol++, &refer); stmt.BindTinyIntCol(nCol++, &ack_result); stmt.BindCharCol(nCol++, ack_name, sizeof(ack_name)); stmt.BindTimeStampCol(nCol++, &tsAck); stmt.BindTinyIntCol(nCol++, &h_result); stmt.BindCharCol(nCol++, handle_name, sizeof(handle_name)); stmt.BindTimeStampCol(nCol++, &tsHandle); stmt.BindCharCol(nCol++, hanele_info, sizeof(hanele_info)); stmt.BindCharCol(nCol++, mo_name, sizeof(mo_name)); stmt.BindCharCol(nCol++, station_id, sizeof(station_id)); stmt.BindCharCol(nCol++, station_name, sizeof(station_name)); stmt.BindTimeStampCol(nCol++, &tsRecovery); stmt.BindTinyIntCol(nCol++, &skylight); stmt.BindCharCol(nCol++, event_id, sizeof(event_id)); stmt.BindCharCol(nCol++, rel_id, sizeof(rel_id)); while (true) { if (stmt.FetchNext() != 0) break; auto arr = mapList[rel_id]; if (arr == nullptr) { ASSERT(0); continue; } auto obj = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(arr, obj);//添加到原有的child里 if (ack_name[0]) yyjson_mut_obj_add_strcpy(doc, obj, "ack_name", ANSItoUTF8(ack_name).c_str()); else yyjson_mut_obj_add_str(doc, obj, "ack_name", ""); if (tsAck.year != 1900) yyjson_mut_obj_add_strcpy(doc, obj, "ack_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tsAck.year, tsAck.month, tsAck.day, tsAck.hour, tsAck.minute, tsAck.second).c_str()); else yyjson_mut_obj_add_str(doc, obj, "ack_time", ""); yyjson_mut_obj_add_int(doc, obj, "ack_result", ack_result); if (handle_name[0]) yyjson_mut_obj_add_strcpy(doc, obj, "handle_name", ANSItoUTF8(handle_name).c_str()); else yyjson_mut_obj_add_str(doc, obj, "handle_name", ""); if (tsHandle.year != 1900) yyjson_mut_obj_add_strcpy(doc, obj, "handle_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tsHandle.year, tsHandle.month, tsHandle.day, tsHandle.hour, tsHandle.minute, tsHandle.second).c_str()); else yyjson_mut_obj_add_str(doc, obj, "handle_time", ""); yyjson_mut_obj_add_int(doc, obj, "handle_result", h_result); yyjson_mut_obj_add_int(doc, obj, "id", id); yyjson_mut_obj_add_int(doc, obj, "level", level); yyjson_mut_obj_add_strcpy(doc, obj, "mo", smo); yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name); yyjson_mut_obj_add_strcpy(doc, obj, "mp", smp); yyjson_mut_obj_add_int(doc, obj, "no", no); yyjson_mut_obj_add_strcpy(doc, obj, "type_name", ANSItoUTF8(GetAlarmName((eZL_ALARMTYPE)utype)).c_str()); yyjson_mut_obj_add_strcpy(doc, obj, "occur_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tsOcccur.year, tsOcccur.month, tsOcccur.day, tsOcccur.hour, tsOcccur.minute, tsOcccur.second).c_str()); if (tsRecovery.year != 1900) yyjson_mut_obj_add_strcpy(doc, obj, "recovery_time", fmt::format("{}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2}", tsRecovery.year, tsRecovery.month, tsRecovery.day, tsRecovery.hour, tsRecovery.minute, tsRecovery.second).c_str()); else yyjson_mut_obj_add_str(doc, obj, "recovery_time", ""); if (suggest[0]) yyjson_mut_obj_add_strcpy(doc, obj, "suggest", ANSItoUTF8(suggest).c_str()); else yyjson_mut_obj_add_str(doc, obj, "suggest", ""); if (desc[0]) yyjson_mut_obj_add_strcpy(doc, obj, "desc", ANSItoUTF8(desc).c_str()); else yyjson_mut_obj_add_str(doc, obj, "desc", ""); yyjson_mut_obj_add_int(doc, obj, "sunroof", skylight); yyjson_mut_obj_add_int(doc, obj, "type", utype); //yyjson_mut_obj_add_strcpy(doc, obj, "type_name", ) yyjson_mut_obj_add_strcpy(doc, obj, "up", ANSItoUTF8(station_id).c_str()); yyjson_mut_obj_add_strcpy(doc, obj, "up_name", ANSItoUTF8(station_name).c_str()); yyjson_mut_obj_add_int(doc, obj, "val", val); yyjson_mut_obj_add_int(doc, obj, "referval", refer); yyjson_mut_obj_add_strcpy(doc, obj, "event_id", event_id); } } while (false); yyjson_mut_obj_add_int(doc, root, "code", code); yyjson_mut_obj_add_strcpy(doc, root, "msg", ANSItoUTF8(msg).c_str()); *json = yyjson_mut_write(doc, 0, json_len); yyjson_mut_doc_free(doc); return code; } //历史数据新接口 10087端口 int DealGetResistData(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 starttime = req.get_param_value("starttime"); string endtime = req.get_param_value("endtime"); string threshold = req.get_param_value("threshold"); int nThreshold = 100; if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.length() == 0) return 400; if (threshold.empty() == false) nThreshold = atoi(threshold.c_str()); //if (nThreshold < 30) nThreshold = 30; //if (nThreshold > 500) nThreshold = 500; COleDateTime odtStart, odtEnd; try { odtStart.ParseDateTime(starttime.c_str()); odtEnd.ParseDateTime(endtime.c_str()); } catch (CException* ) { return 400; } auto momp = mo + "." + mp; auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp); if (pInfo == nullptr) return 404; if (pInfo->pDeivce == nullptr) return 404; if (odtStart >= odtEnd) return 400; char tablename[50] = { 0 }; auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0); //auto dtEndDate = COleDateTime(odtEnd.GetYear(), odtEnd.GetMonth(), odtEnd.GetDay(), 0, 0, 0); auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S"); auto strEndDate = odtEnd.Format("%Y-%m-%d %H:%M:%S");; //auto strStartTime = odtStart.Format("%Y-%m-%d %H:%M:%S"); //auto strEndTime = odtEnd.Format("%Y-%m-%d %H:%M:%S"); CString sql = "SELECT TOP 100000 * FROM ("; { int num = 0; for (auto it = dtStartDate; it < odtEnd;) { sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay()); if (num == 0) { sql += fmt::format("SELECT [acquisitiontime],[data0],[data1],[data2] "\ "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ", tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx).c_str(); } else { sql += fmt::format(" UNION ALL "\ "SELECT [acquisitiontime],[data0],[data1],[data2] "\ "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ", tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str(); } num++; it += COleDateTimeSpan(1, 0, 0, 0); } sql += ") AS A ORDER BY acquisitiontime ASC"; } TIMESTAMP_STRUCT ts; int sdata0, sdata1, sdata2; COdbcStatement stmt; if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE) { SPDLOG_ERROR("查询语句出错:{}", sql); return 500; } int nCol = 1; stmt.BindTimeStampCol(nCol++, &ts); stmt.BindIntCol(nCol++, &sdata0); stmt.BindIntCol(nCol++, &sdata1); stmt.BindIntCol(nCol++, &sdata2); int nCount = 0; 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); auto curve_1 = yyjson_mut_obj(doc); auto curve_2 = yyjson_mut_obj(doc); auto curve_3 = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(data, curve_1); yyjson_mut_arr_add_val(data, curve_2); yyjson_mut_arr_add_val(data, curve_3); yyjson_mut_obj_add_str(doc, root, "cmd", "query_hist"); yyjson_mut_obj_add_strcpy(doc, root, "tag", (momp + ".resist").c_str()); yyjson_mut_obj_add_str(doc, root, "data_fmt", "curve"); yyjson_mut_obj_add_str(doc, root, "unit", "N"); yyjson_mut_obj_add_str(doc, root, "time", ""); //1号测力点 yyjson_mut_obj_add_str(doc, curve_1, "name", pInfo->name1utf.c_str()); auto points1 = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, curve_1, "points", points1); //2号测力点 yyjson_mut_obj_add_str(doc, curve_2, "name", pInfo->name2utf.c_str()); auto points2 = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, curve_2, "points", points2); //3号测力点 yyjson_mut_obj_add_str(doc, curve_3, "name", pInfo->name3utf.c_str()); auto points3 = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, curve_3, "points", points3); if (nThreshold == 0) { 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 tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000; #ifdef SHOW_DATA { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points1, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata0); } { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points2, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata1); } { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points3, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata2); } #endif nCount++; } while (true); } else { int lastdata0 = INT_MAX, lastdata1 = INT_MAX, lastdata2 = INT_MAX; time_t tm = 0; do { if (stmt.FetchNext() != 0) { if (tm != 0) { { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points1, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata0); } { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points2, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata1); } { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points3, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata2); } } break; } CTime ctTime; try { ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second); } catch (...) { continue; } tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000; #ifdef SHOW_DATA if (abs(lastdata0 - sdata0) > nThreshold) { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points1, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata0); lastdata0 = sdata0; } if (abs(lastdata1 - sdata1) > nThreshold) { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points2, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata1); lastdata1 = sdata1; } if (abs(lastdata2 - sdata2) > nThreshold) { auto item = yyjson_mut_arr(doc); yyjson_mut_arr_add_val(points3, item); yyjson_mut_arr_add_uint(doc, item, tm); yyjson_mut_arr_add_int(doc, item, sdata2); lastdata2 = sdata2; } #endif nCount++; } while (true); } stmt.Close(); yyjson_mut_obj_add_int(doc, root, "count", nCount); if (nCount >= 100000) yyjson_mut_obj_add_bool(doc, root, "has_more", true); else yyjson_mut_obj_add_bool(doc, root, "has_more", false); //扳动信息 auto fix_points = yyjson_mut_arr(doc); auto invert_points = yyjson_mut_arr(doc); auto convert_points = yyjson_mut_arr(doc); if (pInfo->name1.find("定位") != -1) { yyjson_mut_obj_add_val(doc, curve_1, "mark_points", fix_points); yyjson_mut_obj_add_val(doc, curve_2, "mark_points", invert_points); } else { yyjson_mut_obj_add_val(doc, curve_1, "mark_points", invert_points); yyjson_mut_obj_add_val(doc, curve_2, "mark_points", fix_points); } yyjson_mut_obj_add_val(doc, curve_3, "mark_points", convert_points); auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT); auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT); auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT); { int num = 0; int lastyearmonth = 0; for (auto it = dtStartDate; it < odtEnd;) { int yearmonth = it.GetYear() * 100 + it.GetMonth(); if (yearmonth != lastyearmonth) { lastyearmonth = yearmonth; sprintf_s(tablename, 50, "rm_move_%04d%02d", it.GetYear(), it.GetMonth()); if (num == 0) { sql = fmt::format("SELECT show_time, curr_val, show_val, posi, [type],[sunroof] FROM {} \ WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' ", tablename, mo, mp, starttime, endtime).c_str(); } else { sql += fmt::format(" UNION ALL "\ "SELECT show_time, curr_val, show_val, posi, [type],[sunroof] FROM {} \ WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' ", tablename, mo, mp, starttime, endtime).c_str(); } num++; } it += COleDateTimeSpan(1, 0, 0, 0); } sql += "order by posi, show_time"; } if (CDBConnectPool::Instance()->DBQuery(stmt, sql)) { TIMESTAMP_STRUCT ts; int curr_val; int show_val; eDaoChaPosi posi; ePowerName pn; uint8_t sunroof; int nCol = 1; stmt.BindTimeStampCol(nCol++, &ts); stmt.BindIntCol(nCol++, &curr_val); stmt.BindIntCol(nCol++, &show_val); stmt.BindTinyIntCol(nCol++, (BYTE*)&posi); stmt.BindTinyIntCol(nCol++, (BYTE*)&pn); stmt.BindTinyIntCol(nCol++, &sunroof); do { if (stmt.FetchNext() != 0) break; auto obj = yyjson_mut_obj(doc); switch (posi) { case eDaoChaPosi::DCP_FIX: { if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_RESIST) { 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 (pFixSuobi && pFixSuobi->enable && !sunroof) { if (pFixSuobi->alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pFixSuobi->alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pFixSuobi->warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); else if (pFixSuobi->warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str()); } //if (show_val < 500)//TODO //{ // 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: { if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_RESIST) { 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 (pInvertSuobi && pInvertSuobi->enable && !sunroof) { if (pInvertSuobi->alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pInvertSuobi->alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pInvertSuobi->warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); else if (pInvertSuobi->warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str()); } //if (show_val < 500)//TODO //{ // 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: { if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_MOVE) { 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 (pConvertLimit && pConvertLimit->enable && !sunroof) { if (pInfo->out_name.find("定扳反") != -1) { if (pConvertLimit->dw_alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->dw_warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } else { if (pConvertLimit->up_alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->up_warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } } 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: { if (pn == ePowerName::PN_UNKNOWN || pn == ePowerName::PN_MOVE) { 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 (pConvertLimit && pConvertLimit->enable && !sunroof) { if (pInfo->out_name.find("反扳定") != -1) { if (pConvertLimit->dw_alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->dw_warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } else { if (pConvertLimit->up_alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->up_warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } } 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(); //报警线 auto warn_line = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, root, "warn_line", warn_line); MAX_OVER_LIMIT_INFO* pFixMax = nullptr; MAX_OVER_LIMIT_INFO* pInvertMax = nullptr; MAX_OVER_LIMIT_INFO* pConvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::MAX_OVER_LIMIT); if (pInfo->name1.find("定位") != -1) { pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT); pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT); } else { pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT); pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT); } //定位 if (pFixMax && pFixMax->enable) { static string fixnameutf = ANSItoUTF8("定位"); if (pFixMax->alarm_high_limit != INT_MAX) { auto object = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(warn_line, object); yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str()); yyjson_mut_obj_add_str(doc, object, "color", "red"); yyjson_mut_obj_add_int(doc, object, "val", pFixMax->alarm_high_limit); } if (pFixMax->warn_high_limit != INT_MAX) { auto object = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(warn_line, object); yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str()); yyjson_mut_obj_add_str(doc, object, "color", "orange"); yyjson_mut_obj_add_int(doc, object, "val", pFixMax->warn_high_limit); } } if (pInvertMax && pInvertMax->enable) { static string invertnameutf = ANSItoUTF8("反位"); if (pInvertMax->alarm_high_limit != INT_MAX) { auto object = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(warn_line, object); yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str()); yyjson_mut_obj_add_str(doc, object, "color", "red"); yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->alarm_high_limit); } if (pInvertMax->warn_high_limit != INT_MAX) { auto object = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(warn_line, object); yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str()); yyjson_mut_obj_add_str(doc, object, "color", "orange"); yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->warn_high_limit); } } if (pConvertMax && pConvertMax->enable) { static string d2fnameutf = ANSItoUTF8("定扳反"); static string f2dnameutf = ANSItoUTF8("反扳定"); if (pConvertMax->alarm_high_limit != INT_MAX) { auto object = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(warn_line, object); yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str()); yyjson_mut_obj_add_str(doc, object, "color", "red"); yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->alarm_high_limit); } if (pConvertMax->warn_high_limit != INT_MAX) { auto object = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(warn_line, object); yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str()); yyjson_mut_obj_add_str(doc, object, "color", "orange"); yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->warn_high_limit); } if (pConvertMax->f_alarm_high_limit != INT_MAX) { auto object = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(warn_line, object); yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str()); yyjson_mut_obj_add_str(doc, object, "color", "red"); yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_alarm_high_limit); } if (pConvertMax->f_warn_high_limit != INT_MAX) { auto object = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(warn_line, object); yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str()); yyjson_mut_obj_add_str(doc, object, "color", "orange"); yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_warn_high_limit); } } *json = yyjson_mut_write(doc, 0, json_len); yyjson_mut_doc_free(doc); return 200; } int DealPutChangeZzjno(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len) { if (token.find("AAAAAAAA") == -1) 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); do { auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo")); auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp")); auto newNumber = yyjson_get_int(yyjson_obj_get(req_root, "newNumber")); if (mo == nullptr || mp == nullptr || newNumber == 0) break; //新编号已存在 if (CMonitorObjectMng::Instance()->GetMoMpInfoByZZJno(newNumber)) { code = 400; break; } auto pMoMp = CMonitorObjectMng::Instance()->GetMoMpInfo(string(mo) + "." + mp); if (pMoMp == nullptr) { code = 404; break; } CString sql = fmt::format("update rm_map set zzjno = {} where mo='{}' and mp = '{}';", newNumber, mo, mp).c_str(); if (!CDBConnectPool::Instance()->DBExecuteSQL(sql)) { code = 500; break; } pMoMp->zzjno = newNumber; code = 200; break; } while (false); return code; } //int DealGetRetentionData(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 starttime = req.get_param_value("starttime"); // string endtime = req.get_param_value("endtime"); // string threshold = req.get_param_value("threshold"); // int nThreshold = 100; // if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.length() == 0) // return 400; // if (threshold.empty() == false) nThreshold = atoi(threshold.c_str()); // if (nThreshold < 30) nThreshold = 30; // if (nThreshold > 500) nThreshold = 500; // COleDateTime odtStart, odtEnd; // try // { // odtStart.ParseDateTime(starttime.c_str()); // odtEnd.ParseDateTime(endtime.c_str()); // } // catch (CException*) // { // return 400; // } // // auto momp = mo + "." + mp; // auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp); // if (pInfo == nullptr) // return 404; // if (pInfo->pDeivce == nullptr) // return 404; // // if (odtStart >= odtEnd) return 400; // char tablename[50] = { 0 }; // auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0); // auto dtEndDate = COleDateTime(odtEnd.GetYear(), odtEnd.GetMonth(), odtEnd.GetDay(), 0, 0, 0); // auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S"); // auto strEndDate = dtEndDate.Format("%Y-%m-%d %H:%M:%S");; // //auto strStartTime = odtStart.Format("%Y-%m-%d %H:%M:%S"); // //auto strEndTime = odtEnd.Format("%Y-%m-%d %H:%M:%S"); // // CString sql = "SELECT TOP 100000 * FROM ("; // { // int num = 0; // for (auto it = dtStartDate; it < odtEnd;) // { // sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay()); // if (num == 0) // { // sql += fmt::format("SELECT [acquisitiontime],[data0],[data1],[data2] "\ // "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ", // tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx).c_str(); // } // else // { // sql += fmt::format(" UNION ALL "\ // "SELECT [acquisitiontime],[data0],[data1],[data2] "\ // "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ", // tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str(); // } // num++; // it += COleDateTimeSpan(1, 0, 0, 0); // } // sql += ") AS A ORDER BY acquisitiontime ASC"; // } // // TIMESTAMP_STRUCT ts; // int sdata0, sdata1, sdata2; // // COdbcStatement stmt; // // if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE) // { // ASSERT(0); // SPDLOG_ERROR("查询语句出错:{}", sql); // return 500; // } // // int nCol = 1; // stmt.BindTimeStampCol(nCol++, &ts); // stmt.BindIntCol(nCol++, &sdata0); // stmt.BindIntCol(nCol++, &sdata1); // stmt.BindIntCol(nCol++, &sdata2); // int nCount = 0; // // 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); // auto curve_1 = yyjson_mut_obj(doc); // auto curve_2 = yyjson_mut_obj(doc); // auto curve_3 = yyjson_mut_obj(doc); // yyjson_mut_arr_add_val(data, curve_1); // yyjson_mut_arr_add_val(data, curve_2); // yyjson_mut_arr_add_val(data, curve_3); // // yyjson_mut_obj_add_str(doc, root, "cmd", "query_hist"); // yyjson_mut_obj_add_strcpy(doc, root, "tag", (momp + ".resist").c_str()); // yyjson_mut_obj_add_str(doc, root, "data_fmt", "curve"); // yyjson_mut_obj_add_str(doc, root, "unit", "N"); // yyjson_mut_obj_add_str(doc, root, "time", ""); // // //1号测力点 // yyjson_mut_obj_add_str(doc, curve_1, "name", pInfo->name1utf.c_str()); // auto points1 = yyjson_mut_arr(doc); // yyjson_mut_obj_add_val(doc, curve_1, "points", points1); // // //2号测力点 // yyjson_mut_obj_add_str(doc, curve_2, "name", pInfo->name2utf.c_str()); // auto points2 = yyjson_mut_arr(doc); // yyjson_mut_obj_add_val(doc, curve_2, "points", points2); // // //3号测力点 // yyjson_mut_obj_add_str(doc, curve_3, "name", pInfo->name3utf.c_str()); // auto points3 = yyjson_mut_arr(doc); // yyjson_mut_obj_add_val(doc, curve_3, "points", points3); // // if (nThreshold == 0) // { // 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 tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000; // //#ifdef SHOW_DATA // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points1, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata0); // } // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points2, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata1); // } // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points3, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata2); // } //#endif // // nCount++; // // } while (true); // } // else { // int lastdata0 = INT_MAX, lastdata1 = INT_MAX, lastdata2 = INT_MAX; // time_t tm = 0; // do // { // if (stmt.FetchNext() != 0) // { // if (tm != 0) // { // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points1, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata0); // } // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points2, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata1); // } // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points3, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata2); // } // } // break; // } // // CTime ctTime; // try // { // ctTime = CTime(ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second); // } // catch (...) // { // continue; // } // tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000; // //#ifdef SHOW_DATA // if (abs(lastdata0 - sdata0) > nThreshold) // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points1, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata0); // lastdata0 = sdata0; // } // if (abs(lastdata1 - sdata1) > nThreshold) // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points2, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata1); // lastdata1 = sdata1; // } // if (abs(lastdata2 - sdata2) > nThreshold) // { // auto item = yyjson_mut_arr(doc); // yyjson_mut_arr_add_val(points3, item); // yyjson_mut_arr_add_uint(doc, item, tm); // yyjson_mut_arr_add_int(doc, item, sdata2); // lastdata2 = sdata2; // } //#endif // // nCount++; // // } while (true); // } // // stmt.Close(); // yyjson_mut_obj_add_int(doc, root, "count", nCount); // if (nCount >= 100000) // yyjson_mut_obj_add_bool(doc, root, "has_more", true); // else // yyjson_mut_obj_add_bool(doc, root, "has_more", false); // //扳动信息 // auto fix_points = yyjson_mut_arr(doc); // auto invert_points = yyjson_mut_arr(doc); // auto convert_points = yyjson_mut_arr(doc); // if (pInfo->name1.find("定位") != -1) // { // yyjson_mut_obj_add_val(doc, curve_1, "mark_points", fix_points); // yyjson_mut_obj_add_val(doc, curve_2, "mark_points", invert_points); // } // else // { // yyjson_mut_obj_add_val(doc, curve_1, "mark_points", invert_points); // yyjson_mut_obj_add_val(doc, curve_2, "mark_points", fix_points); // } // yyjson_mut_obj_add_val(doc, curve_3, "mark_points", convert_points); // // //auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT); // //auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT); // //auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT); // // { // int num = 0; // int lastyearmonth = 0; // for (auto it = dtStartDate; it <= dtEndDate;) // { // int yearmonth = it.GetYear() * 100 + it.GetMonth(); // if (yearmonth != lastyearmonth) // { // lastyearmonth = yearmonth; // sprintf_s(tablename, 50, "rm_move_%04d%02d", it.GetYear(), it.GetMonth()); // if (num == 0) // { // sql = fmt::format("SELECT show_time, curr_val, show_val, posiFROM {} \ // WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' AND [type] = 2 ", // tablename, mo, mp, starttime, endtime).c_str(); // } // else // { // sql += fmt::format(" UNION ALL "\ // "SELECT show_time, curr_val, show_val, posi FROM {} \ // WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}' AND [type] = 2 ", // tablename, mo, mp, starttime, endtime).c_str(); // } // num++; // } // it += COleDateTimeSpan(1, 0, 0, 0); // } // sql += "order by posi, show_time"; // } // // if (CDBConnectPool::Instance()->DBQuery(stmt, sql)) // { // // TIMESTAMP_STRUCT ts; // int curr_val; // int show_val; // eDaoChaPosi posi; // ePowerName pn; // // int nCol = 1; // stmt.BindTimeStampCol(nCol++, &ts); // stmt.BindIntCol(nCol++, &curr_val); // stmt.BindIntCol(nCol++, &show_val); // stmt.BindTinyIntCol(nCol++, (BYTE*)&posi); // stmt.BindTinyIntCol(nCol++, (BYTE*)&pn); // // do // { // if (stmt.FetchNext() != 0) // break; // // auto obj = yyjson_mut_obj(doc); // // switch (posi) // { // case eDaoChaPosi::DCP_FIX: // { // if (pn == ePowerName::PN_RETENTION) // { // 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 (pFixSuobi && pFixSuobi->enable) // //{ // // if (pFixSuobi->alarm_low_limit > show_val) // // yyjson_mut_obj_add_str(doc, obj, "color", "Red"); // // else if (pFixSuobi->alarm_high_limit < show_val) // // yyjson_mut_obj_add_str(doc, obj, "color", "Red"); // // else if (pFixSuobi->warn_high_limit < show_val) // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); // // else if (pFixSuobi->warn_low_limit > show_val) // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); // //} // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("保持力:{}", show_val)).c_str()); // } // //if (show_val < 500)//TODO // //{ // // 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: // { // if (pn == ePowerName::PN_RETENTION) // { // 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 (pInvertSuobi && pInvertSuobi->enable) // //{ // // if (pInvertSuobi->alarm_low_limit > show_val) // // yyjson_mut_obj_add_str(doc, obj, "color", "Red"); // // else if (pInvertSuobi->alarm_high_limit < show_val) // // yyjson_mut_obj_add_str(doc, obj, "color", "Red"); // // else if (pInvertSuobi->warn_high_limit < show_val) // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); // // else if (pInvertSuobi->warn_low_limit > show_val) // // yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); // //} // yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("保持力:{}", show_val)).c_str()); // } // //if (show_val < 500)//TODO // //{ // // 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; // default: // ASSERT(FALSE); // break; // } // // } while (TRUE); // } // stmt.Close(); // // ////报警线 // //auto warn_line = yyjson_mut_arr(doc); // //yyjson_mut_obj_add_val(doc, root, "warn_line", warn_line); // // //MAX_OVER_LIMIT_INFO* pFixMax = nullptr; // //MAX_OVER_LIMIT_INFO* pInvertMax = nullptr; // //MAX_OVER_LIMIT_INFO* pConvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::MAX_OVER_LIMIT); // //if (pInfo->name1.find("定位") != -1) // //{ // // pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT); // // pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT); // //} // //else // //{ // // pFixMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 1, eZL_ALARMTYPE::MAX_OVER_LIMIT); // // pInvertMax = (MAX_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, 0, eZL_ALARMTYPE::MAX_OVER_LIMIT); // //} // ////定位 // //if (pFixMax && pFixMax->enable) // //{ // // static string fixnameutf = ANSItoUTF8("定位"); // // if (pFixMax->alarm_high_limit != INT_MAX) // // { // // auto object = yyjson_mut_obj(doc); // // yyjson_mut_arr_add_val(warn_line, object); // // yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str()); // // yyjson_mut_obj_add_str(doc, object, "color", "red"); // // yyjson_mut_obj_add_int(doc, object, "val", pFixMax->alarm_high_limit); // // } // // if (pFixMax->warn_high_limit != INT_MAX) // // { // // auto object = yyjson_mut_obj(doc); // // yyjson_mut_arr_add_val(warn_line, object); // // yyjson_mut_obj_add_str(doc, object, "label", fixnameutf.c_str()); // // yyjson_mut_obj_add_str(doc, object, "color", "orange"); // // yyjson_mut_obj_add_int(doc, object, "val", pFixMax->warn_high_limit); // // } // //} // //if (pInvertMax && pInvertMax->enable) // //{ // // static string invertnameutf = ANSItoUTF8("反位"); // // if (pInvertMax->alarm_high_limit != INT_MAX) // // { // // auto object = yyjson_mut_obj(doc); // // yyjson_mut_arr_add_val(warn_line, object); // // yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str()); // // yyjson_mut_obj_add_str(doc, object, "color", "red"); // // yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->alarm_high_limit); // // } // // if (pInvertMax->warn_high_limit != INT_MAX) // // { // // auto object = yyjson_mut_obj(doc); // // yyjson_mut_arr_add_val(warn_line, object); // // yyjson_mut_obj_add_str(doc, object, "label", invertnameutf.c_str()); // // yyjson_mut_obj_add_str(doc, object, "color", "orange"); // // yyjson_mut_obj_add_int(doc, object, "val", pInvertMax->warn_high_limit); // // } // //} // //if (pConvertMax && pConvertMax->enable) // //{ // // static string d2fnameutf = ANSItoUTF8("定扳反"); // // static string f2dnameutf = ANSItoUTF8("反扳定"); // // if (pConvertMax->alarm_high_limit != INT_MAX) // // { // // auto object = yyjson_mut_obj(doc); // // yyjson_mut_arr_add_val(warn_line, object); // // yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str()); // // yyjson_mut_obj_add_str(doc, object, "color", "red"); // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->alarm_high_limit); // // } // // if (pConvertMax->warn_high_limit != INT_MAX) // // { // // auto object = yyjson_mut_obj(doc); // // yyjson_mut_arr_add_val(warn_line, object); // // yyjson_mut_obj_add_str(doc, object, "label", d2fnameutf.c_str()); // // yyjson_mut_obj_add_str(doc, object, "color", "orange"); // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->warn_high_limit); // // } // // if (pConvertMax->f_alarm_high_limit != INT_MAX) // // { // // auto object = yyjson_mut_obj(doc); // // yyjson_mut_arr_add_val(warn_line, object); // // yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str()); // // yyjson_mut_obj_add_str(doc, object, "color", "red"); // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_alarm_high_limit); // // } // // if (pConvertMax->f_warn_high_limit != INT_MAX) // // { // // auto object = yyjson_mut_obj(doc); // // yyjson_mut_arr_add_val(warn_line, object); // // yyjson_mut_obj_add_str(doc, object, "label", f2dnameutf.c_str()); // // yyjson_mut_obj_add_str(doc, object, "color", "orange"); // // yyjson_mut_obj_add_int(doc, object, "val", pConvertMax->f_warn_high_limit); // // } // //} // // *json = yyjson_mut_write(doc, 0, json_len); // yyjson_mut_doc_free(doc); // // return 200; //} //设置参考曲线 int DealPostrefer_curve(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); 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,end_time,idx FROM rm_move_{:0>4}{:0>2} WHERE mo = '{}' and mp = '{}' and show_time = '{}' and [type] <> 2", 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 }, tsEnd = { 0 }; uint8_t idx = -1; stmt.BindTimeStampCol(1, &ts); stmt.BindTimeStampCol(2, &tsEnd); stmt.BindTinyIntCol(3, &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(tsEnd.year, tsEnd.month, tsEnd.day, tsEnd.hour, tsEnd.minute, tsEnd.second); 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 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& data0, const std::map& data1, const std::map& 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"); string end_time = req.get_param_value("end_time"); string type = req.get_param_value("type"); if (mo.length() == 0 || mp.length() == 0 || time.length() == 0 || name.length() == 0) return 400; if (type.compare("1") != 0) return 501;//后台未实现 time_t uTime = atoll(time.c_str()); COleDateTime odt(uTime); COleDateTime odtEnd(odt); if (odt.GetStatus() == COleDateTime::invalid) return 400; if (end_time.empty() == false) { odtEnd = COleDateTime(atoll(end_time.c_str())); if (odtEnd.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);//锁闭力数据 //auto baochi_lock = yyjson_mut_obj(doc); //yyjson_mut_obj_add_val(doc, root, "baochi_lock", baochi_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()); //yyjson_mut_obj_add_strcpy(doc, baochi_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 baochi_curve_data = yyjson_mut_arr(doc); //yyjson_mut_obj_add_val(doc, baochi_lock, "curve_data", baochi_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); //auto baochi_line = yyjson_mut_arr(doc); //yyjson_mut_obj_add_val(doc, baochi_lock, "line", baochi_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); //auto d_baochi_obj = yyjson_mut_obj(doc); //yyjson_mut_obj_add_strcpy(doc, d_baochi_obj, "name", ANSItoUTF8("定位保持力值").c_str()); //yyjson_mut_obj_add_str(doc, d_baochi_obj, "color", "#a8ff78");// 苹果绿 //yyjson_mut_arr_add_val(baochi_curve_data, d_baochi_obj); //auto f_baochi_obj = yyjson_mut_obj(doc); //yyjson_mut_obj_add_strcpy(doc, f_baochi_obj, "name", ANSItoUTF8("反位保持力值").c_str()); //yyjson_mut_obj_add_str(doc, f_baochi_obj, "color", "#FFE000");// 芒果黄 //yyjson_mut_arr_add_val(baochi_curve_data, f_baochi_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); //auto d_baochi_data = yyjson_mut_arr(doc); //yyjson_mut_obj_add_val(doc, d_baochi_obj, "data", d_baochi_data); //auto f_baochi_data = yyjson_mut_arr(doc); //yyjson_mut_obj_add_val(doc, f_baochi_obj, "data", f_baochi_data); //query //TODO 查询数据库 填充 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; if (odt.GetMonth() == odtEnd.GetMonth()) { sql = fmt::format("SELECT show_time,show_val,posi,[type],[sunroof] FROM {} WHERE mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}'", table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), odtEnd.Format("%Y-%m-%d 23:59:59.999")).c_str(); } else { string table_name_next = fmt::format("rm_move_{:0>4}{:0>2}", odtEnd.GetYear(), odtEnd.GetMonth()); sql = fmt::format("SELECT show_time,show_val,posi,[type],[sunroof] FROM {0} WHERE mo = '{1}' AND mp = '{2}' AND show_time >= '{3}' \ UNION SELECT show_time, show_val, posi,[type] FROM {4} WHERE mo = '{1}' AND mp = '{2}' AND show_time <= '{5}'", table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), table_name_next, odtEnd.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; ePowerName pn; stmt.BindTimeStampCol(nCol++, &ts); stmt.BindIntCol(nCol++, &show_val); stmt.BindTinyIntCol(nCol++, (BYTE*)&posi); stmt.BindTinyIntCol(nCol++, (BYTE*)&pn); 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: if (pn == ePowerName::PN_RETENTION) { //yyjson_mut_arr_add_val(d_baochi_data, o); } else { yyjson_mut_arr_add_val(d_suobi_data, o); } break; case eDaoChaPosi::DCP_INVERT: if (pn == ePowerName::PN_RETENTION) { //yyjson_mut_arr_add_val(f_baochi_data, o); } else { 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 DealGetRetentionCurve(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"); string end_time = req.get_param_value("end_time"); string type = req.get_param_value("type"); if (mo.length() == 0 || mp.length() == 0 || time.length() == 0 || name.length() == 0) return 400; if (type.compare("1") != 0) return 501;//后台未实现 time_t uTime = atoll(time.c_str()); COleDateTime odt(uTime); COleDateTime odtEnd(odt); if (odt.GetStatus() == COleDateTime::invalid) return 400; if (end_time.empty() == false) { odtEnd = COleDateTime(atoll(end_time.c_str())); if (odtEnd.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 data = yyjson_mut_obj(doc); yyjson_mut_obj_add_val(doc, root, "data", data);//转换阻力 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, data, "title", ANSItoUTF8("保持力趋势图").c_str()); //curve_data and line auto baochi_curve_data = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, data, "curve_data", baochi_curve_data); auto baochi_line = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, data, "line", baochi_line); //curve_obj auto d_baochi_obj = yyjson_mut_obj(doc); yyjson_mut_obj_add_strcpy(doc, d_baochi_obj, "name", ANSItoUTF8("定位保持力").c_str()); yyjson_mut_obj_add_str(doc, d_baochi_obj, "color", "#a8ff78");// 苹果绿 yyjson_mut_arr_add_val(baochi_curve_data, d_baochi_obj); auto f_baochi_obj = yyjson_mut_obj(doc); yyjson_mut_obj_add_strcpy(doc, f_baochi_obj, "name", ANSItoUTF8("反位保持力").c_str()); yyjson_mut_obj_add_str(doc, f_baochi_obj, "color", "#FFE000");// 芒果黄 yyjson_mut_arr_add_val(baochi_curve_data, f_baochi_obj); //curve_data auto d_baochi_data = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, d_baochi_obj, "data", d_baochi_data); auto f_baochi_data = yyjson_mut_arr(doc); yyjson_mut_obj_add_val(doc, f_baochi_obj, "data", f_baochi_data); //query //TODO 查询数据库 填充 d_convert_data f_convert_data d_baochi_data f_baochi_data { string table_name = fmt::format("rm_move_{:0>4}{:0>2}", odt.GetYear(), odt.GetMonth()); CString sql; if (odt.GetMonth() == odtEnd.GetMonth()) { sql = fmt::format("SELECT show_time,show_val,posi FROM {} WHERE [type] = 2 AND mo = '{}' AND mp = '{}' AND show_time >= '{}' AND show_time <= '{}'", table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), odtEnd.Format("%Y-%m-%d 23:59:59.999")).c_str(); } else { string table_name_next = fmt::format("rm_move_{:0>4}{:0>2}", odtEnd.GetYear(), odtEnd.GetMonth()); sql = fmt::format("SELECT show_time,show_val,posi FROM {0} WHERE [type] = 2 AND mo = '{1}' AND mp = '{2}' AND show_time >= '{3}' \ UNION SELECT show_time, show_val, posi FROM {4} WHERE [type] = 2 AND mo = '{1}' AND mp = '{2}' AND show_time <= '{5}'", table_name, mo, mp, odt.Format("%Y-%m-%d 00:00:00"), table_name_next, odtEnd.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; ePowerName pn; stmt.BindTimeStampCol(nCol++, &ts); stmt.BindIntCol(nCol++, &show_val); stmt.BindTinyIntCol(nCol++, (BYTE*)&posi); stmt.BindTinyIntCol(nCol++, (BYTE*)&pn); 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_baochi_data, o); break; case eDaoChaPosi::DCP_INVERT: yyjson_mut_arr_add_val(f_baochi_data, o); break; default: ASSERT(FALSE); break; } } while (TRUE); } stmt.Close(); } //line { //定位告警线 RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::RETENSION_FORCE); if (pInfo && pInfo->enable) { if (pInfo->dw_alarm_low_drop > INT_MIN) { auto obj = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(baochi_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_drop); yyjson_mut_obj_add_str(doc, obj, "color", "Red"); } } } { //反位告警线 RETENSION_FORCE_DROP* pInfo = (RETENSION_FORCE_DROP*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::RETENSION_FORCE); if (pInfo && pInfo->enable) { if (pInfo->dw_alarm_low_drop > INT_MIN) { auto obj = yyjson_mut_obj(doc); yyjson_mut_arr_add_val(baochi_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_drop); 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 DealGetRetentionReport(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 [type] = 2 AND 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_baochi_lock = INT_MAX; int d_baochi_lock_max = INT_MAX; int d_baochi_lock_min = INT_MAX; int d_baochi_lock_avg = INT_MAX; int f_baochi_lock = INT_MAX; int f_baochi_lock_max = INT_MAX; int f_baochi_lock_min = INT_MAX; int f_baochi_lock_avg = INT_MAX; }; std::map 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; ePowerName pn; 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.BindTinyIntCol(nCol++, (BYTE*)&pn); 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_baochi_lock = num; it.d_baochi_lock_max = max; it.d_baochi_lock_min = min; if (num) it.d_baochi_lock_avg = sum / num; break; case eDaoChaPosi::DCP_INVERT: it.f_baochi_lock = num; it.f_baochi_lock_max = max; it.f_baochi_lock_min = min; if (num) it.f_baochi_lock_avg = sum / num; 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_baochi_lock != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "d_retention_fore", it.second.d_baochi_lock); else yyjson_mut_obj_add_str(doc, obj, "d_retention_fore", "-"); if (it.second.d_baochi_lock_max != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_max", it.second.d_baochi_lock_max); else yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max", "-"); if (it.second.d_baochi_lock_min != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_min", it.second.d_baochi_lock_min); else yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min", "-"); if (it.second.d_baochi_lock_avg != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_avg", it.second.d_baochi_lock_avg); else yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg", "-"); if (it.second.f_baochi_lock != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "f_retention_fore", it.second.f_baochi_lock); else yyjson_mut_obj_add_str(doc, obj, "f_retention_fore", "-"); if (it.second.f_baochi_lock_max != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_max", it.second.f_baochi_lock_max); else yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max", "-"); if (it.second.f_baochi_lock_min != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_min", it.second.f_baochi_lock_min); else yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min", "-"); if (it.second.f_baochi_lock_avg != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_avg", it.second.f_baochi_lock_avg); else yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg", "-"); } } *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, CASE WHEN posi = 3 OR posi = 4 THEN 3 WHEN [type] = 0 THEN 1 ELSE [type] END AS [newtype] FROM {} WHERE mo in (SELECT id FROM rm_mo WHERE up = '{}') AND show_time >= '{}' AND show_time <= '{}' GROUP BY mo, mp, posi, \ CASE WHEN posi = 3 OR posi = 4 THEN 3 WHEN [type] = 0 THEN 1 ELSE [type] END ) 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; int d_baochi_lock = INT_MAX; int d_baochi_lock_max = INT_MAX; int d_baochi_lock_min = INT_MAX; int d_baochi_lock_avg = INT_MAX; uint8_t d_baochi_lock_max_color = 0; uint8_t d_baochi_lock_min_color = 0; uint8_t d_baochi_lock_avg_color = 0; int f_baochi_lock = INT_MAX; int f_baochi_lock_max = INT_MAX; int f_baochi_lock_min = INT_MAX; int f_baochi_lock_avg = INT_MAX; uint8_t f_baochi_lock_max_color = 0; uint8_t f_baochi_lock_min_color = 0; uint8_t f_baochi_lock_avg_color = 0; }; std::map 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; ePowerName pn; 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.BindTinyIntCol(nCol++, (BYTE*)&pn); 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: if (pn == ePowerName::PN_RETENTION) { it.d_baochi_lock = num; it.d_baochi_lock_max = max; it.d_baochi_lock_min = min; if (num) it.d_baochi_lock_avg = sum / num; } else { 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: if (pn == ePowerName::PN_RETENTION) { it.f_baochi_lock = num; it.f_baochi_lock_max = max; it.f_baochi_lock_min = min; if (num) it.f_baochi_lock_avg = sum / num; } else { 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"); if (it.second.d_baochi_lock != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "d_retention_fore", it.second.d_baochi_lock); else yyjson_mut_obj_add_str(doc, obj, "d_retention_fore", "-"); if (it.second.d_baochi_lock_max != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_max", it.second.d_baochi_lock_max); else yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max", "-"); if (it.second.d_baochi_lock_min != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_min", it.second.d_baochi_lock_min); else yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min", "-"); if (it.second.d_baochi_lock_avg != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "d_retention_fore_avg", it.second.d_baochi_lock_avg); else yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg", "-"); //颜色 if (it.second.d_baochi_lock_max_color == UINT8_ALARM) yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max_color", "red"); else if (it.second.d_baochi_lock_max_color == UINT8_WARN) yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_max_color", "orange"); if (it.second.d_baochi_lock_min_color == UINT8_ALARM) yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min_color", "red"); else if (it.second.d_baochi_lock_min_color == UINT8_WARN) yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_min_color", "orange"); if (it.second.d_baochi_lock_avg_color == UINT8_ALARM) yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg_color", "red"); else if (it.second.d_baochi_lock_avg_color == UINT8_WARN) yyjson_mut_obj_add_str(doc, obj, "d_retention_fore_avg_color", "orange"); if (it.second.f_baochi_lock != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "f_retention_fore", it.second.f_baochi_lock); else yyjson_mut_obj_add_str(doc, obj, "f_retention_fore", "-"); if (it.second.f_baochi_lock_max != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_max", it.second.f_baochi_lock_max); else yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max", "-"); if (it.second.f_baochi_lock_min != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_min", it.second.f_baochi_lock_min); else yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min", "-"); if (it.second.f_baochi_lock_avg != INT_MAX) yyjson_mut_obj_add_int(doc, obj, "f_retention_fore_avg", it.second.f_baochi_lock_avg); else yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg", "-"); //颜色 if (it.second.f_baochi_lock_max_color == UINT8_ALARM) yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max_color", "red"); else if (it.second.f_baochi_lock_max_color == UINT8_WARN) yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_max_color", "orange"); if (it.second.f_baochi_lock_min_color == UINT8_ALARM) yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min_color", "red"); else if (it.second.f_baochi_lock_min_color == UINT8_WARN) yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_min_color", "orange"); if (it.second.f_baochi_lock_avg_color == UINT8_ALARM) yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_avg_color", "red"); else if (it.second.f_baochi_lock_avg_color == UINT8_WARN) yyjson_mut_obj_add_str(doc, obj, "f_retention_fore_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); auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT); auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT); auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT); string out_name, in_name; CMonitorObjectMng::Instance()->GetDirectByMoMp(mo + "." + mp, out_name, in_name); //string name1, name2, name3, out_name, in_name; //CMonitorObjectMng::Instance()->GetNameByMoMp(mo + "." + mp, name1, name2, name3, out_name, in_name); 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 <= '{}' AND [type] <> 2 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 (pFixSuobi && pFixSuobi->enable) { if (pFixSuobi->alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pFixSuobi->alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pFixSuobi->warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); else if (pFixSuobi->warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str()); //if (show_val < 500)//TODO //{ // 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 (pInvertSuobi && pInvertSuobi->enable) { if (pInvertSuobi->alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pInvertSuobi->alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pInvertSuobi->warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); else if (pInvertSuobi->warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", show_val)).c_str()); //if (show_val < 500)//TODO //{ // 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 (pConvertLimit && pConvertLimit->enable) { if (out_name.find("定扳反") != -1) { if (pConvertLimit->dw_alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->dw_warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } else { if (pConvertLimit->up_alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->up_warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } } 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 (pConvertLimit && pConvertLimit->enable) { if (out_name.find("反扳定") != -1) { if (pConvertLimit->dw_alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->dw_warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } else { if (pConvertLimit->up_alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->up_warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } } 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; } #include "MGWSServer.h" int DealResistMove(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 starttime = req.get_param_value("starttime"); string endtime = req.get_param_value("endtime"); if (mo.length() == 0 || mp.length() == 0 || starttime.length() == 0 || endtime.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; int code = 400; do { auto ret_time = odtEnd.ParseDateTime(endtime.c_str()); if (ret_time == FALSE) break; ret_time = odtStart.ParseDateTime(starttime.c_str()); if (ret_time == FALSE) break; if (odtEnd <= odtStart) break; string momp = mo + "." + mp; auto pInfo = CMonitorObjectMng::Instance()->GetMoMpInfo(momp); if (pInfo == nullptr) { code = 404; break; } char tablename[50] = { 0 }; auto dtStartDate = COleDateTime(odtStart.GetYear(), odtStart.GetMonth(), odtStart.GetDay(), 0, 0, 0); auto strStartDate = dtStartDate.Format("%Y-%m-%d %H:%M:%S"); auto strEndDate = odtEnd.Format("%Y-%m-%d %H:%M:%S");; CString sql; { int num = 0; for (auto it = dtStartDate; it < odtEnd;) { sprintf_s(tablename, 50, "rm_resistance_%04d%02d%02d", it.GetYear(), it.GetMonth(), it.GetDay()); if (num == 0) { sql.Format("SELECT [acquisitiontime],[data0],[data1],[data2] "\ "FROM %s WHERE IMEI = '%s' AND acquisitiontime >= '%s' and acquisitiontime < '%s' AND idx = %d ", tablename, pInfo->imei.c_str(), starttime.c_str(), endtime.c_str(), pInfo->idx); } else { sql += fmt::format(" UNION ALL "\ "SELECT [acquisitiontime],[data0],[data1],[data2] "\ "FROM {} WHERE IMEI = '{}' AND acquisitiontime >= '{}' and acquisitiontime < '{}' AND idx = {} ", tablename, pInfo->imei.c_str(), starttime, endtime, pInfo->idx).c_str(); } num++; it += COleDateTimeSpan(1, 0, 0, 0); } sql += "ORDER BY acquisitiontime ASC"; } TIMESTAMP_STRUCT ts; int sdata0, sdata1, sdata2; COdbcStatement stmt; if (CDBConnectPool::Instance()->DBQuery(stmt, sql) == FALSE) { ASSERT(0); SPDLOG_ERROR("查询语句出错:{}", sql); code = 500; break; } int nCol = 1; stmt.BindTimeStampCol(nCol++, &ts); stmt.BindIntCol(nCol++, &sdata0); stmt.BindIntCol(nCol++, &sdata1); stmt.BindIntCol(nCol++, &sdata2); int nCount = 0; std::map data0, data1, data2; 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 tm = ctTime.GetTime() * 1000 + ts.fraction / 1000000; data0[tm] = sdata0; data1[tm] = sdata1; data2[tm] = sdata2; nCount++; } while (true); stmt.Close(); list maxResist; //转换力数据 list lstPass; //过车数据 std::map maxlock0, maxlock1;//锁闭力 前面时间戳, 后面 高4位显示值, 低4位报警值 std::map retentionforce0, retentionforce1; //保持力 时间戳, 高4位显示值, 低4位报警值 std::map mapSecondStatInfo0, mapSecondStatInfo1, mapSecondStatInfo2; mg_per_session_data::GetMaxResist(data2, mapSecondStatInfo2, maxResist, mo, mp); mg_per_session_data::GetPassNew(mapSecondStatInfo0, &data0, mapSecondStatInfo1, &data1, mo, mp, &lstPass); //过车过滤 for (auto& item : lstPass) { for (auto it = maxResist.begin();it != maxResist.end();) { if (it->tmStart*1000 <= item.show_time && item.show_time <= (it->tmEnd+1)*1000) { it = maxResist.erase(it); break; } ++it; } } if (maxResist.size()) { mg_per_session_data::GetMaxLockNew(data0, maxResist, maxlock0, retentionforce0); mg_per_session_data::GetMaxLockNew(data1, maxResist, maxlock1, retentionforce1); } else { code = 200; continue; //没有检查到转换阻力 } //CalcFixOrInvert(maxResist, maxlock0, maxlock1, name1, name2); //GetMaxForce(data2, maxForce); 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); auto pConvertLimit = (CONVERT_RESIST_OVER_LIMIT*)CResistAlarmMng::Instance()->Find(mo, mp, 2, eZL_ALARMTYPE::CONVERT_LIMIT); auto pFixSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_FIX, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT); auto pInvertSuobi = (SUOBI_OVER_LIMIT_INFO*)CResistAlarmMng::Instance()->Find(mo, mp, (uint8_t)eSuoBiPosi::SB_INVERT, eZL_ALARMTYPE::SUOBI_LOCK_LIMIT); std::map* pmaxlockfix = nullptr, * pmaxlockinvert = nullptr; if (pInfo->name1.find("定位") != -1) { pmaxlockfix = &maxlock0; pmaxlockinvert = &maxlock1; } else { pmaxlockfix = &maxlock1; pmaxlockinvert = &maxlock0; } for (auto& it : *pmaxlockfix) { int curr_val = (int)it.second; int show_val = (it.second >> 32); time_t show_time = it.first; auto obj = yyjson_mut_obj(doc); 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, show_time); yyjson_mut_arr_add_int(doc, coord, curr_val); yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time/1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str()); yyjson_mut_obj_add_int(doc, obj, "val", show_val); if (pFixSuobi && pFixSuobi->enable) { if (pFixSuobi->alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pFixSuobi->alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pFixSuobi->warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); else if (pFixSuobi->warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", ++show_val)).c_str()); //CResistAlarmMng::InsertToDBByMove(mo, mp, it.first, 0, 0, // (int)it.second, show_val, i, (uint8_t)eDaoChaPosi::DCP_FIX, fmt::format("锁闭力:{}", show_val)); //JudgeAlarm(pService, pFixSuobiOverInfo, it.first, show_val, eSuoBiPosi::SB_FIX, mo, mp, zzjno); } for (auto& it : *pmaxlockinvert) { int curr_val = (int)it.second; int show_val = (it.second >> 32); time_t show_time = it.first; auto obj = yyjson_mut_obj(doc); 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, show_time); yyjson_mut_arr_add_int(doc, coord, curr_val); yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str()); yyjson_mut_obj_add_int(doc, obj, "val", show_val); if (pInvertSuobi && pInvertSuobi->enable) { if (pInvertSuobi->alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pInvertSuobi->alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pInvertSuobi->warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); else if (pInvertSuobi->warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } yyjson_mut_obj_add_strcpy(doc, obj, "label", ANSItoUTF8(fmt::format("锁闭力:{}", ++show_val)).c_str()); //int show_val = (it.second >> 32); //CResistAlarmMng::InsertToDBByMove(mo, mp, it.first, 0, 0, // (int)it.second, show_val, i, (uint8_t)eDaoChaPosi::DCP_INVERT, fmt::format("锁闭力:{}", show_val)); //JudgeAlarm(pService, pInvertSuobiOverInfo, it.first, show_val, eSuoBiPosi::SB_INVERT, mo, mp, zzjno); } for (auto& it : maxResist) { auto obj = yyjson_mut_obj(doc); int curr_val = it.val; int show_val = it.fluctuation_val; time_t show_time = it.time; eDaoChaPosi posi = eDaoChaPosi::DCP_UNKNOWN; if (it.bUpOrDown == eUpOrDownInfo::UOD_UP) { if (pInfo->in_name.find("定扳反") != -1) { 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, show_time); yyjson_mut_arr_add_int(doc, coord, curr_val); yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str()); yyjson_mut_obj_add_int(doc, obj, "val", show_val); if (pConvertLimit && pConvertLimit->enable) { if (pInfo->out_name.find("定扳反") != -1) { if (pConvertLimit->dw_alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->dw_warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } else { if (pConvertLimit->up_alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->up_warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } } 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()); //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i, // (uint8_t)eDaoChaPosi::DCP_FIX2INVERT, fmt::format("{}:{}", in_name, it.fluctuation_val)); //posi = eDaoChaPosi::DCP_FIX2INVERT; //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_INVERT); //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno); } else { 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, show_time); yyjson_mut_arr_add_int(doc, coord, curr_val); yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str()); yyjson_mut_obj_add_int(doc, obj, "val", show_val); if (pConvertLimit && pConvertLimit->enable) { if (pInfo->out_name.find("反扳定") != -1) { if (pConvertLimit->dw_alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->dw_warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } else { if (pConvertLimit->up_alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->up_warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } } 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()); //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i, // (uint8_t)eDaoChaPosi::DCP_INVERT2FIX, fmt::format("{}:{}", in_name, it.fluctuation_val)); //posi = eDaoChaPosi::DCP_INVERT2FIX; //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_FIX); //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno); } } else { if (pInfo->out_name.find("定扳反") != -1) { 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, show_time); yyjson_mut_arr_add_int(doc, coord, curr_val); yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str()); yyjson_mut_obj_add_int(doc, obj, "val", show_val); if (pConvertLimit && pConvertLimit->enable) { if (pInfo->out_name.find("定扳反") != -1) { if (pConvertLimit->dw_alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->dw_warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } else { if (pConvertLimit->up_alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->up_warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } } 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()); //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i, // (uint8_t)eDaoChaPosi::DCP_FIX2INVERT, fmt::format("{}:{}", out_name, it.fluctuation_val)); //posi = eDaoChaPosi::DCP_FIX2INVERT; //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_INVERT); //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno); } else { 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, show_time); yyjson_mut_arr_add_int(doc, coord, curr_val); yyjson_mut_obj_add_strcpy(doc, obj, "time", fmt::format("{}.{:0>3}", CTime(show_time / 1000).Format("%Y-%m-%d %H:%M:%S"), show_time % 1000).c_str()); yyjson_mut_obj_add_int(doc, obj, "val", show_val); if (pConvertLimit && pConvertLimit->enable) { if (pInfo->out_name.find("反扳定") != -1) { if (pConvertLimit->dw_alarm_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->dw_warn_low_limit > show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } else { if (pConvertLimit->up_alarm_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Red"); else if (pConvertLimit->up_warn_high_limit < show_val) yyjson_mut_obj_add_str(doc, obj, "color", "Orange"); } } 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()); //CResistAlarmMng::InsertToDBByMove(mo, mp, it.time, it.tmStart, it.tmEnd, it.val, it.fluctuation_val, i, // (uint8_t)eDaoChaPosi::DCP_INVERT2FIX, fmt::format("{}:{}", out_name, it.fluctuation_val)); //posi = eDaoChaPosi::DCP_INVERT2FIX; //CMonitorObjectMng::Instance()->UpdateZZJEPOS(mo + "." + mp, DAOCHA_POSITION::MP_FIX); //JudgeAlarm(pService, pConvertResistOverLimitInfo, it.time, it.fluctuation_val, posi, it.bUpOrDown, mo, mp, zzjno); } } } code = 200; } while (false); *json = yyjson_mut_write(doc, 0, json_len); yyjson_mut_doc_free(doc); return code; }