area_business_speed_checker.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "area_business_speed_checker.h"
  2. #include "event.h"
  3. #include "common_tool.h"
  4. #include "db/db_api/CDBSingletonDefine.h"
  5. #include "log.h"
  6. #include "area.h"
  7. #include "card.h"
  8. struct over_speed_data:business_data
  9. {
  10. over_speed_data()
  11. {
  12. m_over_speed_count=0;
  13. m_normal_speed_count=0;
  14. m_limit_speed=0;
  15. m_is_warning=false;
  16. }
  17. int m_over_speed_count;
  18. int m_normal_speed_count;
  19. double m_limit_speed;
  20. bool m_is_warning;
  21. };
  22. void area_business_speed_checker::on_load_his(const std::shared_ptr<area_hover>&area_hover_ptr,
  23. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
  24. {
  25. if(!card_ptr->is_vehicle())
  26. return;
  27. on_enter(area_hover_ptr, card_ptr, ptr);
  28. EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED;
  29. auto ev_ptr_temp = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ev_type,DT_COMMON);
  30. auto ptr_temp = std::dynamic_pointer_cast<over_speed_data>(ptr);
  31. ptr_temp->m_is_warning = (ev_ptr_temp && !ev_ptr_temp->is_end());
  32. if(ptr_temp->m_is_warning)
  33. card_ptr->set_event_flag(ev_type);
  34. }
  35. void area_business_speed_checker::on_enter(const std::shared_ptr<area_hover>&a,
  36. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&p)
  37. {
  38. if(!c->is_vehicle())
  39. return;
  40. auto ptr_temp = std::make_shared<over_speed_data>();
  41. p = ptr_temp;
  42. double limit = a->m_area->get_speed(c->get_vehicle_category_id());
  43. ptr_temp->m_limit_speed = limit;
  44. log_info("[speed_checker:on_enter]%d,%f",c->m_id,limit);
  45. }
  46. void area_business_speed_checker::on_hover(const std::shared_ptr<area_hover>&area_hover_ptr,
  47. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
  48. {
  49. if(!card_ptr->is_vehicle())
  50. return;
  51. if(nullptr == ptr)
  52. {
  53. log_error("area_business_speed_checker::on_hover:nullptr == ptr");
  54. return;
  55. }
  56. auto ptr_temp = static_cast<over_speed_data*>(ptr.get());
  57. double limit = ptr_temp->m_limit_speed;
  58. int _id = area_hover_ptr->id();
  59. if(limit < card_ptr->m_speed)//超速
  60. {
  61. ptr_temp->m_normal_speed_count=0;
  62. log_info("[speed_checker:on_hover_1]%d %.2f,%.2f areaid:%d",card_ptr->m_id,limit,card_ptr->m_speed,_id);
  63. if(!ptr_temp->m_is_warning && ++ptr_temp->m_over_speed_count>=SPEED_COUNT_LIMIT)
  64. {
  65. EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED;
  66. ptr_temp->m_is_warning = true;
  67. card_ptr->set_event_flag(ev_type);
  68. uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
  69. event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, true);
  70. log_info("[speed_checker:on_hover_true]%d,id:%d",card_ptr->m_id,_id);
  71. }
  72. }
  73. else//速度正常
  74. {
  75. ptr_temp->m_over_speed_count=0;
  76. log_info("[speed_checker:on_hover_2]%d %.2f,%.2f id:%d",card_ptr->m_id,limit,card_ptr->m_speed,_id);
  77. if(ptr_temp->m_is_warning && ++ptr_temp->m_normal_speed_count>=SPEED_COUNT_LIMIT)
  78. {
  79. EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED;
  80. ptr_temp->m_is_warning = false;
  81. card_ptr->set_event_flag(ev_type,0);
  82. uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
  83. event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, false);
  84. log_info("[speed_checker:on_hover_false]%d id:%d",card_ptr->m_id,_id);
  85. }
  86. }
  87. }
  88. void area_business_speed_checker::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
  89. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
  90. {
  91. if(!card_ptr->is_vehicle())
  92. return;
  93. if(nullptr == ptr)
  94. {
  95. log_error("area_business_speed_checker::on_leave:nullptr == ptr");
  96. return;
  97. }
  98. auto ptr_temp = static_cast<over_speed_data*>(ptr.get());
  99. if(ptr_temp->m_is_warning)
  100. {
  101. EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED;
  102. card_ptr->set_event_flag(ev_type,0);
  103. double limit = ptr_temp ->m_limit_speed;
  104. uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
  105. event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, ptr_temp->m_is_warning=false);
  106. log_info("[speed_checker:on_leave_false]%d,id:%d",card_ptr->m_id,area_hover_ptr->id());
  107. }
  108. }