Browse Source

Merge branch 'master' of http://local.beijingyongan.com:3000/linux-dev/ya-serv

liulei 6 years ago
parent
commit
c65fa4c62e

+ 1 - 0
.gitignore

@@ -23,5 +23,6 @@ CMakeFiles/
 .idea/
 .git/
 .vscode/
+Makefile
 
 

+ 12 - 0
area_business.cpp

@@ -10,6 +10,11 @@
 #include "area_business_person_attendance.h"
 #include "area_business_post_area.h"
 #include "area_business_speed_checker.h"
+#include"area_business_motionless_persion.h"
+#include"area_business_geofault.h"
+#include"area_business_work_rate.h"
+
+
 
 struct area_business_factory
 {
@@ -34,7 +39,10 @@ struct area_business_factory
 				break;
 
 			if((business_type&1)==0)
+            {
+                business_type >>= 1;
 				continue;
+            }
 
 			business_type >>= 1;
 
@@ -62,6 +70,10 @@ private:
 		regist(7,new area_business_forbid);
 		//regist(8,new area_business_monkey_area);
 		regist(9,new area_business_card_enter_or_leave);
+
+        regist(10, new area_business_motionless_persion);
+        regist(11, new area_business_geofault);
+        regist(12, new area_business_work_rate);
 	}
 
 };

+ 8 - 2
module_service/area_business_card_enter_or_leave.cpp

@@ -48,16 +48,19 @@ void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hove
 
 ///入库
 void area_business_card_enter_or_leave::save_his_area_location_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
-                                                                     const std::shared_ptr<card_location_base> card_ptr,
+                                                                     const std::shared_ptr<card_location_base>&card_ptr,
                                                                      uint64_t start_time_ms)
 {
     char sql[LENGTH_SQL] = {0};
 
+    std::string call(card_ptr->is_vehicle()?"add_area_vehicle":"add_area_staff");
+#if 0
     std::string call("add_area_staff");
     if(card_ptr->is_vehicle())//车卡
     {
         call="add_area_vehicle";
     }
+#endif
 
     std::string start_str = tool_time::to_str_ex(start_time_ms);
 
@@ -70,16 +73,19 @@ void area_business_card_enter_or_leave::save_his_area_location_enter(const std::
 
 ///入库
 void area_business_card_enter_or_leave::save_his_area_location_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
-                                                                     const std::shared_ptr<card_location_base> card_ptr,
+                                                                     const std::shared_ptr<card_location_base>&card_ptr,
                                                                      uint64_t start_time_ms)
 {
     char sql[LENGTH_SQL] = {0};
 
+    std::string call(card_ptr->is_vehicle()?"add_area_vehicle":"add_area_staff");
+#if 0
     std::string call("add_area_staff");
     if(card_ptr->is_vehicle())//车卡
     {
         call="add_area_vehicle";
     }
+#endif
 
     std::string start_str = tool_time::to_str_ex(start_time_ms);
     std::string end_str = tool_time::to_str_ex(tool_time::now_to_ms());

+ 2 - 2
module_service/area_business_card_enter_or_leave.h

@@ -18,12 +18,12 @@ struct area_business_card_enter_or_leave:area_business
 
     ///入库
     static void save_his_area_location_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
-                                             const std::shared_ptr<card_location_base> card_ptr,
+                                             const std::shared_ptr<card_location_base>&card_ptr,
                                              uint64_t start_time_ms);
 
     ///入库
     static void save_his_area_location_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
-                                             const std::shared_ptr<card_location_base> card_ptr,
+                                             const std::shared_ptr<card_location_base>&card_ptr,
                                              uint64_t start_time_ms);
 };
 

+ 1 - 1
module_service/area_business_geofault.h

@@ -23,7 +23,7 @@ class area_business_geofault:public area_business
 public:
     int area_business_type()
     {
-        return 10;
+        return 11;
     }
 
     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 - 16
module_service/area_business_motionless_persion.cpp

@@ -8,22 +8,36 @@
 #include"tool_time.h"
 #include"area_business.h"
 #include"card.h"
