台账更新添加comtype
This commit is contained in:
@@ -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 << "<series>" << json_data.dev_series << "</series>" << std::endl;
|
||||
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "<comType>" << (json_data.com_type[0] ? json_data.com_type : "MMS") << "</comType>" << std::endl;
|
||||
|
||||
//lnk20250210
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "<processNo>" << json_data.processNo << "</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 << "<id>" << json_data.terminal_id << "</id>" << std::endl;
|
||||
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "<comType>" << (json_data.com_type[0] ? json_data.com_type : "MMS") << "</comType>" << std::endl;
|
||||
|
||||
indentLevel--;
|
||||
add_indent(xmlStream, indentLevel);
|
||||
xmlStream << "</terminalData>" << 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 != ""){
|
||||
|
||||
Reference in New Issue
Block a user