area_business_count_checker.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include "event.h"
  2. #include "area.h"
  3. #include "card_base.h"
  4. #include "common_tool.h"
  5. #include "log.h"
  6. #include "area_business_count_checker.h"
  7. /*
  8. 判断当前区域a中的人数是否超过设定人数,超过后告警
  9. 区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
  10. 整个井下的超员和某个区域的超员都使用这个代码
  11. */
  12. //服务器重启加载数据
  13. void area_business_count_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)
  14. {
  15. if (nullptr == a->m_area )
  16. return ;
  17. if (c->is_person() && !a->m_area->m_event_person_count)
  18. {
  19. EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON ;
  20. auto ev_ptr_temp = event_list::instance()->get_event_area(a->m_area->id(),ev);
  21. if (ev_ptr_temp && !ev_ptr_temp->is_end())
  22. a->m_area->m_event_person_count = true;
  23. }
  24. else if (c->is_vehicle() && !a->m_area->m_event_vehicle_count)
  25. {
  26. EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_VEHICLE : EVENT_TYPE::ET_AREA_OVER_COUNT_VEHICLE ;
  27. auto ev_ptr_temp = event_list::instance()->get_event_area(a->m_area->id(),ev);
  28. if (ev_ptr_temp && !ev_ptr_temp->is_end())
  29. {
  30. a->m_area->m_event_vehicle_count = true;
  31. }
  32. }
  33. on_enter(a,c,ptr);
  34. }
  35. //增加计数,并进行判断
  36. void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
  37. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  38. {
  39. if (nullptr == a->m_area )
  40. return ;
  41. if (c->is_person())
  42. {
  43. a->m_area->m_person_count ++ ;
  44. int pc=a->m_area->m_person_count.load();
  45. if (!a->m_area->m_event_person_count && pc > a->m_area->m_limit_person_count)
  46. {
  47. a->m_area->m_event_person_count = true;
  48. EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON ;
  49. event_tool::instance()->handle_event(OT_AREA,ev,a->m_area->id(),a->m_area->m_limit_person_count,pc,true);
  50. log_info("area_business_count_checker::on_enter : Event OVER_COUNT=%d AreaId=%d,Limit=%d,CurNum=%d"
  51. ,ev,a->m_area->id(),a->m_area->m_limit_person_count,pc);
  52. }
  53. }
  54. else if (c->is_vehicle())
  55. {
  56. a->m_area->m_vehicle_count ++ ;
  57. int vc=a->m_area->m_vehicle_count.load();
  58. log_info("area_id:%d,v_count:%d",a->m_area->m_id,vc);
  59. if (vc > a->m_area->m_limit_vehicle_count && !a->m_area->m_event_vehicle_count)
  60. {
  61. a->m_area->m_event_vehicle_count = true;
  62. EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_VEHICLE : EVENT_TYPE::ET_AREA_OVER_COUNT_VEHICLE ;
  63. event_tool::instance()->handle_event(OT_AREA,ev,a->m_area->id(),a->m_area->m_limit_vehicle_count,vc,true);
  64. log_info("area_business_count_checker::on_enter : Event OVER_COUNT=%d AreaId=%d,Limit=%d,CurNum=%d"
  65. ,ev,a->m_area->id(),a->m_area->m_limit_vehicle_count,vc);
  66. }
  67. }
  68. }
  69. void area_business_count_checker::on_hover(const std::shared_ptr<area_hover>&a,
  70. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  71. {
  72. }
  73. //减少计数
  74. void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
  75. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  76. {
  77. if (nullptr == a->m_area )
  78. {
  79. return ;
  80. }
  81. int limitVal = 0;
  82. int curVal = 0;
  83. bool tmp_event = false;
  84. EVENT_TYPE ev = EVENT_TYPE::ET_OVER_COUNT_PERSON;
  85. if (c->is_person())
  86. {
  87. a->m_area->m_person_count -- ;
  88. limitVal = a->m_area->m_limit_person_count;
  89. curVal = a->m_area->m_person_count.load();
  90. tmp_event = a->m_area->m_event_person_count;
  91. ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON ;
  92. if(tmp_event && curVal <= limitVal)
  93. {
  94. a->m_area->m_event_person_count = false;
  95. log_info("area_business_count_checker::on_leave :Cancel Event OVER_COUNT=%d AreaId=%d,Limit=%d,CurNum=%d"
  96. ,ev,a->m_area->id(),limitVal,curVal);
  97. event_tool::instance()->handle_event(OT_AREA,ev,a->m_area->id(),limitVal,curVal,false);
  98. }
  99. }
  100. else if (c->is_vehicle())
  101. {
  102. a->m_area->m_vehicle_count -- ;
  103. limitVal = a->m_area->m_limit_vehicle_count;
  104. curVal = a->m_area->m_vehicle_count.load();
  105. tmp_event = a->m_area->m_event_vehicle_count;
  106. ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_VEHICLE : EVENT_TYPE::ET_AREA_OVER_COUNT_VEHICLE ;
  107. if(tmp_event && curVal <= limitVal)
  108. {
  109. a->m_area->m_event_vehicle_count = false;
  110. log_info("area_business_count_checker::on_leave :Cancel Event OVER_COUNT=%d AreaId=%d,Limit=%d,CurNum=%d"
  111. ,ev,a->m_area->id(),limitVal,curVal);
  112. event_tool::instance()->handle_event(OT_AREA,ev,a->m_area->id(),limitVal,curVal,false);
  113. }
  114. }
  115. }