123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include "area.h"
- #include "card_base.h"
- #include "event.h"
- #include "tool_time.h"
- #include "common_tool.h"
- #include "area_business_person_dwell_checker.h"
- /*
- 判断当前区域a中的人卡停留时间
- 人员进入区域时间存储在area_hover对象中,在当前类on_enter/on_leave中进行更新
- 人员&车辆的代码重用,请自行设计
- */
- struct SPersonDwellChecker : business_data
- {
- uint64_t m_enter_time;
- point m_enter_point;
- SPersonDwellChecker()
- {
- m_enter_time = 0;
- }
- };
- //进入区域,记录进入时间
- void area_business_person_dwell_checker::on_enter(const std::shared_ptr<area_hover>&a,
- const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
- {
- auto ptr_temp = std::make_shared<SPersonDwellChecker>();
- ptr_temp->m_enter_point.set(c->x,c->y,c->z);
- ptr_temp->m_enter_time = tool_time::now_to_ms();
- ptr = ptr_temp;
- }
- //判断是否超时
- void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hover>&a,
- const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
- {
- auto ptr_temp = static_cast<SPersonDwellChecker*>(ptr.get());
- if(nullptr == ptr_temp)
- {
- return ;
- }
- double limit_val = 0;
- double cur_val = (tool_time::now_to_ms() - ptr_temp->m_enter_time)/1000;
- EVENT_TYPE evType = EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
- if(c->is_person())
- {
- if (a->m_area->m_limit_person_second > cur_val)
- {
- return;
- }
- evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
- limit_val = a->m_area->m_limit_person_second;
- }
- else if (c->is_vehicle())
- {
- return ;
- }
- else
- {
- return;
- }
- uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
- event_tool::instance()->handle_event(OT_CARD,evType,id,limit_val,cur_val,true);
- }
- //如果有超时告警,取消超时告警
- void area_business_person_dwell_checker::on_leave(const std::shared_ptr<area_hover>&a,
- const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
- {
- auto ptr_temp = static_cast<SPersonDwellChecker*>(ptr.get());
- if(nullptr == ptr_temp)
- {
- return ;
- }
- ptr_temp->m_enter_point.set(c->x,c->y,c->z);
- ptr_temp->m_enter_time = tool_time::now_to_ms();
- EVENT_TYPE evType = EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
- if(c->is_person())
- {
- evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
- }
- else
- {
- return ;
- }
- uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
- event_tool::instance()->handle_event(OT_CARD,evType,id,0,0,false);
- }
|