Ver código fonte

增加地标和地质断层更新代码,修正升级后loction_card未初始化情况

liulei 5 anos atrás
pai
commit
77c92731ed

+ 1 - 1
card_base.cpp

@@ -127,7 +127,7 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 	{
         log_info("%d被井上分站[%d]收到",m_id,site_ptr->id());
 		area_tool->on_point(shared_from_this(),point(1,1));
-
+		m_his_location_card->deal_up_well();
 		this->site_hover(loc.m_site_id);
 	}
 	else

+ 13 - 0
his_location.cpp

@@ -306,3 +306,16 @@ bool location_card::handle_path(std::vector<point> &rc,uint64_t timestamp,bool f
     }
     return false;
 }
+
+void location_card::deal_up_well()
+{
+	//更新location
+	if (m_d.size()>0)
+	{
+		last_timestamp = 0;
+		update(m_d.back().p, m_d.back().time);
+	}
+	
+	//重置参数
+	init();
+}

+ 2 - 0
his_location.h

@@ -66,5 +66,7 @@ struct location_card
 	bool  handle_message(const point &p,uint64_t timestamp);
     // 处理获取到点的集合,在路径上
     bool handle_path(std::vector<point> &rc,uint64_t timestamp,bool flag);
+	//升井后处理
+	void deal_up_well();
 };
 #endif

+ 59 - 6
landmark.cpp

@@ -40,13 +40,22 @@ void Landmark_list::init_from_db()
 	init_mapDirection();
 }
 
-void Landmark_list::init_landmarkInfo()
+void Landmark_list::init_landmarkInfo(int id/*=-1*/)
 {
-	const char * sql = "select landmark_id, name, map_id, area_id, x, y, z from dat_landmark;";
+	std::string sql = "select landmark_id, name, map_id, area_id, x, y, z from dat_landmark";
+	if (-1 == id)
+	{
+		sql += ";";
+	}
+	else
+	{
+		sql += " WHERE landmark_id=" + std::to_string(id) +";";
+	}
 	std::string Error;
 	YADB::CDBResultSet DBRes;
-	sDBConnPool.Query(sql,DBRes,Error);
+	sDBConnPool.Query(sql.c_str(),DBRes,Error);
 	int nCount = DBRes.GetRecordCount( Error );
+	std::lock_guard<std::mutex> lock(m_mutex);
 	if (nCount > 0)
 	{
 		log_info( "init_landmark_info. The record count=%d\n", nCount );
@@ -74,19 +83,63 @@ void Landmark_list::init_landmarkInfo()
 			double z = 0;
 			DBRes.GetField( "z",z, Error );
 			point p(x,y,z);
-			std::shared_ptr<LandmarkInfo> landmark = std::make_shared<LandmarkInfo>(p,landmark_id,name,map_id,area_id);
-			m_v.push_back(landmark);
-			log_info("landmark ......id:%d,name:%s,mapid:%d,area_id:%d,x:%.2f,y:%.2f,z:%.2f",landmark_id,name.c_str(),map_id,area_id,x,y,z);
+			std::shared_ptr<LandmarkInfo> landmark = std::make_shared<LandmarkInfo>(p, landmark_id, name, map_id, area_id);
+			if (-1 == id)
+			{				
+				m_v.push_back(landmark);
+				log_info("landmark ......id:%d,name:%s,mapid:%d,area_id:%d,x:%.2f,y:%.2f,z:%.2f", landmark_id, name.c_str(), map_id, area_id, x, y, z);
+			}
+			else
+			{
+				bool befind = false;
+				for (size_t i = 0; i < m_v.size(); i++)
+				{
+					if (m_v[i]->landmark_id==id)
+					{
+						m_v[i]->set(p);
+						m_v[i]->landmark_id = landmark_id;
+						m_v[i]->landmark_name = name;
+						m_v[i]->map_id = map_id;
+						m_v[i]->area_id = area_id;
+						befind = true;
+						log_info("update landmark ......id:%d,name:%s,mapid:%d,area_id:%d,x:%.2f,y:%.2f,z:%.2f", landmark_id, name.c_str(), map_id, area_id, x, y, z);
+						break;
+					}
+				}
+				if (!befind)
+				{
+					log_info("add landmark ......id:%d,name:%s,mapid:%d,area_id:%d,x:%.2f,y:%.2f,z:%.2f", landmark_id, name.c_str(), map_id, area_id, x, y, z);
+					m_v.push_back(landmark);
+				}
+				break;
+			}
 		}
 	}
 
 }
 
