area_business_person_dwell_checker.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. struct SPersonDwellChecker : business_data
  13. {
  14. uint64_t m_enter_time;
  15. point m_enter_point;
  16. SPersonDwellChecker()
  17. {
  18. m_enter_time = 0;
  19. }
  20. };
  21. //进入区域,记录进入时间
  22. void area_business_person_dwell_checker::on_enter(const std::shared_ptr<area_hover>&a,
  23. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  24. {
  25. auto ptr_temp = std::make_shared<SPersonDwellChecker>();
  26. ptr_temp->m_enter_point.set(c->x,c->y,c->z);
  27. ptr_temp->m_enter_time = tool_time::now_to_ms();
  28. ptr = ptr_temp;
  29. }
  30. //判断是否超时
  31. void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hover>&a,
  32. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  33. {
  34. auto ptr_temp = static_cast<SPersonDwellChecker*>(ptr.get());
  35. if(nullptr == ptr_temp)
  36. {
  37. return ;
  38. }
  39. double limit_val = 0;
  40. double cur_val = (tool_time::now_to_ms() - ptr_temp->m_enter_time)/1000;
  41. EVENT_TYPE evType = EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  42. if(c->is_person())
  43. {
  44. if (a->m_area->m_limit_person_second > cur_val)
  45. {
  46. return;
  47. }
  48. evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  49. limit_val = a->m_area->m_limit_person_second;
  50. }
  51. else if (c->is_vehicle())
  52. {
  53. return ;
  54. }
  55. else
  56. {
  57. return;
  58. }
  59. uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
  60. event_tool::instance()->handle_event(OT_CARD,evType,id,limit_val,cur_val,true);
  61. }
  62. //如果有超时告警,取消超时告警
  63. void area_business_person_dwell_checker::on_leave(const std::shared_ptr<area_hover>&a,
  64. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  65. {
  66. auto ptr_temp = static_cast<SPersonDwellChecker*>(ptr.get());
  67. if(nullptr == ptr_temp)
  68. {
  69. return ;
  70. }
  71. ptr_temp->m_enter_point.set(c->x,c->y,c->z);
  72. ptr_temp->m_enter_time = tool_time::now_to_ms();
  73. EVENT_TYPE evType = EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  74. if(c->is_person())
  75. {
  76. evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  77. }
  78. else
  79. {
  80. return ;
  81. }
  82. uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
  83. event_tool::instance()->handle_event(OT_CARD,evType,id,0,0,false);
  84. }