area_business_card_enter_or_leave.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. //进入区域则入库操作
  9. void area_business_card_enter_or_leave::on_enter(const std::shared_ptr<area_hover>&a,
  10. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  11. {
  12. char sql[LENGTH_SQL]{0};
  13. std::string start_time = tool_time::to_str_ex(a->m_enter_time);
  14. std::string card_id = tool_other::type_id_to_str(c->m_type,c->m_id);
  15. const auto &p=a->m_enter_point;
  16. 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');",
  17. card_id.c_str(),a->id(),a->mapid(),start_time.c_str(),p.x,p.y);
  18. db_tool::PushAsync(sql);
  19. }
  20. void area_business_card_enter_or_leave::on_hover(const std::shared_ptr<area_hover>&a,
  21. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  22. {
  23. }
  24. //出区域则入库
  25. void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hover>&a,
  26. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  27. {
  28. char sql[LENGTH_SQL]{0};
  29. std::string start_time = tool_time::to_str_ex(a->m_enter_time);
  30. std::string end_time = tool_time::to_str_ex(a->m_last_time);
  31. std::string card_id = tool_other::type_id_to_str(c->m_type,c->m_id);
  32. const auto &ep=a->m_last_point;
  33. 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';",
  34. end_time.c_str(),ep.x,ep.y,card_id.c_str(),a->id(),start_time.c_str());
  35. db_tool::PushAsync(sql);
  36. }