#include "area_business_speed_checker.h" #include "event.h" #include "common_tool.h" #include "db/db_api/CDBSingletonDefine.h" #include "log.h" #include "area.h" #include "card.h" struct over_speed_data:business_data { over_speed_data() { m_over_speed_count=0; m_normal_speed_count=0; m_limit_speed=0; m_is_warning=false; } int m_over_speed_count; int m_normal_speed_count; double m_limit_speed; bool m_is_warning; }; void area_business_speed_checker::on_load_his(const std::shared_ptr&area_hover_ptr, const std::shared_ptr&card_ptr,std::shared_ptr&ptr) { if(!card_ptr->is_vehicle()) return; on_enter(area_hover_ptr, card_ptr, ptr); EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED; auto ev_ptr_temp = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ev_type,DT_COMMON); auto ptr_temp = std::dynamic_pointer_cast(ptr); ptr_temp->m_is_warning = (ev_ptr_temp && !ev_ptr_temp->is_end()); if(ptr_temp->m_is_warning) card_ptr->set_event_flag(ev_type); } void area_business_speed_checker::on_enter(const std::shared_ptr&a, const std::shared_ptr&c,std::shared_ptr&p) { if(!c->is_vehicle()) return; auto ptr_temp = std::make_shared(); p = ptr_temp; double limit = a->m_area->get_speed(c->get_vehicle_category_id()); ptr_temp->m_limit_speed = limit; log_info("[speed_checker:on_enter]%d,%f",c->m_id,limit); } void area_business_speed_checker::on_hover(const std::shared_ptr&area_hover_ptr, const std::shared_ptr&card_ptr,std::shared_ptr ptr) { if(!card_ptr->is_vehicle()) return; if(nullptr == ptr) { log_error("area_business_speed_checker::on_hover:nullptr == ptr"); return; } auto ptr_temp = static_cast(ptr.get()); double limit = ptr_temp->m_limit_speed; int _id = area_hover_ptr->id(); if(limit < card_ptr->m_speed)//超速 { ptr_temp->m_normal_speed_count=0; log_info("[speed_checker:on_hover_1]%d %.2f,%.2f areaid:%d",card_ptr->m_id,limit,card_ptr->m_speed,_id); if(!ptr_temp->m_is_warning && ++ptr_temp->m_over_speed_count>=SPEED_COUNT_LIMIT) { EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED; ptr_temp->m_is_warning = true; card_ptr->set_event_flag(ev_type); uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id); event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, true); log_info("[speed_checker:on_hover_true]%d,id:%d",card_ptr->m_id,_id); } } else//速度正常 { ptr_temp->m_over_speed_count=0; log_info("[speed_checker:on_hover_2]%d %.2f,%.2f id:%d",card_ptr->m_id,limit,card_ptr->m_speed,_id); if(ptr_temp->m_is_warning && ++ptr_temp->m_normal_speed_count>=SPEED_COUNT_LIMIT) { EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED; ptr_temp->m_is_warning = false; card_ptr->set_event_flag(ev_type,0); uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id); event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, false); log_info("[speed_checker:on_hover_false]%d id:%d",card_ptr->m_id,_id); } } } void area_business_speed_checker::on_leave(const std::shared_ptr&area_hover_ptr, const std::shared_ptr&card_ptr,std::shared_ptr ptr) { if(!card_ptr->is_vehicle()) return; if(nullptr == ptr) { log_error("area_business_speed_checker::on_leave:nullptr == ptr"); return; } auto ptr_temp = static_cast(ptr.get()); if(ptr_temp->m_is_warning) { EVENT_TYPE ev_type =area_hover_ptr->m_area->is_mine()?ET_CARD_OVER_SPEED: ET_CARD_AREA_OVER_SPEED; card_ptr->set_event_flag(ev_type,0); double limit = ptr_temp ->m_limit_speed; uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id); event_tool::instance()->handle_event(OT_CARD, ev_type, id, limit, card_ptr->m_speed, ptr_temp->m_is_warning=false); log_info("[speed_checker:on_leave_false]%d,id:%d",card_ptr->m_id,area_hover_ptr->id()); } }