1
0

module_call_help.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "module_call_help.h"
  2. #include "event.h"
  3. #include "common_tool.h"
  4. #include "websocket/constdef.h"
  5. #include "log.h"
  6. #include "db/db_tool.h"
  7. #include "tool_time.h"
  8. /**
  9. * @brief //1.如果已经有呼救告警
  10. //2.web取消告警。status_help && status_help_cancel 置为status_help_dealed
  11. //3.如果底层已经没有呼救则,取消后,不会再次进行呼救。因为status_help已经不会置为status_error。
  12. //4.如果底层还在呼救。这时候不管status_help是何种状态,极大的可能是error.status_help_cancel的存在都会取消。
  13. //并且还要保证等待线程把json传送到前端
  14. */
  15. void module_call_help::rev_from_card_help(std::shared_ptr<card_location_base> card_ptr)
  16. {
  17. if(card_ptr->m_type == CT_PERSON){
  18. uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
  19. event_tool::instance()->handle_event(OT_CARD, ET_CARD_HELP, id, 0, 0, true);
  20. if(card_ptr)card_ptr->set_event_flag(ET_CARD_HELP);
  21. }
  22. }
  23. /**
  24. * @brief 接收到web端发来的处理呼救请求
  25. * @param data_map
  26. */
  27. void module_call_help::accept_web_deal_help(sio::message::ptr const& data)
  28. {
  29. int64_t ev_id = 0;
  30. std::string s_card_id;
  31. if(!tool_map::try_get_value(s_card_id, JSON_KEY_ID, data)
  32. ||!tool_map::try_get_value(ev_id, JSON_KEY_EVENT_EVENT_ID, data))
  33. {
  34. log_error("处理呼救,web发来的数据 card_id 或 ev_id格式不对");
  35. return;
  36. }
  37. uint32_t id = tool_other::id64_to_id(s_card_id);
  38. int type = tool_other::id64_to_type(s_card_id);
  39. auto card_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
  40. if(card_ptr)
  41. {
  42. log_info("处理呼救,card_id=%d, type=%d, ev_id=%d", id, type, ev_id);
  43. auto ev_ptr = event_list::instance()->get_event_card(id, type, ET_CARD_HELP,DT_COMMON);
  44. if(ev_ptr && ES_DEAL_HELP != ev_ptr->m_status)
  45. {
  46. ev_ptr->m_status = ES_DEAL_HELP;
  47. }
  48. }
  49. else
  50. {
  51. log_error("处理呼救,在全局列表中找不到卡,卡id=%d,卡type=%d", id, type);
  52. }
  53. }
  54. std::string module_call_help::get_json_help()
  55. {
  56. rapidjson::Document doc(rapidjson::kObjectType);
  57. rapidjson::Value data(rapidjson::kArrayType);
  58. rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
  59. auto tmp = event_list::instance()->m_map;
  60. auto it_ev=tmp.begin();
  61. for(;it_ev!=tmp.end();++it_ev)
  62. {
  63. //if(!it_ev->second->m_is_display || ET_CARD_HELP != it_ev->second->m_ev_type)
  64. if(ET_CARD_HELP != it_ev->second->m_ev_type)
  65. {
  66. continue;
  67. }
  68. std::string obj_id = it_ev->second->m_obj_id;
  69. int type= tool_other::id64_to_type(obj_id);
  70. rapidjson::Value alarm(rapidjson::kObjectType);
  71. tool_json::add_member(alarm, JSON_KEY_CARD_ID,it_ev->second->m_obj_id, allocator);
  72. alarm.AddMember(JSON_KEY_CARD_TYPE_ID,type, allocator);
  73. std::string time = tool_time::to_str(it_ev->second->m_cur_time);
  74. tool_json::add_member(alarm, "start_time",time, allocator);
  75. data.PushBack(alarm, allocator);
  76. }
  77. if(!data.Size())
  78. {
  79. return "";
  80. }
  81. doc.AddMember(JSON_ROOT_KEY_CMD,"helpme_req", allocator);
  82. doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
  83. doc.AddMember(JSON_ROOT_KEY_DATA,data, allocator);
  84. rapidjson::StringBuffer sb;
  85. rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
  86. doc.Accept(writer);
  87. return sb.GetString();
  88. }