/* * @Description: file content * @Author: why * @version: * @Date: 2025-02-21 14:03:54 * @LastEditors: why * @LastEditTime: 2025-02-28 17:55:37 */ #include #include #include #include #include #include #include "json.hpp" #include "F_InsertRecord.h" #include "bizservice.h" #include "sqlite3.h" #include "ToolUtils.h" using namespace std; using json = nlohmann::json ;// for convenience typedef unsigned char BYTE; typedef struct topic{ std::string src; std::string des; std::string sid; std::string fid; } topic_type; REGISTER_BIZSERVICE("F-InsertRecord",InsertRecord); InsertRecord::InsertRecord(void){ handpara = nullptr; initpara = nullptr; } InsertRecord::~InsertRecord(void){ } void InsertRecord::Init(initparam_t *param){ initpara = param; } int InsertRecord::SQLBatch_exc(std::vector &sql_list,std::vector &result){ sqlite3 *db = (sqlite3 *)handpara; char *errMsg = nullptr; const char *sql; int rc; int resp = 0; // 开启事务 if (sqlite3_exec(db, "BEGIN TRANSACTION;", nullptr, nullptr, &errMsg) != SQLITE_OK) { std::cerr << "事务开启失败: " << errMsg << std::endl; sqlite3_free(errMsg); return -1; } // 执行批量插入操作 sqlite3_stmt *stmt; int idx = 0; for(const auto &k:sql_list){ std::cout << "cmd:"< sql_list; std::vector result; sql_list.clear(); result.clear(); std::string table_name("dayfrozen"); try{ value = json::parse(msg.payload); } catch(const std::exception &e){ std::cout << "topic "<() != "0D"){ afn_flag = -1; continue; } //根据afn/idclass 确定数据库表位置 待添加 ss << "insert into " <())<<","\ <().c_str()<<","\ <())<<","\ <())<<","\ <().c_str()<<");"; printf("insert sql:%s \n",ss.str().c_str()); sql_list.push_back(ss.str()); ss.clear(); } } } // ret = SQLBatch_exc(sql_list,result); resp["time"]=ToolUtils::now_to_string(); if(ret == -1 || afn_flag == -1) resp["ack"]="false"; else if(ret == 0) resp["ack"]="true"; resp["data"]["dataidex"]=result; outMsg.topic = ToolUtils::makeTpopicStr(topic); outMsg.timestamp = time(NULL); outMsg.payload = resp.dump(); std::cout << "resp InsertRecord payload:"<