daiyueteng il y a 6 ans
Parent
commit
83da6a2d66
3 fichiers modifiés avec 81 ajouts et 34 suppressions
  1. 17 0
      common_tool.h
  2. 58 14
      module_service/area_business_geofault.cpp
  3. 6 20
      module_service/area_business_geofault.h

+ 17 - 0
common_tool.h

@@ -87,6 +87,23 @@ public:
 	{
 		return type_id_to_u64(card_id_to_type(cardid),card_id_to_id(cardid));
 	}
+
+    ///采煤机
+    static bool is_coal(int32_t type)
+    {
+        return CT_COAL_CUTTER == type;
+    }
+
+    /// 掘进机
+    static bool is_driving(int32_t type)
+    {
+        return CT_HEADING_MACHINE == type;
+    }
+
+    static bool is_coal_or_driving(int32_t type)
+    {
+        return CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
+    }
 };
 
 class tool_map

+ 58 - 14
module_service/area_business_geofault.cpp

@@ -10,6 +10,9 @@
 #include"common_tool.h"
 #include"log.h"
 #include"card.h"
+#include"config_file.h"
+#include"point.h"
+#include"area.h"
 
 struct geofault_data:business_data
 {
@@ -17,18 +20,25 @@ struct geofault_data:business_data
     {
         m_near_geofault_count=0;
         m_far_geofault_count=0;
+        m_is_warning=false;
     }
 
     int m_near_geofault_count;
     int m_far_geofault_count;
+    bool m_is_warning;
 };
 
 std::unordered_map<int, std::vector<point>> area_business_geofault::_area_geofault_map;
 int area_business_geofault::_geofault_count_limit;
 
 void area_business_geofault::on_enter(const std::shared_ptr<area_hover>&area_hover_ptr,
-                                                       const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>& ptr)
+                                      const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data>& ptr)
 {
+    if(!tool_other::is_coal_or_driving(card_ptr->m_type))
+    {
+        return;
+    }
+
     auto ptr_temp = std::make_shared<geofault_data>();
     ptr = ptr_temp;
 
@@ -37,20 +47,34 @@ void area_business_geofault::on_enter(const std::shared_ptr<area_hover>&area_hov
     {
         ptr_temp->m_near_geofault_count++;
     }
+    else
+    {
+        ptr_temp->m_far_geofault_count++;
+    }
+
+    auto ev_ptr_temp = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_VEHICLE_NEAR_GEOFAULT);
+    ptr_temp->m_is_warning = (nullptr != ev_ptr_temp && !ev_ptr_temp->is_end());
 }
 
 void area_business_geofault::on_hover(const std::shared_ptr<area_hover>&area_hover_ptr,
                                       const std::shared_ptr<card_location_base>&card_ptr,std::shared_ptr<business_data> ptr)
 {
+    if(!tool_other::is_coal_or_driving(card_ptr->m_type))
+    {
+        return;
+    }
+
     auto ptr_temp = static_cast<geofault_data*>(ptr.get());
 
     double dist=0;
     if(_is_near(area_hover_ptr->m_area, card_ptr->x, card_ptr->y, dist))
     {
+        ptr_temp->m_far_geofault_count=0;
         ptr_temp->m_near_geofault_count++;
     }
     else
     {
+        ptr_temp->m_near_geofault_count=0;
         ptr_temp->m_far_geofault_count++;
     }
 
@@ -59,14 +83,13 @@ void area_business_geofault::on_hover(const std::shared_ptr<area_hover>&area_hov
     {
         ptr_temp->m_near_geofault_count=_geofault_count_limit;
 
-        auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_VEHICLE_NEAR_GEOFAULT);
-        if(!ev_ptr)//从没有告警状态转化为告警状态
+        if(!ptr_temp->m_is_warning)
         {
-            ptr_temp->m_far_geofault_count=0;
+            ptr_temp->m_is_warning = true;
+            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_VEHICLE_NEAR_GEOFAULT, id,
+                                                 CYaSetting::m_sys_setting.geofault_warn_dis, dist, true);
         }
-
-        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_VEHICLE_NEAR_GEOFAULT, id, CYaSetting::m_sys_setting.geofault_warn_dis, dist, true);
     }
 
     //确定正常