+void Landmark_list::remove_landmarkInfo(int id)
+{
+	std::lock_guard<std::mutex> lock(m_mutex);
+	std::vector<std::shared_ptr<LandmarkInfo>>::iterator it_s = m_v.begin();
+	while (it_s!= m_v.end())
+	{
+		if ((*it_s)->landmark_id == id)
+		{
+			m_v.erase(it_s);
+			log_info("delete landmark ......id:%d,name:%s", (*it_s)->landmark_id, (*it_s)->landmark_name);
+			break;
+		}
+		it_s++;
+	}
+}
+
 std::tuple<int,int,double> Landmark_list::get(int mapid ,int areaid,const point &pt)
 {
 	int32_t id = -1;
 	double dis = DBL_MAX;
 	point p;
+	std::lock_guard<std::mutex> lock(m_mutex);
 	for(const auto &lm : m_v)	
 	{
 		if(lm->area_id == areaid)

+ 4 - 1
landmark.h

@@ -2,6 +2,7 @@
 #define __LAND_MARK_HPP__
 #include <string>
 #include <vector>
+#include <mutex>
 #include <map>
 #include <memory>
 #include <tuple>
@@ -48,11 +49,13 @@ struct Landmark_list
 	std::map<int,std::shared_ptr<map_direction>> m_map;
 	static Landmark_list * instance();
 	void init_from_db();
-	void init_landmarkInfo();
+	void init_landmarkInfo(int id = -1);
+	void remove_landmarkInfo(int id);
 	void init_mapDirection();
 	//landmarkId landmark_direction  landmark_dis
 	std::tuple<int,int,double> get(int mapid,int areaid,const point &pt);
 	DIRECTION_TYPE GetDirectionType(point card_point, point landmark_point, int map_id);
+	std::mutex m_mutex;
 };
 #endif
 

+ 25 - 0
module_service/module_meta_date_changed.cpp

@@ -11,6 +11,8 @@
 #include"card.h"
 #include"area.h"
 #include "forbid_staff_down_mine.h"
+#include "landmark.h"
+#include"area_business_geofault.h"
 #include <boost/format.hpp>
 #include <boost/tokenizer.hpp>
 #include <boost/algorithm/string/split.hpp>
@@ -95,6 +97,14 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
         {
             deal_call_edit_forbid_person_down_mine(szParam,edit_type_id);
         }
+		else if (JSON_KEY_NAME_GEO_FAULT == name)//地址断层更新
+		{
+			area_business_geofault::init_geofault_from_db();
+		}
+		else if (JSON_KEY_NAME_LANDMARK == name)//地标信息更新
+		{
+			deal_call_edit_landmark(szParam, edit_type_id);
+		}
         else
         {
             log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
@@ -307,6 +317,21 @@ void module_meta_date_changed::deal_call_edit_forbid_person_down_mine(const std:
     }
 }
 
+// 修改地标信息
+void module_meta_date_changed::deal_call_edit_landmark(const std::string & landmarkid, EDIT_TYPE_ID edit_type_id)
+{
+	int id = atoi(landmarkid.c_str());
+
+	if (ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+	{
+		Landmark_list::instance()->init_landmarkInfo(id);
+	}
+	else if (ET_DELETE == edit_type_id)
+	{
+		Landmark_list::instance()->remove_landmarkInfo(id);
+	}
+}
+
 void module_meta_date_changed::init_setting()
 {
     //pRes = getMysqlRes("select setting_id, name, type, value from dat_setting;");

+ 2 - 0
module_service/module_meta_date_changed.h

@@ -71,6 +71,8 @@ private:
 
     // 禁止指定人员下井
     void deal_call_edit_forbid_person_down_mine(const std::string & lszId,EDIT_TYPE_ID edit_type_id);
+	//地标
+	void deal_call_edit_landmark(const std::string & landmarkid, EDIT_TYPE_ID edit_type_id);
 
     ///待实现
     void init_setting();

+ 3 - 0
websocket/constdef.h

@@ -71,6 +71,9 @@
 #define JSON_KEY_NAME_DRIVINGFACE "drivingface_vehicle"
 #define JSON_KEY_NAME_DRIVINGFACE_WARNING_POINT "dat_drivingface_warning_point"
 #define JSON_KEY_NAME_HAND_UP "dat_handup_vehicle"
+
+#define JSON_KEY_NAME_GEO_FAULT "geofault"
+#define JSON_KEY_NAME_LANDMARK "landmark"
 //禁止指定人员下井
 #define JSON_KEY_NAME_FORBID_PERSON_DOWN_MINE "rt_person_forbid_down_mine"