card_person.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 "tool_time.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 "event.h"
  15. #include "mine_business.h"
  16. #include "common_tool.h"
  17. #include "db/db_tool.h"
  18. #include "forbid_staff_down_mine.h"
  19. #include <config_file.h>
  20. #include "cardMgr.h"
  21. extern config_file config;
  22. int person::m_limit_detained_time=-1;
  23. int person::m_auto_up_mine_time=-1;
  24. int person::m_person_cards_flag=-1;
  25. 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)
  26. :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
  27. ,m_workLine(wl)
  28. ,m_worktype_id(worketype_id)
  29. ,m_stafferName(sname)
  30. ,m_deptName(dname)
  31. {
  32. if(person::m_auto_up_mine_time==-1){
  33. person::m_limit_detained_time=config.get("service.detained_time",10);
  34. person::m_auto_up_mine_time=config.get("service.auto_up_mine_time",20);
  35. person::m_person_cards_flag=config.get("service.person_cards_flag",0);
  36. }
  37. m_message_handle.reset(new card_message_handle(this));
  38. //m_his_location_card.reset(new location_staff(m_id,m_type,cid));
  39. }
  40. person::~person()
  41. {
  42. }
  43. void person::clear()
  44. {
  45. make_his_location(m_time,*this,true);
  46. m_mine_tool->clear();
  47. m_area_tool->clear();
  48. //清除部分信息
  49. card_location_base::clear();
  50. //清除告警信息
  51. uint64_t id = tool_other::type_id_to_u64(m_type,m_id);
  52. for(std::uint8_t i=0;i<CARD_EVENT_COUNT_MAX;i++)
  53. {
  54. if(m_event[i]!=0)
  55. {
  56. log_info("clear_person_card_event:%d,%d",m_id,i);
  57. event_tool::instance()->handle_event(OT_CARD,static_cast<EVENT_TYPE>(i),id,0,0,false);
  58. m_event[i]=0;
  59. }
  60. }
  61. //清除一人多卡功能内存中的人卡相关数据,
  62. if(m_person_cards_flag){
  63. Msg m;
  64. m.cmd=CMD_CLEAR;m.cardid=m_type<<32|m_id;
  65. cardMgr::instance()->tryPut(m);
  66. }
  67. }
  68. void person::set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)
  69. {
  70. m_area_tool->set_area_info(mapid,scale,areaid,*this,t,type);
  71. }
  72. void person::site_hover(int sid)
  73. {
  74. IKSDK_DB(sid);
  75. }
  76. //虹膜识别入库功能
  77. void person::IKSDK_DB(int sid)
  78. {
  79. time_t now = time(0);
  80. if(now - m_iris_recognition_timeval > 5)
  81. {
  82. if (forbid_staff_down_mine::instance()->IsForbid(m_cid,now))
  83. {
  84. log_info("Staff:%d forbid down mine",m_cid); //禁止指定人员下井
  85. return;
  86. }
  87. int f=0;
  88. if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_LOW_POWER_SERIOUS)) {
  89. f = 1;
  90. }
  91. std::string card_id = tool_other::type_id_to_str(m_type,m_id);
  92. std::string st = tool_time::to_str(now);
  93. char nsql[256]={0};
  94. const char*sql="REPLACE INTO his_att_interface (staff_id,card_id,reader_id,staff_name,dept_id,dept_name,upt_time,low_power_warn)"
  95. " VALUES (%d,%s,%d,'%s',%d,'%s','%s',%d);";
  96. snprintf(nsql,256,sql,m_cid,card_id.c_str(),sid,m_stafferName.c_str(),m_deptid,m_deptName.c_str(),st.c_str(),f);
  97. db_tool::PushAsync(nsql);
  98. m_iris_recognition_timeval = now;
  99. }
  100. }
  101. std::shared_ptr<mine_tool> person::get_mine_tool()
  102. {
  103. return m_mine_tool;
  104. }
  105. void person::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
  106. {
  107. m_area_tool->on_point(shared_from_this(),pt);
  108. make_his_location(m_time,pt);
  109. m_timeval=m_time;
  110. handle_three_rates(pt);
  111. //一人多卡数据输入
  112. if(m_person_cards_flag){
  113. Msg m;
  114. m.type=m_type;m.x=(int)x;m.y=(int)y;m.cmd=CMD_HANDLE;m.cardid=m_type<<32|m_id;
  115. cardMgr::instance()->tryPut(m);
  116. }
  117. }
  118. void person::reset(std::shared_ptr<monkey_person> mp)
  119. {
  120. m_monkeyPerson = mp;
  121. }
  122. void person::handle_three_rates(const point & pt)
  123. {
  124. card_pos cp;
  125. cp.work_line=m_workLine;
  126. cp.work_type_id = m_worktype_id;
  127. m_biz_stat=get_stat();
  128. cp.biz_stat = m_biz_stat;
  129. cp.x=pt.x;cp.y=pt.y;cp.z=pt.z;
  130. cp.work_type_id=m_worktype_id;
  131. put_three_rates(cp);
  132. }
  133. void person::on_timer()
  134. {
  135. if(!m_mine_tool->m_is_attendance)
  136. {
  137. if(m_upmine_flag.load())
  138. {
  139. log_warn("up_mine:att=false,upmine_flag=%d",m_upmine_flag.load());
  140. m_upmine_flag=0;
  141. }
  142. return;
  143. }
  144. YA::_CARD_POS_ cp;
  145. uint64_t _time=0;
  146. point pt = getSmoothPoint(_time);
  147. cp.area_info=m_area_tool->m_area_info;
  148. cp.map_id =m_area_tool->get_mapid();
  149. cp.biz_stat = m_biz_stat;
  150. cp.down_time = m_mine_tool->get_down_time();
  151. cp.work_time = m_mine_tool->get_work_time();
  152. cp.is_on_duty= m_mine_tool->is_on_duty();
  153. upt_card_pos(cp,pt);
  154. log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d--%d,speed=%.2f",m_id,_time,pt.x,pt.y,cp.map_id,cp.area_info.size(),person::m_limit_detained_time,m_speed);
  155. //int sid=0; if(auto st=m_area_tool->m_site)sid=st->m_area_id; m_his_location_card->push(_time,pt,sid,cp.map_id);
  156. uint64_t _now=tool_time::now_to_ms();
  157. uint64_t t=_now>m_timeval?_now-m_timeval:m_timeval-_now;
  158. if(t>10*1000)
  159. {
  160. m_area_tool->on_point(shared_from_this(),pt);
  161. m_biz_stat=get_stat();
  162. }
  163. print_card_detained();
  164. if(m_upmine_flag.load())
  165. {
  166. log_info("card=%d user-id=%d up_mine:upmine_flag=%d",m_id,m_cid, m_upmine_flag.load());
  167. m_area_tool->on_leave(shared_from_this());
  168. m_upmine_flag=0;
  169. }
  170. }
  171. //***********************************************
  172. //整点打印入井超过设定时长(默认10h)
  173. //进入盲区超过2h的卡
  174. void person::print_card_detained()
  175. {
  176. const point p(4677,-193.7);
  177. const double limit_dist=45.0;
  178. int h=tool_time::get_hour();
  179. uint64_t _now=tool_time::now_to_ms();
  180. uint64_t work_time=m_mine_tool->get_work_time();
  181. uint64_t lost_time=_now>m_time?_now-m_time:m_time-_now;
  182. if(m_thour != h && (work_time > static_cast<uint64_t>(person::m_limit_detained_time*60*60*1000)) && lost_time>2*60*60*1000)
  183. {
  184. m_thour=h;
  185. auto start = m_mine_tool->m_attendance_start_time;
  186. std::string enter_time=tool_time::to_str(start);
  187. uint32_t min=work_time/1000/60;
  188. uint32_t lmin=lost_time/1000/60;
  189. double dist=p.dist(*this);
  190. std::string last_time=tool_time::to_str_ex(m_time);
  191. std::string alarm_time{"No Alarm."};
  192. auto event_power=event_list::instance()->get_event_card(m_id,m_type,ET_CARD_LOW_POWER_SERIOUS);
  193. if(event_power)
  194. alarm_time=tool_time::to_str(event_power->m_cur_time);
  195. log_warn("[card_detained]卡号:%03d%010d,分站:%d,入井时间点:%s,入井时长:%d小时%d分钟,(%.2f,%.2f)是否在处在井底范围内:%s,最后接收时间点:%s,进入盲区时长:%d小时%d分钟,是否低电量告警:%s,低电量开始时间点:%s",
  196. m_type,m_id,m_area_tool->get_site_id(),enter_time.c_str(),min/60,min%60,x,y,dist<limit_dist?"True":"False",last_time.c_str(),lmin/60,lmin%60,event_power?"Ture":"False",alarm_time.c_str());
  197. //超过设置的时长后,开始自动升井
  198. if(work_time > static_cast<uint64_t>(person::m_auto_up_mine_time*60*60*1000))
  199. inc_upmine_flag(2);
  200. }
  201. }
  202. point person::getSmoothPoint(uint64_t& t)
  203. {
  204. point pt;
  205. loc_point lp = m_smo_tool->smooth_strategy();
  206. m_speed = lp.m_speed;
  207. m_stat = lp.m_stat;
  208. pt.x = lp.x;
  209. pt.y = -lp.y;
  210. t=lp.m_time;
  211. if(auto p = m_monkeyPerson.lock() )
  212. {
  213. if(p->is_on_bus())
  214. {
  215. m_stat = 7;
  216. pt = p->getPoint(t);
  217. log_info("getpoint_oncar:%d,%lld",m_id,t);
  218. }
  219. }
  220. return pt;
  221. }
  222. void person::get_card(bool f)
  223. {
  224. if (!m_mine_tool->m_is_attendance)
  225. return ;
  226. mine_business::inst()->fetch_add(m_display);
  227. }