Files
zgj 717aaa0274 1、调整目录结构
2、调整公共接口
2025-03-12 17:40:43 +08:00

76 lines
2.0 KiB
C++

/**
* @文件路径: \datacenter\datacenter\src\userinterface.cpp
* @作者名称: zjp
* @文件版本: V1.0.0
* @创建日期: 2025-02-20 10:13:44
* @简要说明:
* @编辑时间: 2025-02-21 15:06:47
* @Copyright: 2025 Shenzhen ShenBao Electrical instruments CO.,LTD. All Rights Reserved.
*/
#include <iostream>
#include <vector>
#include <map>
#include <unistd.h>
#include "ToolUtils.h"
#include "bizservice.h"
#include "msg.h"
#include "json.hpp"
#include "version.h"
#include "datacenter/bizService/F_GetVersion.h"
REGISTER_BIZSERVICE("F-GetVersion",GetVersion);
/**
* @brief 初始化
*
* @param param 输入初始化参数
*/
void GetVersion::Init(initparam_t *param) {
}
/**
* @brief 业务处理
*
* @param msg 输入消息体
* @param param 可用数据库连接句柄
* @return int 返回值 成功为1 失败为0
*/
int GetVersion::HandleMsg(const msg_t msg,msg_t &outMsg, handparam_t *param) {
// 正常业务处理...
std::string tokenStr = "";
std::string recvTimeStr = "";
try {
nlohmann::json jsObj = nlohmann::json::parse(msg.payload);
tokenStr = jsObj["token"];
recvTimeStr = jsObj["time"];
}catch (nlohmann::json::parse_error& e) {
std::cerr << "Parsing error: " << e.what() << std::endl;
return -1;
}
//封装json响应
makeGetVersionReponse(tokenStr,msg.subTopicV,outMsg);
return 0;
}
/**
* @brief 获取FID
*
* @return const std::string FID名称
*/
std::string GetVersion::GetFID(void) {
return "F-GetVersion";
}
void GetVersion::makeGetVersionReponse(std::string tokenStr,const std::vector<std::string>topicV,msg_t &outMsg) {
nlohmann::json js;
js["token"] = tokenStr;
js["time"] = ToolUtils::getCurTimeStringWithFomat(false);
js["data"] = {{"version",DATA_CENTER_VERSION}};
outMsg.topic = "/" + topicV[1] + "/" + topicV[0] + "/" + topicV[2] + "/" + topicV[3];
outMsg.payload = js.dump();
outMsg.timestamp = ToolUtils::getUtcTime(false);
}