Selaa lähdekoodia

新增一个修改转辙机编号的接口。未实现

git-svn-id: https://202.107.226.68:8443/svn/Services/ResistanceMonitor@8 a05970a1-87b9-9d4f-9ee5-fa77e2ec115b
shenchunzhong 1 vuosi sitten
vanhempi
commit
bf305dc7c5
3 muutettua tiedostoa jossa 65 lisäystä ja 0 poistoa
  1. 2 0
      4.Data/AppService.cpp
  2. 59 0
      4.Data/HttpPrcess.cpp
  3. 4 0
      4.Data/HttpPrcess.h

+ 2 - 0
4.Data/AppService.cpp

@@ -534,6 +534,7 @@ void CAppService::ThreadProcForHTTP10088(DWORD_PTR pThis)
 	using namespace httplib;
 	m_svr10088.Post("/data/.*", DealHttpPost);
 	m_svr10088.Get("/data/.*", DealHttpGet);
+	m_svr10088.Put("/data/.*", DealHttpPut);
 
 	//string strPath = CSimpleLog::GetAppDir();
 	//auto ret = m_svr.set_mount_point("/", strPath);
@@ -553,6 +554,7 @@ void CAppService::ThreadProcForHTTP10087(DWORD_PTR)
 	using namespace httplib;
 	m_svr10087.Post("/hist/.*", DealHttpPost);
 	m_svr10087.Get("/hist/.*", DealHttpGet);
+	m_svr10087.Put("/hist/.*", DealHttpPut);
 
 	//string strPath = CSimpleLog::GetAppDir();
 	//auto ret = m_svr.set_mount_point("/", strPath);

+ 59 - 0
4.Data/HttpPrcess.cpp

@@ -152,6 +152,42 @@ void DealHttpPost(const httplib::Request& req, httplib::Response& res)
 	if (json) free(json);
 }
 
+void DealHttpPut(const httplib::Request& req, httplib::Response& res)
+{
+	int code = 500;
+	auto start = chrono::steady_clock::now();
+	auto token = req.get_header_value("token");
+	if (token.length() == 0 || token.empty())
+		token = req.get_header_value("Authorization");
+	char* json = nullptr;
+	size_t json_len = 0;
+	SPDLOG_INFO("[HTTP][POST][START] {}:{} {} body:{}", req.remote_addr, req.remote_port, req.path, req.body);
+	try
+	{
+		if (token.empty())
+		{
+			code = 401;
+		}
+		if (req.path.find("/data/zzjno") != -1)
+			code = DealPutChangeZzjno(req.body.c_str(), req.body.length(), token, &json, &json_len);
+		else
+			code = 405;
+	}
+	catch (...)
+	{
+		code = 500;
+	}
+	if (json)
+		res.set_content(json, "application/json");
+
+	auto cost = chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - start).count();
+	SPDLOG_INFO("[HTTP][POST][END] code:{} COST:{} {}:{} {} body:{}", code, cost, req.remote_addr, req.remote_port, req.path, req.body);
+	res.set_header("cost", to_string(cost) + " ms");
+	res.status = code;
+
+	if (json) free(json);
+}
+
 int DealPostSvgData(const httplib::Request& req, const string token, httplib::Response& res)
 {
 	if (token.find("AAAAAAAA") == -1) return 403;
@@ -2344,6 +2380,29 @@ int DealGetResistData(const httplib::Request& req, const string token, char** js
 	return 200;
 }
 
+int DealPutChangeZzjno(const char* body_ptr, const size_t body_len, const string token, char** json, size_t* json_len)
+{
+	int code = 400;
+	string msg;
+	auto req_doc = yyjson_read(body_ptr, body_len, 0);
+	if (req_doc == nullptr) return 400;
+	auto req_root = yyjson_doc_get_root(req_doc);
+	do
+	{
+		auto mo = yyjson_get_str(yyjson_obj_get(req_root, "mo"));
+		auto mp = yyjson_get_str(yyjson_obj_get(req_root, "mp"));
+		auto newNumber = yyjson_get_int(yyjson_obj_get(req_root, "newNumber"));
+		if (mo == nullptr || mp == nullptr || newNumber == 0) break;
+
+
+
+
+		code = 200;
+	} while (false);
+
+	return code;
+}
+
 //int DealGetRetentionData(const httplib::Request& req, const string token, char** json, size_t* json_len)
 //{
 //	string mo = req.get_param_value("mo");

+ 4 - 0
4.Data/HttpPrcess.h

@@ -6,6 +6,7 @@
 
 void DealHttpGet(const httplib::Request& req, httplib::Response& res);
 void DealHttpPost(const httplib::Request& req, httplib::Response& res);
+void DealHttpPut(const httplib::Request& req, httplib::Response& res);
 
 //SVG
 int DealPostSvgData(const httplib::Request& req,const string token, httplib::Response& res);
@@ -54,3 +55,6 @@ int deal_get_alarm_list(const httplib::Request& req, const string token, char**
 
 //历史数据
 int DealGetResistData(const httplib::Request& req, const string token, char** json, size_t* json_len);
+
+//修改转辙机编号
+int DealPutChangeZzjno(const char* body_ptr, const size_t body_len, const string token, char** json, size_t *json_len);