module_area_over_person.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. //超员配置是否为0,0则不会进行告警
  29. if(0 == area_ptr->m_limit_person_count)
  30. {
  31. return;
  32. }
  33. if(area_ptr->m_limit_person_count <= area_ptr->m_person_count)//超员
  34. {
  35. auto ev_ptr = event_list::instance()->get(static_cast<uint32_t>(area_ptr->id()), ET_AREA_OVER_COUNT_PERSON);
  36. if(ev_ptr)
  37. {
  38. event_list::copy_event(card_ptr, ev_ptr);
  39. ev_ptr->m_limit_value=area_ptr->m_limit_person_count;
  40. ev_ptr->m_cur_value=area_ptr->m_person_count;
  41. }
  42. else//从没有告警状态转化为告警状态
  43. {
  44. auto ev_ptr = event_list::create_event_not_card(OT_AREA, area_ptr->id(), ET_AREA_OVER_COUNT_PERSON);
  45. event_list::copy_event(card_ptr, ev_ptr);
  46. ev_ptr->m_limit_value = area_ptr->m_limit_person_count;
  47. ev_ptr->m_cur_value = area_ptr->m_person_count;
  48. //保存到数据库
  49. event_list::save_event(ev_ptr);
  50. event_list::instance()->add(ev_ptr->get_list_id(),ev_ptr);
  51. log_info("区域人卡超员开始:区域id=%d,区域人卡门限=%d,当前人卡数=%d",
  52. area_ptr->id(), area_ptr->m_limit_person_count, area_ptr->m_person_count.load());
  53. }
  54. }
  55. }
  56. // void on_hover(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
  57. // {
  58. // }
  59. void on_leave(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
  60. {
  61. auto area_ptr = c->m_area;
  62. //超员配置是否为0,0则不会进行告警
  63. if(0 == area_ptr->m_limit_person_count)
  64. {
  65. return;
  66. }
  67. if(area_ptr->m_limit_person_count > area_ptr->m_person_count)//没有超员
  68. {
  69. //取消告警状态
  70. auto ev_ptr = event_list::instance()->get(static_cast<uint32_t>(area_ptr->id()), ET_AREA_OVER_COUNT_PERSON);
  71. if(ev_ptr)
  72. {
  73. event_list::copy_event(card_ptr, ev_ptr);
  74. ev_ptr->m_limit_value=area_ptr->m_limit_person_count;
  75. ev_ptr->m_cur_value = area_ptr->m_person_count;
  76. ev_ptr->m_status = ES_END;
  77. //保存到数据库
  78. event_list::save_event(ev_ptr);
  79. log_info("区域人卡超员结束:区域id=%d,区域人卡门限=%d,当前人卡数=%d",
  80. area_ptr->id(), area_ptr->m_limit_person_count, area_ptr->m_person_count.load());
  81. }
  82. }
  83. }
  84. };
  85. #endif // MODULE_AREA_OVER_PERSON_H