area_business.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #include <assert.h>
  2. #include "card_base.h"
  3. #include "area_business.h"
  4. struct area_business_factory
  5. {
  6. area_business_factory()
  7. {
  8. }
  9. void regist(int type,std::shared_ptr<area_business> ab)
  10. {
  11. if(type>=(int)m_check_list.size())
  12. {
  13. m_check_list.resize(type+1);
  14. }
  15. assert(m_check_list[type]);
  16. m_check_list[type]=ab;
  17. }
  18. std::vector<std::shared_ptr<area_business>> get_check_list(int business_type)
  19. {
  20. std::vector<std::shared_ptr<area_business>> check_list;
  21. for(int i=0,B=1;i<32;i++)
  22. {
  23. if((B&business_type)==0)
  24. continue;
  25. check_list.push_back(m_check_list[i]);
  26. }
  27. return std::move(m_check_list);
  28. }
  29. std::vector<std::shared_ptr<area_business>> m_check_list;
  30. static area_business_factory& instance()
  31. {
  32. static area_business_factory _instance;
  33. return _instance;
  34. }
  35. };
  36. /*
  37. 确定推送人员信息时的区域,每一个明确需要推送的区域,都要推送
  38. */
  39. struct area_business_post_area:area_business
  40. {
  41. virtual int area_business_type()
  42. {
  43. return 1;
  44. }
  45. //将推送区域信息加入人员数据
  46. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  47. {
  48. }
  49. //从人员数据中清除区域信息
  50. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  51. {
  52. }
  53. };
  54. /*
  55. 判断车辆超速,确定超速后记录日志、数据库并告警
  56. 每张卡在每个区域的超速相关的数据信息记录在 area_hover 对象
  57. 人员&车辆的代码重用,请自行设计
  58. */
  59. struct area_business_speed_checker:area_business
  60. {
  61. virtual int area_business_type()
  62. {
  63. return 4;
  64. }
  65. //在ptr对象中初始化超速检测所需的对象
  66. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  67. {
  68. }
  69. //根据超速检测的策略,进行超速判断,超速时进行告警
  70. //建议使用最近M秒内N秒超时进行判断,M=20,N=15,策略数据记录在ptr中
  71. virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  72. {
  73. }
  74. //清除超速检测所需的对象
  75. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  76. {
  77. }
  78. };
  79. /*
  80. 禁区
  81. */
  82. struct area_business_restricted:area_business
  83. {
  84. virtual int area_business_type()
  85. {
  86. return 7;
  87. }
  88. //记录进入时间等信息,生成告警
  89. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> )
  90. {
  91. }
  92. //记录退出时间等信息
  93. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> )
  94. {
  95. }
  96. };
  97. /*
  98. 猴车区域
  99. */
  100. struct area_business_monkey_area:area_business
  101. {
  102. virtual int area_business_type()
  103. {
  104. return 8;
  105. }
  106. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  107. {
  108. }
  109. virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  110. {
  111. }
  112. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  113. {
  114. }
  115. };
  116. /*
  117. 车辆考勤
  118. */
  119. struct area_business_car_attendance:area_business
  120. {
  121. virtual int area_business_type()
  122. {
  123. return 6;
  124. }
  125. //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
  126. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  127. {
  128. }
  129. //记录离开考勤区域信息,开始考勤
  130. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  131. {
  132. }
  133. };
  134. /*
  135. 人员考勤
  136. */
  137. struct area_business_person_attendance:area_business
  138. {
  139. virtual int area_business_type()
  140. {
  141. return 5;
  142. }
  143. //记录进入时间等信息,开始考勤
  144. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  145. {
  146. }
  147. //记录离开考勤区域信息,结束考勤
  148. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  149. {
  150. }
  151. };
  152. /*
  153. 判断当前区域a中的人数是否超过设定人数,超过后告警
  154. 区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
  155. 整个井下的超员和某个区域的超员都使用这个代码
  156. */
  157. struct area_business_count_checker:area_business
  158. {
  159. virtual int area_business_type()
  160. {
  161. return 3;
  162. }
  163. //增加计数,并进行判断
  164. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  165. {
  166. }
  167. //减少计数
  168. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  169. {
  170. }
  171. };
  172. /*
  173. 判断当前区域a中的人卡停留时间
  174. 人员进入区域时间存储在area_hover对象中,在当前类on_enter/on_leave中进行更新
  175. 人员&车辆的代码重用,请自行设计
  176. */
  177. struct area_business_person_dwell_checker:area_business
  178. {
  179. virtual int area_business_type()
  180. {
  181. return 2;
  182. }
  183. //初始化 ptr 的相关数据项
  184. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  185. {
  186. }
  187. //更新 ptr 的相关数据项,并进行超时判断
  188. virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  189. {
  190. }
  191. };
  192. std::vector<std::shared_ptr<area_business>> area_business::get_instance_list(int business_type)
  193. {
  194. return area_business_factory::instance().get_check_list(business_type);
  195. }