2025-02-28 17:34:41 +08:00
|
|
|
/*
|
|
|
|
|
* @Description: file content
|
|
|
|
|
* @Author: why
|
|
|
|
|
* @version:
|
|
|
|
|
* @Date: 2025-02-28 14:24:59
|
|
|
|
|
* @LastEditors: why
|
2025-02-28 17:59:36 +08:00
|
|
|
* @LastEditTime: 2025-02-28 17:56:12
|
2025-02-28 17:34:41 +08:00
|
|
|
*/
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <chrono>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <ctime>
|
2025-03-12 17:09:02 +08:00
|
|
|
#include "common/inc/json.hpp"
|
2025-02-28 17:34:41 +08:00
|
|
|
#include "F_SetSupportNum.h"
|
|
|
|
|
#include "bizservice.h"
|
2025-03-12 17:40:43 +08:00
|
|
|
#include "ToolUtils.h"
|
2025-03-03 17:21:36 +08:00
|
|
|
|
2025-02-28 17:34:41 +08:00
|
|
|
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;
|
|
|
|
|
|
2025-03-03 17:21:36 +08:00
|
|
|
REGISTER_BIZSERVICE("F-SetSupportNum",SetSupportNum);
|
2025-02-28 17:34:41 +08:00
|
|
|
|
|
|
|
|
SetSupportNum::SetSupportNum(void){
|
|
|
|
|
handpara = nullptr;
|
|
|
|
|
initpara = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetSupportNum::~SetSupportNum(void){
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SetSupportNum::Init(initparam_t *param){
|
|
|
|
|
initpara = param;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static std::string search_table_db(int afn,unsigned int dataid){
|
|
|
|
|
std::string table;
|
|
|
|
|
return table;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string SetSupportNum::GetFID(){
|
|
|
|
|
std::string value("F-SetSupportNum");
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
int SetSupportNum::SQLBatch_exc(sqlite3 *db,std::vector<std::string> &sql_list,std::vector<int> &result){
|
|
|
|
|
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;
|
|
|
|
|
int count = 0;
|
|
|
|
|
for(const auto &k:sql_list){
|
|
|
|
|
std::cout << "cmd:"<<k.c_str()<<std::endl;
|
|
|
|
|
if (sqlite3_prepare_v2(db, k.c_str(), -1, &stmt, nullptr) != SQLITE_OK) {
|
|
|
|
|
std::cerr << "准备语句失败: " << sqlite3_errmsg(db) << std::endl;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
rc = sqlite3_step(stmt);
|
|
|
|
|
while(rc == SQLITE_ROW){
|
|
|
|
|
result[idx] = sqlite3_column_int(stmt, 0); // For integer columns use sqlite3_column_int()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
if (rc != SQLITE_DONE) {
|
|
|
|
|
std::cerr << "插入失败: " << sqlite3_errmsg(db) << std::endl;
|
|
|
|
|
result[idx] = "-1";
|
|
|
|
|
}else
|
|
|
|
|
result[idx] = "0"; //SUCCESS
|
|
|
|
|
*/
|
|
|
|
|
sqlite3_reset(stmt); // 重置语句
|
|
|
|
|
}
|
|
|
|
|
// 提交事务
|
|
|
|
|
if (sqlite3_exec(db, "COMMIT;", nullptr, nullptr, &errMsg) != SQLITE_OK) {
|
|
|
|
|
std::cerr << "事务提交失败: " << errMsg << std::endl;
|
|
|
|
|
sqlite3_free(errMsg);
|
|
|
|
|
resp = -1;
|
|
|
|
|
}
|
|
|
|
|
// 清理
|
|
|
|
|
sqlite3_finalize(stmt);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int SetSupportNum::HandleMsg(const msg_t msg, msg_t &outMsg,handparam_t *param){
|
|
|
|
|
|
|
|
|
|
topic.clear();
|
2025-03-12 17:40:43 +08:00
|
|
|
topic = msg.subTopicV;
|
2025-02-28 17:34:41 +08:00
|
|
|
json value,resp;
|
|
|
|
|
int ret = 0;
|
|
|
|
|
int afn_flag = 0, update_flag = 0;;
|
|
|
|
|
std::vector<std::string> sql_list;
|
|
|
|
|
std::vector<int> result;
|
|
|
|
|
sql_list.clear();
|
|
|
|
|
result.clear();
|
|
|
|
|
std::string table_name ;
|
|
|
|
|
try{
|
|
|
|
|
value = json::parse(msg.payload);
|
|
|
|
|
}
|
|
|
|
|
catch(const std::exception &e){
|
|
|
|
|
std::cout << "topic "<<msg.topic.c_str()<<" prase error:"<<e.what();
|
|
|
|
|
return -1;//format fail
|
|
|
|
|
}
|
|
|
|
|
if(!value.is_object())return -1;
|
|
|
|
|
if(value.contains("token")){
|
|
|
|
|
resp["token"] = value["token"];
|
|
|
|
|
}
|
|
|
|
|
if(value.contains("time")){
|
|
|
|
|
;// value["time"]
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
if(value.contains("data")){
|
|
|
|
|
json subvalue = value["data"];
|
|
|
|
|
int afn = 0;
|
|
|
|
|
int dataid = 0;
|
|
|
|
|
decode_blob(&dataid,4, subvalue["dataid"].get<std::string>().c_str());
|
|
|
|
|
decode_blob(&afn,4,subvalue["afn"].get<std::string>().c_str());
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
//table_name =search_table_db(afn,dataid);
|
|
|
|
|
table_name = "frozen";
|
|
|
|
|
ss << "seletc count (*) from " <<table_name.c_str()\
|
|
|
|
|
<<"where dataid = '"<<subvalue["dataid"].get<std::string>().c_str()<<"' and"\
|
|
|
|
|
<<"metid = "<< std::stoi(subvalue["metid"].get<std::string>())<<";";
|
|
|
|
|
printf("getsupportnum sql:%s \n",ss.str().c_str());
|
|
|
|
|
sql_list.push_back(ss.str());
|
|
|
|
|
ss.clear();
|
|
|
|
|
}
|
|
|
|
|
ret = SQLBatch_exc((sqlite3*)handpara,sql_list,result);
|
|
|
|
|
*/
|
|
|
|
|
resp_process:
|
2025-03-12 17:40:43 +08:00
|
|
|
resp["time"]=ToolUtils::now_to_string();
|
2025-02-28 17:34:41 +08:00
|
|
|
resp["ack"]="true";
|
|
|
|
|
|
2025-03-12 17:40:43 +08:00
|
|
|
outMsg.topic = ToolUtils::makeTpopicStr(topic);
|
2025-02-28 17:34:41 +08:00
|
|
|
outMsg.timestamp = time(NULL);;
|
|
|
|
|
outMsg.payload = resp.dump();
|
|
|
|
|
std::cout << "resp UpdateRecord payload:"<<resp.dump().c_str()<<std::endl;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|