123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #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>&area_hover_ptr,
- const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&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<over_speed_data>(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<area_hover>&a,
- const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&p)
- {
- if(!c->is_vehicle())
- return;
- auto ptr_temp = std::make_shared<over_speed_data>();
- 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>&area_hover_ptr,
- const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> 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<over_speed_data*>(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>&area_hover_ptr,
- const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> 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<over_speed_data*>(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());
- }
- }
|