Files
energy_storage/src/protocol/HttpEntity.h

106 lines
5.8 KiB
C
Raw Normal View History

2025-09-05 19:44:26 +08:00
#include "httplib.h"
2025-08-31 14:38:53 +08:00
#include "common/JsonN.h"
#include "errcode.h"
2025-09-05 19:44:26 +08:00
#include <functional>
class HttpEntity;
using HandlerFunc = Errcode(HttpEntity::*)(const httplib::Request& req, njson& jnode, std::string& errmsg);
2025-09-05 19:44:26 +08:00
struct HandlerOptions
{
HandlerFunc func;
std::vector<std::string> requiredKeys;
std::vector<std::string> keys;
HandlerOptions(HandlerFunc func, const std::vector<std::string>& requiredKeys)
: func(func), requiredKeys(requiredKeys)
{
}
};
2025-08-31 14:38:53 +08:00
class HttpEntity
{
public:
httplib::Server httpsvr;
HttpEntity();
2025-08-31 14:38:53 +08:00
void listen(std::string addr, int port);
2025-09-05 19:44:26 +08:00
void runHandler(std::string name, const HandlerOptions& handler, const httplib::Request& req, httplib::Response& resp);
2025-08-31 14:38:53 +08:00
void registGet(std::string name, void (HttpEntity::* func)(const httplib::Request& req, httplib::Response& resp));
//void onGet(const httplib::Request& req, httplib::Response& resp);
Errcode login(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode queryUserList(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode insertUser(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode updateUser(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode deleteUser(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode queryPermissionList(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode insertPermission(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode updatePermission(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode deletePermission(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode queryRoleList(const httplib::Request& req, njson& json, std::string& errmsg);
2025-09-12 18:44:34 +08:00
Errcode queryRolePermission(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode insertRole(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode updateRole(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode deleteRole(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode queryStationList(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode insertStation(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode updateStation(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode deleteStation(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode queryStationOverview(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryStationInfo(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryStationData(const httplib::Request& req, njson& json, std::string& errmsg);
2025-09-04 19:31:04 +08:00
Errcode queryDeviceList(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode insertDevice(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode updateDevice(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode deleteDevice(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryDevicTypeDef(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryDevicByCategory(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryDevicCharts(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryDeviceBCUDetail(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode queryPolicyList(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode insertPolicy(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode updatePolicy(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode deletePolicy(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode querySystemLogList(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
//Errcode insertSystemLog(const httplib::Request& req, httplib::Response& resp, NJsonNode& json);
Errcode updateSystemLog(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode queryAlertLogList(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
//Errcode insertAlertLog(const httplib::Request& req, httplib::Response& resp, NJsonNode& json);
Errcode updateAlertLog(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
Errcode queryPredictionDetail(const httplib::Request& req, njson& json, std::string& errmsg);
2025-09-12 18:44:34 +08:00
// 系统总览所有场站统计 (总览页 运行状况)
Errcode queryStatSystem(const httplib::Request& req, njson& json, std::string& errmsg);
2025-09-16 19:38:46 +08:00
Errcode queryStatStationGroup(const httplib::Request& req, njson& json, std::string& errmsg);
2025-09-12 18:44:34 +08:00
// 一个场站的累计统计
Errcode queryStatTotal(const httplib::Request& req, njson& json, std::string& errmsg);
// 场站按类别按天统计
Errcode queryStatDayList(const httplib::Request& req, njson& json, std::string& errmsg);
2025-09-04 19:31:04 +08:00
2025-09-16 19:38:46 +08:00
//Errcode queryStatDayList(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryStatDetailList(const httplib::Request& req, njson& json, std::string& errmsg);
// 场站按类某一天的历史曲线数据
Errcode queryStatCharts(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryEnvironment(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode queryServiceApiList(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode insertServiceApi(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode updateServiceApi(const httplib::Request& req, njson& json, std::string& errmsg);
Errcode deleteServiceApi(const httplib::Request& req, njson& json, std::string& errmsg);
2025-08-31 14:38:53 +08:00
};