|
@@ -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);
|