area_business_card_enter_or_leave.cpp 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. const char * get_area_table_name(const std::shared_ptr<area_hover>&a)
  9. {
  10. static const char * g_sz_area_name = "his_location_area";
  11. // 分站定位数据保存(进入分站,离开分站保存记录)
  12. static const char * g_sz_reader_area_name = "his_location_reader";
  13. if (a->m_area->is_reader_area())
  14. {
  15. return g_sz_reader_area_name;
  16. }
  17. return g_sz_area_name;
  18. }
  19. void area_business_card_enter_or_leave::on_load_his(const std::shared_ptr<area_hover>&area_hover_ptr,
  20. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
  21. {
  22. }
  23. //进入区域则入库操作
  24. void area_business_card_enter_or_leave::on_enter(const std::shared_ptr<area_hover>&a,
  25. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
  26. {
  27. char sql[LENGTH_SQL]{0};
  28. std::string start_time = tool_time::to_str(a->m_enter_time/1000);
  29. const auto &p=a->m_enter_point;
  30. // 根据区域无法区分是否井上区域[分站创建的区域没有代入区域类型-导致都是井上区域] 只能通过分站区分
  31. if (nullptr == c->get_area_tool()->m_site || !c->get_area_tool()->m_site->is_up_site())
  32. {
  33. snprintf(sql, LENGTH_SQL, "INSERT INTO %s (obj_id,card_type_id,ident,area_id,map_id,enter_time,start_point) \
  34. VALUES ('%d','%lu','%d',%d,%d,'%s','%.2f,%.2f');",get_area_table_name(a)
  35. ,c->m_cid, c->m_type, c->m_id, a->id(), a->mapid(), start_time.c_str(), p.x, p.y);
  36. }
  37. else
  38. {
  39. // 井上分站时,插入时把离开时间也写入 防止员工出井后最后一个区域没有leave_time
  40. snprintf(sql, LENGTH_SQL, "INSERT INTO %s (obj_id,card_type_id,ident,area_id,map_id,enter_time,leave_time,start_point) \
  41. VALUES ('%d','%lu','%d',%d,%d,'%s','%s','%.2f,%.2f');",get_area_table_name(a)
  42. ,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);
  43. }
  44. db_tool::PushAsync(sql);
  45. // std_info("card:%d Enter Area:%d ",c->m_cid,a->id());
  46. }
  47. void area_business_card_enter_or_leave::on_hover(const std::shared_ptr<area_hover>&a,
  48. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  49. {
  50. // 根据区域无法区分是否井上区域[分站创建的区域没有代入区域类型-导致都是井上区域] 只能通过分站区分
  51. if (nullptr != c->get_area_tool()->m_site && c->get_area_tool()->m_site->is_up_site())
  52. {
  53. // 井上分站时,员工在行走过程中更新时间
  54. char sql[LENGTH_SQL]{0};
  55. std::string start_time = tool_time::to_str(a->m_enter_time/1000);
  56. std::string end_time = tool_time::to_str(tool_time::now_to_seconds());
  57. const auto &ep=a->m_last_point;
  58. snprintf(sql,LENGTH_SQL,"UPDATE %s SET leave_time='%s',end_point='%.2f,%.2f'"
  59. " WHERE enter_time='%s' AND obj_id=%d AND area_id=%d;"
  60. ,get_area_table_name(a),end_time.c_str(),ep.x,ep.y,start_time.c_str(),c->m_cid,a->id());
  61. db_tool::PushAsync(sql);
  62. }
  63. }
  64. //出区域则入库
  65. void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hover>&a,
  66. const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  67. {
  68. char sql[LENGTH_SQL]{0};
  69. std::string start_time = tool_time::to_str(a->m_enter_time/1000);
  70. std::string end_time = tool_time::to_str(a->m_last_time/1000);
  71. // std::string card_id = tool_other::type_id_to_str(c->m_type,c->m_id);
  72. const auto &ep=a->m_last_point;
  73. snprintf(sql,LENGTH_SQL,"UPDATE %s SET leave_time='%s',end_point='%.2f,%.2f' \
  74. WHERE enter_time='%s' AND obj_id=%d AND area_id=%d;"
  75. ,get_area_table_name(a),end_time.c_str(),ep.x,ep.y,start_time.c_str(),c->m_cid,a->id());
  76. log_info("card_enter_leave:%s",sql);
  77. //std_info("card:%d leave Area:%d ",c->m_cid,a->id());
  78. db_tool::PushAsync(sql);
  79. }