area_business.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. 人员推送哪个区域,存储在card_localtion_base上,每次调用前清空,该类只将优先级最高的区域设定给该值即可
  39. */
  40. struct area_business_post_area:area_business
  41. {
  42. virtual int area_business_type()
  43. {
  44. return 1;
  45. }
  46. //记录所在区域
  47. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  48. {
  49. }
  50. //根据超速检测的策略,进行超速判断,超速时进行告警
  51. //建议使用最近M秒内N秒超时进行判断,M=20,N=15,策略数据记录在area_hove中
  52. virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  53. {
  54. }
  55. };
  56. /*
  57. 判断车辆超速,确定超速后记录日志、数据库并告警
  58. 每张卡在每个区域的超速相关的数据信息记录在 area_hover 对象
  59. 人员&车辆的代码重用,请自行设计
  60. */
  61. struct area_business_speed_checker:area_business
  62. {
  63. virtual int area_business_type()
  64. {
  65. return 4;
  66. }
  67. //在area_hover对象中初始化超速检测所需的对象
  68. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  69. {
  70. }
  71. //根据超速检测的策略,进行超速判断,超速时进行告警
  72. //建议使用最近M秒内N秒超时进行判断,M=20,N=15,策略数据记录在area_hove中
  73. virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  74. {
  75. }
  76. //清除超速检测所需的对象
  77. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  78. {
  79. }
  80. };
  81. /*
  82. 禁区
  83. */
  84. struct area_business_restricted:area_business
  85. {
  86. virtual int area_business_type()
  87. {
  88. return 7;
  89. }
  90. //记录进入时间等信息
  91. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  92. {
  93. }
  94. //卡在猴车区域移动
  95. virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  96. {
  97. }
  98. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  99. {
  100. }
  101. };
  102. /*
  103. 猴车区域
  104. */
  105. struct area_business_monkey_area:area_business
  106. {
  107. virtual int area_business_type()
  108. {
  109. return 8;
  110. }
  111. //记录进入时间等信息,开始考勤
  112. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  113. {
  114. }
  115. //记录离开考勤区域信息,结束考勤
  116. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  117. {
  118. }
  119. };
  120. /*
  121. 车辆考勤
  122. */
  123. struct area_business_car_attendance:area_business
  124. {
  125. virtual int area_business_type()
  126. {
  127. return 6;
  128. }
  129. //记录进入时间等信息,开始考勤
  130. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  131. {
  132. }
  133. //记录离开考勤区域信息,结束考勤
  134. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  135. {
  136. }
  137. };
  138. /*
  139. 人员考勤
  140. */
  141. struct area_business_person_attendance:area_business
  142. {
  143. virtual int area_business_type()
  144. {
  145. return 5;
  146. }
  147. //记录进入时间等信息,开始考勤
  148. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  149. {
  150. }
  151. //记录离开考勤区域信息,结束考勤
  152. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  153. {
  154. }
  155. };
  156. /*
  157. 判断当前区域a中的人数是否超过设定人数,超过后告警
  158. 区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
  159. */
  160. struct area_business_count_checker:area_business
  161. {
  162. virtual int area_business_type()
  163. {
  164. return 3;
  165. }
  166. //增加计数,并进行判断
  167. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  168. {
  169. }
  170. //减少计数
  171. virtual void on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
  172. {
  173. }
  174. };
  175. /*
  176. 判断当前区域a中的人卡停留时间
  177. 人员进入区域时间存储在area_hover对象中,在当前类on_enter/on_leave中进行更新
  178. 人员&车辆的代码重用,请自行设计
  179. */
  180. struct area_business_person_dwell_checker:area_business
  181. {
  182. virtual int area_business_type()
  183. {
  184. return 2;
  185. }
  186. //初始化 area_hover 的相关数据项
  187. virtual void on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  188. {
  189. }
  190. //更新 area_hover 的相关数据项,并进行超时判断
  191. virtual void on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>*ptr)
  192. {
  193. }
  194. };
  195. std::vector<std::shared_ptr<area_business>> area_business::get_instance_list(int business_type)
  196. {
  197. return area_business_factory::instance().get_check_list(business_type);
  198. }