add reply in recall and +5 sec in recall and fix utc time in recall
This commit is contained in:
@@ -6926,6 +6926,34 @@ void send_reply_to_kafka(const std::string& guid, const std::string& step, const
|
||||
kafka_data_list_mutex.unlock();
|
||||
}
|
||||
|
||||
void send_reply_to_kafka_recall(const std::string& guid, const std::string& step, const std::string& result,const std::string& lineIndex,const std::string& recallStartDate,const std::string& recallEndDate){
|
||||
// 构造 JSON 字符串
|
||||
std::ostringstream oss;
|
||||
oss << "{"
|
||||
<< "\"guid\":\"" << guid << "\","
|
||||
<< "\"step\":\"" << step << "\","
|
||||
<< "\"result\":\"" << result << "\","
|
||||
<< "\"lineIndex\":\"" << lineIndex << "\","
|
||||
<< "\"recallStartDate\":\"" << recallStartDate << "\","
|
||||
<< "\"recallEndDate\":\"" << recallEndDate << "\","
|
||||
<< "\"processNo\":\"" << g_front_seg_index << "\","
|
||||
<< "\"frontType\":\"" << get_front_type_from_subdir() << "\","
|
||||
<< "\"nodeId\":\"" << FRONT_INST << "\""
|
||||
<< "}";
|
||||
|
||||
std::string jsonString = oss.str();
|
||||
|
||||
// 封装 Kafka 消息
|
||||
Ckafka_data_t connect_info;
|
||||
connect_info.strTopic = QString::fromStdString(Topic_Reply_Topic);
|
||||
connect_info.strText = QString::fromStdString(jsonString);
|
||||
|
||||
// 加入发送队列(带互斥锁保护)
|
||||
kafka_data_list_mutex.lock();
|
||||
kafka_data_list.append(connect_info);
|
||||
kafka_data_list_mutex.unlock();
|
||||
}
|
||||
|
||||
void send_heartbeat_to_kafka(const std::string& status) {
|
||||
// 构造 JSON 字符串
|
||||
std::ostringstream oss;
|
||||
|
||||
@@ -535,6 +535,10 @@ extern "C" {
|
||||
send_reply_to_kafka(std::string(guid), std::string(step), std::string(result));
|
||||
}
|
||||
|
||||
void send_reply_to_kafka_recall_c(const char* guid, const char* step, const char* result,const char* lineIndex,const char* recallStartDate,const char* recallEndDate) {
|
||||
send_reply_to_kafka_recall(std::string(guid), std::string(step), std::string(result),std::string(lineIndex), std::string(recallStartDate), std::string(recallEndDate));
|
||||
}
|
||||
|
||||
//标准化日志接口
|
||||
void format_log_msg(char* buf, size_t buf_size, const char* fmt, ...) {
|
||||
// 写入时间
|
||||
|
||||
@@ -1710,6 +1710,13 @@ int transfer_json_block_data(char v_wiring_type[], json_block_data *data) //json
|
||||
while (it != pMonitor->ItemList.end())
|
||||
{
|
||||
CItem* pItem = *it++;
|
||||
//////////////////////////////////////////////////////////lnk20250306为了数据入库,构造数据添加FLAG
|
||||
if ("FLAG" == pItem->strItemName) //剔除"FLAG",防止sq相别出现错误指针
|
||||
{
|
||||
KafkaData.strText.append(QString("\"FLAG\":%1, ").arg(data->flag)); //拼接 json剔除标记,1不剔除,0剔除,默认剔除
|
||||
continue;
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
if ("TIME" == pItem->strItemName) //剔除"FLAG",防止sq相别出现错误指针
|
||||
{
|
||||
KafkaData.strText.append(QString("\"TIME\":\"%1\", ").arg(data->time)); //拼接 json发生时刻,毫秒
|
||||
@@ -2011,6 +2018,13 @@ int transfer_json_block_data(char v_wiring_type[], json_block_data *data) //json
|
||||
while (it != pMonitor->ItemList.end())
|
||||
{
|
||||
CItem* pItem = *it++;
|
||||
//////////////////////////////////////////////////////////lnk20250306为了数据入库,构造数据添加FLAG
|
||||
if ("FLAG" == pItem->strItemName) //剔除"FLAG",防止sq相别出现错误指针
|
||||
{
|
||||
KafkaData.strText.append(QString("\"FLAG\":%1, ").arg(data->flag)); //拼接 json剔除标记,1不剔除,0剔除,默认剔除
|
||||
continue;
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
if ("TIME" == pItem->strItemName) //剔除"FLAG",防止sq相别出现错误指针
|
||||
{
|
||||
KafkaData.strText.append(QString("\"TIME\":\"%1\", ").arg(data->time)); //拼接 json发生时刻,毫秒
|
||||
@@ -2128,6 +2142,13 @@ int transfer_json_block_data(char v_wiring_type[], json_block_data *data) //json
|
||||
while (it != pMonitor->ItemList.end())
|
||||
{
|
||||
CItem* pItem = *it++;
|
||||
//////////////////////////////////////////////////////////lnk20250306为了数据入库,构造数据添加FLAG
|
||||
if ("FLAG" == pItem->strItemName) //剔除"FLAG",防止sq相别出现错误指针
|
||||
{
|
||||
KafkaData.strText.append(QString("\"FLAG\":%1, ").arg(data->flag)); //拼接 json剔除标记,1不剔除,0剔除,默认剔除
|
||||
continue;
|
||||
}
|
||||
//////////////////////////////////////////////////////////
|
||||
if ("TIME" == pItem->strItemName) //剔除"FLAG",防止sq相别出现错误指针
|
||||
{
|
||||
KafkaData.strText.append(QString("\"TIME\":\"%1\", ").arg(data->time)); //拼接 json发生时刻,毫秒
|
||||
|
||||
@@ -54,6 +54,7 @@ extern std::map<std::string, TypedLogger> logger_map;
|
||||
extern DebugSwitch g_debug_switch;
|
||||
|
||||
extern void send_reply_to_kafka(const std::string& guid, const std::string& step, const std::string& result);
|
||||
extern void send_reply_to_kafka_recall(const std::string& guid, const std::string& step, const std::string& result,const std::string& lineIndex,const std::string& recallStartDate,const std::string& recallEndDate);
|
||||
|
||||
|
||||
std::string get_front_type_from_subdir();
|
||||
@@ -88,6 +89,7 @@ void log_warn(const char* key, const char* msg);
|
||||
void log_error(const char* key, const char* msg);
|
||||
|
||||
void send_reply_to_kafka_c(const char* guid, const char* step, const char* result);
|
||||
void send_reply_to_kafka_recall(const char* guid, const char* step, const char* result,const char* lineIndex,const char* recallStartDate,const char* recallEndDate);
|
||||
void format_log_msg(char* buf, size_t buf_size, const char* fmt, ...);
|
||||
|
||||
// ====================== ★新增:线程局部变量透传 code ======================
|
||||
|
||||
@@ -482,6 +482,15 @@ void ChannelCheckWaveFiles(chnl_usr_t *chnl_usr)
|
||||
}
|
||||
}
|
||||
|
||||
//lnk20250821时间转换:秒转本地时间
|
||||
static void sec_to_timestr(long long sec, char *out, size_t out_sz)
|
||||
{
|
||||
time_t t = (time_t)sec;
|
||||
struct tm tmv;
|
||||
localtime_r(&t, &tmv); // 本地时间
|
||||
strftime(out, out_sz, "%Y-%m-%d %H:%M:%S", &tmv);
|
||||
}
|
||||
|
||||
void ChannelCheckIECLogs(chnl_usr_t *chnl_usr)
|
||||
{
|
||||
ST_RET ret;
|
||||
@@ -559,20 +568,33 @@ void ChannelCheckIECLogs(chnl_usr_t *chnl_usr)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
//记录本次补招的时间范围
|
||||
long long min_start_sec = LLONG_MAX;
|
||||
long long max_end_sec = 0;
|
||||
/////////////////////////////////////////////////////////////
|
||||
|
||||
for (i = 0; i < LD_info->autorecallcount; i++) {
|
||||
|
||||
// ===== [新增] 累计全局最小/最大区间(直接用原始 start/end)=====
|
||||
if (LD_info->autorecall[i]->start < min_start_sec) {
|
||||
min_start_sec = LD_info->autorecall[i]->start;
|
||||
}
|
||||
if (LD_info->autorecall[i]->end > max_end_sec) {
|
||||
max_end_sec = LD_info->autorecall[i]->end;
|
||||
}
|
||||
// ===== [新增结束] =====
|
||||
|
||||
LD_info->autorecallflag = 1;//正在补招
|
||||
|
||||
//当前不区分稳态和暂态lnk20241030,如果做区分修改:Check_Recall_Config从xml文件获取数据后,赋值给了LD_info
|
||||
loginfo->need_steady = LD_info->autorecall[i]->need_steady; loginfo->need_voltage = LD_info->autorecall[i]->need_voltage;
|
||||
|
||||
loginfo->start_time = apr_time_from_sec(LD_info->autorecall[i]->start - 5);//保证时间开头
|
||||
loginfo->end_time = apr_time_from_sec(LD_info->autorecall[i]->end - 5);//不保证时间结尾,可以+5保证时间结尾
|
||||
loginfo->end_time = apr_time_from_sec(LD_info->autorecall[i]->end + 5);//不保证时间结尾,可以+5保证时间结尾
|
||||
|
||||
/////////////////////////////////////////////////////根据配置文件控制下发补招时间为北京时间还是utc时间,上送的数据61850库会转换成北京时间?
|
||||
loginfo->start_time = loginfo->start_time - utc_or_beijing;//下发utc时间需要减去8小时-秒
|
||||
loginfo->end_time = loginfo->end_time - utc_or_beijing;
|
||||
loginfo->start_time = loginfo->start_time - utc_or_beijing * APR_USEC_PER_SEC;//下发utc时间需要减去8小时-秒
|
||||
loginfo->end_time = loginfo->end_time - utc_or_beijing * APR_USEC_PER_SEC;
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
if (loginfo->need_steady == 0 && loginfo->need_voltage == 0)
|
||||
@@ -618,6 +640,36 @@ void ChannelCheckIECLogs(chnl_usr_t *chnl_usr)
|
||||
//不管是否成功,这个补招文件必须删除,可能出现一直失败,循环读取文件和循环补招导致程序崩溃202050724lnk
|
||||
//if (failed_count==0) {//成功
|
||||
Delete_recall_Xml(LD_info->mp_id);
|
||||
|
||||
// ===== [新增] 组装上送的补招开始/结束时间字符串(本地时区,直接“秒转字符串”)=====
|
||||
char recallStartDate[32] = {0};
|
||||
char recallEndDate[32] = {0};
|
||||
|
||||
if (min_start_sec == LLONG_MAX) {
|
||||
// 理论上不会进来:有 autorecallcount != 0。兜底写成当前时间
|
||||
time_t nowt = time(NULL);
|
||||
sec_to_timestr((long long)nowt, recallStartDate, sizeof(recallStartDate));
|
||||
sec_to_timestr((long long)nowt, recallEndDate, sizeof(recallEndDate));
|
||||
} else {
|
||||
sec_to_timestr(min_start_sec, recallStartDate, sizeof(recallStartDate));
|
||||
sec_to_timestr(max_end_sec, recallEndDate, sizeof(recallEndDate));
|
||||
}
|
||||
|
||||
//拼接result
|
||||
const char *ld_name_safe = (LD_info->name && LD_info->name[0])
|
||||
? LD_info->name : "-";
|
||||
|
||||
char result_buf[256];
|
||||
snprintf(result_buf, sizeof(result_buf),
|
||||
"监测点:%s 补招时间最小值和最大值:%s ~ %s 本次补招执行结束",
|
||||
ld_name_safe, recallStartDate, recallEndDate);
|
||||
|
||||
// guid 固定 "12345",step 固定 "2"
|
||||
//send_reply_to_kafka_c("12345", "2", result_buf);
|
||||
send_reply_to_kafka_recall_c("12345", "2", result_buf,LD_info->mp_id,recallStartDate,recallEndDate);
|
||||
|
||||
// ===== [新增结束] =====
|
||||
|
||||
DIY_WARNLOG_CODE(full_key_m_c,LOG_CODE_RECALL,"【WARN】监测点:%s - id:%s结束补招数据", LD_info->name,LD_info->mp_id);
|
||||
//}
|
||||
}
|
||||
@@ -1920,7 +1972,7 @@ int ld_has_qvvr_nonempty(const LD_info_t* info)
|
||||
const QVVR_t* it = &info->qvvr[i];
|
||||
|
||||
/* 只要有任一“有效迹象”就视为非空 */
|
||||
if (it->used_status != 0 )
|
||||
if (it->used_status != 0 && it->QVVR_time != 0 && it->QVVR_PerTime != 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -1991,8 +2043,9 @@ apr_status_t call_cn_wavelist(LD_info_t *LD_info )
|
||||
//WW 2023-11-01 end
|
||||
if (ret2 !=APR_SUCCESS){
|
||||
//mq日志
|
||||
DIY_WARNLOG_CODE(full_key_m_c,LOG_CODE_COMTRADE_FILE,"【WARN】监测点:%s - id:%s前置记录的录波事件上传的录波号段%d与从装置获取的录波文件列表匹配失败,装置没有对应的号段的录波文件,清除该记录", LD_info->name,LD_info->mp_id,LD_info->FltNum[i]);
|
||||
//DIY_WARNLOG_CODE(full_key_m_c,LOG_CODE_COMTRADE_FILE,"【WARN】监测点:%s - id:%s前置记录的录波事件上传的录波号段%d与从装置获取的录波文件列表匹配失败,装置没有对应的号段的录波文件,清除该记录", LD_info->name,LD_info->mp_id,LD_info->FltNum[i]);
|
||||
//lnk20250819装置没有对应的文件时清除录波号段
|
||||
printf("【WARN】监测点:%s - id:%s前置记录的录波事件上传的录波号段%d与从装置获取的录波文件列表匹配失败,装置没有对应的号段的录波文件,清除该记录", LD_info->name,LD_info->mp_id,LD_info->FltNum[i]);
|
||||
LD_info->FltNum[i] = -1;
|
||||
return ret2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user