123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #ifndef MODULE_AREA_OVER_PERSON_H
- #define MODULE_AREA_OVER_PERSON_H
- /**
- *@brief 区域超员模块:当某个区域人数超过指定值时开始告警,当低于指定值时停止告警
- *@author 戴月腾
- *@date 2018-08-26
- */
- #include <string>
- #include <memory>
- #include <atomic>
- #include <mutex>
- #include <map>
- #include "module_const.h"
- /**
- * @brief 区域超员模块:当某个区域人数超过指定值时开始告警,当低于指定值时停止告警
- */
- class module_area_over_person:public singleton_base<module_area_over_person>
- {
- private:
- friend class singleton_base<module_area_over_person>;
- module_area_over_person()
- {
- }
- public:
- void on_enter(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
- {
- auto area_ptr = c->m_area;
- //超员配置是否为0,0则不会进行告警
- if(0 == area_ptr->m_limit_person_count)
- {
- return;
- }
- if(area_ptr->m_limit_person_count <= area_ptr->m_person_count)//超员
- {
- auto ev_ptr = event_list::instance()->get(static_cast<uint32_t>(area_ptr->id()), ET_AREA_OVER_COUNT_PERSON);
- if(ev_ptr)
- {
- event_list::copy_event(card_ptr, ev_ptr);
- ev_ptr->m_limit_value=area_ptr->m_limit_person_count;
- ev_ptr->m_cur_value=area_ptr->m_person_count;
- }
- else//从没有告警状态转化为告警状态
- {
- auto ev_ptr = event_list::create_event_not_card(OT_AREA, area_ptr->id(), ET_AREA_OVER_COUNT_PERSON);
- event_list::copy_event(card_ptr, ev_ptr);
- ev_ptr->m_limit_value = area_ptr->m_limit_person_count;
- ev_ptr->m_cur_value = area_ptr->m_person_count;
- //保存到数据库
- event_list::save_event(ev_ptr);
- event_list::instance()->add(ev_ptr->get_list_id(),ev_ptr);
- log_info("区域人卡超员开始:区域id=%d,区域人卡门限=%d,当前人卡数=%d",
- area_ptr->id(), area_ptr->m_limit_person_count, area_ptr->m_person_count.load());
- }
- }
- }
- // void on_hover(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
- // {
- // }
- void on_leave(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
- {
- auto area_ptr = c->m_area;
- //超员配置是否为0,0则不会进行告警
- if(0 == area_ptr->m_limit_person_count)
- {
- return;
- }
- if(area_ptr->m_limit_person_count > area_ptr->m_person_count)//没有超员
- {
- //取消告警状态
- auto ev_ptr = event_list::instance()->get(static_cast<uint32_t>(area_ptr->id()), ET_AREA_OVER_COUNT_PERSON);
- if(ev_ptr)
- {
- event_list::copy_event(card_ptr, ev_ptr);
- ev_ptr->m_limit_value=area_ptr->m_limit_person_count;
- ev_ptr->m_cur_value = area_ptr->m_person_count;
- ev_ptr->m_status = ES_END;
- //保存到数据库
- event_list::save_event(ev_ptr);
- log_info("区域人卡超员结束:区域id=%d,区域人卡门限=%d,当前人卡数=%d",
- area_ptr->id(), area_ptr->m_limit_person_count, area_ptr->m_person_count.load());
- }
- }
- }
- };
- #endif // MODULE_AREA_OVER_PERSON_H
|