Sfoglia il codice sorgente

fix load_his_event

zhuyf 2 anni fa
parent
commit
0b9666c406
4 ha cambiato i file con 150 aggiunte e 18 eliminazioni
  1. 27 18
      card_car.cpp
  2. 121 0
      event.cpp
  3. 1 0
      event.h
  4. 1 0
      main.cpp

+ 27 - 18
card_car.cpp

@@ -38,6 +38,19 @@ void car::set_area_info(int mapid,double scale,int areaid,uint64_t t,int type)
 	m_area_tool->set_area_info(mapid, scale, areaid, *this, t, type);
 }
 
+/*
+ *	@brief
+ *		车辆业务
+ *	@param
+ *		const std::shared_ptr<site>& site		基站对象
+ *		const point& pt							车辆定位坐标
+ *		double acc								加速度值
+ *	@return
+ *		无
+ *	@note
+ *	@warning
+ *	@bug
+ * */
 void car::do_business(const std::shared_ptr<site>&site,const point &pt,double acc)
 {
 	m_acc=acc;
@@ -75,14 +88,14 @@ void car::handle_over_speed()
 	// 结束:连续10个定位点小于35km认为结束超速告警			
 	m_speeds.push_back(m_speed);
 
-	bool status = true;
 	if(m_speeds.size() < 30){
-		status = false;
-	}else{
-		for(size_t i = 0;i < m_speeds.size();i++){
-			if(m_speed < 35){
-				status = false;
-			}
+		return;
+	}
+
+	bool status = true;
+	for(size_t i = 0;i < m_speeds.size();i++){
+		if(m_speed < 35){
+			status = false;
 		}
 	}
 
@@ -92,19 +105,15 @@ void car::handle_over_speed()
 	}
 
 	status = true;
-	if(m_speeds.size() == 30){
-		for(size_t i = 20;i < m_speeds.size();i++){
-			if(m_speed>35){
-				status = false;
-			}
-		}
-		if(status){
-			// 结束告警
-			event_tool::instance()->handle_event(OT_CARD, ET_CARD_OVER_SPEED, m_id, 0, 0, false);
+	for(size_t i = 20;i < m_speeds.size();i++){
+		if(m_speed>35){
+			status = false;
 		}
 	}
-	
-	
+	if(status){
+		// 结束告警
+		event_tool::instance()->handle_event(OT_CARD, ET_CARD_OVER_SPEED, m_id, 0, 0, false);
+	}	
 }
 
 int car::get_vehicle_type_id()

+ 121 - 0
event.cpp

@@ -361,6 +361,8 @@ void event_list::save_event_v(const std::shared_ptr<ya_event> &ev_ptr)
 		case 100:
 			sprintf(sql, "update his_event_data_v set end_time='%s' where id=%ld;", _time.c_str(), ev_ptr->m_ev_id);
 			break;
+		default:
+			break;
 	}
     
 	db_tool::PushAsync(sql);
@@ -521,6 +523,123 @@ void event_list::load_his_data_from_db(bool init /*=true*/)
     }
 }
 
