area_business.cpp 8.8 KB

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