为数据库插入增加保护

This commit is contained in:
zjk
2026-01-19 21:52:26 +08:00
parent 481171d9ea
commit b5ca051831
97 changed files with 363231 additions and 98 deletions
@@ -0,0 +1,46 @@
#ifndef UEXTERCOMM_SETOPMODE_CMD_H
#define UEXTERCOMM_SETOPMODE_CMD_H
#include <string>
#include "../logc/loguru.hpp"
//外部通信消息
#define DB_TO_PM_SETOPMODE "uExternComm_setOpMode_cmd"
class uExternComm_setOpModeMsg
{
private:
/* data */
public:
std::string key = "uExternComm_setOpMode_cmd";
uExternComm_setOpModeMsg(/* args */){};
~uExternComm_setOpModeMsg(){};
int getSetOpMode(const std::string& msgkey, const std::string& msg){
if (msgkey!= key)
{
LOG_F(WARNING, "消息类型错误 %s", msgkey.c_str());
return 0;
}
Json::Value root;
Json::CharReaderBuilder builder;
JSONCPP_STRING errs;
// 解析JSON字符串
std::istringstream stream(msg);
if (!Json::parseFromStream(builder, stream, &root, &errs)) {
LOG_F(WARNING, "JSON解析失败: %s", errs.c_str());
return -1;
}
// 检查并读取操作模式
if (root.isMember("state_uint8") && root["state_uint8"].isUInt()) {
return root["state_uint8"].asUInt();
} else {
LOG_F(WARNING, "缺少或类型不匹配: opMode");
return -1;
}
};
};
#endif