1
0

module_area.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. #ifndef MODULE_AREA_H
  2. #define MODULE_AREA_H
  3. /**
  4. * @brief 与区域相关的业务模块总接口
  5. * @author 戴月腾
  6. * @date 2018-08-25
  7. */
  8. #include"area.h"
  9. #include"module_const.h"
  10. #include"module_web.h"
  11. #include"module_attendance_vehicle.h"
  12. #include"module_area_over_count.h"
  13. #include"module_area_timeout.h"
  14. class module_area: public singleton_base<module_area>
  15. {
  16. private:
  17. friend class singleton_base<module_area>;
  18. module_area()
  19. {
  20. }
  21. public:
  22. static void on_enter(uint32_t card_id,std::shared_ptr<area_hover>&c, int32_t type)
  23. {
  24. if(0==c->id() || 0==c->mapid())
  25. {
  26. return;
  27. }
  28. auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
  29. if(!card_ptr)
  30. {
  31. log_error("卡不存在card_id=%d", card_id);
  32. return;
  33. }
  34. c->m_enter_time = card_ptr->m_time/1000;
  35. if(card_ptr->is_person())//统计人卡
  36. {
  37. c->m_area->m_person_count++;
  38. }
  39. if(card_ptr->is_vehicle())//统计车卡
  40. {
  41. c->m_area->m_vehicle_count++;
  42. //车卡考勤
  43. module_attendance_vehicle::instance()->on_enter(card_ptr, c);
  44. }
  45. //区域超员
  46. module_area_over_count::instance()->on_enter(card_ptr, c);
  47. //区域超时
  48. module_area_timeout::instance()->on_enter(card_ptr, c);
  49. save_his_area_location_enter(card_ptr);
  50. }
  51. static void on_hover(uint32_t card_id,std::shared_ptr<area_hover>&c, int32_t type)
  52. {
  53. if(0==c->id() || 0==c->mapid())
  54. {
  55. return;
  56. }
  57. auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
  58. if(!card_ptr)
  59. {
  60. log_error("卡不存在card_id=%d", card_id);
  61. return;
  62. }
  63. // if(card_ptr->is_person())//人卡
  64. // {
  65. // }
  66. // if(card_ptr->is_vehicle())//车卡
  67. // {
  68. // }
  69. //区域超时
  70. module_area_timeout::instance()->on_hover(card_ptr, c);
  71. }
  72. static void on_leave(uint32_t card_id, std::shared_ptr<area_hover>&c, int32_t type)
  73. {
  74. if(0==c->id() || 0==c->mapid())
  75. {
  76. return;
  77. }
  78. auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
  79. if(!card_ptr)
  80. {
  81. log_error("卡不存在card_id=%d", card_id);
  82. return;
  83. }
  84. if(card_ptr->is_person())//统计人卡
  85. {
  86. c->m_area->m_person_count--;
  87. }
  88. if(card_ptr->is_vehicle())//统计车卡
  89. {
  90. c->m_area->m_vehicle_count--;
  91. }
  92. //区域超员
  93. module_area_over_count::instance()->on_leave(card_ptr, c);
  94. //区域超时
  95. module_area_timeout::instance()->on_leave(card_ptr, c);
  96. save_his_area_location_leave(card_ptr);
  97. }
  98. ///入库
  99. static void save_his_area_location_enter(const std::shared_ptr<card_location_base> card_ptr)
  100. {
  101. auto area_hover_ptr = card_ptr->get_area_hover();
  102. char sql[LENGTH_SQL] = {0};
  103. std::string call("add_area_staff");
  104. if(card_ptr->is_vehicle())//车卡
  105. {
  106. call="add_area_vehicle";
  107. }
  108. std::string start_str = tool_time::to_str_ex(static_cast<uint64_t>(area_hover_ptr->m_enter_time) *1000);
  109. sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
  110. card_list::to_id64_str(card_ptr->m_type, card_ptr->m_id).c_str(),
  111. card_ptr->m_id, area_hover_ptr->id(), area_hover_ptr->mapid(), start_str.c_str(), start_str.c_str());
  112. tool_db::PushAsync(sql);
  113. }
  114. ///入库
  115. static void save_his_area_location_leave(const std::shared_ptr<card_location_base> card_ptr)
  116. {
  117. auto area_hover_ptr = card_ptr->get_area_hover();
  118. char sql[LENGTH_SQL] = {0};
  119. std::string call("add_area_staff");
  120. if(card_ptr->is_vehicle())//车卡
  121. {
  122. call="add_area_vehicle";
  123. }
  124. std::string start_str = tool_time::to_str_ex(static_cast<uint64_t>(area_hover_ptr->m_enter_time) *1000);
  125. std::string end_str = tool_time::to_str_ex(card_ptr->m_time);
  126. sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
  127. card_list::to_id64_str(card_ptr->m_type, card_ptr->m_id).c_str(),
  128. card_ptr->m_id, area_hover_ptr->id(), area_hover_ptr->mapid(), start_str.c_str(), end_str.c_str());
  129. tool_db::PushAsync(sql);
  130. }
  131. };
  132. #endif // MODULE_AREA_H