card.h 3.8 KB

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