@@ -74,25 +97,46 @@ void area_business_geofault::on_hover(const std::shared_ptr<area_hover>&area_hov
     {
         ptr_temp->m_far_geofault_count=_geofault_count_limit;
 
-        auto ev_ptr = event_list::instance()->get_event_card(card_ptr->m_id, card_ptr->m_type, ET_VEHICLE_NEAR_GEOFAULT);
-        if(ev_ptr && !ev_ptr->is_end())
+        if(ptr_temp->m_is_warning)
         {
-            ptr_temp->m_near_geofault_count=0;
+            ptr_temp->m_is_warning = false;
 
             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_VEHICLE_NEAR_GEOFAULT, id, CYaSetting::m_sys_setting.geofault_warn_dis, dist, false);
+            event_tool::instance()->handle_event(OT_CARD, ET_VEHICLE_NEAR_GEOFAULT, id,
+                                                 CYaSetting::m_sys_setting.geofault_warn_dis, dist, false);
         }
     }
 }
 
-
 void area_business_geofault::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)
 {
+    if(!tool_other::is_coal_or_driving(card_ptr->m_type))
+    {
+        return;
+    }
+
     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_VEHICLE_NEAR_GEOFAULT, id, CYaSetting::m_sys_setting.geofault_warn_dis, 1000, false);
 }
 
+void area_business_geofault::init(config_file& config)
+{
+    _geofault_count_limit = std::stoi(config.get("service.geofault_count_limit","10"));
+}
+
+std::string area_business_geofault::_points2str(std::vector<point>& points)
+{
+    std::string str;
+    for(auto&p : points)
+    {
+        char ch[64] = {0};
+        sprintf(ch, "x=%f,y=%f;", p.x, p.y);
+        str.append(ch);
+    }
+
+    return str;
+}
 
 void area_business_geofault::init_geofault_from_db()
 {
@@ -148,8 +192,8 @@ void area_business_geofault::init_geofault_from_db()
     for(const auto &p : _area_geofault_map)
     {
         auto kk = p.second;
-        std_debug("init_geofault_from_db:area_id:%d--points: %s",p.first, points2str(kk).c_str());
-        log_info("init_geofault_from_db:area_id:%d--points: %s",p.first, points2str(kk).c_str());
+        std_debug("init_geofault_from_db:area_id:%d--points: %s",p.first, _points2str(kk).c_str());
+        log_info("init_geofault_from_db:area_id:%d--points: %s",p.first, _points2str(kk).c_str());
     }
 }
 

+ 6 - 20
module_service/area_business_geofault.h

@@ -7,13 +7,13 @@
  * @date 2019-01-15
  */
 
-#include<area_business.h>
+#include"area_business.h"
 #include <unordered_map>
 #include<vector>
-#include<area.h>
-#include<point.h>
 
-#include"config_file.h"
+struct config_file;
+struct point;
+struct area;
 
 /**
  * @brief 当采煤机和掘进机有数据点过来的时候,判断当前点与地址断层坐标点的距离d。如d<设置的阈值,则告警,d>阈值则取消。
@@ -30,10 +30,7 @@ public:
     void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
     void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
 
-    static void init(config_file& config)
-    {
-        _geofault_count_limit = std::stoi(config.get("service.geofault_count_limit","10"));
-    }
+    static void init(config_file& config);
 
     static void init_geofault_from_db();
 
@@ -69,18 +66,7 @@ private:
         return arr;
     }
 
-    static std::string points2str(std::vector<point>& points)
-    {
-        std::string str;
-        for(auto&p : points)
-        {
-            char ch[64] = {0};
-            sprintf(ch, "x=%f,y=%f;", p.x, p.y);
-            str.append(ch);
-        }
-
-        return str;
-    }
+    static std::string _points2str(std::vector<point>& points);
 
 private:
     //area_id: points