1
0

area_business_card_enter_or_leave.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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(a->m_enter_time/1000);
  18. const auto &p=a->m_enter_point;
  19. snprintf(sql,LENGTH_SQL,"INSERT INTO his_location_area (obj_id,card_type_id,ident,area_id,map_id,enter_time,start_point) \
  20. VALUES ('%d','%lu','%d',%d,%d,'%s','%.2f,%.2f');",
  21. c->m_cid,c->m_type,c->m_id, a->id(),a->mapid(),start_time.c_str(),p.x,p.y);
  22. db_tool::PushAsync(sql);
  23. }
  24. void area_business_card_enter_or_leave::on_hover(const std::shared_ptr<area_hover>&a,
  25. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  26. {
  27. }
  28. //出区域则入库
  29. void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hover>&a,
  30. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  31. {
  32. char sql[LENGTH_SQL]{0};
  33. std::string start_time = tool_time::to_str(a->m_enter_time/1000);
  34. std::string end_time = tool_time::to_str(a->m_last_time/1000);
  35. // std::string card_id = tool_other::type_id_to_str(c->m_type,c->m_id);
  36. const auto &ep=a->m_last_point;
  37. snprintf(sql,LENGTH_SQL,"UPDATE his_location_area SET leave_time='%s',end_point='%.2f,%.2f' \
  38. WHERE enter_time='%s' AND obj_id=%d AND area_id=%d;",
  39. end_time.c_str(),ep.x,ep.y,
  40. start_time.c_str(),c->m_cid,a->id());
  41. log_info("card_enter_leave:%s",sql);
  42. db_tool::PushAsync(sql);
  43. }