card.h 3.6 KB

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