From 0e2ade351c79a140b11deb232095def55461679f Mon Sep 17 00:00:00 2001 From: lnk Date: Fri, 17 Jul 2026 13:57:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B0=E8=B4=A6=E6=9B=B4=E6=96=B0=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0comtype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cfg_parse/cfg_parser.cpp | 69 ++++++++++++++++++++++++++++++++++++-- cfg_parse/log4.cpp | 2 +- json/save2json.cpp | 71 +++++++++++++++++++++++++++++++++++++++- json/save2json.h | 3 +- mms/mms_process.c | 2 +- mms/rdb_client.h | 1 + 6 files changed, 142 insertions(+), 6 deletions(-) diff --git a/cfg_parse/cfg_parser.cpp b/cfg_parse/cfg_parser.cpp index 8fea8ce..07e25a0 100644 --- a/cfg_parse/cfg_parser.cpp +++ b/cfg_parse/cfg_parser.cpp @@ -1704,6 +1704,8 @@ void add_terminal_to_trigger_update(trigger_update_xml_t* trigger_update_xml, co } } +static bool terminal_update_should_bind_to_current_process(const terminal* dev); + // 解析 XML 数据并提取 terminal 信息 void parse_terminal_from_data(trigger_update_xml_t* trigger_update_xml, const std::string& str_tag, const std::string& data,const std::string& guid_value) { terminal work_terminal = {}; // 创建新的 terminal 对象 @@ -1719,6 +1721,13 @@ void parse_terminal_from_data(trigger_update_xml_t* trigger_update_xml, const st strcpy(work_terminal.dev_type, extract_value(data, "devType").c_str()); strcpy(work_terminal.dev_key, extract_value(data, "devKey").c_str()); strcpy(work_terminal.dev_series, extract_value(data, "series").c_str()); + std::string com_type = extract_value(data, "comType"); + if (com_type.empty()) + com_type = extract_value(data, "com_type"); + if (com_type.empty()) + com_type = "MMS"; + strncpy(work_terminal.com_type, com_type.c_str(), sizeof(work_terminal.com_type) - 1); + work_terminal.com_type[sizeof(work_terminal.com_type) - 1] = '\0'; strcpy(work_terminal.processNo, extract_value(data, "processNo").c_str()); strcpy(work_terminal.addr_str, extract_value(data, "ip").c_str()); strcpy(work_terminal.port, extract_value(data, "port").c_str()); @@ -1805,6 +1814,13 @@ void parse_terminal_from_data(trigger_update_xml_t* trigger_update_xml, const st // 根据 str_tag 将 terminal 添加到相应的数组 + if (!terminal_update_should_bind_to_current_process(&work_terminal)) { + std::cout << "skip ledger update xml by comType:" << work_terminal.com_type + << " terminal:" << work_terminal.terminal_id + << " process:" << subdir << g_front_seg_index << std::endl; + return; + } + add_terminal_to_trigger_update(trigger_update_xml, str_tag, work_terminal); } @@ -1825,11 +1841,25 @@ void parse_ledger_update(trigger_update_xml_t* trigger_update_xml, const std::st if (strTag == "delete") { // 填充终端信息 strcpy(delete_terminal.terminal_id, extract_value(data, "id").c_str()); + std::string com_type = extract_value(data, "comType"); + if (com_type.empty()) + com_type = extract_value(data, "com_type"); + if (com_type.empty()) + com_type = "MMS"; + strncpy(delete_terminal.com_type, com_type.c_str(), sizeof(delete_terminal.com_type) - 1); + delete_terminal.com_type[sizeof(delete_terminal.com_type) - 1] = '\0'; //添加guid20250506 strncpy(delete_terminal.guid, guid_value.c_str(), sizeof(delete_terminal.guid) - 1); delete_terminal.guid[sizeof(delete_terminal.guid) - 1] = '\0'; + if (!terminal_update_should_bind_to_current_process(&delete_terminal)) { + std::cout << "skip delete ledger update xml by comType:" << delete_terminal.com_type + << " terminal:" << delete_terminal.terminal_id + << " process:" << subdir << g_front_seg_index << std::endl; + return; + } + // 将删除信息写入 delete_updates std::cout << "delete ledger!!!!!"<delete_update_num < MAX_UPDATEA_NUM) { @@ -3400,7 +3430,7 @@ static bool is_cfg_pqdif_process() static bool is_pqdif_com_type(const char* com_type) { QString type = com_type ? QString::fromLocal8Bit(com_type).trimmed() : QString(); - return type.compare("pqdif", Qt::CaseInsensitive) == 0; + return type.compare("PQDIF", Qt::CaseInsensitive) == 0; } static bool terminal_should_bind_to_current_process(const terminal_dev* dev) @@ -3417,6 +3447,20 @@ static bool terminal_should_bind_to_current_process(const terminal_dev* dev) return (atoi(dev->processNo) == g_front_seg_index || g_front_seg_index == 0); } +static bool terminal_update_should_bind_to_current_process(const terminal* dev) +{ + if (dev == NULL) + return false; + + if (is_pqdif_com_type(dev->com_type)) + return is_cfg_pqdif_process(); + + if (is_cfg_pqdif_process()) + return false; + + return true; +} + void printTerminalDevMap(const QMap& terminal_dev_map) { QMap::const_iterator it; for (it = terminal_dev_map.constBegin(); it != terminal_dev_map.constEnd(); ++it) { @@ -3470,6 +3514,7 @@ void printLedger(const ied_usr_t& ied_usr) { std::cout << "|-- dev_type: " << ied_usr.dev_type << std::endl; std::cout << "|-- dev_key: " << ied_usr.dev_key << std::endl; std::cout << "|-- dev_series: " << ied_usr.dev_series << std::endl; + std::cout << "|-- com_type: " << ied_usr.com_type << std::endl; std::cout << "|-- dev_flag: " << ied_usr.dev_flag << std::endl; std::cout << "|-- last_call_wavelist_time: " << ied_usr.last_call_wavelist_time << std::endl; @@ -3564,6 +3609,7 @@ void printLedgerinshell(const ied_usr_t& ied_usr, QIODevice* outputDevice) { outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_type: " + QByteArray(ied_usr.dev_type) + "\n"); outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_key: " + QByteArray(ied_usr.dev_key) + "\n"); outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_series: " + QByteArray(ied_usr.dev_series) + "\n"); + outputDevice->write("\r\x1B[K");outputDevice->write("|-- com_type: " + QByteArray(ied_usr.com_type) + "\n"); outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_processNo: " + QByteArray(ied_usr.processNo) + "\n"); outputDevice->write("\r\x1B[K");outputDevice->write("|-- dev_flag: " + QByteArray::number(ied_usr.dev_flag) + "\n"); outputDevice->write("\r\x1B[K");outputDevice->write("|-- last_call_wavelist_time: " + QByteArray::number(ied_usr.last_call_wavelist_time) + "\n"); @@ -4119,7 +4165,7 @@ int terminal_ledger_web(QMap* terminal_dev_map, if (comType == NULL) comType = cJSON_GetObjectItem(item, "com_type"); if (comType && comType->type == cJSON_String) strncpy(dev->com_type, comType->valuestring, sizeof(dev->com_type) - 1); - else strncpy(dev->com_type, "mms", sizeof(dev->com_type) - 1); + else strncpy(dev->com_type, "MMS", sizeof(dev->com_type) - 1); dev->com_type[sizeof(dev->com_type) - 1] = '\0'; //lnk20250210台账进程号 @@ -4409,6 +4455,7 @@ int parse_device_cfg_web() char dev_type[64]; char dev_key[255]; char dev_series[255]; + char com_type[32]; char addr_str[64]; char port_char[64]; @@ -4438,6 +4485,8 @@ int parse_device_cfg_web() strncpy(dev_type, value->dev_type, sizeof(dev_type) - 1); strncpy(dev_key, value->dev_key, sizeof(dev_key) - 1); strncpy(dev_series, value->dev_series, sizeof(dev_series) - 1); + strncpy(com_type, value->com_type, sizeof(com_type) - 1); + com_type[sizeof(com_type) - 1] = '\0'; strncpy(addr_str, value->addr_str, sizeof(addr_str) - 1); strncpy(port_char, value->port, sizeof(port_char) - 1); strncpy(processNo, value->processNo, sizeof(processNo) - 1);//进程号 @@ -4503,6 +4552,14 @@ int parse_device_cfg_web() cout << "ied_usr->dev_type:" << ied_usr->dev_type << endl; } //lnk20250210台账进程号 + if (com_type != NULL && com_type[0] != '\0') { + apr_snprintf(ied_usr->com_type, sizeof(ied_usr->com_type), "%s", com_type);//comType + cout << "ied_usr->com_type:" << ied_usr->com_type << endl; + } + else { + apr_snprintf(ied_usr->com_type, sizeof(ied_usr->com_type), "%s", "MMS"); + cout << "ied_usr->com_type(default):" << ied_usr->com_type << endl; + } if (processNo != NULL) { apr_snprintf(ied_usr->processNo, sizeof(ied_usr->processNo), "%s", processNo);//processNo cout << "ied_usr->processNo:" << ied_usr->processNo << endl; @@ -5772,6 +5829,13 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i apr_snprintf(ied_usr->dev_type, sizeof(ied_usr->dev_type), "%s", update[i].dev_type); printf("ied_usr->dev_type: %s\n", ied_usr->dev_type); } + if (update[i].com_type != NULL && update[i].com_type[0] != '\0') { + apr_snprintf(ied_usr->com_type, sizeof(ied_usr->com_type), "%s", update[i].com_type); + printf("ied_usr->com_type: %s\n", ied_usr->com_type); + } else { + apr_snprintf(ied_usr->com_type, sizeof(ied_usr->com_type), "%s", "MMS"); + printf("ied_usr->com_type (default): %s\n", ied_usr->com_type); + } if (update[i].processNo != NULL) { apr_snprintf(ied_usr->processNo, sizeof(ied_usr->processNo), "%s", update[i].processNo); printf("ied_usr->processNo: %s\n", ied_usr->processNo); @@ -6602,6 +6666,7 @@ void clearIedUsr(ied_usr_t *ied_usr) { memset(ied_usr->dev_type, 0, sizeof(ied_usr->dev_type)); memset(ied_usr->dev_key, 0, sizeof(ied_usr->dev_key)); memset(ied_usr->dev_series, 0, sizeof(ied_usr->dev_series)); + memset(ied_usr->com_type, 0, sizeof(ied_usr->com_type)); memset(ied_usr->terminal_id, 0, sizeof(ied_usr->terminal_id)); memset(ied_usr->org_name, 0, sizeof(ied_usr->org_name)); memset(ied_usr->maint_name, 0, sizeof(ied_usr->maint_name)); diff --git a/cfg_parse/log4.cpp b/cfg_parse/log4.cpp index 6447644..789cdb3 100644 --- a/cfg_parse/log4.cpp +++ b/cfg_parse/log4.cpp @@ -230,7 +230,7 @@ std::string get_front_type_from_subdir() { else if (std::strstr(subdir, "cfg_soe_comtrade") != NULL) return "comtrade"; else if (std::strstr(subdir, "cfg_pqdif_data") != NULL) - return "pqdif"; + return "PQDIF"; else if (std::strstr(subdir, "cfg_recallhis_data") != NULL) return "recall"; else if (std::strstr(subdir, "cfg_stat_data") != NULL) diff --git a/json/save2json.cpp b/json/save2json.cpp index d46e2b7..d06ad62 100644 --- a/json/save2json.cpp +++ b/json/save2json.cpp @@ -1196,6 +1196,48 @@ void add_indent(std::stringstream& stream, int level) { } } +static bool is_cfg_pqdif_process() +{ + return std::strstr(subdir, "cfg_pqdif_data") != NULL; +} + +static bool is_pqdif_com_type(const char* com_type) +{ + QString type = com_type ? QString::fromLocal8Bit(com_type).trimmed() : QString(); + return type.compare("PQDIF", Qt::CaseInsensitive) == 0; +} + +static void fill_terminal_com_type(terminal* tmnl, cJSON* item) +{ + if (tmnl == NULL) + return; + + cJSON* comType = cJSON_GetObjectItem(item, "comType"); + if (comType == NULL) + comType = cJSON_GetObjectItem(item, "com_type"); + + if (comType && comType->type == cJSON_String) + std::strncpy(tmnl->com_type, comType->valuestring, sizeof(tmnl->com_type) - 1); + else + std::strncpy(tmnl->com_type, "MMS", sizeof(tmnl->com_type) - 1); + + tmnl->com_type[sizeof(tmnl->com_type) - 1] = '\0'; +} + +static bool terminal_update_should_write_file(const terminal* tmnl) +{ + if (tmnl == NULL) + return false; + + if (is_pqdif_com_type(tmnl->com_type)) + return is_cfg_pqdif_process(); + + if (is_cfg_pqdif_process()) + return false; + + return true; +} + std::string prepare_update(const std::string& code_str, const terminal& json_data,const std::string& guid) //添加guid { std::cout << "prepare update" << std::endl; @@ -1267,6 +1309,9 @@ std::string prepare_update(const std::string& code_str, const terminal& json_dat add_indent(xmlStream, indentLevel); xmlStream << "" << json_data.dev_series << "" << std::endl; + add_indent(xmlStream, indentLevel); + xmlStream << "" << (json_data.com_type[0] ? json_data.com_type : "MMS") << "" << std::endl; + //lnk20250210 add_indent(xmlStream, indentLevel); xmlStream << "" << json_data.processNo << "" << std::endl; @@ -1349,6 +1394,9 @@ std::string prepare_update(const std::string& code_str, const terminal& json_dat add_indent(xmlStream, indentLevel); xmlStream << "" << json_data.terminal_id << "" << std::endl; + add_indent(xmlStream, indentLevel); + xmlStream << "" << (json_data.com_type[0] ? json_data.com_type : "MMS") << "" << std::endl; + indentLevel--; add_indent(xmlStream, indentLevel); xmlStream << "" << std::endl; @@ -1627,7 +1675,7 @@ int parse_control(const std::string& json_str, const std::string& output_dir) { std::string guid = guidstr->valuestring; //进程号为0的进程处理所有台账更新消息 - if (process_No != g_front_seg_index && g_front_seg_index !=0) { + if (!is_cfg_pqdif_process() && process_No != g_front_seg_index && g_front_seg_index !=0) { std::cout << "msg index:"<< process_No <<"doesnt match self index:" << g_front_seg_index << std::endl; cJSON_Delete(messageBody); cJSON_Delete(root); @@ -1656,6 +1704,7 @@ int parse_control(const std::string& json_str, const std::string& output_dir) { cJSON* item = cJSON_GetArrayItem(data, i); terminal json_data; + memset(&json_data, 0, sizeof(json_data)); // 填充 terminal_dev 的数据 cJSON* id = cJSON_GetObjectItem(item, "id"); // terminal_id if (id && id->type == cJSON_String) @@ -1717,6 +1766,8 @@ int parse_control(const std::string& json_str, const std::string& output_dir) { else std::strncpy(json_data.dev_series, "N/A", sizeof(json_data.dev_series) - 1); + fill_terminal_com_type(&json_data, item); + //lnk20250210台账进程号 cJSON* processNo = cJSON_GetObjectItem(item, "processNo"); // processNo转为字符串 if (processNo && processNo->type == cJSON_Number) snprintf(json_data.processNo, sizeof(json_data.processNo), "%d", processNo->valueint); @@ -1767,6 +1818,7 @@ int parse_control(const std::string& json_str, const std::string& output_dir) { for (int j = 0; j < monitorData_size && j < 10; j++) { // 最多 10 个监测点 cJSON* monitor_item = cJSON_GetArrayItem(monitorData, j); monitor monitor_data; + memset(&monitor_data, 0, sizeof(monitor_data)); cJSON* monitor_id = cJSON_GetObjectItem(monitor_item, "id"); // monitor_id if (monitor_id && monitor_id->type == cJSON_String) @@ -1837,6 +1889,13 @@ int parse_control(const std::string& json_str, const std::string& output_dir) { print_terminal(&json_data); + if (!terminal_update_should_write_file(&json_data)) { + std::cout << "skip ledger update by comType:" << json_data.com_type + << " terminal:" << json_data.terminal_id + << " process:" << subdir << g_front_seg_index << std::endl; + continue; + } + // 准备 XML 内容并写入文件 std::string xmlContent = prepare_update(code_str, json_data,guid);//添加guid20250506 if (xmlContent != "") { @@ -1870,7 +1929,17 @@ int parse_control(const std::string& json_str, const std::string& output_dir) { cJSON* id = cJSON_GetObjectItem(item, "id"); if (id != nullptr) { terminal json_data; + memset(&json_data, 0, sizeof(json_data)); std::strncpy(json_data.terminal_id, cJSON_GetObjectItem(item, "id")->valuestring, sizeof(json_data.terminal_id) - 1); + fill_terminal_com_type(&json_data, item); + + if (!terminal_update_should_write_file(&json_data)) { + std::cout << "skip delete ledger update by comType:" << json_data.com_type + << " terminal:" << json_data.terminal_id + << " process:" << subdir << g_front_seg_index << std::endl; + continue; + } + // 准备 XML 内容并写入文件 std::string xmlContent = prepare_update(code_str, json_data,guid);//添加guid20250506 if(xmlContent != ""){ diff --git a/json/save2json.h b/json/save2json.h index d96206c..c59b453 100644 --- a/json/save2json.h +++ b/json/save2json.h @@ -688,6 +688,7 @@ struct terminal // 终端台账 char dev_type[64]; char dev_key[255]; char dev_series[255]; + char com_type[32]; char processNo[64]; //lnk20250210进程号 char addr_str[64]; char port[64]; @@ -702,4 +703,4 @@ struct terminal // 终端台账 #endif ///////////////////////////////////////////////////////////////////////////// -#endif //SAVE2DB_8ue3hy0923r_H \ No newline at end of file +#endif //SAVE2DB_8ue3hy0923r_H diff --git a/mms/mms_process.c b/mms/mms_process.c index 13bf469..792db3a 100644 --- a/mms/mms_process.c +++ b/mms/mms_process.c @@ -1423,6 +1423,7 @@ void print_terminal(const terminal* tmnl) { printf("Device Type: %s\n", is_empty(tmnl->dev_type) ? "N/A" : tmnl->dev_type); printf("Device Key: %s\n", is_empty(tmnl->dev_key) ? "N/A" : tmnl->dev_key); printf("Device Series: %s\n", is_empty(tmnl->dev_series) ? "N/A" : tmnl->dev_series); + printf("Com Type: %s\n", is_empty(tmnl->com_type) ? "MMS" : tmnl->com_type); printf("Address: %s\n", is_empty(tmnl->addr_str) ? "N/A" : tmnl->addr_str); printf("Port: %s\n", is_empty(tmnl->port) ? "N/A" : tmnl->port); printf("Timestamp: %s\n", is_empty(tmnl->timestamp) ? "N/A" : tmnl->timestamp); @@ -2473,4 +2474,3 @@ char* convertMsToDateTimeString(int64_t usTime) { return buffer; } - \ No newline at end of file diff --git a/mms/rdb_client.h b/mms/rdb_client.h index 60b1cd5..c0c0ce3 100644 --- a/mms/rdb_client.h +++ b/mms/rdb_client.h @@ -337,6 +337,7 @@ struct ied_usr_t{ char dev_type[256]; /**< 设备类型 */ char dev_key[256]; /**< 设备秘钥 */ char dev_series[256]; /**< 设备识别码 */ + char com_type[32]; /**< 通讯类型 mms/pqdif */ int dev_flag; /**< 设备标志 */ void *cookie; double last_call_wavelist_time ; //上次召录波列表时间