1
0

area_business_person_attendance.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. #include "area_business_person_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"common_tool.h"
  8. #include"mine.h"
  9. #include"websocket/constdef.h"
  10. #include "websocket/wsClientMgr.h"
  11. #include"tool_time.h"
  12. #include "module_meta_date_changed.h"
  13. //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
  14. void area_business_person_attendance::on_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
  15. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
  16. {
  17. log_info("on_enter:person_att:%d",card_ptr->m_id);
  18. if(!card_ptr->is_person())
  19. return;
  20. auto mine_tool_ptr = card_ptr->get_mine_tool();
  21. if(!mine_tool_ptr->m_is_attendance)
  22. {
  23. mine_tool_ptr->m_is_attendance=true;
  24. mine_tool_ptr->m_attendance_start_time=
  25. std::chrono::system_clock::time_point(std::chrono::milliseconds(area_hover_ptr->m_enter_time));
  26. //作为一条开始考勤记录保存到数据库
  27. db_tool::save_attendance(card_ptr, area_hover_ptr);
  28. }
  29. }
  30. void area_business_person_attendance::on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  31. {
  32. }
  33. //记录离开考勤区域信息,开始考勤
  34. void area_business_person_attendance::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
  35. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
  36. {
  37. if(!card_ptr->is_person())
  38. return;
  39. auto mine_tool_ptr = card_ptr->get_mine_tool();
  40. if(!mine_tool_ptr->m_is_attendance)
  41. return;
  42. //考勤结束
  43. mine_tool_ptr->m_is_attendance=false;
  44. //作为一条结束考勤记录保存到数据库
  45. db_tool::save_attendance(card_ptr, area_hover_ptr);
  46. rapidjson::Document doc(rapidjson::kObjectType);
  47. rapidjson::Value datas(rapidjson::kArrayType);
  48. rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
  49. _to_json_card_up_one(card_ptr, datas, allocator);
  50. //升井json发给web
  51. if(datas.Size() > 0)
  52. {
  53. doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
  54. //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
  55. doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
  56. swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
  57. }
  58. }
  59. /**
  60. * @brief 手工升井函数
  61. */
  62. void area_business_person_attendance::handle_up_mine(sio::message::ptr const& data)
  63. {
  64. std::vector<sio::message::ptr> card_vec;
  65. if(!tool_map::try_get_value(card_vec, JSON_ROOT_KEY_DATA, data) || card_vec.size() == 0)
  66. {
  67. log_error("手工升井,web发来的数据data字段为空 或者不是数组");
  68. return;
  69. }
  70. // rapidjson::Document doc(rapidjson::kObjectType);
  71. // rapidjson::Value datas(rapidjson::kArrayType);
  72. // rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
  73. std::vector<sio::message::ptr>::const_iterator it_card = card_vec.begin();
  74. int type = 0;
  75. std::string s_card_id;
  76. for(; it_card != card_vec.end(); ++it_card)
  77. {
  78. if(!tool_map::try_get_value(s_card_id, JSON_KEY_CALL_CARD_CARD_ID, (*it_card))
  79. ||!tool_map::try_get_value(type, JSON_KEY_CALL_CARD_CARD_TYPE_ID, (*it_card)))
  80. {
  81. log_error("手工升井,web发来的数据 card_id 或 card_type格式不对");
  82. continue;
  83. }
  84. uint32_t id = tool_other::id64_to_id(s_card_id);
  85. auto card_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
  86. if(card_ptr && card_ptr->is_person())
  87. {
  88. std_debug("手工升井,处理,卡id=%d,卡type=%d", id, type);
  89. log_info("手工升井,处理,卡id=%d,卡type=%d", id, type);
  90. module_meta_date_changed::clear_card(card_ptr);
  91. // auto rea_tool = card_ptr->get_area_tool();
  92. // rea_tool->on_leave(card_ptr);
  93. //card_ptr->clear();
  94. // auto mine_tool_ptr = card_ptr->get_mine_tool();
  95. // if(mine_tool_ptr->m_is_attendance)
  96. // {
  97. // //考勤结束
  98. // mine_tool_ptr->m_is_attendance=false;
  99. // //作为一条结束考勤记录保存到数据库
  100. // db_tool::save_attendance(card_ptr);
  101. // }
  102. //检查井下是否超员--是否需要取消
  103. //CMineCardManager::instance()->OnPersonUp(card_ptr);
  104. // auto rea_tool = card_ptr->get_area_tool();
  105. // rea_tool->on_leave(card_ptr);
  106. // card_ptr->clear();
  107. }
  108. else
  109. {
  110. log_error("手工升井,在全局列表中找不到卡,卡id=%d,卡type=%d", id, type);
  111. }
  112. }
  113. // //升井json发给web
  114. // if(datas.Size() > 0)
  115. // {
  116. // doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
  117. // //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
  118. // doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
  119. // swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
  120. // }
  121. }
  122. ///升井json
  123. void area_business_person_attendance::_to_json_card_up_one(std::shared_ptr<card_location_base> card_ptr,
  124. rapidjson::Value& out_datas, rapidjson::Document::AllocatorType& allocator)
  125. {
  126. if(!card_ptr->m_display)
  127. {
  128. return;
  129. }
  130. auto mine_tool_ptr = card_ptr->get_mine_tool();
  131. rapidjson::Value data(rapidjson::kArrayType);
  132. //卡号
  133. std::string id = tool_other::type_id_to_str(card_ptr->m_type, card_ptr->m_id);
  134. tool_json::push_back(data, id, allocator);
  135. //x,y坐标
  136. data.PushBack(card_ptr->x, allocator);
  137. data.PushBack(card_ptr->y, allocator); //CFunctions::round(card->y_offset_after(),2)
  138. //入井时间戳
  139. uint64_t t = tool_time::to_ms(mine_tool_ptr->m_attendance_start_time); //转为ms
  140. data.PushBack(t, allocator);
  141. //进入区域时间戳
  142. data.PushBack(0, allocator);
  143. //接收时间戳
  144. data.PushBack(0, allocator);
  145. //工作时长
  146. t = tool_time::elapse_ms(mine_tool_ptr->m_attendance_start_time); //转为ms
  147. data.PushBack(t, allocator);
  148. //地图编号
  149. data.PushBack(0, allocator);
  150. //区域编号
  151. data.PushBack(0, allocator);
  152. //部门编号
  153. data.PushBack(card_ptr->m_deptid, allocator);
  154. //状态
  155. data.PushBack(0, allocator);
  156. //运行状态
  157. data.PushBack(card_ptr->m_stat, allocator);
  158. //业务状态
  159. data.PushBack(0, allocator);
  160. //速度
  161. data.PushBack(card_ptr->m_speed, allocator);
  162. out_datas.PushBack(data, allocator);
  163. }
  164. /////升井或收到web的删除卡命令 site_ptr==nullptr表示收到web的删除卡命令
  165. ///// 保存考勤记录,发升井json,清理卡
  166. //void area_business_person_attendance::up_mine(std::shared_ptr<card_location_base> card_ptr, bool is_web_delete)
  167. //{
  168. // auto mine_tool_ptr = card_ptr->get_mine_tool();
  169. // if(!mine_tool_ptr->m_is_attendance)
  170. // {
  171. // return;
  172. // }
  173. // //考勤结束
  174. // mine_tool_ptr->m_is_attendance=false;
  175. // //作为一条结束考勤记录保存到数据库
  176. // db_tool::save_attendance(card_ptr);
  177. // rapidjson::Document doc(rapidjson::kObjectType);
  178. // rapidjson::Value datas(rapidjson::kArrayType);
  179. // rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
  180. // _to_json_card_up_one(card_ptr, datas, allocator);
  181. // //module_meta_date_changed::clear_card(card_ptr);
  182. // auto rea_tool = card_ptr->get_area_tool();
  183. // rea_tool->on_leave(card_ptr);
  184. // card_ptr->clear();
  185. // //升井json发给web
  186. // if(datas.Size() > 0)
  187. // {
  188. // doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
  189. // //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
  190. // doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
  191. // swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
  192. // }
  193. //// if(is_web_delete)
  194. //// {
  195. //// log_info("人卡考勤结束:卡id=%d,卡type=%d,分站id=%d,分站reader_type_id=%d,stat_attendance=%d",
  196. //// card_ptr->m_id, card_ptr->m_type,
  197. //// site_ptr->m_id,site_ptr->m_reader_type_id,mine_tool_ptr->m_is_attendance);
  198. //// }
  199. //// else
  200. //// {
  201. //// log_info("收到web的删除卡命令,人卡考勤结束:卡id=%d,卡type=%d, stat_attendance=%d",
  202. //// card_ptr->m_id, card_ptr->m_type, mine_tool_ptr->m_is_attendance);
  203. //// }
  204. //}