area_business_card_enter_or_leave.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "area_business_card_enter_or_leave.h"
  2. #include "area.h"
  3. #include "card_base.h"
  4. #include"common_tool.h"
  5. #include"tool_time.h"
  6. #include"db/db_tool.h"
  7. #include"log.h"
  8. void area_business_card_enter_or_leave::on_load_his(const std::shared_ptr<area_hover>&area_hover_ptr,
  9. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
  10. {
  11. }
  12. //进入区域则入库操作
  13. void area_business_card_enter_or_leave::on_enter(const std::shared_ptr<area_hover>&a,
  14. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  15. {
  16. char sql[LENGTH_SQL]{0};
  17. std::string start_time = tool_time::to_str_ex(a->m_enter_time);
  18. // std::string card_id = tool_other::type_id_to_str(c->m_type,c->m_id);
  19. const auto &p=a->m_enter_point;
  20. snprintf(sql,LENGTH_SQL,"INSERT INTO his_location_area (obj_id,card_type_id,ident,area_id,map_id,enter_time,start_point) \
  21. VALUES ('%lld','%d','%lld',%d,%d,'%s','%.2f,%.2f');",
  22. c->m_cid,c->m_type,c->m_id, a->id(),a->mapid(),start_time.c_str(),p.x,p.y);
  23. db_tool::PushAsync(sql);
  24. }
  25. void area_business_card_enter_or_leave::on_hover(const std::shared_ptr<area_hover>&a,
  26. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  27. {
  28. }
  29. //出区域则入库
  30. void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hover>&a,
  31. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  32. {
  33. char sql[LENGTH_SQL]{0};
  34. std::string start_time = tool_time::to_str_ex(a->m_enter_time);
  35. std::string end_time = tool_time::to_str_ex(a->m_last_time);
  36. std::string card_id = tool_other::type_id_to_str(c->m_type,c->m_id);
  37. const auto &ep=a->m_last_point;
  38. snprintf(sql,LENGTH_SQL,"UPDATE his_location_area SET leave_time='%s',end_point='%.2f,%.2f' \
  39. WHERE enter_time='%s' AND obj_id=%d AND AND area_id=%d;",
  40. end_time.c_str(),ep.x,ep.y,
  41. start_time.c_str(),c->m_cid,a->id());
  42. log_info("card_enter_leave:%s",sql);
  43. db_tool::PushAsync(sql);
  44. }