area_business_person_attendance.cpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 "card_person.h"
  7. #include"area.h"
  8. #include"common_tool.h"
  9. #include"mine.h"
  10. #include"websocket/constdef.h"
  11. #include "websocket/wsClientMgr.h"
  12. #include "websocket/wsTimerThread.h"
  13. #include"tool_time.h"
  14. #include "module_meta_date_changed.h"
  15. #include "his_location.h"
  16. //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
  17. void area_business_person_attendance::on_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
  18. const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
  19. {
  20. log_info("on_enter:person_att:%d",card_ptr->m_id);
  21. if(!card_ptr->is_person())
  22. return;
  23. auto mine_tool_ptr = card_ptr->get_mine_tool();
  24. if(!mine_tool_ptr->m_is_attendance)
  25. {
  26. mine_tool_ptr->m_is_attendance=true;
  27. mine_tool_ptr->m_attendance_start_time=
  28. std::chrono::system_clock::time_point(std::chrono::milliseconds(area_hover_ptr->m_enter_time));
  29. //作为一条开始考勤记录保存到数据库
  30. db_tool::save_attendance(card_ptr, area_hover_ptr);
  31. }
  32. }
  33. 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)
  34. {
  35. }
  36. //记录离开考勤区域信息,开始考勤
  37. void area_business_person_attendance::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
  38. {
  39. if(!card_ptr->is_person())return;
  40. auto mine_tool_ptr = card_ptr->get_mine_tool();
  41. if(!mine_tool_ptr->m_is_attendance)return;
  42. log_info("on_leave_person_att:%d",card_ptr->m_id);
  43. //考勤结束
  44. mine_tool_ptr->m_is_attendance=false;
  45. if(card_ptr->upmine_flag()){
  46. auto start = mine_tool_ptr->m_attendance_start_time;
  47. std::string start_time = tool_time::to_str(start);
  48. std::string card_id = tool_other::type_id_to_str(card_ptr->m_type,card_ptr->m_id);
  49. char nsql[512]{0};
  50. const char *sql = "update rpt_att_staff set is_auto=%d where card_id=%s and start_time='%s';";
  51. snprintf(nsql,512,sql,card_ptr->upmine_flag(),card_id.c_str(),start_time.c_str());
  52. db_tool::PushAsync(nsql);
  53. }
  54. //作为一条结束考勤记录保存到数据库
  55. db_tool::save_attendance(card_ptr, area_hover_ptr);
  56. //升井 更新his_location中的数据
  57. card_ptr->m_his_location_card->up_mine(point(card_ptr->x,card_ptr->y,0),card_ptr->get_area(),tool_time::now_to_ms());
  58. YA::_CARD_POS_ cp;
  59. cp.Type=card_ptr->m_type;
  60. cp.ID = card_ptr->m_id;
  61. swsTimerThrd.del_card_pos(cp);
  62. rapidjson::Document doc(rapidjson::kObjectType);
  63. rapidjson::Value datas(rapidjson::kArrayType);
  64. rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
  65. _to_json_card_up_one(card_ptr, datas, allocator);
  66. //升井json发给web
  67. if(datas.Size() > 0)
  68. {
  69. doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
  70. //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
  71. doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
  72. swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
  73. }
  74. auto per = std::dynamic_pointer_cast<person>(card_ptr);
  75. per->clear();
  76. }
  77. /**
  78. * @brief 手工升井函数
  79. */
  80. void area_business_person_attendance::handle_up_mine(sio::message::ptr const& data)
  81. {
  82. std::vector<sio::message::ptr> card_vec;
  83. if(!tool_map::try_get_value(card_vec, JSON_ROOT_KEY_DATA, data) || card_vec.size() == 0)
  84. {
  85. log_error("手工升井,web发来的数据data字段为空 或者不是数组");
  86. return;
  87. }
  88. std::vector<sio::message::ptr>::const_iterator it_card = card_vec.begin();
  89. int type = 0;
  90. std::string s_card_id;
  91. for(; it_card != card_vec.end(); ++it_card)
  92. {
  93. if(!tool_map::try_get_value(s_card_id, JSON_KEY_CALL_CARD_CARD_ID, (*it_card))
  94. ||!tool_map::try_get_value(type, JSON_KEY_CALL_CARD_CARD_TYPE_ID, (*it_card))
  95. )
  96. {
  97. log_error("手工升井,web发来的数据 card_id 或 card_type格式不对");
  98. continue;
  99. }
  100. log_info("handle_up_card:%s,接收到手动升井的请求",s_card_id.c_str());
  101. if(!tool_other::is_person(type))
  102. continue;
  103. auto card_ptr = card_list::instance()->get(tool_other::card_id_to_u64(s_card_id));
  104. if(card_ptr && STATUS_LOST == card_ptr->m_biz_stat)
  105. {
  106. log_info("handle_up_card:%s 手工升井,处理",s_card_id.c_str());
  107. card_ptr->inc_upmine_flag(1);
  108. }
  109. else
  110. log_warn("handle_up_card:%s,手动升井的卡找不到,或者该卡不在盲区",s_card_id.c_str());
  111. }
  112. }
  113. ///升井json
  114. void area_business_person_attendance::_to_json_card_up_one(std::shared_ptr<card_location_base> card_ptr,
  115. rapidjson::Value& out_datas, rapidjson::Document::AllocatorType& allocator)
  116. {
  117. auto mine_tool_ptr = card_ptr->get_mine_tool();
  118. rapidjson::Value data(rapidjson::kArrayType);
  119. //卡号
  120. std::string id = tool_other::type_id_to_str(card_ptr->m_type, card_ptr->m_id);
  121. tool_json::push_back(data, id, allocator);
  122. //x,y坐标
  123. data.PushBack(card_ptr->x, allocator);
  124. data.PushBack(card_ptr->y, allocator); //CFunctions::round(card->y_offset_after(),2)
  125. //入井时间戳
  126. uint64_t t = tool_time::to_ms(mine_tool_ptr->m_attendance_start_time); //转为ms
  127. data.PushBack(t, allocator);
  128. //进入区域时间戳
  129. data.PushBack(0, allocator);
  130. //接收时间戳
  131. data.PushBack(0, allocator);
  132. //工作时长
  133. t = tool_time::elapse_ms(mine_tool_ptr->m_attendance_start_time); //转为ms
  134. data.PushBack(t, allocator);
  135. //地图编号
  136. data.PushBack(0, allocator);
  137. //区域编号
  138. data.PushBack(0, allocator);
  139. //部门编号
  140. data.PushBack(card_ptr->m_deptid, allocator);
  141. //状态
  142. data.PushBack(0, allocator);
  143. //运行状态
  144. data.PushBack(card_ptr->m_stat, allocator);
  145. //业务状态
  146. data.PushBack(0, allocator);
  147. //速度
  148. data.PushBack(card_ptr->m_speed, allocator);
  149. out_datas.PushBack(data, allocator);
  150. }