card.h 3.8 KB

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