card.cpp 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. #include <memory>
  2. #include <log.h>
  3. #include <zloop.h>
  4. #include "select_tool.h"
  5. #include "loc_tool.h"
  6. #include <area.h>
  7. #include <site_area.h>
  8. #include <card.h>
  9. #include "config_file.h"
  10. #include "db_api/CDBConnPool.h"
  11. #include "websocket/wsTimerThread.h"
  12. #include "websocket/wsClientMgr.h"
  13. #include "timestamp.h"
  14. #include "monkey_car/monkeycar_area.h"
  15. #include "monkey_car/monkeycar_person.h"
  16. #include "special_area.h"
  17. #include "cardMgr.h"
  18. #include "ant.h"
  19. #include "mine.h"
  20. #include "module_service/module_mgr.h"
  21. #include "visit.h"
  22. #include "his_location.h"
  23. extern config_file config;
  24. //一张卡一个ct的所有不同天线的信息
  25. struct one_ct_message_handle
  26. {
  27. static loc_tool_main m_loc_tool;
  28. ev::timer m_min_timer,m_max_timer;
  29. //loc_message.
  30. std::vector<loc_message> m_msg_list;
  31. card_location_base*m_card;
  32. const algo_config*m_ac=nullptr;
  33. int m_ct;
  34. bool m_min_timeout=false;
  35. ev::dynamic_loop * m_loop = nullptr;
  36. one_ct_message_handle(card_location_base*card)
  37. {
  38. m_card=card;
  39. m_ct=-1;
  40. }
  41. void reset()
  42. {
  43. m_ct=-1;
  44. m_min_timeout=false;
  45. m_msg_list.clear();
  46. }
  47. void on_min_timer()
  48. {
  49. m_min_timer.stop();
  50. if((int)m_msg_list.size()>=m_ac->best_msg_cnt)
  51. {
  52. m_max_timer.stop();
  53. calc_location();
  54. return;
  55. }
  56. m_min_timeout=true;
  57. }
  58. void on_max_timer()
  59. {
  60. m_max_timer.stop();
  61. calc_location();
  62. }
  63. void set(ev::dynamic_loop * loop)
  64. {
  65. m_loop = loop;
  66. m_min_timer.set(*m_loop);
  67. m_min_timer.set<one_ct_message_handle,&one_ct_message_handle::on_min_timer>(this);
  68. m_max_timer.set(*m_loop);
  69. m_max_timer.set<one_ct_message_handle,&one_ct_message_handle::on_max_timer>(this);
  70. }
  71. void on_message(ev::dynamic_loop *loop,const message_locinfo&loc)
  72. {
  73. if(m_loop == nullptr && loop!=nullptr)
  74. set(loop);
  75. else if(loop == nullptr)
  76. return;
  77. if(!m_msg_list.empty()&& m_ct!=loc.m_card_ct)
  78. {
  79. m_msg_list.clear();
  80. }
  81. auto sitPtr = sit_list::instance()->get(loc.m_site_id);
  82. if(sitPtr==nullptr)
  83. {
  84. log_warn("分站信息缺失,SitId:%d",loc.m_site_id);
  85. return;
  86. }
  87. const site &s=*(sit_list::instance()->get(loc.m_site_id));
  88. if(m_msg_list.empty())
  89. {
  90. m_ct=loc.m_card_ct;
  91. m_ac=&s.config();
  92. m_min_timeout=false;
  93. //这里构造loc_message 保存数据
  94. m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,
  95. loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
  96. loc.m_sync_ct,loc.m_rssi));
  97. //启动本CT的最小、最大两个定时器
  98. m_min_timer.start(m_ac->min_wait_time);
  99. m_max_timer.start(m_ac->min_wait_time);
  100. return;
  101. }
  102. m_msg_list.push_back(loc_message(s,loc.m_tof,loc.m_time_stamp,loc.m_card_id,
  103. loc.m_card_ct,loc.m_card_type,loc.m_ant_id,loc.m_rav,loc.m_acc,
  104. loc.m_sync_ct,loc.m_rssi));
  105. if(m_min_timeout && (int)m_msg_list.size()>=m_ac->best_msg_cnt)
  106. {
  107. calc_location();
  108. m_max_timer.stop();
  109. }
  110. }
  111. void calc_location()
  112. {
  113. auto v = m_msg_list;
  114. std::vector<point> rc=std::move(m_loc_tool.calc_location(v));
  115. if(!rc.empty()) m_card->on_location(std::move(rc),v);
  116. reset();
  117. }
  118. };
  119. struct card_message_handle
  120. {
  121. card_location_base*m_card;
  122. std::array<one_ct_message_handle*,16> m_ct_list;
  123. card_message_handle(card_location_base*card)
  124. {
  125. m_card=card;
  126. for(size_t i=0;i<m_ct_list.size();i++)
  127. {
  128. m_ct_list[i]=new one_ct_message_handle(card);
  129. }
  130. }
  131. ~card_message_handle()
  132. {
  133. for(auto&it:m_ct_list)
  134. {
  135. delete it;
  136. }
  137. }
  138. void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  139. {
  140. if(is_history)
  141. {
  142. log_warn("%s","当前代码没有处理历史消息记录。");
  143. return;
  144. }
  145. //
  146. m_card->site_hover(loc.m_site_id);
  147. if(loc.m_batty_status == 2)
  148. {
  149. m_card->do_status(STATUS_POWER_LOWER_SERIOUS);
  150. }
  151. else
  152. {
  153. m_card->do_status(STATUS_POWER_NOMARL);
  154. }
  155. if(loc.m_callinfo & 0x80)
  156. {
  157. m_card->do_status(STATUS_HELP);
  158. }
  159. if((loc.m_callinfo & 0x01) || (loc.m_callinfo & 0x02))
  160. {
  161. m_card->do_status(STATUS_CALL);
  162. }
  163. m_ct_list[loc.m_card_ct&(m_ct_list.size()-1)]->on_message(loop,loc);
  164. }
  165. };
  166. struct card_area
  167. {
  168. card_area()
  169. {
  170. m_site_area.reset(new site_area_hover);
  171. m_area_tool.reset(new area_tool);
  172. m_mine_tool.reset(new mine_tool);
  173. }
  174. std::shared_ptr<site_area_hover> m_site_area=nullptr;
  175. std::shared_ptr<area_tool> m_area_tool=nullptr;
  176. std::shared_ptr<mine_tool> m_mine_tool=nullptr;
  177. };
  178. struct person:card_location_base, card_area
  179. {
  180. std::weak_ptr<monkey_person> m_monkeyPerson;
  181. person(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,int32_t level_id)
  182. :card_location_base(type,cardid,needdisplay,t,deptid,level_id)
  183. {
  184. m_message_handle.reset(new card_message_handle(this));
  185. m_his_location_card.reset(new location_staff(m_id,m_type));
  186. }
  187. void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  188. {
  189. m_message_handle->on_message(loop,loc,is_history);
  190. }
  191. void clear()
  192. {
  193. m_site_area.reset(new site_area_hover);
  194. m_area_tool.reset(new area_tool);
  195. m_mine_tool.reset(new mine_tool);
  196. card_location_base::clear();
  197. }
  198. virtual void site_hover(int sid)
  199. {
  200. if(m_time<=0)
  201. {
  202. return;
  203. }
  204. m_site_area->on_point(m_id,sid,nullptr, m_type);
  205. }
  206. virtual std::shared_ptr<area_hover> get_area_hover()
  207. {
  208. return m_area_tool->m_area_hover;
  209. }
  210. virtual std::shared_ptr<mine_tool> get_mine_tool()
  211. {
  212. return m_mine_tool;
  213. }
  214. virtual std::shared_ptr<site_area_hover> get_site_area()
  215. {
  216. return m_site_area;
  217. }
  218. virtual void do_business(const point &pt)
  219. {
  220. m_area_tool->on_point(m_id,pt,m_speed,m_type);
  221. m_site_area->on_point(m_id,0,this, m_type);
  222. }
  223. void reset(std::shared_ptr<monkey_person> mp)
  224. {
  225. m_monkeyPerson = mp;
  226. }
  227. ~person(){}
  228. private:
  229. void on_timer()
  230. {
  231. if(!m_mine_tool->is_attendance())
  232. return;
  233. YA::_CARD_POS_ cp;
  234. uint64_t _time=0;
  235. point pt = getSmoothPoint(_time);
  236. const auto lm = m_area_tool->getLandmark();
  237. cp.enter_area_time = std::get<0>(lm)*1000;
  238. cp.rec_time = std::get<1>(lm);
  239. int32_t map_id = std::get<2>(lm);
  240. int32_t area_id = std::get<3>(lm);
  241. cp.map_id=map_id;cp.area_id=area_id;
  242. cp.landmark_id = std::get<4>(lm);
  243. cp.lm_direction = std::get<5>(lm);
  244. cp.landmark_dis=std::get<6>(lm);
  245. cp.biz_stat = get_stat();
  246. cp.down_time = m_mine_tool->get_down_time();
  247. cp.work_time = m_mine_tool->get_work_time();
  248. cp.is_on_duty= m_mine_tool->is_on_duty();
  249. log_info("on_timer here ...%d,%lld,%.2f,%.2f,%d,%d",m_id,_time,pt.x,pt.y,area_id,map_id);
  250. m_his_location_card->push(_time,pt,area_id,map_id);
  251. upt_card_pos(cp,pt);
  252. }
  253. point getSmoothPoint(uint64_t& t)
  254. {
  255. point pt;
  256. loc_point lp = m_smo_tool->smooth_strategy();
  257. m_speed = lp.m_speed;
  258. m_stat = lp.m_stat;
  259. pt.x = lp.x;
  260. pt.y = -lp.y;
  261. t=lp.m_time;
  262. if(auto p = m_monkeyPerson.lock() )
  263. {
  264. if(p->is_on_bus())
  265. {
  266. m_stat = 7;
  267. pt = p->getPoint(t);
  268. log_info("getpoint_oncar:%d,%lld",m_id,t);
  269. }
  270. }
  271. return pt;
  272. }
  273. };
  274. struct car:card_location_base,card_area
  275. {
  276. int m_vehicle_category_id=0;
  277. int m_vehicle_type_id=0;
  278. car(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,
  279. int32_t categoryid, int type_id,int32_t level_id)
  280. :card_location_base(type,cardid,needdisplay,t,deptid,level_id)
  281. ,m_vehicle_category_id(categoryid)
  282. ,m_vehicle_type_id(type_id)
  283. {
  284. m_message_handle.reset(new card_message_handle(this));
  285. m_his_location_card.reset(new location_vehicle(m_id,m_type));
  286. }
  287. virtual void site_hover(int sid)
  288. {
  289. if(m_time<=0)
  290. {
  291. return;
  292. }
  293. m_site_area->on_point(m_id,sid,0, m_type);
  294. }
  295. virtual std::shared_ptr<area_hover> get_area_hover()
  296. {
  297. return m_area_tool->m_area_hover;
  298. }
  299. virtual std::shared_ptr<mine_tool> get_mine_tool()
  300. {
  301. return m_mine_tool;
  302. }
  303. virtual std::shared_ptr<site_area_hover> get_site_area()
  304. {
  305. return m_site_area;
  306. }
  307. virtual void do_business(const point &pt)
  308. {
  309. m_area_tool->on_point(m_id,pt,m_speed,m_type);
  310. m_site_area->on_point(m_id,0,this, m_type);
  311. m_mine_tool->on_point(m_id, m_type, m_vehicle_category_id);
  312. }
  313. int get_vehicle_type_id()
  314. {
  315. return m_vehicle_type_id;
  316. }
  317. ~car(){}
  318. private:
  319. void on_timer()
  320. {
  321. make_package();
  322. }
  323. int statbiz(int32_t special_id)
  324. {
  325. int status = get_stat();
  326. if(status == STATUS_LOST)
  327. {
  328. if(!m_area_tool->special_area())
  329. {
  330. special_id = special_area_list::instance()->get_special_id(m_id,*this,m_vehicle_category_id);
  331. log_info("enter_special_area:%.2f,%2.f,id:%d,special_area_id:%d",x,y,m_id,special_id);
  332. if(special_id != -1)
  333. m_area_tool->change_area(m_id,m_speed,m_type,special_id);//自动拖车
  334. }
  335. }
  336. return status;
  337. }
  338. void make_package()
  339. {
  340. int32_t special_id=-1;
  341. YA::_CARD_POS_ cp;
  342. loc_point pt = getSmoothPoint();
  343. const auto lm = m_area_tool->getLandmark();
  344. cp.enter_area_time = std::get<0>(lm);
  345. cp.rec_time = std::get<1>(lm);
  346. uint32_t map_id = std::get<2>(lm);
  347. uint32_t area_id = std::get<3>(lm);
  348. cp.map_id =map_id;cp.area_id=area_id;
  349. cp.landmark_id = std::get<4>(lm);
  350. cp.lm_direction = std::get<5>(lm);
  351. cp.landmark_dis=std::get<6>(lm);
  352. int32_t biz_stat=statbiz(special_id);
  353. cp.biz_stat=biz_stat;
  354. cp.down_time = m_mine_tool->get_down_time();
  355. cp.work_time = m_mine_tool->get_work_time();
  356. //for now
  357. cp.is_on_duty=m_mine_tool->is_on_duty();
  358. upt_card_pos(cp,pt);
  359. m_his_location_card->push(pt.m_time,pt,area_id,map_id);
  360. if(biz_stat==STATUS_LOST && special_id != -1 && m_display==1)
  361. {
  362. cp.area_id = special_id;
  363. swsClientMgr.SendSpecialAreaProcess(cp);
  364. }
  365. }
  366. loc_point getSmoothPoint()
  367. {
  368. loc_point lp = m_smo_tool->smooth_strategy();
  369. m_speed = lp.m_speed;
  370. m_stat = lp.m_stat;
  371. lp.y = -lp.y;
  372. return lp;
  373. }
  374. };
  375. loc_tool_main one_ct_message_handle::m_loc_tool;
  376. uint64_t card_list::getId(uint32_t cardid,uint64_t type)
  377. {
  378. return type<<32|cardid;
  379. }
  380. void card_list::init_staffer(int32_t id)
  381. {
  382. std::string strategy = config.get("person.strategy","person1");
  383. std::string sql = "SELECT staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
  384. ol.occupation_level_id,s.worktype_id,s.need_display \
  385. FROM dat_staff_extend s \
  386. LEFT JOIN dat_card c ON s.card_id = c.card_id \
  387. LEFT JOIN dat_occupation o ON s.occupation_id = o.occupation_id \
  388. LEFT JOIN dat_occupation_level ol ON ol.occupation_level_id = o.occupation_level_id \
  389. WHERE c.card_type_id = 1 AND s.duty_id = 0 AND c.state_id = 0";
  390. int type = CT_PERSON;
  391. std::string card_id_str = card_list::to_id64_str(type, static_cast<uint32_t>(id));
  392. if(-1 == id)
  393. {
  394. sql.append(";");
  395. }
  396. else
  397. {
  398. sql.append(" AND s.card_id = '");
  399. sql.append(card_id_str);
  400. sql.append("';");
  401. std_debug("基础数据 增加或修改人卡 sql=%s", sql.c_str());
  402. log_info("基础数据 增加或修改人卡 sql=%s", sql.c_str());
  403. }
  404. std::string Error;
  405. YADB::CDBResultSet DBRes;
  406. sDBConnPool.Query(sql.c_str(),DBRes,Error);
  407. int nCount = DBRes.GetRecordCount( Error );
  408. if (nCount < 1)
  409. {
  410. log_error("增加或修改失败,数据库中找不到: card_id=%s", card_id_str.c_str());
  411. return ;
  412. }
  413. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  414. while ( DBRes.GetNextRecod(Error) )
  415. {
  416. unsigned int staff_id = 0;
  417. DBRes.GetField( "staff_id",staff_id, Error );
  418. std::string card_id;
  419. DBRes.GetField( "card_id",card_id, Error );
  420. uint32_t vsid = atoi(card_id.substr(3).c_str());
  421. unsigned int card_type_id = 0;
  422. DBRes.GetField( "card_type_id",card_type_id, Error );
  423. int dept_id = 0;
  424. DBRes.GetField( "dept_id",dept_id, Error );
  425. int group_id = 0;
  426. DBRes.GetField( "group_id",group_id, Error );
  427. int occupation_id = 0;
  428. DBRes.GetField( "occupation_id",occupation_id, Error );
  429. int occupation_level_id = 0;
  430. DBRes.GetField( "occupation_level_id",occupation_level_id, Error );
  431. int need_display = 0;
  432. DBRes.GetField( "need_display",need_display, Error );
  433. //for now;
  434. staff_id = vsid;
  435. if(-1 == id)
  436. {
  437. std::shared_ptr<card_location_base> clb =
  438. std::make_shared<person>(strategy,staff_id,need_display,card_type_id,dept_id,occupation_level_id);
  439. uint64_t cardid = getId(staff_id,type);
  440. log_info("cardId:%llu,staff_id:%d dept_id:%d,need_display:%d--c-ard:%s",
  441. cardid,staff_id,dept_id,need_display,card_id.c_str());
  442. map.insert({cardid,clb});
  443. }
  444. else
  445. {
  446. auto card_id64 = card_list::to_id64(type, static_cast<uint32_t>(id));
  447. auto card_ptr = card_list::instance()->get(card_id64);
  448. if(card_ptr)
  449. {
  450. person* tmp_ptr= static_cast<person*>(card_ptr.get());
  451. tmp_ptr->m_display = static_cast<uint16_t>(need_display);
  452. tmp_ptr->m_deptid = dept_id;
  453. //group_id
  454. //occ_id
  455. tmp_ptr->m_level_id = occupation_level_id;
  456. //worktype_id
  457. }
  458. else
  459. {
  460. auto clb = std::make_shared<person>(strategy,staff_id,need_display,card_type_id,dept_id,occupation_level_id);
  461. card_list::instance()->add(card_id64, clb);
  462. }
  463. log_info("基础数据 增加或修改人卡成功:卡id:%d,卡type:%d dept_id:%d,need_display:%d,occupation_level_id:%d",
  464. id,type,dept_id,need_display,occupation_level_id);
  465. std_debug("基础数据 增加或修改人卡成功:卡id:%d,卡type:%d dept_id:%d,need_display:%d,occupation_level_id:%d",
  466. id,type,dept_id,need_display,occupation_level_id);
  467. }
  468. }
  469. if(-1 == id)
  470. {
  471. log_info( "init_staffer. The record count=%d\n", nCount );
  472. card_list::instance()->add(map);
  473. }
  474. }
  475. void card_list::init_vehicle(int32_t id)
  476. {
  477. std::string strategy = config.get("car.strategy","car1");
  478. std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
  479. ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
  480. vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
  481. vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
  482. FROM dat_vehicle_extend ve \
  483. LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
  484. LEFT JOIN dat_card c ON ve.card_id = c.card_id \
  485. LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
  486. LEFT JOIN dat_group g ON ve.group_id = g.group_id \
  487. LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
  488. LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
  489. WHERE c.card_type_id = 2 AND c.state_id = 0";
  490. int type = CT_VEHICLE;
  491. std::string card_id_str = card_list::to_id64_str(type, static_cast<uint32_t>(id));
  492. if(-1 == id)
  493. {
  494. sql.append(";");
  495. }
  496. else
  497. {
  498. sql.append(" AND ve.card_id ='");
  499. sql.append(card_id_str);
  500. sql.append("';");
  501. std_debug("基础数据 增加或修改车卡 sql=%s", sql.c_str());
  502. log_info("基础数据 增加或修改车卡 sql=%s", sql.c_str());
  503. }
  504. std::string Error;
  505. YADB::CDBResultSet DBRes;
  506. sDBConnPool.Query(sql.c_str(),DBRes,Error);
  507. int nCount = DBRes.GetRecordCount( Error );
  508. if (nCount < 1)
  509. {
  510. log_error("增加或修改失败,数据库中找不到: card_id=%s", card_id_str.c_str());
  511. return ;
  512. }
  513. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  514. while ( DBRes.GetNextRecod(Error) )
  515. {
  516. unsigned int vehicle_id = 0;
  517. DBRes.GetField( "vehicle_id",vehicle_id, Error );
  518. std::string card_id;
  519. DBRes.GetField( "card_id",card_id, Error );
  520. uint32_t vsid = atoi(card_id.substr(3).c_str());
  521. unsigned int card_type_id = 0;
  522. DBRes.GetField( "card_type_id",card_type_id, Error );
  523. int dept_id = 0;
  524. DBRes.GetField( "dept_id",dept_id, Error );
  525. int group_id = 0;
  526. DBRes.GetField( "group_id",group_id, Error );
  527. int vehicle_type_id = 0;
  528. DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
  529. int vehicle_level_id = 0;
  530. DBRes.GetField( "vehicle_level_id",vehicle_level_id, Error );
  531. int need_display = 0;
  532. DBRes.GetField( "need_display",need_display, Error );
  533. int power_alarm = 0;
  534. DBRes.GetField( "power_alarm",power_alarm, Error );
  535. int vehicle_category_id = 0;
  536. DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
  537. int bigger_car_flag= 0;
  538. DBRes.GetField( "bigger_car_flag",bigger_car_flag, Error );
  539. double over_speed= 0;
  540. DBRes.GetField( "over_speed",over_speed, Error );
  541. //for now
  542. vehicle_id = vsid;
  543. if(-1 == id)
  544. {
  545. auto clb = std::make_shared<car>(strategy,vehicle_id,need_display,card_type_id,
  546. dept_id,vehicle_category_id, vehicle_type_id,vehicle_level_id);
  547. uint64_t cardid = getId(vehicle_id,type);
  548. log_info("cardId:%llu,vehicle_id:%d dept_id:%d,need_display:%d---cardid:%s,categoryid:%d",
  549. cardid,vehicle_id,dept_id,need_display,card_id.c_str(),vehicle_category_id);
  550. map.insert({cardid,clb});
  551. }
  552. else
  553. {
  554. auto card_id64 = card_list::to_id64(type, static_cast<uint32_t>(id));
  555. auto card_ptr = card_list::instance()->get(card_id64);
  556. if(card_ptr)
  557. {
  558. car* tmp_ptr= static_cast<car*>(card_ptr.get());
  559. tmp_ptr->m_display = static_cast<uint16_t>(need_display);
  560. tmp_ptr->m_deptid = dept_id;
  561. tmp_ptr->m_vehicle_category_id = vehicle_category_id;
  562. tmp_ptr->m_vehicle_type_id = vehicle_type_id;
  563. tmp_ptr->m_level_id = vehicle_level_id;
  564. }
  565. else
  566. {
  567. auto clb = std::make_shared<car>(strategy,id,need_display,card_type_id,dept_id,
  568. vehicle_category_id, vehicle_type_id,vehicle_level_id);
  569. card_list::instance()->add(card_id64, clb);
  570. }
  571. log_info("基础数据 增加或修改车卡成功:卡id:%d,卡type:%d dept_id:%d,need_display:%d,categoryid:%d",
  572. id,type,dept_id,need_display,vehicle_category_id);
  573. std_debug("基础数据 增加或修改车卡成功:卡id:%d,卡type:%d dept_id:%d,need_display:%d,categoryid:%d",
  574. id,type,dept_id,need_display,vehicle_category_id);
  575. }
  576. }
  577. if(-1 == id)
  578. {
  579. log_info( "init_vehicle. The record count=%d\n", nCount );
  580. card_list::instance()->add(map);
  581. }
  582. }
  583. #if 0
  584. void card_list::init_vehicle()
  585. {
  586. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  587. std::string strategy = config.get("car.strategy","car1");
  588. const char *sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
  589. ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
  590. vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
  591. vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
  592. FROM dat_vehicle_extend ve \
  593. LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
  594. LEFT JOIN dat_card c ON ve.card_id = c.card_id \
  595. LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
  596. LEFT JOIN dat_group g ON ve.group_id = g.group_id \
  597. LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
  598. LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
  599. WHERE c.card_type_id = 2 AND c.state_id = 0;";
  600. std::string Error;
  601. YADB::CDBResultSet DBRes;
  602. sDBConnPool.Query(sql,DBRes,Error);
  603. int nCount = DBRes.GetRecordCount( Error );
  604. if (nCount > 0)
  605. {
  606. log_info( "init_vehicle. The record count=%d\n", nCount );
  607. while ( DBRes.GetNextRecod(Error) )
  608. {
  609. unsigned int vehicle_id = 0;
  610. DBRes.GetField( "vehicle_id",vehicle_id, Error );
  611. std::string card_id;
  612. DBRes.GetField( "card_id",card_id, Error );
  613. uint32_t vsid = atoi(card_id.substr(3).c_str());
  614. unsigned int card_type_id = 0;
  615. DBRes.GetField( "card_type_id",card_type_id, Error );
  616. int dept_id = 0;
  617. DBRes.GetField( "dept_id",dept_id, Error );
  618. int group_id = 0;
  619. DBRes.GetField( "group_id",group_id, Error );
  620. int vehicle_type_id = 0;
  621. DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
  622. int vehicle_level_id = 0;
  623. DBRes.GetField( "vehicle_level_id",vehicle_level_id, Error );
  624. int need_display = 0;
  625. DBRes.GetField( "need_display",need_display, Error );
  626. int power_alarm = 0;
  627. DBRes.GetField( "power_alarm",power_alarm, Error );
  628. int vehicle_category_id = 0;
  629. DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
  630. int bigger_car_flag= 0;
  631. DBRes.GetField( "bigger_car_flag",bigger_car_flag, Error );
  632. double over_speed= 0;
  633. DBRes.GetField( "over_speed",over_speed, Error );
  634. //for now
  635. vehicle_id = vsid;
  636. std::shared_ptr<card_location_base> clb = std::make_shared<car>(strategy,vehicle_id,
  637. need_display,card_type_id,dept_id,vehicle_category_id, vehicle_type_id,vehicle_level_id);
  638. uint64_t cardid = getId(vehicle_id,2);
  639. log_info("cardId:%llu,vehicle_id:%d dept_id:%d,need_display:%d---cardid:%s,categoryid:%d",cardid,vehicle_id,dept_id,need_display,card_id.c_str(),vehicle_category_id);
  640. map.insert({cardid,clb});
  641. }
  642. }
  643. card_list::instance()->add(map);
  644. }
  645. void card_list::init_staffer()
  646. {
  647. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  648. std::string strategy = config.get("person.strategy","person1");
  649. const char *sql = "SELECT staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
  650. ol.occupation_level_id,s.worktype_id,s.need_display \
  651. FROM dat_staff_extend s \
  652. LEFT JOIN dat_card c ON s.card_id = c.card_id \
  653. LEFT JOIN dat_occupation o ON s.occupation_id = o.occupation_id \
  654. LEFT JOIN dat_occupation_level ol ON ol.occupation_level_id = o.occupation_level_id \
  655. WHERE c.card_type_id = 1 AND s.duty_id = 0 AND c.state_id = 0;";
  656. std::string Error;
  657. YADB::CDBResultSet DBRes;
  658. sDBConnPool.Query(sql,DBRes,Error);
  659. int nCount = DBRes.GetRecordCount( Error );
  660. if (nCount > 0)
  661. {
  662. log_info( "init_staffer. The record count=%d\n", nCount );
  663. while ( DBRes.GetNextRecod(Error) )
  664. {
  665. unsigned int staff_id = 0;
  666. DBRes.GetField( "staff_id",staff_id, Error );
  667. std::string card_id;
  668. DBRes.GetField( "card_id",card_id, Error );
  669. uint32_t vsid = atoi(card_id.substr(3).c_str());
  670. unsigned int card_type_id = 0;
  671. DBRes.GetField( "card_type_id",card_type_id, Error );
  672. int dept_id = 0;
  673. DBRes.GetField( "dept_id",dept_id, Error );
  674. int group_id = 0;
  675. DBRes.GetField( "group_id",group_id, Error );
  676. int occupation_id = 0;
  677. DBRes.GetField( "occupation_id",occupation_id, Error );
  678. int occupation_level_id = 0;
  679. DBRes.GetField( "occupation_level_id",occupation_level_id, Error );
  680. int need_display = 0;
  681. DBRes.GetField( "need_display",need_display, Error );
  682. //for now;
  683. staff_id = vsid;
  684. std::shared_ptr<card_location_base> clb = std::make_shared<person>(strategy,staff_id,need_display,card_type_id,dept_id,occupation_level_id);
  685. uint64_t cardid = getId(staff_id,1);
  686. log_info("cardId:%llu,staff_id:%d dept_id:%d,need_display:%d--c-ard:%s",cardid,staff_id,dept_id,need_display,card_id.c_str());
  687. map.insert({cardid,clb});
  688. }
  689. }
  690. card_list::instance()->add(map);
  691. }
  692. #endif
  693. void card_list::init_card_from_db()
  694. {
  695. init_staffer(-1);
  696. init_vehicle(-1);
  697. }
  698. void card_list::load_his_card_postion_from_db()
  699. {
  700. load_his_card_postion_vehicle();
  701. load_his_card_postion_staff();
  702. run();
  703. for(auto&iter: m_map)
  704. {
  705. auto card_ptr = iter.second;
  706. auto mine_tool_ptr = card_ptr->get_mine_tool();
  707. if(mine_tool_ptr->is_attendance())
  708. {
  709. auto str = tool_time::to_str_ex( tool_time::to_ms(mine_tool_ptr->m_attendance_start_time));
  710. std_debug("加载考勤,考勤开始时间: %s, 卡id=%d,卡type=%d", str.c_str(), card_ptr->m_id, card_ptr->m_type);
  711. log_info("加载考勤,考勤开始时间: %s, 卡id=%d,卡type=%d", str.c_str(), card_ptr->m_id, card_ptr->m_type);
  712. }
  713. }
  714. auto area_map = area_list::instance()->m_map;
  715. for(auto&iter: area_map)
  716. {
  717. auto area_ptr = iter.second;
  718. if(area_ptr->m_person_count)
  719. {
  720. std_debug("加载区域人数: 区域id=%d,区域人数=%d",area_ptr->m_id, area_ptr->m_person_count.load());
  721. log_info("加载区域人数: 区域id=%d,区域人数=%d",area_ptr->m_id, area_ptr->m_person_count.load());
  722. }
  723. if(area_ptr->m_vehicle_count)
  724. {
  725. std_debug("加载区域车数: 区域id=%d,区域车数=%d",area_ptr->m_id, area_ptr->m_vehicle_count.load());
  726. log_info("加载区域车数: 区域id=%d,区域车数=%d",area_ptr->m_id, area_ptr->m_vehicle_count.load());
  727. }
  728. }
  729. }
  730. void card_list::load_his_card_postion_vehicle()
  731. {
  732. const char *sql = "select l.card_id, l.cur_time, l.x, l.y, l.z, l.map_id, la.area_id, l.state, \
  733. case when l.cur_time >= date_sub(now(), interval 2 minute) then l.speed else 0 end as speed, \
  734. l.mileage, la.enter_time, att.start_time, \
  735. att.end_time, \
  736. l.landmark_id, l.direction_mapper_id, l.landmark_dist \
  737. from rt_location l, rt_location_area la, rt_att_vehicle att, dat_card c, dat_vehicle_extend v \
  738. where l.card_id = c.card_id and l.card_id = la.card_id and l.card_id = att.card_id and l.card_id=v.card_id \
  739. and c.state_id=0;";
  740. std::string Error;
  741. YADB::CDBResultSet DBRes;
  742. sDBConnPool.Query(sql,DBRes,Error);
  743. if(!Error.empty())
  744. log_error("load_his_card_postion_vehicle列表 Error,%s",Error.c_str());
  745. uint64_t nCount = DBRes.GetRecordCount( Error );
  746. if (nCount > 0)
  747. {
  748. log_info( "load_his_card_postion_vehicle. The record count=%ld\n", nCount );
  749. while ( DBRes.GetNextRecod(Error) )
  750. {
  751. std::string card_id = "";
  752. DBRes.GetField( "card_id",card_id, Error );
  753. uint32_t id = tool_other::id64_to_id(card_id);
  754. int type = tool_other::id64_to_type(card_id);
  755. auto temp_ptr = card_list::instance()->get(card_list::to_id64(type, id));
  756. if(!temp_ptr || !temp_ptr->is_vehicle())
  757. {
  758. log_error("全局卡列表中找不到卡,卡id=%d,卡type=%d", id, type);
  759. continue;
  760. }
  761. auto card_ptr = static_cast<car*>(temp_ptr.get());
  762. double x = 0;
  763. DBRes.GetField( "x",x, Error );
  764. double y = 0;
  765. DBRes.GetField( "y",y, Error );
  766. double z = 0;
  767. DBRes.GetField( "z",z, Error );
  768. int map_id = 0;
  769. DBRes.GetField( "map_id",map_id, Error );
  770. int area_id = 0;
  771. DBRes.GetField( "area_id",area_id, Error );
  772. int state = 0;
  773. DBRes.GetField( "state",state, Error );
  774. double speed = 0;
  775. DBRes.GetField( "speed",speed, Error );
  776. std::string enter_time = "";
  777. DBRes.GetField( "enter_time",enter_time, Error );
  778. std::string start_time = "";
  779. DBRes.GetField( "start_time",start_time, Error );
  780. std::string end_time = "";
  781. DBRes.GetField( "end_time",end_time, Error );
  782. int landmark_id = 0;
  783. DBRes.GetField( "landmark_id",landmark_id, Error );
  784. int direction_mapper_id = 0;
  785. DBRes.GetField( "direction_mapper_id",direction_mapper_id, Error );
  786. double landmark_dist = 0;
  787. DBRes.GetField( "landmark_dist",landmark_dist, Error );
  788. card_ptr->x = x;
  789. card_ptr->y = y;
  790. card_ptr->z = z;
  791. auto area = area_list::instance()->get(area_id);
  792. if(area == nullptr)
  793. {
  794. log_error("load_vehicle...area_list 找不到区域:区域id=%d", area_id);
  795. continue;
  796. }
  797. area->m_vehicle_count++;
  798. point pt = *card_ptr;
  799. card_ptr->m_area_tool->m_area_hover = std::make_shared<area_hover>( area, pt,speed);
  800. auto area_hover_ptr = card_ptr->get_area_hover();
  801. auto e_t = tool_time::to_time_ex(enter_time);
  802. area_hover_ptr->m_enter_time = std::chrono::system_clock::to_time_t(e_t);
  803. //int map_id = 0;
  804. //int state = 0;
  805. card_ptr->m_speed = speed;
  806. if(end_time.empty())
  807. {
  808. auto mine_tool_ptr = card_ptr->get_mine_tool();
  809. mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
  810. mine_tool_ptr->m_stat_attendance = AS_ATTENDANCE;
  811. }
  812. area_hover_ptr->landmark_id = landmark_id;
  813. area_hover_ptr->landmark_dir = direction_mapper_id;
  814. area_hover_ptr->landmark_dis = landmark_dist;
  815. card_ptr->m_time = tool_time::now_to_ms();
  816. }
  817. }
  818. }
  819. void card_list::load_his_card_postion_staff()
  820. {
  821. const char *sql = "select l.card_id, l.cur_time, l.x, l.y, l.z, l.map_id, la.area_id, l.state, \
  822. case when l.cur_time >= date_sub(now(), interval 2 minute) then l.speed else 0 end as speed, \
  823. l.mileage, la.enter_time, att.start_time, \
  824. att.end_time, \
  825. l.landmark_id, l.direction_mapper_id, l.landmark_dist \
  826. from rt_location l, rt_location_area la, rt_att_staff att, dat_card c, dat_staff_extend s \
  827. where l.card_id = c.card_id and l.card_id = la.card_id and l.card_id = att.card_id and l.card_id=s.card_id\
  828. and c.state_id=0;";
  829. std::string Error;
  830. YADB::CDBResultSet DBRes;
  831. sDBConnPool.Query(sql,DBRes,Error);
  832. if(!Error.empty())
  833. log_error("load_his_card_postion_vehicle列表 Error,%s",Error.c_str());
  834. uint64_t nCount = DBRes.GetRecordCount( Error );
  835. if (nCount > 0)
  836. {
  837. log_info( "load_his_card_postion_vehicle. The record count=%ld\n", nCount );
  838. while ( DBRes.GetNextRecod(Error) )
  839. {
  840. std::string end_time = "";
  841. DBRes.GetField( "end_time",end_time, Error );
  842. if(!end_time.empty()) // 已升井,不再读入
  843. {
  844. continue;
  845. }
  846. std::string card_id = "";
  847. DBRes.GetField( "card_id",card_id, Error );
  848. uint32_t id = tool_other::id64_to_id(card_id);
  849. int type = tool_other::id64_to_type(card_id);
  850. auto temp_ptr = card_list::instance()->get(card_list::to_id64(type, id));
  851. if(!temp_ptr || !temp_ptr->is_person())
  852. {
  853. log_error("全局卡列表中找不到卡,卡id=%d,卡type=%d", id, type);
  854. continue;
  855. }
  856. auto card_ptr = static_cast<car*>(temp_ptr.get());
  857. double x = 0;
  858. DBRes.GetField( "x",x, Error );
  859. double y = 0;
  860. DBRes.GetField( "y",y, Error );
  861. double z = 0;
  862. DBRes.GetField( "z",z, Error );
  863. int map_id = 0;
  864. DBRes.GetField( "map_id",map_id, Error );
  865. int area_id = 0;
  866. DBRes.GetField( "area_id",area_id, Error );
  867. int state = 0;
  868. DBRes.GetField( "state",state, Error );
  869. double speed = 0;
  870. DBRes.GetField( "speed",speed, Error );
  871. std::string enter_time = "";
  872. DBRes.GetField( "enter_time",enter_time, Error );
  873. std::string start_time = "";
  874. DBRes.GetField( "start_time",start_time, Error );
  875. int landmark_id = 0;
  876. DBRes.GetField( "landmark_id",landmark_id, Error );
  877. int direction_mapper_id = 0;
  878. DBRes.GetField( "direction_mapper_id",direction_mapper_id, Error );
  879. double landmark_dist = 0;
  880. DBRes.GetField( "landmark_dist",landmark_dist, Error );
  881. card_ptr->x = x;
  882. card_ptr->y = y;
  883. card_ptr->z = z;
  884. auto area = area_list::instance()->get(area_id);
  885. if(area == nullptr)
  886. {
  887. log_error("area_list 找不到区域:区域id=%d", area_id);
  888. continue;
  889. }
  890. area->m_person_count++;
  891. point pt = *card_ptr;
  892. card_ptr->m_area_tool->m_area_hover = std::make_shared<area_hover>(area,pt,speed);
  893. auto area_hover_ptr = card_ptr->get_area_hover();
  894. auto e_t = tool_time::to_time_ex(enter_time);
  895. area_hover_ptr->m_enter_time = std::chrono::system_clock::to_time_t(e_t);
  896. log_info("load_staff...%d,areaid:%d,mapid:%d",id,area->id(),area->mapid());
  897. //int map_id = 0;
  898. //int state = 0;
  899. card_ptr->m_speed = speed;
  900. if(end_time.empty())
  901. {
  902. auto mine_tool_ptr = card_ptr->get_mine_tool();
  903. mine_tool_ptr->m_attendance_start_time = tool_time::to_time_ex(start_time);
  904. mine_tool_ptr->m_stat_attendance = AS_ATTENDANCE;
  905. }
  906. area_hover_ptr->landmark_id = landmark_id;
  907. area_hover_ptr->landmark_dir = direction_mapper_id;
  908. area_hover_ptr->landmark_dis = landmark_dist;
  909. card_ptr->m_time = tool_time::now_to_ms();
  910. }
  911. }
  912. }
  913. void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history)
  914. {
  915. //std::shared_ptr<card_location_base>c=get(loc.m_card_id);
  916. uint64_t cardid = getId(loc.m_card_id,loc.m_card_type);
  917. const auto c=get(cardid);
  918. if(c==nullptr)
  919. {
  920. log_warn("数据库中未定义该卡的信息,card_id=%d", loc.m_card_id);
  921. return;
  922. }
  923. log_info("card message:site=%d,ant=%d,card=%d,tof=%lld,rav=%02X,acc=%02X,rssi=%d,stamp=%llu",
  924. loc.m_site_id,loc.m_ant_id,loc.m_card_id,loc.m_tof,loc.m_rav,loc.m_acc,loc.m_rssi,loc.m_time_stamp);
  925. c->on_message(loop,loc,is_history);
  926. }
  927. struct local_visit:visitor<std::shared_ptr<card_location_base>>
  928. {
  929. bool visit(std::shared_ptr<card_location_base> c)
  930. {
  931. c->on_timer();
  932. return true;
  933. }
  934. };
  935. void card_list::onTimer()
  936. {
  937. local_visit lv;
  938. while(!m_bflag)
  939. {
  940. card_list::instance()->accept(lv);
  941. std::this_thread::sleep_for(std::chrono::seconds(1));
  942. }
  943. }
  944. //-----------------card_location_base..
  945. card_location_base::card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t deptid,int32_t level_id)
  946. :card(id,dis,t,deptid,level_id)
  947. {
  948. select_tool_manage::instance()->create_tool(type,m_sel_tool,m_smo_tool);
  949. }
  950. void card_location_base::do_status(STATUS_CARD st)
  951. {
  952. module_mgr::do_status(st, m_id, m_type);
  953. }
  954. void card_location_base::on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm )
  955. {
  956. //ct timestamp;
  957. //m_ct = lm[0].m_card_ct;
  958. //m_time = lm[0].m_loc_time;
  959. loc_point pt = m_sel_tool->select_solution(vp,lm);
  960. pt.y=-pt.y;
  961. if(pt.m_useless)
  962. {
  963. x = pt.x;
  964. y = pt.y;
  965. Msg m;
  966. m.type=m_type;m.x=(int)x;m.y=(int)y;m.cmd=CMD_HANDLE;m.cardid=m_type<<32|m_id;
  967. cardMgr::instance()->tryPut(m);
  968. log_info("useful:card_id:%d,ct:%d,timestamp:%llu, loc_point,x:%.2f,y:%.2f ",m_id,m_ct,m_time,pt.x,pt.y);
  969. do_business(pt);
  970. }
  971. }
  972. void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
  973. {
  974. m_ct = loc.m_card_ct;
  975. m_time = loc.m_time_stamp;
  976. m_message_handle->on_message(loop,loc,is_history);
  977. }
  978. //前端推送位置函数
  979. void card_location_base::upt_card_pos(YA::_CARD_POS_ &cp,const point &pt)
  980. {
  981. cp.x = pt.x;
  982. cp.y = pt.y;
  983. cp.z = pt.z;
  984. cp.Type=m_type;
  985. cp.ID = m_id;
  986. cp.speed = abs(ceil(m_speed));
  987. cp.running_stat = m_stat;
  988. cp.dept_id = m_deptid;
  989. cp.display=m_display;
  990. cp.rec_time=m_time;
  991. cp.level_id = m_level_id;
  992. swsTimerThrd.upt_card_pos(cp);
  993. }
  994. void card_location_base::del_card_pos()
  995. {
  996. YA::_CARD_POS_ cp;
  997. cp.ID = m_id;
  998. cp.Type=m_type;
  999. swsTimerThrd.del_card_pos(cp);
  1000. }
  1001. int card_location_base::get_stat()
  1002. {
  1003. //盲区>呼救>呼叫>超时>超速>正常
  1004. uint64_t now = time(0)*1000;
  1005. if(now-m_time>CARD_LOST_TIME_OUT)
  1006. {
  1007. return STATUS_LOST;
  1008. }
  1009. else if(auto ev_ptr = event_list::instance()->get_event_card(m_id, m_type, ET_CARD_HELP))
  1010. {
  1011. return (ES_DEAL_HELP == ev_ptr->m_status) ? STATUS_HELP_DEALED : STATUS_HELP;
  1012. }
  1013. else if(CALL_NONE != get_mine_tool()->m_status_call)
  1014. {
  1015. return STATUS_CALL;
  1016. }
  1017. else if(event_list::instance()->get_event_card(m_id, m_type,
  1018. is_person()? ET_CARD_AREA_OVER_TIME_PERSON: ET_CARD_AREA_OVER_TIME_VEHICLE))
  1019. {
  1020. return STATUS_AREA_OVER_TIME;
  1021. }
  1022. else if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_OVER_SPEED))
  1023. {
  1024. return STATUS_OVER_SPEED;
  1025. }
  1026. return STATUS_NORMAL;
  1027. }
  1028. void card_location_base::clear()
  1029. {
  1030. // uint16_t m_display; //1显示0不显示,往前端推送
  1031. m_speed=0; //速度
  1032. m_is_attendance=0; //井上井下状态 0初始状态 1 井上 2 井下
  1033. m_stat=0; //运动静止状态
  1034. //m_ct; //ct
  1035. m_time=0; //时间戳
  1036. }
  1037. card_location_base::~card_location_base()
  1038. {
  1039. }
  1040. template<> std::shared_ptr<card_list>
  1041. single_base<card_list, uint64_t, std::shared_ptr<card_location_base>>::m_instance=std::make_shared<card_list>();