area_business_card_enter_or_leave.cpp 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // 根据区域无法区分是否井上分站[分站创建的区域没有代入区域类型-导致都是井上区域] 只能通过分站区分
  20. if (nullptr == c->get_area_tool()->m_site || !c->get_area_tool()->m_site->is_up_site())
  21. {
  22. snprintf(sql, LENGTH_SQL, "INSERT INTO his_location_area (obj_id,card_type_id,ident,area_id,map_id,enter_time,start_point) \
  23. VALUES ('%d','%lu','%d',%d,%d,'%s','%.2f,%.2f');",
  24. c->m_cid, c->m_type, c->m_id, a->id(), a->mapid(), start_time.c_str(), p.x, p.y);
  25. }
  26. else
  27. {
  28. // 井上分站时,插入时把离开时间也写入 防止员工出井后最后一个区域没有leave_time
  29. snprintf(sql, LENGTH_SQL, "INSERT INTO his_location_area (obj_id,card_type_id,ident,area_id,map_id,enter_time,leave_time,start_point) \
  30. VALUES ('%d','%lu','%d',%d,%d,'%s','%s','%.2f,%.2f');",
  31. c->m_cid, c->m_type, c->m_id, a->id(), a->mapid(), start_time.c_str(),start_time.c_str(), p.x, p.y);
  32. }
  33. db_tool::PushAsync(sql);
  34. }
  35. void area_business_card_enter_or_leave::on_hover(const std::shared_ptr<area_hover>&a,
  36. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  37. {
  38. // 根据区域无法区分是否井上分站[分站创建的区域没有代入区域类型-导致都是井上区域] 只能通过分站区分
  39. if (nullptr != c->get_area_tool()->m_site && c->get_area_tool()->m_site->is_up_site())
  40. {
  41. // 井上分站时,员工在行走过程中更新时间
  42. char sql[LENGTH_SQL]{0};
  43. std::string start_time = tool_time::to_str(a->m_enter_time/1000);
  44. std::string end_time = tool_time::to_str(tool_time::now_to_seconds());
  45. const auto &ep=a->m_last_point;
  46. snprintf(sql,LENGTH_SQL,"UPDATE his_location_area SET leave_time='%s',end_point='%.2f,%.2f' \
  47. WHERE enter_time='%s' AND obj_id=%d AND area_id=%d;",
  48. end_time.c_str(),ep.x,ep.y,
  49. start_time.c_str(),c->m_cid,a->id());
  50. db_tool::PushAsync(sql);
  51. }
  52. }
  53. //出区域则入库
  54. void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hover>&a,
  55. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  56. {
  57. char sql[LENGTH_SQL]{0};
  58. std::string start_time = tool_time::to_str(a->m_enter_time/1000);
  59. std::string end_time = tool_time::to_str(a->m_last_time/1000);
  60. // std::string card_id = tool_other::type_id_to_str(c->m_type,c->m_id);
  61. const auto &ep=a->m_last_point;
  62. snprintf(sql,LENGTH_SQL,"UPDATE his_location_area SET leave_time='%s',end_point='%.2f,%.2f' \
  63. WHERE enter_time='%s' AND obj_id=%d AND area_id=%d;",
  64. end_time.c_str(),ep.x,ep.y,
  65. start_time.c_str(),c->m_cid,a->id());
  66. log_info("card_enter_leave:%s",sql);
  67. db_tool::PushAsync(sql);
  68. }