area_business.cpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #include <assert.h>
  2. #include "card_base.h"
  3. #include "area_business.h"
  4. #include "area.h"
  5. #include "card.h"
  6. #include "ya_event.h"
  7. #include "module_service/module_call.h"
  8. /*
  9. 确定推送人员信息时的区域,每一个明确需要推送的区域,都要推送
  10. */
  11. struct area_business_post_area:area_business
  12. {
  13. virtual int area_business_type()
  14. {
  15. return 1;
  16. }
  17. //将推送区域信息加入人员数据
  18. virtual void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  19. virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  20. //从人员数据中清除区域信息
  21. virtual void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  22. };
  23. /*
  24. 判断车辆超速,确定超速后记录日志、数据库并告警
  25. 每张卡在每个区域的超速相关的数据信息记录在 area_hover 对象
  26. 人员&车辆的代码重用,请自行设计
  27. */
  28. struct area_business_speed_checker:area_business
  29. {
  30. struct speed_checker_data:business_data
  31. {
  32. std::vector<double> speed;
  33. };
  34. virtual int area_business_type()
  35. {
  36. return 4;
  37. }
  38. //在ptr对象中初始化超速检测所需的对象
  39. virtual void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  40. //根据超速检测的策略,进行超速判断,超速时进行告警
  41. //建议使用最近M秒内N秒超时进行判断,M=20,N=15,策略数据记录在ptr中..如此:一辆车理想情况下15s才能检测出来。15*4m/s=60mbut.15s内有可能只上来一个超速点。
  42. virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  43. //清除超速检测所需的对象
  44. virtual void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  45. };
  46. /*
  47. 禁区
  48. */
  49. struct area_business_restricted:area_business
  50. {
  51. virtual int area_business_type()
  52. {
  53. return 7;
  54. }
  55. //记录进入时间等信息,生成告警
  56. virtual void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr)
  57. {
  58. #if 0
  59. a->m_enter_point = point(c->x,c->y,c->z);
  60. a->m_last_point.set(0,0,0);
  61. a->m_last_time = 0;
  62. a->m_enter_time = time(nullptr);
  63. event_ptr evPtr = event_list::instance()->get_event_card(c->m_id,c->m_type,ET_CARD_AREA_FORBIDDEN_PERSON);
  64. if (nullptr == evPtr)
  65. {
  66. event_ptr evPtr = event_list::create_event_card(c->m_id, c->m_type, ET_CARD_AREA_FORBIDDEN_PERSON);
  67. event_list::instance()->copy_event(c, evPtr);
  68. event_list::instance()->add(evPtr->get_list_id(), evPtr);
  69. }
  70. evPtr->m_limit_value = 0;
  71. evPtr->m_cur_value = 0;
  72. evPtr->m_is_display = false;
  73. evPtr->m_status = EVENT_STATUS::ES_START ;
  74. evPtr->m_cur_time = std::chrono::system_clock::now();
  75. event_list::save_event(evPtr);
  76. //呼叫
  77. module_call::instance()->system_call_apoint(c->m_id,c->m_type);
  78. #endif
  79. }
  80. virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  81. //记录退出时间等信息
  82. virtual void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr)
  83. {
  84. #if 0
  85. a->m_last_point = point(c->x,c->y,c->z);
  86. a->m_last_time = time(nullptr);
  87. // 发送警告
  88. int oldStatus = -1;
  89. event_ptr evPtr = event_list::instance()->get_event_card(c->m_id,c->m_type,ET_CARD_AREA_FORBIDDEN_PERSON);
  90. if (nullptr == evPtr)
  91. {
  92. event_ptr evPtr = event_list::create_event_card(c->m_id, c->m_type, ET_CARD_AREA_FORBIDDEN_PERSON);
  93. event_list::instance()->copy_event(c, evPtr);
  94. event_list::instance()->add(evPtr->get_list_id(), evPtr);
  95. oldStatus = EVENT_STATUS::ES_END;
  96. } else{
  97. if (evPtr->m_status != EVENT_STATUS::ES_END)
  98. {
  99. oldStatus = EVENT_STATUS::ES_END;
  100. }
  101. }
  102. evPtr->m_limit_value = 0;
  103. evPtr->m_cur_value = 0;
  104. evPtr->m_is_display = false;
  105. evPtr->m_status = EVENT_STATUS::ES_END ;
  106. evPtr->m_cur_time = std::chrono::system_clock::now();
  107. if (oldStatus != -1)
  108. {
  109. event_list::save_event(evPtr);
  110. }
  111. //取消呼叫
  112. module_call::instance()->system_cancel_call_apoint(c->m_id,c->m_type);
  113. #endif
  114. }
  115. };
  116. /*
  117. 猴车区域
  118. */
  119. struct area_business_monkey_area:area_business
  120. {
  121. virtual int area_business_type()
  122. {
  123. return 8;
  124. }
  125. };
  126. /*
  127. 车辆考勤
  128. */
  129. struct area_business_car_attendance:area_business
  130. {
  131. virtual int area_business_type()
  132. {
  133. return 6;
  134. }
  135. //记录进入时间等信息,结束考勤,根据离开的时间和距离,判断是否记录一条新的考勤记录
  136. virtual void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  137. virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  138. //记录离开考勤区域信息,开始考勤
  139. virtual void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  140. };
  141. /*
  142. 人员考勤
  143. */
  144. struct area_business_person_attendance:area_business
  145. {
  146. virtual int area_business_type()
  147. {
  148. return 5;
  149. }
  150. //记录进入时间等信息,开始考勤
  151. virtual void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  152. virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  153. //记录离开考勤区域信息,结束考勤
  154. virtual void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  155. };
  156. /*
  157. 判断当前区域a中的人数是否超过设定人数,超过后告警
  158. 区域内实时人数存储在area对象中,在当前类on_enter/on_leave中进行更新
  159. 整个井下的超员和某个区域的超员都使用这个代码
  160. */
  161. struct area_business_count_checker:area_business
  162. {
  163. virtual int area_business_type()
  164. {
  165. return 3;
  166. }
  167. //增加计数,并进行判断
  168. virtual void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  169. virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  170. //减少计数
  171. virtual void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  172. };
  173. /*
  174. 判断当前区域a中的人卡停留时间
  175. 人员进入区域时间存储在area_hover对象中,在当前类on_enter/on_leave中进行更新
  176. 人员&车辆的代码重用,请自行设计
  177. */
  178. struct area_business_person_dwell_checker:area_business
  179. {
  180. virtual int area_business_type()
  181. {
  182. return 2;
  183. }
  184. //进入区域,记录进入时间
  185. virtual void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  186. //判断是否超时
  187. virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  188. //如果有超时告警,取消超时告警
  189. virtual void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  190. };
  191. struct area_business_card_enter_or_leave:area_business
  192. {
  193. virtual int area_business_type()
  194. {
  195. return 9;
  196. }
  197. //进入区域则入库操作
  198. virtual void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  199. virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  200. //出区域则入库
  201. virtual void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> &ptr){}
  202. };
  203. struct area_business_factory
  204. {
  205. void regist(int type,area_business* ab)
  206. {
  207. if(type>=(int)m_check_list.size())
  208. {
  209. m_check_list.resize(type+1);
  210. }
  211. assert(!m_check_list[type]);
  212. m_check_list[type].reset(ab);
  213. }
  214. std::vector<area_business*> get_check_list(int business_type)
  215. {
  216. std::vector<area_business*> check_list;
  217. for(int i=0;i<32;i++)
  218. {
  219. if(business_type==0)
  220. break;
  221. if((business_type&1)==0)
  222. continue;
  223. check_list.push_back(m_check_list[i].get());
  224. }
  225. return std::move(check_list);
  226. }
  227. static area_business_factory& instance()
  228. {
  229. static area_business_factory _instance;
  230. return _instance;
  231. }
  232. private:
  233. std::vector<std::unique_ptr<area_business>> m_check_list;
  234. area_business_factory()
  235. {
  236. regist(1,new area_business_post_area);
  237. regist(2,new area_business_person_dwell_checker);
  238. regist(3,new area_business_count_checker);
  239. regist(4,new area_business_speed_checker);
  240. regist(5,new area_business_person_attendance);
  241. regist(6,new area_business_car_attendance);
  242. regist(7,new area_business_restricted);
  243. //regist(8,new area_business_monkey_area);
  244. regist(9,new area_business_card_enter_or_leave);
  245. }
  246. };
  247. std::vector<area_business*> area_business::get_instance_list(int business_type)
  248. {
  249. return area_business_factory::instance().get_check_list(business_type);
  250. }