card.h 3.2 KB

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