area_business_card_enter_or_leave.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 (card_id,area_id,map_id,enter_time,start_point)VALUES ('%s',%d,%d,'%s','%.2f,%.2f');",
  21. card_id.c_str(),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_ex(a->m_enter_time);
  34. std::string end_time = tool_time::to_str_ex(a->m_last_time);
  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' WHERE card_id = '%s' AND area_id=%d AND enter_time='%s';",
  38. end_time.c_str(),ep.x,ep.y,card_id.c_str(),a->id(),start_time.c_str());
  39. db_tool::PushAsync(sql);
  40. }