module_area_over_person.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef MODULE_AREA_OVER_PERSON_H
  2. #define MODULE_AREA_OVER_PERSON_H
  3. /**
  4. *@brief 区域超员模块:当某个区域人数超过指定值时开始告警,当低于指定值时停止告警
  5. *@author 戴月腾
  6. *@date 2018-08-26
  7. */
  8. #include <string>
  9. #include <memory>
  10. #include <atomic>
  11. #include <mutex>
  12. #include <map>
  13. #include "module_const.h"
  14. /**
  15. * @brief 区域超员模块:当某个区域人数超过指定值时开始告警,当低于指定值时停止告警
  16. */
  17. class module_area_over_person:public singleton_base<module_area_over_person>
  18. {
  19. private:
  20. friend class singleton_base<module_area_over_person>;
  21. module_area_over_person()
  22. {
  23. }
  24. public:
  25. void on_enter(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
  26. {
  27. auto area_ptr = c->m_area;
  28. if(area_ptr->m_limit_person_count <= area_ptr->m_person_count)//超员
  29. {
  30. auto ev_ptr = event_list::instance()->get(static_cast<uint32_t>(area_ptr->id()), ET_AREA_OVER_COUNT_PERSON);
  31. if(ev_ptr)
  32. {
  33. event_list::copy_event(card_ptr, ev_ptr);
  34. ev_ptr->m_limit_value=area_ptr->m_limit_person_count;
  35. ev_ptr->m_cur_value=area_ptr->m_person_count;
  36. }
  37. else//从没有告警状态转化为告警状态
  38. {
  39. auto ev_ptr = event_list::create_event_not_card(OT_AREA, area_ptr->id(), ET_AREA_OVER_COUNT_PERSON);
  40. event_list::copy_event(card_ptr, ev_ptr);
  41. ev_ptr->m_limit_value = area_ptr->m_limit_person_count;
  42. ev_ptr->m_cur_value = area_ptr->m_person_count;
  43. //保存到数据库
  44. event_list::save_event(ev_ptr);
  45. event_list::instance()->add(ev_ptr->get_list_id(),ev_ptr);
  46. log_info("区域人卡超员开始:区域id=%d,区域人卡门限=%d,当前人卡数=%d",
  47. area_ptr->id(), area_ptr->m_limit_person_count, area_ptr->m_person_count.load());
  48. }
  49. }
  50. }
  51. // void on_hover(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
  52. // {
  53. // }
  54. void on_leave(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
  55. {
  56. auto area_ptr = c->m_area;
  57. if(area_ptr->m_limit_person_count > area_ptr->m_person_count)//没有超员
  58. {
  59. //取消告警状态
  60. auto ev_ptr = event_list::instance()->get(static_cast<uint32_t>(area_ptr->id()), ET_AREA_OVER_COUNT_PERSON);
  61. if(ev_ptr)
  62. {
  63. event_list::copy_event(card_ptr, ev_ptr);
  64. ev_ptr->m_limit_value=area_ptr->m_limit_person_count;
  65. ev_ptr->m_cur_value = area_ptr->m_person_count;
  66. ev_ptr->m_status = ES_END;
  67. //保存到数据库
  68. event_list::save_event(ev_ptr);
  69. log_info("区域人卡超员结束:区域id=%d,区域人卡门限=%d,当前人卡数=%d",
  70. area_ptr->id(), area_ptr->m_limit_person_count, area_ptr->m_person_count.load());
  71. }
  72. }
  73. }
  74. };
  75. #endif // MODULE_AREA_OVER_PERSON_H