1
0

area_business_person_dwell_checker.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /*
  9. * @brief 加载人员历史区域停留时长数据
  10. * @param const std::shared_ptr<area_hover>& a
  11. * @param const std::shared_ptr<card_location_base>& c 卡对象
  12. * @param std::shared_ptr<business_data>& ptr 业务数据
  13. * @return
  14. * @note
  15. * @warning
  16. * @bug
  17. * */
  18. 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)
  19. {
  20. if(!c->is_person())
  21. return;
  22. EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  23. auto ev_ptr_temp = event_list::instance()->get_event_card(c->m_id,c->m_type,evType,DT_COMMON);
  24. if (ev_ptr_temp && !ev_ptr_temp->is_end())
  25. c->set_event_flag(evType);
  26. }
  27. //进入区域,记录进入时间
  28. void area_business_person_dwell_checker::on_enter(const std::shared_ptr<area_hover>&a,
  29. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  30. {
  31. log_info("area_business_person_dwell_checker::on_enter : In Area=%d Card = %d ",a->m_area->id(),c->m_id);
  32. if( a->m_area->m_limit_person_min == 0 )
  33. {
  34. log_warn("区域area_id=%d超时值设置为0,不会检查超时。",a->m_area->m_id);
  35. }
  36. }
  37. //判断是否超时
  38. void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hover>&a,
  39. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  40. {
  41. if(!c->is_person()||a->m_enter_time==0||a->m_area->m_limit_person_min==0)
  42. return;
  43. int limit_val = a->m_area->m_limit_person_min*60;
  44. int cur_val = ( tool_time::now_to_seconds() - a->m_enter_time / 1000);
  45. EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  46. if (limit_val < cur_val)
  47. {
  48. c->set_event_flag(evType);
  49. uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
  50. event_tool::instance()->handle_event(OT_CARD,evType,id, a->m_area->m_limit_person_min,cur_val/60,true);
  51. }
  52. }
  53. //如果有超时告警,取消超时告警
  54. void area_business_person_dwell_checker::on_leave(const std::shared_ptr<area_hover>&a,
  55. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  56. {
  57. if(!c->is_person()||a->m_enter_time==0||a->m_area->m_limit_person_min==0)
  58. return;
  59. EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON:EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
  60. if(c->get_event_flag(evType))
  61. {
  62. c->set_event_flag(evType,0);
  63. uint64_t id = tool_other::type_id_to_u64(c->m_type, c->m_id);
  64. event_tool::instance()->handle_event(OT_CARD, evType, id, 0, 0, false);
  65. }
  66. }