card.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef _CARD_HPP_
  2. #define _CARD_HPP_
  3. #include <message.h>
  4. #include <ev++.h>
  5. #include "point.h"
  6. #include "write-copy.h"
  7. #include "websocket/ws_common.h"
  8. #include "common.h"
  9. #include "area.h"
  10. #include "site_area.h"
  11. #include "loc_message.h"
  12. #include "thread"
  13. #define CARD_LOST_TIME_OUT (30*1000)
  14. struct task;
  15. template<typename T> struct zloop;
  16. struct select_tool;
  17. struct smooth_tool;
  18. struct monkey_person;
  19. struct card_message_handle;
  20. struct mine_tool;
  21. struct card:point
  22. {
  23. card(uint32_t id,uint16_t dis,uint64_t type,int32_t deptid,int32_t level_id)
  24. :m_id(id)
  25. ,m_type(type)
  26. ,m_display(dis)
  27. ,m_speed(0)
  28. ,m_is_attendance(0)
  29. ,m_stat(0)
  30. ,m_ct(0)
  31. ,m_time(0)
  32. ,m_deptid(deptid)
  33. ,m_level_id(level_id)
  34. {}
  35. uint64_t type_(){return m_type;}
  36. uint64_t time_(){return m_time;}
  37. uint32_t m_id; //卡号
  38. uint64_t m_type; //类型
  39. uint16_t m_display; //1显示0不显示,往前端推送
  40. double m_speed; //速度
  41. int m_is_attendance; //井上井下状态 0初始状态 1 井上 2 井下
  42. int m_stat; //运动静止状态
  43. uint16_t m_ct; //ct
  44. ///时间戳 ms
  45. uint64_t m_time;
  46. int32_t m_deptid; //部门编号
  47. int32_t m_level_id; //部门级别
  48. };
  49. struct card_location_base:card
  50. {
  51. std::unique_ptr<select_tool> m_sel_tool;
  52. std::unique_ptr<smooth_tool> m_smo_tool;
  53. card_message_handle *m_message_handle=nullptr;
  54. // ev::dynamic_loop * m_loop = nullptr;
  55. // ev::timer m_timer;
  56. card_location_base()=default;
  57. card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t,int32_t );
  58. virtual void do_business(const point &pt)=0;
  59. // virtual void set(ev::dynamic_loop * loop)=0;
  60. virtual void on_timer()=0;
  61. virtual void site_hover(int sid)=0;
  62. virtual std::shared_ptr<area_hover> get_area_hover()=0;
  63. virtual std::shared_ptr<mine_tool> get_mine_tool()=0;
  64. virtual std::shared_ptr<site_area_hover> get_site_area()=0;
  65. virtual void clear();
  66. virtual void reset(std::shared_ptr<monkey_person> mp){}
  67. virtual int get_vehicle_type_id(){return 0;}
  68. void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history);
  69. void on_location(const std::vector<point>&vp,const std::vector<loc_message> &lm );
  70. void do_status(STATUS_CARD st);
  71. void upt_card_pos(YA::_CARD_POS_ &,const point &pt);
  72. void del_card_pos();
  73. int get_stat();
  74. bool is_person() const
  75. {
  76. return CT_PERSON == m_type;
  77. }
  78. bool is_vehicle() const
  79. {
  80. return CT_VEHICLE == m_type;
  81. }
  82. virtual ~card_location_base();
  83. };
  84. struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_base>>
  85. {
  86. void init_staffer();
  87. void init_vehicle();
  88. uint64_t getId(uint32_t cardid,uint64_t);
  89. void on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history);
  90. void init_card_from_db();
  91. void load_his_card_postion_vehicle();
  92. void load_his_card_postion_staff();
  93. void load_his_card_postion_from_db();
  94. std::unique_ptr<std::thread> m_pThread;
  95. bool m_bflag=false;
  96. void run()
  97. {
  98. m_pThread.reset(new std::thread(std::bind(&card_list::onTimer,this)));
  99. }
  100. void onTimer();
  101. /// (类型<<32)|卡号
  102. //公用函数最好不要使用成员函数,改成公共函数。
  103. static uint64_t to_id64(int32_t type, uint32_t id)
  104. {
  105. return (static_cast<uint64_t>(type)<<32)|id;
  106. }
  107. static std::string to_id64_str(int32_t type, uint32_t id)
  108. {
  109. char sql[15] = {'\0'};
  110. sprintf(sql, "%03d%010d", type, id);
  111. return std::string(sql);
  112. }
  113. ~card_list(){m_bflag=true;}
  114. };
  115. #endif