fix ledger update
This commit is contained in:
@@ -771,6 +771,10 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
"终端 id: " + json_data.terminal_id + " 已存在该装置,修改这个装置的台账");*/
|
"终端 id: " + json_data.terminal_id + " 已存在该装置,修改这个装置的台账");*/
|
||||||
|
|
||||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||||
|
//删除旧的
|
||||||
|
ClientManager::instance().remove_device(json_data.terminal_id);
|
||||||
|
|
||||||
|
|
||||||
init_loggers_bydevid(json_data.terminal_id);
|
init_loggers_bydevid(json_data.terminal_id);
|
||||||
terminal_devlist.push_back(json_data);
|
terminal_devlist.push_back(json_data);
|
||||||
|
|
||||||
@@ -781,13 +785,13 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||||
"终端 id: " + json_data.terminal_id + " 台账修改成功");*/
|
"终端 id: " + json_data.terminal_id + " 台账修改成功");*/
|
||||||
one.code = static_cast<int>(ResponseCode::OK);
|
one.code = static_cast<int>(ResponseCode::OK);
|
||||||
one.result = "台账修改成功";
|
one.result = "装置已存在,台账修改成功";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||||
"终端 id: " + json_data.terminal_id + " 台账修改失败");*/
|
"终端 id: " + json_data.terminal_id + " 台账修改失败");*/
|
||||||
one.code = static_cast<int>(ResponseCode::BAD_REQUEST);
|
one.code = static_cast<int>(ResponseCode::BAD_REQUEST);
|
||||||
one.result = "台账修改失败";
|
one.result = "装置已存在,但是无法擦除旧数据,台账修改失败";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply_list.push_back(std::move(one));
|
reply_list.push_back(std::move(one));
|
||||||
@@ -820,12 +824,14 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||||
"终端 id: " + json_data.terminal_id + " 台账添加成功");*/
|
"终端 id: " + json_data.terminal_id + " 台账添加成功");*/
|
||||||
one.code = static_cast<int>(ResponseCode::OK);
|
one.code = static_cast<int>(ResponseCode::OK);
|
||||||
one.result = "台账添加成功";
|
one.result = "装置不存在,台账添加成功";
|
||||||
reply_list.push_back(std::move(one));
|
|
||||||
continue;//修改下一个
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||||
|
//删除旧的
|
||||||
|
ClientManager::instance().remove_device(json_data.terminal_id);
|
||||||
|
|
||||||
init_loggers_bydevid(json_data.terminal_id);
|
init_loggers_bydevid(json_data.terminal_id);
|
||||||
terminal_devlist.push_back(json_data);
|
terminal_devlist.push_back(json_data);
|
||||||
|
|
||||||
@@ -842,7 +848,9 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||||
"终端 id: " + json_data.terminal_id + " 台账修改失败");*/
|
"终端 id: " + json_data.terminal_id + " 台账修改失败");*/
|
||||||
one.code = static_cast<int>(ResponseCode::BAD_REQUEST);
|
one.code = static_cast<int>(ResponseCode::BAD_REQUEST);
|
||||||
one.result = "台账修改失败";
|
one.result = "无法擦除旧数据,台账修改失败";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
reply_list.push_back(std::move(one));
|
reply_list.push_back(std::move(one));
|
||||||
}
|
}
|
||||||
@@ -871,6 +879,20 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
|
|
||||||
//直接加锁删除
|
//直接加锁删除
|
||||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
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()) {
|
||||||
|
// 终端 id 不存在于当前进程维护的终端列表中
|
||||||
|
one.code = static_cast<int>(ResponseCode::OK);
|
||||||
|
one.result = "装置不存在,无法删除台账";
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// 终端 id 存在于当前进程维护的终端列表中
|
||||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||||
ClientManager::instance().remove_device(json_data.terminal_id);
|
ClientManager::instance().remove_device(json_data.terminal_id);
|
||||||
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::OK),
|
||||||
@@ -882,9 +904,9 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::BAD_REQUEST),
|
||||||
"终端 id: " + json_data.terminal_id + " 台账删除失败");*/
|
"终端 id: " + json_data.terminal_id + " 台账删除失败");*/
|
||||||
one.code = static_cast<int>(ResponseCode::BAD_REQUEST);
|
one.code = static_cast<int>(ResponseCode::BAD_REQUEST);
|
||||||
one.result = "台账删除失败";
|
one.result = "无法擦除旧数据,台账删除失败";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reply_list.push_back(std::move(one));
|
reply_list.push_back(std::move(one));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user