+/*
+ *	@brief
+ *		加载车辆历史告警表
+ *	@param
+ *		
+ *	@return
+ *		无
+ *	@note
+ *	@warning
+ *	@bug
+ * */
+void event_list::load_his_data_v_from_db()
+{
+    static std::time_t s_last_time=0;
+    if(!init){
+        std::time_t t=time(0);
+        if(t-s_last_time<15)return;
+        s_last_time=t;
+    }
+    
+	std::unordered_map<uint64_t, std::shared_ptr<ya_event>> map;
+    std::string sql("SELECT id, obj_id, event_type_id, x, y, start_time from his_event_data_v where id in (select max(id), obj_id, event_type_id, x, y, start_time from his_event_data_v where end_time is null and start_time > DATE_SUB(NOW(), INTERVAL 1 DAY) GROUP BY obj_id_id, event_type_id);");
+
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    if(!Error.empty())
+        log_error("初始化事件列表 Error,%s",Error.c_str());
+    uint64_t nCount = DBRes.GetRecordCount( Error );
+    if (nCount > 0)
+    {
+        log_info( "init_event_list. The record count=%ld\n", nCount );
+
+        while ( DBRes.GetNextRecod(Error) )
+        {
+            long long int event_id  = 0;
+            DBRes.GetField( "id",event_id, Error );
+
+            long long int id  = 0;
+			id = event_id;
+
+            int event_type_id  = 0;
+            DBRes.GetField( "event_type_id",event_type_id, Error );
+
+            int obj_type_id  = 0;
+
+            std::string obj_id  = "";
+            DBRes.GetField( "obj_id",obj_id, Error );
+
+            int dis_type  = 0;
+
+            int map_id  = 0;
+
+            int area_id  = 0;
+
+            double limit_value = 0;
+
+            double cur_value = 0;
+
+            double x = 0;
+            DBRes.GetField( "x",x, Error );
+
+            double y = 0;
+            DBRes.GetField( "y",y, Error );
+
+            std::string cur_time  = "";
+            DBRes.GetField( "start_time",cur_time, Error );
+
+            int stat  = 0;
+            //增加虚拟告警处理逻辑
+            std::shared_ptr<ya_event> ev=nullptr;
+            bool flag=false;
+            if(!init){
+                ev=event_list::instance()->get(id);
+                if(!ev){
+                    ev = std::make_shared<ya_event>(event_id);
+                }else{
+                    flag=true;
+                    if(stat==100)ev->m_is_sent=false;
+                }
+            }else{
+                ev = std::make_shared<ya_event>(event_id);
+            }
+
+            ev->m_status = static_cast<EVENT_STATUS>(stat);
+            ev->m_ev_type = static_cast<EVENT_TYPE>(event_type_id);
+
+            ev->m_obj_type = static_cast<OBJECT_TYPE>(obj_type_id);
+            ev->m_dis_type = static_cast<EVENT_DIS_TYPE>(dis_type);
+            ev->m_obj_id = obj_id;
+            ev->m_cur_time = tool_time::to_time_ex(cur_time);
+
+            ev->m_cur_value = cur_value;
+            ev->m_limit_value = limit_value;
+
+            ev->m_map_id = map_id;
+            ev->m_area_id = area_id;
+            ev->x = x;
+            ev->y = y;
+            ev->m_id = id;
+            //这里当是卡告警的时候,对m_event数据进行赋值
+            //方便清理
+            //备注防追尾告警和一人多卡告警可能不适用,后续整理
+           
+            if(!flag) 
+                map.insert(std::make_pair(id, ev));
+				log_info("event_list %lld,%lld,%d,%d,%d,%s,%d,%d,%d,%.2f,%.2f,%.2f,%.2f,%s"
+                     , ev->m_ev_id,ev->m_id,ev->m_status,ev->m_ev_type,ev->m_obj_type,ev->m_obj_id.c_str(),ev->m_dis_type
+                     ,ev->m_map_id,ev->m_area_id,ev->m_limit_value,ev->m_cur_value
+                     ,ev->x,ev->y
+                     ,tool_time::to_str_ex(ev->m_cur_time).c_str());
+        }
+        if(!map.empty())
+            event_list::instance()->add(map);
+    }
+}
+
 /*
  *	@brief
  *		事件转为json
@@ -649,6 +768,8 @@ void event_list::_ev_to_node_v(std::shared_ptr<ya_event> ev_ptr,
 		case 100:
 			ev.AddMember("end_time", tool_time::to_ms(ev_ptr->m_cur_time), allocator);
 			break;
+		default:
+			break;
 	}
     
 	out_data.PushBack(ev, allocator);

+ 1 - 0
event.h

@@ -133,6 +133,7 @@ public:
 	static void save_event_v(const std::shared_ptr<ya_event>& event_ptr);
 
     void load_his_data_from_db(bool init=true);
+	void load_his_data_v_from_db();
 
     ~event_list(){}
 

+ 1 - 0
main.cpp

@@ -95,6 +95,7 @@ struct Init_Setting
 		mine_business::inst()->load();
         card_list::instance()->load_his_card_postion_from_db();
         event_list::instance()->load_his_data_from_db(true);
+		event_list::instance()->load_his_data_v_from_db();
         if(three_rates_flag){
             db_para dp;	
             dp.Host     = DBSetting.Host;