module_attendance_person.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef MODULE_ATTENDANCE_PERSON_H
  2. #define MODULE_ATTENDANCE_PERSON_H
  3. /**
  4. *@brief 人员考勤模块 2018-08-26 戴月腾修改
  5. *主要是针对人卡进行考勤,人卡从井上切换到井下为考勤开始,人卡从井下切换到井上为考勤结束
  6. *@author 陈欧美
  7. *@date 2018-08-03
  8. */
  9. #include <memory>
  10. #include <mutex>
  11. #include <map>
  12. #include <string>
  13. #include <chrono>
  14. #include <vector>
  15. #include<card.h>
  16. #include"ant.h"
  17. #include"area.h"
  18. #include"site_area.h"
  19. #include"module_const.h"
  20. /**
  21. * @brief 主要是针对人卡进行考勤,人卡从井上切换到井下为考勤开始,人卡从井下切换到井上为考勤结束
  22. */
  23. class module_attendance_person:public singleton_base<module_attendance_person>
  24. {
  25. private:
  26. friend class singleton_base<module_attendance_person>;
  27. module_attendance_person()
  28. {
  29. }
  30. public:
  31. /**
  32. * @brief 进入分站覆盖区域处理,考勤
  33. * @param card_id
  34. * @param enter_site
  35. */
  36. void enter_site(uint64_t card_id,int enter_site,uint64_t type)
  37. {
  38. if(!tool_other::is_person(type))
  39. {
  40. return;
  41. }
  42. auto card_ptr=card_list::instance()->get(tool_other::to_uint64_cardid(type, card_id));
  43. if(!card_ptr)
  44. {
  45. log_error("卡不存在card_id=%ld, type=%ld", card_id, type);
  46. return;
  47. }
  48. auto site_ptr=sit_list::instance()->get(enter_site);
  49. if(!site_ptr)
  50. {
  51. log_error("在分站列表中找不到分站,分站id=%d", enter_site);
  52. return;
  53. }
  54. // 从井下切换到井上为考勤结束
  55. if(tool_other::is_up_site(site_ptr->m_reader_type_id))
  56. {
  57. if(tool_other::is_attendance(card_ptr->m_stat_attendance))
  58. {
  59. //考勤结束
  60. card_ptr->m_stat_attendance=AS_NOT_ATTENDANCE;
  61. //作为一条结束考勤记录保存到数据库
  62. tool_db::save_attendance(card_ptr);
  63. log_debug("人卡考勤结束:site_id=%d,reader_type_id=%d,stat_attendance=%d",
  64. site_ptr->m_id,site_ptr->m_reader_type_id,card_ptr->m_stat_attendance);
  65. }
  66. }
  67. // 从井上切换到井下为考勤开始
  68. if(!tool_other::is_up_site(site_ptr->m_reader_type_id))
  69. {
  70. if(!tool_other::is_attendance(card_ptr->m_stat_attendance))
  71. {
  72. //考勤开始
  73. card_ptr->m_stat_attendance=AS_ATTENDANCE;
  74. //card_ptr->m_attendance_start_time=std::chrono::system_clock::now();
  75. std::time_t start= card_ptr->m_time/1000;
  76. card_ptr->m_attendance_start_time=std::chrono::system_clock::from_time_t(start);
  77. //作为一条开始考勤记录保存到数据库
  78. tool_db::save_attendance(card_ptr);
  79. log_debug("人卡考勤开始:site_id=%d,reader_type_id=%d,stat_attendance=%d",
  80. site_ptr->m_id,site_ptr->m_reader_type_id,card_ptr->m_stat_attendance);
  81. }
  82. }
  83. }
  84. /**
  85. * @brief 离开现有分站处理,记录现有分站的进出时间和地点
  86. * @param card_id
  87. * @param enter_site
  88. */
  89. void leave_site(uint64_t card_id,int enter_site,uint64_t type)
  90. {
  91. }
  92. /**
  93. * @brief 手工升井函数
  94. */
  95. void up_well(std::vector<std::string>& card_ids)
  96. {
  97. // std::chrono::system_clock::time_point time_current = std::chrono::system_clock::now();
  98. // std::vector<std::string> ids;
  99. // {
  100. // //std::lock_guard<std::mutex> lock(m_mutex);
  101. // for(auto iter = card_ids.begin(); iter != card_ids.end(); ++iter)
  102. // {
  103. // auto iter_card = g_card_map_ptr->find(*iter);
  104. // if(g_card_map_ptr->end() == iter_card)
  105. // {
  106. // continue;
  107. // }
  108. // if(!iter_card->second->is_attendance) // 该卡当前没在井下,不能形成考勤记录
  109. // {
  110. // // 该卡当前没在井下,不能形成考勤记录
  111. // continue;
  112. // }
  113. //// // 添加到考勤处理列表
  114. //// iter_card->second->last_status_well = enum_status_well::STATUS_WELL_UP;
  115. //// iter_card->second->time_end = time_current;
  116. //// attendances.push_back(iter_card->second);
  117. // ids.push_back(*iter);
  118. // }
  119. // }
  120. // // 插入考勤记录到数据库
  121. // for(auto iter = ids.begin(); iter != ids.end(); ++iter)
  122. // {
  123. // g_card_map_ptr->erase(*iter);
  124. // // 插入考勤记录到数据库
  125. // }
  126. }
  127. };
  128. #endif // MODULE_ATTENDANCE_PERSON_H