|
@@ -8,13 +8,9 @@
|
|
|
* @date 2018-08-09
|
|
|
*/
|
|
|
|
|
|
-#include <mutex>
|
|
|
-#include <map>
|
|
|
-#include <chrono>
|
|
|
-#include <boost/thread.hpp>
|
|
|
-#include <boost/enable_shared_from_this.hpp>
|
|
|
-#include "module_web.h"
|
|
|
-#include "module_const.h"
|
|
|
+#include "module_singleton_base.h"
|
|
|
+#include"card.h"
|
|
|
+#include"websocket/sio/sio_client.h"
|
|
|
|
|
|
/**
|
|
|
* @brief 呼救类
|
|
@@ -36,108 +32,15 @@ public:
|
|
|
//4.如果底层还在呼救。这时候不管status_help是何种状态,极大的可能是error.status_help_cancel的存在都会取消。
|
|
|
//并且还要保证等待线程把json传送到前端
|
|
|
*/
|
|
|
- void rev_from_card_help(std::shared_ptr<card_location_base> card_ptr)
|
|
|
- {
|
|
|
- auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_HELP);
|
|
|
- if(!ev_ptr)
|
|
|
- {
|
|
|
- auto ev_ptr = event_list::create_event_card(card_ptr->m_id, card_ptr->m_type, ET_CARD_HELP);
|
|
|
-
|
|
|
- event_list::copy_event(card_ptr, ev_ptr);
|
|
|
-
|
|
|
- //保存到数据库
|
|
|
- event_list::save_event(ev_ptr);
|
|
|
-
|
|
|
- event_list::instance()->add(ev_ptr->get_list_id(), ev_ptr);
|
|
|
- }
|
|
|
- }
|
|
|
+ void rev_from_card_help(std::shared_ptr<card_location_base> card_ptr);
|
|
|
|
|
|
/**
|
|
|
* @brief 接收到web端发来的处理呼救请求
|
|
|
* @param data_map
|
|
|
*/
|
|
|
- void accept_web_deal_help(sio::message::ptr const& data)
|
|
|
- {
|
|
|
- int64_t ev_id = 0;
|
|
|
- std::string s_card_id;
|
|
|
- if(!tool_map::try_get_value(s_card_id, JSON_KEY_ID, data)
|
|
|
- ||!tool_map::try_get_value(ev_id, JSON_KEY_EVENT_EVENT_ID, data))
|
|
|
- {
|
|
|
- log_error("处理呼救,web发来的数据 card_id 或 ev_id格式不对");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- uint32_t id = tool_other::id64_to_id(s_card_id);
|
|
|
- int type = tool_other::id64_to_type(s_card_id);
|
|
|
-
|
|
|
- auto card_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
|
|
|
- if(card_ptr)
|
|
|
- {
|
|
|
- log_info("处理呼救,card_id=%d, type=%d, ev_id=%d", id, type, ev_id);
|
|
|
-
|
|
|
- auto ev_ptr = event_list::instance()->get_event_card(id, type, ET_CARD_HELP);
|
|
|
- if(ev_ptr && ES_DEAL_HELP != ev_ptr->m_status)
|
|
|
- {
|
|
|
- event_list::copy_event(card_ptr, ev_ptr);
|
|
|
-
|
|
|
- ev_ptr->m_status = ES_DEAL_HELP;
|
|
|
-
|
|
|
- event_list::save_event(ev_ptr);
|
|
|
-
|
|
|
- //删除
|
|
|
- //event_list::instance()->remove(ev_ptr->get_list_id(), ev_ptr);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- log_error("处理呼救,在全局列表中找不到卡,卡id=%d,卡type=%d", id, type);
|
|
|
- }
|
|
|
- }
|
|
|
+ void accept_web_deal_help(sio::message::ptr const& data);
|
|
|
|
|
|
- static std::string get_json_help()
|
|
|
- {
|
|
|
- rapidjson::Document doc(rapidjson::kObjectType);
|
|
|
- rapidjson::Value data(rapidjson::kArrayType);
|
|
|
- rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
|
|
|
-
|
|
|
- auto tmp = event_list::instance()->m_map;
|
|
|
- auto it_ev=tmp.begin();
|
|
|
- for(;it_ev!=tmp.end();++it_ev)
|
|
|
- {
|
|
|
- if(!it_ev->second->m_is_display || ET_CARD_HELP != it_ev->second->m_ev_type)
|
|
|
- {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- std::string obj_id = it_ev->second->m_obj_id;
|
|
|
- int type= tool_other::id64_to_type(obj_id);
|
|
|
-
|
|
|
- rapidjson::Value alarm(rapidjson::kObjectType);
|
|
|
-
|
|
|
- tool_json::add_member(alarm, JSON_KEY_CARD_ID,it_ev->second->m_obj_id, allocator);
|
|
|
- alarm.AddMember(JSON_KEY_CARD_TYPE_ID,type, allocator);
|
|
|
-
|
|
|
- std::string time = tool_time::to_str(it_ev->second->m_cur_time);
|
|
|
- tool_json::add_member(alarm, "start_time",time, allocator);
|
|
|
-
|
|
|
- data.PushBack(alarm, allocator);
|
|
|
- }
|
|
|
-
|
|
|
- if(!data.Size())
|
|
|
- {
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
- doc.AddMember(JSON_ROOT_KEY_CMD,"helpme_req", allocator);
|
|
|
- doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
|
|
|
- doc.AddMember(JSON_ROOT_KEY_DATA,data, allocator);
|
|
|
-
|
|
|
- rapidjson::StringBuffer sb;
|
|
|
- rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
|
|
|
- doc.Accept(writer);
|
|
|
-
|
|
|
- return sb.GetString();
|
|
|
- }
|
|
|
+ static std::string get_json_help();
|
|
|
};
|
|
|
|
|
|
|