area_business_person_dwell_checker.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "area.h"
  2. #include "card_base.h"
  3. #include "event.h"
  4. #include "tool_time.h"
  5. #include "common_tool.h"
  6. #include "log.h"
  7. #include "area_business_person_dwell_checker.h"
  8. void area_business_person_dwell_checker::on_load_his(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  9. {
  10. if(!c->is_person())
  11. return;
  12. EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  13. auto ev_ptr_temp = event_list::instance()->get_event_card(c->m_id,c->m_type,evType,DT_COMMON);
  14. if (ev_ptr_temp && !ev_ptr_temp->is_end())
  15. c->set_event_flag(evType);
  16. }
  17. //进入区域,记录进入时间
  18. void area_business_person_dwell_checker::on_enter(const std::shared_ptr<area_hover>&a,
  19. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  20. {
  21. log_info("area_business_person_dwell_checker::on_enter : In Area=%d Card = %d ",a->m_area->id(),c->m_id);
  22. if( a->m_area->m_limit_person_min == 0 )
  23. {
  24. log_warn("区域area_id=%d超时值设置为0,不会检查超时。",a->m_area->m_id);
  25. }
  26. }
  27. //判断是否超时
  28. void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hover>&a,
  29. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  30. {
  31. if(!c->is_person()||a->m_enter_time==0||a->m_area->m_limit_person_min==0)
  32. return;
  33. int limit_val = a->m_area->m_limit_person_min*60;
  34. int cur_val = ( tool_time::now_to_seconds() - a->m_enter_time / 1000);
  35. EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  36. if (limit_val < cur_val)
  37. {
  38. c->set_event_flag(evType);
  39. uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
  40. event_tool::instance()->handle_event(OT_CARD,evType,id, a->m_area->m_limit_person_min,cur_val/60,true);
  41. }
  42. }
  43. //如果有超时告警,取消超时告警
  44. void area_business_person_dwell_checker::on_leave(const std::shared_ptr<area_hover>&a,
  45. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  46. {
  47. if(!c->is_person()||a->m_enter_time==0||a->m_area->m_limit_person_min==0)
  48. return;
  49. EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON:EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  50. if(c->get_event_flag(evType))
  51. {
  52. c->set_event_flag(evType,0);
  53. uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
  54. event_tool::instance()->handle_event(OT_CARD, evType, id, 0, 0, false);
  55. }
  56. }