1
0

card_person.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 "his_location.h"
  9. #include "three_rates.h"
  10. #include "select_tool.h"
  11. #include "monkey_car/monkeycar_person.h"
  12. #include "websocket/ws_common.h"
  13. #include "event.h"
  14. #include "mine_business.h"
  15. #include"common_tool.h"
  16. #include"db/db_tool.h"
  17. #include "forbid_staff_down_mine.h"
  18. 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,int worketype_id)
  19. :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
  20. ,m_workLine(wl)
  21. ,m_stafferName(sname)
  22. ,m_deptName(dname)
  23. ,m_worktype_id(worketype_id)
  24. {
  25. m_message_handle.reset(new card_message_handle(this));
  26. m_his_location_card.reset(new location_staff(m_id,m_type,cid));
  27. }
  28. person::~person()
  29. {
  30. }
  31. void person::clear()
  32. {
  33. //m_area_tool.reset(new area_tool);
  34. //m_mine_tool.reset(new mine_tool);
  35. m_mine_tool->clear();
  36. m_area_tool->clear();
  37. card_location_base::clear();
  38. uint64_t id = tool_other::type_id_to_u64(m_type,m_id);
  39. for(std::uint8_t i=0;i<CARD_EVENT_COUNT_MAX;i++)
  40. {
  41. if(m_event[i]!=0)
  42. {
  43. log_info("clear_person_card_event:%d,%d",m_id,i);
  44. event_tool::instance()->handle_event(OT_CARD,static_cast<EVENT_TYPE>(i),id,0,0,false);
  45. m_event[i]=0;
  46. }
  47. }
  48. }
  49. void person::set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)
  50. {
  51. m_area_tool->set_area_info(mapid,scale,areaid,*this,t,type);
  52. }
  53. void person::site_hover(int sid)
  54. {
  55. IKSDK_DB(sid);
  56. }
  57. //虹膜识别入库功能
  58. void person::IKSDK_DB(int sid)
  59. {
  60. time_t now = time(0);
  61. if(now - m_iris_recognition_timeval > 5)
  62. {
  63. if (forbid_staff_down_mine::instance()->IsForbid(m_cid,now))
  64. {
  65. log_info("Staff:%d forbid down mine",m_cid); //禁止指定人员下井
  66. return;
  67. }
  68. int f=0;
  69. if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_LOW_POWER_SERIOUS)) {
  70. f = 1;
  71. }
  72. std::string card_id = tool_other::type_id_to_str(m_type,m_id);
  73. std::string st = tool_time::to_str(now);
  74. char nsql[256]={0};
  75. 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);";
  76. snprintf(nsql,256,sql,m_cid,card_id.c_str(),sid,m_stafferName.c_str(),m_deptName.c_str(),st.c_str(),f);
  77. db_tool::PushAsync(nsql);
  78. m_iris_recognition_timeval = now;
  79. }
  80. }
  81. std::shared_ptr<mine_tool> person::get_mine_tool()
  82. {
  83. return m_mine_tool;
  84. }
  85. void person::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
  86. {
  87. m_area_tool->set(site);
  88. m_area_tool->on_point(shared_from_this(),pt);
  89. m_timeval=m_time;
  90. handle_three_rates(pt);
  91. }
  92. void person::reset(std::shared_ptr<monkey_person> mp)
  93. {
  94. m_monkeyPerson = mp;
  95. }
  96. void person::handle_three_rates(const point & pt)
  97. {
  98. card_pos cp;
  99. cp.work_line=m_workLine;
  100. cp.work_type_id = m_worktype_id;
  101. m_biz_stat=get_stat();
  102. cp.biz_stat = m_biz_stat;
  103. cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;
  104. cp.work_type_id=m_worktype_id;
  105. put_three_rates(cp);
  106. }
  107. void person::on_timer()
  108. {
  109. if(!m_mine_tool->m_is_attendance)
  110. return;
  111. YA::_CARD_POS_ cp;
  112. uint64_t _time=0;
  113. point pt = getSmoothPoint(_time);
  114. cp.area_info=m_area_tool->m_area_info;
  115. cp.map_id =m_area_tool->m_mapid;
  116. cp.biz_stat = m_biz_stat;
  117. cp.down_time = m_mine_tool->get_down_time();
  118. cp.work_time = m_mine_tool->get_work_time();
  119. cp.is_on_duty= m_mine_tool->is_on_duty();
  120. upt_card_pos(cp,pt);
  121. log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d--",m_id,_time,pt.x,pt.y,cp.map_id,cp.area_info.size());
  122. int sid=0;
  123. if(auto st=m_area_tool->m_site)sid=st->m_area_id;
  124. m_his_location_card->push(_time,pt,sid,cp.map_id);
  125. uint64_t _now=tool_time::now_to_ms();
  126. uint64_t t=_now>m_timeval?_now-m_timeval:m_timeval-_now;
  127. if(t>10*1000)
  128. {
  129. m_area_tool->on_point(shared_from_this(),pt);
  130. m_biz_stat=get_stat();
  131. }
  132. }
  133. point person::getSmoothPoint(uint64_t& t)
  134. {
  135. point pt;
  136. loc_point lp = m_smo_tool->smooth_strategy();
  137. m_speed = lp.m_speed;
  138. m_stat = lp.m_stat;
  139. pt.x = lp.x;
  140. pt.y = -lp.y;
  141. t=lp.m_time;
  142. if(auto p = m_monkeyPerson.lock() )
  143. {
  144. if(p->is_on_bus())
  145. {
  146. m_stat = 7;
  147. pt = p->getPoint(t);
  148. log_info("getpoint_oncar:%d,%lld",m_id,t);
  149. }
  150. }
  151. return pt;
  152. }
  153. void person::get_card(bool f)
  154. {
  155. if(!m_mine_tool->m_is_attendance)
  156. return;
  157. mine_business::inst()->fetch_add(m_display);
  158. }