area_business_person_dwell_checker.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "area_business_person_dwell_checker.h"
  7. /*
  8. 判断当前区域a中的人卡停留时间
  9. 人员进入区域时间存储在area_hover对象中,在当前类on_enter/on_leave中进行更新
  10. 人员&车辆的代码重用,请自行设计
  11. */
  12. //进入区域,记录进入时间
  13. void area_business_person_dwell_checker::on_enter(const std::shared_ptr<area_hover>&a,
  14. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  15. {
  16. a->m_enter_point.set(c->x,c->y,c->z);
  17. a->m_enter_time = tool_time::now_to_ms();
  18. }
  19. //判断是否超时
  20. void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hover>&a,
  21. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  22. {
  23. double limit_val = 0;
  24. double cur_val = (tool_time::now_to_ms() - a->m_enter_time)/1000;
  25. EVENT_TYPE evType = EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  26. if(c->is_person())
  27. {
  28. if (a->m_area->m_limit_person_second > cur_val)
  29. {
  30. return;
  31. }
  32. evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  33. limit_val = a->m_area->m_limit_person_second;
  34. }
  35. else if (c->is_vehicle())
  36. {
  37. return ;
  38. }
  39. else
  40. {
  41. return;
  42. }
  43. uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
  44. event_tool::instance()->handle_event(OT_CARD,evType,id,limit_val,cur_val,true);
  45. }
  46. //如果有超时告警,取消超时告警
  47. void area_business_person_dwell_checker::on_leave(const std::shared_ptr<area_hover>&a,
  48. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  49. {
  50. a->m_enter_point.set(c->x,c->y,c->z);
  51. a->m_enter_time = time(nullptr);
  52. EVENT_TYPE evType = EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  53. if(c->is_person())
  54. {
  55. evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  56. }
  57. else
  58. {
  59. return ;
  60. }
  61. uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
  62. event_tool::instance()->handle_event(OT_CARD,evType,id,0,0,true);
  63. }