fix some error and add some fun
This commit is contained in:
@@ -1156,7 +1156,7 @@ int recall_json_handle_from_mq(const std::string& body)
|
|||||||
return 10004;
|
return 10004;
|
||||||
}
|
}
|
||||||
std::string guid = messageBody["guid"].get<std::string>();
|
std::string guid = messageBody["guid"].get<std::string>();
|
||||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::OK), "收到补招指令");
|
//send_reply_to_queue(guid, static_cast<int>(ResponseCode::OK), "收到补招指令");
|
||||||
|
|
||||||
// 提取 data 数组
|
// 提取 data 数组
|
||||||
if (!messageBody.contains("data") || !messageBody["data"].is_array()) {
|
if (!messageBody.contains("data") || !messageBody["data"].is_array()) {
|
||||||
@@ -2233,14 +2233,14 @@ void execute_bash(string fun,int process_num,string type)
|
|||||||
char p_num_str[20];
|
char p_num_str[20];
|
||||||
// 使用 sprintf 转换
|
// 使用 sprintf 转换
|
||||||
std::sprintf(p_num_str, "%d", process_num);
|
std::sprintf(p_num_str, "%d", process_num);
|
||||||
const char* script = std::string(FRONT_PATH + "/bin/set_process.sh").c_str();//使用setsid防止端口占用
|
std::string script = FRONT_PATH + "/bin/set_process.sh";//使用setsid防止端口占用
|
||||||
const char* param1 = fun.c_str();
|
const char* param1 = fun.c_str();
|
||||||
const char* param2 = p_num_str;
|
const char* param2 = p_num_str;
|
||||||
const char* param3 = type.c_str();
|
const char* param3 = type.c_str();
|
||||||
|
|
||||||
// 构造完整的命令
|
// 构造完整的命令
|
||||||
char command[256];
|
char command[256];
|
||||||
snprintf(command, sizeof(command), "%s %s %s %s &", script, param1, param2, param3);
|
snprintf(command, sizeof(command), "%s %s %s %s &", script.c_str(), param1, param2, param3);
|
||||||
|
|
||||||
std::cout << "command:" << command <<std::endl;
|
std::cout << "command:" << command <<std::endl;
|
||||||
|
|
||||||
|
|||||||
@@ -424,8 +424,8 @@ void download_xml_for_icd(const std::string& MODEL_ID,
|
|||||||
|
|
||||||
//读最新本地台账
|
//读最新本地台账
|
||||||
std::string read_latest_ledger_file() {
|
std::string read_latest_ledger_file() {
|
||||||
const char* dir = std::string(FRONT_PATH + "/dat/ledger").c_str();
|
std::string dir = FRONT_PATH + "/dat/ledger";
|
||||||
DIR* dp = opendir(dir);
|
DIR* dp = opendir(dir.c_str());
|
||||||
if (!dp) return "";
|
if (!dp) return "";
|
||||||
|
|
||||||
struct dirent* entry;
|
struct dirent* entry;
|
||||||
|
|||||||
@@ -322,6 +322,13 @@ public:
|
|||||||
std::string key; // 消息key
|
std::string key; // 消息key
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//台账更新回复
|
||||||
|
struct DeviceReply {
|
||||||
|
std::string deviceId;
|
||||||
|
int code;
|
||||||
|
std::string result;
|
||||||
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// SOE 事件类
|
// SOE 事件类
|
||||||
@@ -676,6 +683,8 @@ void check_device_busy_timeout();
|
|||||||
|
|
||||||
//业务上报
|
//业务上报
|
||||||
void send_reply_to_cloud(int reply_code, const std::string& dev_id, int type, const std::string& guid, const std::string& mac);
|
void send_reply_to_cloud(int reply_code, const std::string& dev_id, int type, const std::string& guid, const std::string& mac);
|
||||||
|
void send_batch_reply_to_queue(const std::string& guid,
|
||||||
|
const std::vector<DeviceReply>& replies);
|
||||||
|
|
||||||
//内部定值响应
|
//内部定值响应
|
||||||
bool send_internal_value_reply(const std::string &dev_id, const std::vector<DZ_kzz_bit> &control_words);
|
bool send_internal_value_reply(const std::string &dev_id, const std::vector<DZ_kzz_bit> &control_words);
|
||||||
|
|||||||
@@ -673,12 +673,14 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
DIY_INFOLOG("process", "【NORMAL】前置的%d号进程处理topic:%s_%s的台账更新消息",
|
DIY_INFOLOG("process", "【NORMAL】前置的%d号进程处理topic:%s_%s的台账更新消息",
|
||||||
g_front_seg_index, FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_UD.c_str());
|
g_front_seg_index, FRONT_INST.c_str(), G_MQCONSUMER_TOPIC_UD.c_str());
|
||||||
|
|
||||||
send_reply_to_queue(guid, static_cast<int>(ResponseCode::ACCEPTED), "收到台账更新指令");
|
//send_reply_to_queue(guid, static_cast<int>(ResponseCode::ACCEPTED), "收到台账更新指令");
|
||||||
|
std::vector<DeviceReply> reply_list;
|
||||||
|
|
||||||
if (code_str == "add_terminal" || code_str == "ledger_modify") {
|
if (code_str == "add_terminal" || code_str == "ledger_modify") {
|
||||||
std::cout << "add or modify ledger" << std::endl;
|
std::cout << "add or modify ledger" << std::endl;
|
||||||
|
|
||||||
if (messageBody.contains("data") && messageBody["data"].is_array()) {
|
if (messageBody.contains("data") && messageBody["data"].is_array()) {
|
||||||
|
|
||||||
for (const auto& item : messageBody["data"]) {
|
for (const auto& item : messageBody["data"]) {
|
||||||
terminal_dev json_data;
|
terminal_dev json_data;
|
||||||
|
|
||||||
@@ -734,6 +736,10 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
writeToFile(file_name, xmlContent);
|
writeToFile(file_name, xmlContent);
|
||||||
}*/
|
}*/
|
||||||
if(code_str == "add_terminal"){
|
if(code_str == "add_terminal"){
|
||||||
|
|
||||||
|
DeviceReply one;
|
||||||
|
one.deviceId = json_data.terminal_id;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
std::lock_guard<std::mutex> lock(ledgermtx);
|
||||||
// ① 先判断 json_data.terminal_id 是否已在当前进程维护的终端列表中
|
// ① 先判断 json_data.terminal_id 是否已在当前进程维护的终端列表中
|
||||||
const std::string& tid = json_data.terminal_id;
|
const std::string& tid = json_data.terminal_id;
|
||||||
@@ -749,12 +755,15 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
DeviceInfo device = make_device_from_terminal(json_data);
|
DeviceInfo device = make_device_from_terminal(json_data);
|
||||||
ClientManager::instance().add_device(device);
|
ClientManager::instance().add_device(device);
|
||||||
|
|
||||||
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.result = "台账添加成功";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
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 + " 已存在该装置,修改这个装置的台账");*/
|
||||||
|
|
||||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||||
init_loggers_bydevid(json_data.terminal_id);
|
init_loggers_bydevid(json_data.terminal_id);
|
||||||
@@ -764,16 +773,25 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
DeviceInfo device = make_device_from_terminal(json_data);
|
DeviceInfo device = make_device_from_terminal(json_data);
|
||||||
ClientManager::instance().add_device(device);
|
ClientManager::instance().add_device(device);
|
||||||
|
|
||||||
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.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.result = "台账修改失败";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reply_list.push_back(std::move(one));
|
||||||
}
|
}
|
||||||
else if(code_str == "ledger_modify"){
|
else if(code_str == "ledger_modify"){
|
||||||
|
|
||||||
|
DeviceReply one;
|
||||||
|
one.deviceId = json_data.terminal_id;
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
std::lock_guard<std::mutex> lock(ledgermtx);
|
||||||
|
|
||||||
// ① 先判断 json_data.terminal_id 是否已在当前进程维护的终端列表中
|
// ① 先判断 json_data.terminal_id 是否已在当前进程维护的终端列表中
|
||||||
@@ -782,8 +800,8 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
[&](const terminal_dev& d){ return d.terminal_id == tid; });
|
[&](const terminal_dev& d){ return d.terminal_id == tid; });
|
||||||
|
|
||||||
if (it == terminal_devlist.end()) {
|
if (it == terminal_devlist.end()) {
|
||||||
send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::NOT_FOUND),
|
/*send_reply_to_queue(json_data.guid, static_cast<int>(ResponseCode::NOT_FOUND),
|
||||||
"终端 id: " + tid + " 无法修改台账,未找到指定装置,改为添加这个装置");
|
"终端 id: " + tid + " 无法修改台账,未找到指定装置,改为添加这个装置");*/
|
||||||
|
|
||||||
DIY_WARNLOG("process", "【WARN】无法修改台账,未找到指定装置: %s ,改为添加这个装置", tid.c_str());
|
DIY_WARNLOG("process", "【WARN】无法修改台账,未找到指定装置: %s ,改为添加这个装置", tid.c_str());
|
||||||
|
|
||||||
@@ -794,8 +812,12 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
DeviceInfo device = make_device_from_terminal(json_data);
|
DeviceInfo device = make_device_from_terminal(json_data);
|
||||||
ClientManager::instance().add_device(device);
|
ClientManager::instance().add_device(device);
|
||||||
|
|
||||||
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.result = "台账添加成功";
|
||||||
|
reply_list.push_back(std::move(one));
|
||||||
|
continue;//修改下一个
|
||||||
}
|
}
|
||||||
|
|
||||||
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
if(erase_one_terminals_by_id(json_data.terminal_id) == 1){
|
||||||
@@ -806,13 +828,18 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
DeviceInfo device = make_device_from_terminal(json_data);
|
DeviceInfo device = make_device_from_terminal(json_data);
|
||||||
ClientManager::instance().add_device(device);
|
ClientManager::instance().add_device(device);
|
||||||
|
|
||||||
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.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.result = "台账修改失败";
|
||||||
}
|
}
|
||||||
|
reply_list.push_back(std::move(one));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -820,6 +847,7 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
} else if (code_str == "delete_terminal") {
|
} else if (code_str == "delete_terminal") {
|
||||||
std::cout << "delete ledger" << std::endl;
|
std::cout << "delete ledger" << std::endl;
|
||||||
if (messageBody.contains("data") && messageBody["data"].is_array()) {
|
if (messageBody.contains("data") && messageBody["data"].is_array()) {
|
||||||
|
|
||||||
for (const auto& item : messageBody["data"]) {
|
for (const auto& item : messageBody["data"]) {
|
||||||
terminal_dev json_data{};
|
terminal_dev json_data{};
|
||||||
auto id = item.value("id", "");
|
auto id = item.value("id", "");
|
||||||
@@ -833,23 +861,34 @@ bool parseJsonMessageUD(const std::string& json_str, const std::string& output_d
|
|||||||
writeToFile(file_name, xmlContent);
|
writeToFile(file_name, xmlContent);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
DeviceReply one;
|
||||||
|
one.deviceId = json_data.terminal_id;
|
||||||
|
|
||||||
//直接加锁删除
|
//直接加锁删除
|
||||||
std::lock_guard<std::mutex> lock(ledgermtx);
|
std::lock_guard<std::mutex> lock(ledgermtx);
|
||||||
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),
|
||||||
"终端 id: " + json_data.terminal_id + " 台账删除成功");
|
"终端 id: " + json_data.terminal_id + " 台账删除成功");*/
|
||||||
|
one.code = static_cast<int>(ResponseCode::OK);
|
||||||
|
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.result = "台账删除失败";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reply_list.push_back(std::move(one));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cout << "code_str error" << std::endl;
|
std::cout << "code_str error" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send_batch_reply_to_queue(guid, reply_list);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1385,6 +1424,37 @@ void send_reply_to_queue(const std::string& guid, const int code, const std::str
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//台账更新批量回复
|
||||||
|
void send_batch_reply_to_queue(const std::string& guid,
|
||||||
|
const std::vector<DeviceReply>& replies) {
|
||||||
|
try {
|
||||||
|
nlohmann::json root;
|
||||||
|
root["guid"] = guid;
|
||||||
|
|
||||||
|
nlohmann::json arr = nlohmann::json::array();
|
||||||
|
|
||||||
|
for (const auto& r : replies) {
|
||||||
|
nlohmann::json item;
|
||||||
|
item["deviceId"] = r.deviceId;
|
||||||
|
item["code"] = r.code;
|
||||||
|
item["result"] = r.result;
|
||||||
|
arr.push_back(std::move(item));
|
||||||
|
}
|
||||||
|
root["data"] = std::move(arr);
|
||||||
|
|
||||||
|
queue_data_t connect_info;
|
||||||
|
connect_info.strTopic = Topic_Reply_Topic;
|
||||||
|
connect_info.strText = root.dump();
|
||||||
|
connect_info.tag = Topic_Reply_Tag;
|
||||||
|
connect_info.key = Topic_Reply_Key;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(queue_data_list_mutex);
|
||||||
|
queue_data_list.push_back(std::move(connect_info));
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << "send_batch_reply_to_queue exception: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////心跳消息
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////心跳消息
|
||||||
|
|
||||||
void send_heartbeat_to_queue(const std::string& status) {
|
void send_heartbeat_to_queue(const std::string& status) {
|
||||||
|
|||||||
BIN
LFtid1056_bak.rar
Normal file
BIN
LFtid1056_bak.rar
Normal file
Binary file not shown.
Reference in New Issue
Block a user