1
0

module_web.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "module_web.h"
  2. #include"module_const.h"
  3. #include"module_call_help.h"
  4. #include"module_call.h"
  5. #include"module_area.h"
  6. #include"module_attendance_person.h"
  7. void module_web::accept( int ID, std::string const& name,
  8. sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp )
  9. {
  10. if(data->get_flag() != sio::message::flag_object)
  11. {
  12. log_error("web发来的数据不是对象");
  13. return;
  14. }
  15. std::string cmd = "";
  16. if(!tool_map::try_get_value(cmd, JSON_ROOT_KEY_CMD, data) || cmd.empty())
  17. {
  18. log_error("web发来的数据cmd字段为空");
  19. return;
  20. }
  21. std_debug("web发来的数据 cmd=%s", cmd.c_str());
  22. log_info("web发来的数据 cmd=%s", cmd.c_str());
  23. if(JSON_CMD_VALUE_CLEAR_CARD == cmd)//手动升井
  24. {
  25. module_attendance_person::instance()->handle_up_mine(data);
  26. }
  27. else if (JSON_CMD_VALUE_REQUEST_ALL_DATA == cmd)//web登录请求所有信息
  28. {
  29. module_web::instance()->response_login();
  30. }
  31. else
  32. {
  33. sio::message::ptr data_value;
  34. if(!tool_map::try_get_value(data_value, JSON_ROOT_KEY_DATA, data))
  35. {
  36. log_error("web发来的数据data字段格式不对, 不是map");
  37. return;
  38. }
  39. if(JSON_CMD_VALUE_DEAL_HELP == cmd) // 处理呼救信息
  40. {
  41. module_call_help::instance()->accept_web_deal_help(data_value);
  42. }
  43. else if(JSON_CMD_VALUE_CALL_CARD_REQUEST == cmd)//呼叫
  44. {
  45. module_call::instance()->accept_call(data_value);
  46. }
  47. else if(JSON_CMD_VALUE_CALL_CARD_CANCEL_REQUEST == cmd)//取消呼叫
  48. {
  49. module_call::instance()->accept_cancel(data_value);
  50. }
  51. }
  52. }
  53. void module_web::response_login()
  54. {
  55. rapidjson::Document doc(rapidjson::kObjectType);
  56. auto& allocator = doc.GetAllocator();
  57. rapidjson::Value nodes(rapidjson::kArrayType);
  58. //所有的呼叫信息
  59. std::string str=module_call::instance()->accept_login();
  60. if(!str.empty())
  61. {
  62. tool_json::push_back(nodes, str, allocator);
  63. }
  64. //所有告警
  65. std::vector<std::shared_ptr<ya_event>> arr;
  66. get_all_events(arr);
  67. if(!arr.empty())
  68. {
  69. tool_json::push_back(nodes, event_list::evs_to_json(arr), allocator);
  70. }
  71. if(nodes.Size()>0)
  72. {
  73. doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_RESPONSE_ALL_DATA, allocator);
  74. doc.AddMember(JSON_ROOT_KEY_VERSION, INTERFACE_VERSION, allocator);
  75. doc.AddMember(JSON_ROOT_KEY_DATA, nodes, allocator);
  76. tool_other::send_json(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
  77. }
  78. }
  79. void module_web::run()
  80. {
  81. std::vector<std::shared_ptr<ya_event>> arr;
  82. get_all_events(arr);
  83. if(!arr.empty())//发送给web端
  84. {
  85. delete_end(arr);
  86. tool_other::send_json(JSON_CMD_VALUE_PUSH, event_list::evs_to_json(arr));
  87. }
  88. std::string help = module_call_help::get_json_help();
  89. if(!help.empty())
  90. {
  91. tool_other::send_json(JSON_CMD_VALUE_PUSH, help);
  92. }
  93. }