modify ledger update and rtdata
This commit is contained in:
@@ -408,7 +408,7 @@ bool parseJsonMessageRT(const std::string& body,std::string& devSeries,ushort& l
|
||||
|
||||
// 回复:执行结果直接看实时数据,不需要再回复,1是收到消息
|
||||
if (!guid.empty()) {
|
||||
send_reply_to_queue(guid, "1", "收到三秒数据指令");
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::ACCEPTED), "收到三秒数据指令");
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -500,7 +500,7 @@ bool parseJsonMessageSET(const std::string& json_str) {
|
||||
|
||||
DIY_WARNLOG("process", "【WARN】前置的%d号进程执行指令:%s,reset表示重启所有进程,add表示添加进程", g_front_seg_index, fun.c_str());
|
||||
|
||||
send_reply_to_queue(guid, "1", "收到重置进程指令,重启所有进程!");
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::ACCEPTED), "收到重置进程指令,重启所有进程!");
|
||||
std::cout << "this msg should only execute once" << std::endl;
|
||||
} else {
|
||||
std::cout << "only cfg_stat_data index 1 can control process, this process not handle this msg" << std::endl;
|
||||
@@ -508,7 +508,7 @@ bool parseJsonMessageSET(const std::string& json_str) {
|
||||
}
|
||||
else if (fun == "delete") {
|
||||
|
||||
send_reply_to_queue(guid, "1", "收到删除进程指令,这个进程将会重启 ");
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::ACCEPTED), "收到删除进程指令,这个进程将会重启 ");
|
||||
|
||||
DIY_WARNLOG("process", "【WARN】前置的%d号进程执行指令:%s,即将重启", g_front_seg_index, fun.c_str());
|
||||
|
||||
@@ -602,7 +602,7 @@ bool parseJsonMessageLOG(const std::string& json_str) {
|
||||
/*std::cout << "msg frontType: " << frontType << " self frontType: " << subdir << std::endl;*/
|
||||
|
||||
// 回复消息
|
||||
send_reply_to_queue(guid, "1", "收到实时日志指令");
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::ACCEPTED), "收到实时日志指令");
|
||||
|
||||
if (code_str == "set_log") {
|
||||
// 校验数据合法性
|
||||
@@ -673,7 +673,7 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
||||
DIY_INFOLOG("process", "【NORMAL】前置的%d号进程处理topic:%s_%s的台账更新消息",
|
||||
g_front_seg_index, FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_UD.c_str());
|
||||
|
||||
send_reply_to_queue(guid, "1", "收到台账更新指令");
|
||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::ACCEPTED), "收到台账更新指令");
|
||||
|
||||
if (code_str == "add_terminal" || code_str == "ledger_modify") {
|
||||
std::cout << "add or modify ledger" << std::endl;
|
||||
@@ -717,10 +717,10 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
||||
m.terminal_connect = monitor_item.value("ptType", "");
|
||||
//m.timestamp = json_data.timestamp;
|
||||
m.terminal_id = monitor_item.value("deviceId", json_data.terminal_id);
|
||||
m.CT1 = monitor_item.value("CT1", "");
|
||||
m.CT2 = monitor_item.value("CT2", "");
|
||||
m.PT1 = monitor_item.value("PT1", "");
|
||||
m.PT2 = monitor_item.value("PT2", "");
|
||||
m.CT1 = monitor_item.value("CT1", 0.0);
|
||||
m.CT2 = monitor_item.value("CT2", 0.0);
|
||||
m.PT1 = monitor_item.value("PT1", 0.0);
|
||||
m.PT2 = monitor_item.value("PT2", 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -734,32 +734,84 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
||||
writeToFile(file_name, xmlContent);
|
||||
}*/
|
||||
if(code_str == "add_terminal"){
|
||||
init_loggers_bydevid(target_dev.terminal_id);
|
||||
terminal_devlist.push_back(json_data);
|
||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
||||
// ① 先判断 json_data.terminal_id 是否已在当前进程维护的终端列表中
|
||||
const std::string& tid = json_data.terminal_id;
|
||||
auto it = std::find_if(terminal_devlist.begin(), terminal_devlist.end(),
|
||||
[&](const terminal_dev& d){ return d.terminal_id == tid; });
|
||||
|
||||
//调用接口添加到通讯列表
|
||||
DeviceInfo device = make_device_from_terminal(json_data);
|
||||
ClientManager::instance().add_device(device);
|
||||
if (it == terminal_devlist.end()) {
|
||||
|
||||
send_reply_to_queue(new_dev.guid, "2",
|
||||
"终端 id: " + new_dev.terminal_id + " 台账添加成功");
|
||||
}
|
||||
else if(code_str == "ledger_modify"){
|
||||
|
||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||
init_loggers_bydevid(target_dev.terminal_id);
|
||||
init_loggers_bydevid(json_data.terminal_id);
|
||||
terminal_devlist.push_back(json_data);
|
||||
|
||||
//调用接口添加到通讯列表
|
||||
DeviceInfo device = make_device_from_terminal(json_data);
|
||||
ClientManager::instance().add_device(device);
|
||||
|
||||
send_reply_to_queue(del_dev.guid, "2",
|
||||
"终端 id: " + del_dev.terminal_id + " 台账修改成功");
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||
"终端 id: " + json_data.terminal_id + " 台账添加成功");
|
||||
}
|
||||
else{
|
||||
send_reply_to_queue(del_dev.guid, "2",
|
||||
"终端 id: " + del_dev.terminal_id + " 台账修改失败");
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||
"终端 id: " + json_data.terminal_id + " 已存在该装置,修改这个装置的台账");
|
||||
|
||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||
init_loggers_bydevid(json_data.terminal_id);
|
||||
terminal_devlist.push_back(json_data);
|
||||
|
||||
//调用接口添加到通讯列表
|
||||
DeviceInfo device = make_device_from_terminal(json_data);
|
||||
ClientManager::instance().add_device(device);
|
||||
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||
"终端 id: " + json_data.terminal_id + " 台账修改成功");
|
||||
}
|
||||
else{
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + json_data.terminal_id + " 台账修改失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(code_str == "ledger_modify"){
|
||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
||||
|
||||
// ① 先判断 json_data.terminal_id 是否已在当前进程维护的终端列表中
|
||||
const std::string& tid = json_data.terminal_id;
|
||||
auto it = std::find_if(terminal_devlist.begin(), terminal_devlist.end(),
|
||||
[&](const terminal_dev& d){ return d.terminal_id == tid; });
|
||||
|
||||
if (it == terminal_devlist.end()) {
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::NOT_FOUND),
|
||||
"终端 id: " + tid + " 无法修改台账,未找到指定装置,改为添加这个装置");
|
||||
|
||||
DIY_WARNLOG("process", "【WARN】无法修改台账,未找到指定装置: %s ,改为添加这个装置", tid.c_str());
|
||||
|
||||
init_loggers_bydevid(json_data.terminal_id);
|
||||
terminal_devlist.push_back(json_data);
|
||||
|
||||
//调用接口添加到通讯列表
|
||||
DeviceInfo device = make_device_from_terminal(json_data);
|
||||
ClientManager::instance().add_device(device);
|
||||
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||
"终端 id: " + json_data.terminal_id + " 台账添加成功");
|
||||
}
|
||||
|
||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||
init_loggers_bydevid(json_data.terminal_id);
|
||||
terminal_devlist.push_back(json_data);
|
||||
|
||||
//调用接口添加到通讯列表
|
||||
DeviceInfo device = make_device_from_terminal(json_data);
|
||||
ClientManager::instance().add_device(device);
|
||||
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||
"终端 id: " + json_data.terminal_id + " 台账修改成功");
|
||||
}
|
||||
else{
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + json_data.terminal_id + " 台账修改失败");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,13 +836,13 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
||||
//直接加锁删除
|
||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||
lientManager::instance().remove_device(json_data.terminal_id);
|
||||
send_reply_to_queue(del_dev.guid, "2",
|
||||
"终端 id: " + del_dev.terminal_id + " 台账删除成功");
|
||||
ClientManager::instance().remove_device(json_data.terminal_id);
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||
"终端 id: " + json_data.terminal_id + " 台账删除成功");
|
||||
}
|
||||
else{
|
||||
send_reply_to_queue(del_dev.guid, "2",
|
||||
"终端 id: " + del_dev.terminal_id + " 台账删除失败");
|
||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||
"终端 id: " + json_data.terminal_id + " 台账删除失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1307,15 +1359,14 @@ void connect_status_to_queue(const std::string& id, const std::string& datetime,
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////响应消息
|
||||
|
||||
void send_reply_to_queue(const std::string& guid, const std::string& step, const std::string& result) {
|
||||
void send_reply_to_queue(const std::string& guid, const int code, const std::string& result) {
|
||||
try {
|
||||
// 构造 JSON 对象
|
||||
nlohmann::json obj;
|
||||
obj["guid"] = guid;
|
||||
obj["step"] = step;
|
||||
obj["code"] = code;
|
||||
obj["result"] = result;
|
||||
obj["processNo"] = g_front_seg_index;
|
||||
obj["frontType"] = "cloudfront";
|
||||
obj["nodeId"] = FRONT_INST;
|
||||
|
||||
// 构造 queue 消息
|
||||
|
||||
Reference in New Issue
Block a user