+#include"config_file.h"
 
 
 struct motionless_data:business_data
 {
     motionless_data()
+		:m_acc_0count(0)
+		,m_warn_flag(false)
     {
-        m_acc_0count=0;
+//        m_acc_0count=0;
 //        m_acc_start_time=0;
     }
 
-    ///;检测到多少次之后定位完全静止
-    std::atomic<int> m_acc_0count;
+
+   ///;检测到多少次之后定位完全静止
+ //   std::atomic<int> m_acc_0count;
 //    ///检测到多久之后告警
 //    time_t m_acc_start_time;
+
+	int m_acc_0count; //连续静止数量
+	bool m_warn_flag;  //告警推送标志
 };
 
+void area_business_motionless_persion::init(config_file& config)
+{
+	//       sleep_ms = std::stoi(config.get("service.motionless_thread_sleep_ms","5000"));
+	_acc_0count_limit = std::stoi(config.get("service.motionless_acc_0count_limit","40"));
+	//        _acc_seconds_limit = std::stoi(config.get("service.motionless_acc_seconds_limit","120"));
+}
+
 void area_business_motionless_persion::on_enter(const std::shared_ptr<area_hover>&a,
                                  const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>&ptr)
 {
@@ -35,34 +49,44 @@ void area_business_motionless_persion::on_hover(const std::shared_ptr<area_hover
                                          const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
 {
     auto ptr_temp = static_cast<motionless_data*>(ptr.get());
+
+	bool do_send=false;//是否需要发送
+
     if(0 == static_cast<int>(card_ptr->m_acc))
     {
-        ptr_temp->m_acc_0count++;
+        if((do_send = ++ptr_temp->m_acc_0count >= _acc_0count_limit && !ptr_temp->m_warn_flag))		//检测计数 && 是否已经发送,已经发送的话,就不发了
+		{
+			ptr_temp->m_warn_flag=true;	//如果确定发送的话,更新数据状态
+		}
     }
     else
     {
         ptr_temp->m_acc_0count=0;
+		if((do_send=ptr_temp->m_warn_flag))//如果正在告警,则取消告警
+		{
+			ptr_temp->m_warn_flag=false;
+		}
     }
 
-    if(ptr_temp->m_acc_0count >= _acc_0count_limit)
-    {
-        ptr_temp->m_acc_0count = _acc_0count_limit;
-    }
-
-    bool is_alarm = ptr_temp->m_acc_0count >= _acc_0count_limit;
-
-    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-    event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, is_alarm);
+	if(do_send)//需要发送
+	{
+		uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+		event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, ptr_temp->m_warn_flag);
+	}
 }
 
 void area_business_motionless_persion::on_leave(const std::shared_ptr<area_hover>&area_hover_ptr,
                                          const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
 {
-    uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
-    event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, false);
+    auto ptr_temp = static_cast<motionless_data*>(ptr.get());
+	if(ptr_temp->m_warn_flag)//如果正在告警,则发送取消告警的信息
+	{
+		uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
+		event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, false);
+	}
 }
 
-int area_business_motionless_persion::_acc_0count_limit;
+int area_business_motionless_persion::_acc_0count_limit=20;
 
 //void module_motionless_persion::deal_alarm(std::shared_ptr<card_location_base>& card_ptr)
 //{

+ 3 - 8
module_service/area_business_motionless_persion.h

@@ -11,8 +11,8 @@
 //#include"module_i_thread.h"
 //#include"card.h"
 #include"area_business.h"
-#include"config_file.h"
 
+struct config_file;
 /**
  * @brief 一、硬件输出的状态
 当完全静止时人卡会连续发送 30 次定位数据,在该定位数据中的加速度状态为 0;发送
@@ -43,15 +43,10 @@ private:
 public:
     int area_business_type()
     {
-        return 5;
+        return 10;
     }
+	static void init(config_file& config);
 
-    static void init(config_file& config)
-    {
- //       sleep_ms = std::stoi(config.get("service.motionless_thread_sleep_ms","5000"));
-        _acc_0count_limit = std::stoi(config.get("service.motionless_acc_0count_limit","40"));
-//        _acc_seconds_limit = std::stoi(config.get("service.motionless_acc_seconds_limit","120"));
-    }
 
     void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);
     void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);

+ 1 - 1
module_service/area_business_work_rate.h

@@ -11,7 +11,7 @@ class area_business_work_rate:public area_business
 public:
     int area_business_type()
     {
-        return 13;
+        return 12;
     }
 
     void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr);