area_business_car_attendance.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "area_business_car_attendance.h"
  2. #include "db/db_tool.h"
  3. #include"db/db_api/CDBSingletonDefine.h"
  4. #include"log.h"
  5. #include"card.h"
  6. #include"area.h"
  7. #include"mine.h"
  8. struct car_attendance_data:business_data
  9. {
  10. car_attendance_data():m_is_attendance(false)
  11. ,m_attendance_start_time(std::chrono::seconds(0))
  12. {
  13. }
  14. ///考勤状态 0初始状态 1 没在考勤 2 考勤;参看ATTENDANCE_STATUS
  15. bool m_is_attendance;
  16. ///考勤开始时间
  17. std::chrono::system_clock::time_point m_attendance_start_time;
  18. };
  19. area_business_car_attendance::area_business_car_attendance()
  20. {
  21. }
  22. void area_business_car_attendance::on_load_his(const std::shared_ptr<area_hover>&area_hover_ptr,
  23. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
  24. {
  25. }
  26. //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
  27. void area_business_car_attendance::on_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
  28. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
  29. {
  30. if(!card_ptr->is_vehicle())
  31. {
  32. return;
  33. }
  34. //save_attendance(card_ptr, area_hover_ptr);
  35. auto mine_tool_ptr = card_ptr->get_mine_tool();
  36. if(!mine_tool_ptr->m_is_attendance
  37. || !is_attendance_area(area_hover_ptr->m_area->m_id, card_ptr->get_vehicle_type_id()))
  38. {
  39. return;
  40. }
  41. //考勤结束
  42. mine_tool_ptr->m_is_attendance=false;
  43. //作为一条结束考勤记录保存到数据库
  44. db_tool::save_attendance(card_ptr, area_hover_ptr);
  45. }
  46. void area_business_car_attendance::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  47. {
  48. }
  49. //记录离开考勤区域信息,开始考勤
  50. void area_business_car_attendance::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
  51. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
  52. {
  53. if(!card_ptr->is_vehicle())
  54. {
  55. return;
  56. }
  57. //没在考勤状态转换为考勤状态
  58. auto mine_tool_ptr = card_ptr->get_mine_tool();
  59. if(!mine_tool_ptr->m_is_attendance
  60. && is_attendance_area(area_hover_ptr->m_area->m_id, card_ptr->get_vehicle_type_id()))
  61. {
  62. //考勤开始
  63. mine_tool_ptr->m_is_attendance = true;
  64. //mine_tool_ptr->m_attendance_start_time=std::chrono::system_clock::now();
  65. mine_tool_ptr->m_attendance_start_time=
  66. std::chrono::system_clock::time_point(std::chrono::milliseconds(area_hover_ptr->m_last_time));
  67. //作为一条开始考勤记录保存到数据库
  68. db_tool::save_attendance(card_ptr, area_hover_ptr);
  69. }
  70. }
  71. void area_business_car_attendance::init_attendance_area_from_db()
  72. {
  73. const char *sql = "select a.area_id, a.att_rule_id, vt.vehicle_type_id \
  74. from dat_att_rule_area a, dat_att_rule_vehicle_type vt, dat_att_rule r\
  75. where a.att_rule_id=vt.att_rule_id and a.att_rule_id=r.att_rule_id;";
  76. std::string Error;
  77. YADB::CDBResultSet DBRes;
  78. sDBConnPool.Query(sql,DBRes,Error);
  79. if(!Error.empty())
  80. log_error("初始化attendance_area Error,%s",Error.c_str());
  81. uint64_t nCount = DBRes.GetRecordCount( Error );
  82. if(int64_t(nCount) <= 0)
  83. {
  84. log_error("初始化attendance_area Error,%s",Error.c_str());
  85. }
  86. log_info( "init_attendance_area_from_db. The record count=%ld\n", nCount );
  87. m_map.clear();
  88. while ( DBRes.GetNextRecod(Error) )
  89. {
  90. int area_id = 0;
  91. DBRes.GetField( "area_id",area_id, Error );
  92. int att_rule_id = 0;
  93. DBRes.GetField( "att_rule_id",att_rule_id, Error );
  94. int vehicle_type_id = 0;
  95. DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
  96. m_map.insert(std::make_pair(to_list_id(area_id, vehicle_type_id), att_rule_id));
  97. }
  98. }
  99. std::unordered_map<uint64_t, int> area_business_car_attendance::m_map;