card_person.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #include <string>
  2. #include <thread>
  3. #include "card_person.h"
  4. #include "loc_point.h"
  5. #include "card_message_handle.h"
  6. #include "area.h"
  7. #include "mine.h"
  8. #include "site_area.h"
  9. #include "his_location.h"
  10. #include "three_rates.h"
  11. #include "select_tool.h"
  12. #include "monkey_car/monkeycar_person.h"
  13. #include "websocket/ws_common.h"
  14. #include "ya_event.h"
  15. person::person(const std::string &type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid,int wl,const std::string &sname,const std::string &dname)
  16. :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
  17. ,m_workLine(wl)
  18. ,m_stafferName(sname)
  19. ,m_deptName(dname)
  20. {
  21. m_message_handle.reset(new card_message_handle(this));
  22. m_his_location_card.reset(new location_staff(m_id,m_type));
  23. }
  24. person::~person()
  25. {
  26. }
  27. void person::clear()
  28. {
  29. //m_site_area.reset(new site_area_hover);
  30. m_area_tool.reset(new area_tool);
  31. m_mine_tool.reset(new mine_tool);
  32. card_location_base::clear();
  33. }
  34. void person::site_hover(int sid)
  35. {
  36. if(m_time<=0)
  37. return;
  38. m_site_area->on_point(m_id,sid,nullptr, m_type);
  39. IKSDK_DB(sid);
  40. }
  41. //虹膜识别入库功能
  42. void person::IKSDK_DB(int sid)
  43. {
  44. auto sit_ptr = sit_list::instance()->get(sid);
  45. if(nullptr == sit_ptr)
  46. return;
  47. if(sit_ptr->m_reader_type_id == READER_TYPE_ID_UP)
  48. {
  49. time_t now = time(0);
  50. if(now - m_iris_recognition_timeval > 5)
  51. {
  52. int f=0;
  53. if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_LOW_POWER_SERIOUS))
  54. f=1;
  55. std::string card_id = tool_other::type_id_to_str(m_type,m_id);
  56. std::string st = tool_time::to_str(now);
  57. char nsql[256]={0};
  58. const char*sql="REPLACE INTO his_att_interface (staff_id,card_id,reader_id,staff_name,dept_name,upt_time,low_power_warn) VALUES (%d,%s,%d,'%s','%s','%s',%d);";
  59. snprintf(nsql,256,sql,m_cid,card_id.c_str(),sid,m_stafferName.c_str(),m_deptName.c_str(),st.c_str(),f);
  60. db_tool::PushAsync(nsql);
  61. logn_info(2,"%s",nsql);
  62. m_iris_recognition_timeval = now;
  63. }
  64. }
  65. }
  66. std::shared_ptr<area_hover> person::get_area_hover()
  67. {
  68. return m_area_tool->m_area_hover;
  69. }
  70. std::shared_ptr<mine_tool> person::get_mine_tool()
  71. {
  72. return m_mine_tool;
  73. }
  74. std::shared_ptr<site_area_hover> person::get_site_area()
  75. {
  76. return m_site_area;
  77. }
  78. void person::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
  79. {
  80. m_area_tool->on_point(site,shared_from_this(),pt);
  81. m_site_area->on_point(m_id,0,this, m_type);
  82. handle_three_rates(pt);
  83. }
  84. void person::reset(std::shared_ptr<monkey_person> mp)
  85. {
  86. m_monkeyPerson = mp;
  87. }
  88. std::tuple<time_t,time_t,int,int,int,int,double> person::getLandmark()
  89. {
  90. return m_area_tool->getLandmark();
  91. }
  92. void person::handle_three_rates(const point & pt)
  93. {
  94. card_pos cp;
  95. cp.work_line=m_workLine;
  96. cp.biz_stat = get_stat();
  97. cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;
  98. const auto lm = m_area_tool->getLandmark();
  99. cp.enter_time = std::get<0>(lm)*1000;
  100. cp.area_id = std::get<3>(lm);
  101. put_three_rates(cp);
  102. }
  103. void person::on_timer()
  104. {
  105. if(!m_mine_tool->is_attendance())
  106. return;
  107. YA::_CARD_POS_ cp;
  108. uint64_t _time=0;
  109. point pt = getSmoothPoint(_time);
  110. const auto lm = m_area_tool->getLandmark();
  111. cp.enter_area_time = std::get<0>(lm)*1000;
  112. cp.rec_time = std::get<1>(lm);
  113. int32_t map_id = std::get<2>(lm);
  114. int32_t area_id = std::get<3>(lm);
  115. cp.map_id=map_id;cp.area_id=area_id;
  116. cp.landmark_id = std::get<4>(lm);
  117. cp.lm_direction = std::get<5>(lm);
  118. cp.landmark_dis=std::get<6>(lm);
  119. cp.biz_stat = get_stat();
  120. cp.down_time = m_mine_tool->get_down_time();
  121. cp.work_time = m_mine_tool->get_work_time();
  122. cp.is_on_duty= m_mine_tool->is_on_duty();
  123. log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d",m_id,_time,pt.x,pt.y,area_id,map_id);
  124. m_his_location_card->push(_time,pt,area_id,map_id);
  125. upt_card_pos(cp,pt);
  126. }
  127. point person::getSmoothPoint(uint64_t& t)
  128. {
  129. point pt;
  130. loc_point lp = m_smo_tool->smooth_strategy();
  131. m_speed = lp.m_speed;
  132. m_stat = lp.m_stat;
  133. pt.x = lp.x;
  134. pt.y = -lp.y;
  135. t=lp.m_time;
  136. if(auto p = m_monkeyPerson.lock() )
  137. {
  138. if(p->is_on_bus())
  139. {
  140. m_stat = 7;
  141. pt = p->getPoint(t);
  142. log_info("getpoint_oncar:%d,%lld",m_id,t);
  143. }
  144. }
  145. return pt;
  146. }