Browse Source

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

chensongchao 5 years ago
parent
commit
38216c9b03

+ 1 - 1
area.cpp

@@ -900,7 +900,7 @@ void area_tool::set_area_info(int mapid,double scale,int areaid,const point &pt,
 
 void area_tool::set_area_info(int mapid,int areaid,const point &pt,uint64_t t)
 {
-	auto lm = Landmark_list::instance()->get(mapid,areaid,pt);
+	auto lm = Landmark_list::instance()->get_landmark(mapid,areaid,pt);
 	int landmark_id = std::get<0>(lm);
 	int landmark_dir = std::get<1>(lm);
 	double landmark_dis = std::get<2>(lm)*m_scale;

+ 0 - 1
card_base.cpp

@@ -128,7 +128,6 @@ 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));
-
 		this->site_hover(loc.m_site_id);
 	}
 	else

+ 2 - 1
his_location.cpp

@@ -149,6 +149,7 @@ void location_card::push(uint64_t timestamp,const point & p,int32_t areaid,int32
     if (bclose) //卡移除后直接更新his_location
     {
         update(p,timestamp);
+		init();
         return;
     }
     if(m_p.empty() || m_timestamp==0||m_areaid<0||m_mapid<0)
@@ -305,4 +306,4 @@ bool location_card::handle_path(std::vector<point> &rc,uint64_t timestamp,bool f
         flag=true;
     }
     return false;
-}
+}

+ 57 - 17
landmark.cpp

@@ -4,11 +4,11 @@
 #include "log.h"
 
 
-Landmark_list * Landmark_list::instance()
-{
-	static Landmark_list  lm_list;
-	return &lm_list;
-}
+//Landmark_list * Landmark_list::instance()
+//{
+//	static Landmark_list  lm_list;
+//	return &lm_list;
+//}
 void Landmark_list::init_mapDirection()
 {
 	const char * sql = "select map_direction_id, map_id, north_angle from dat_map_direction;";
@@ -29,7 +29,7 @@ void Landmark_list::init_mapDirection()
 			DBRes.GetField( "north_angle",north_angle, Error );
 
 			std::shared_ptr<map_direction> md = std::make_shared<map_direction>(map_id,north_angle);
-			m_map.insert({map_id,md});
+			m_map_direction.insert({map_id,md});
 			log_info("map_direction.....mapid:%d,north:%d",map_id,north_angle);
 		}
 	}
@@ -40,17 +40,26 @@ 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 );
+	
 	if (nCount > 0)
 	{
 		log_info( "init_landmark_info. The record count=%d\n", nCount );
-
+		std::unordered_map<int, std::shared_ptr<LandmarkInfo>> map;
 		while ( DBRes.GetNextRecod(Error) )
 		{
 			int landmark_id  = 0;
@@ -74,21 +83,51 @@ 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)
+			{	
+				map.insert(std::make_pair(landmark_id, landmark));
+				//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
+			{
+				auto markptr = Landmark_list::instance()->get(landmark_id);
+				if (markptr != nullptr)
+				{
+					markptr->set(p);
+					markptr->landmark_id = landmark_id;
+					markptr->landmark_name = name;
+					markptr->map_id = map_id;
+					markptr->area_id = area_id;
+					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);
+				}
+				else
+				{
+					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);
+					Landmark_list::instance()->add(landmark_id, landmark);
+				}
+				break;
+			}
+		}
+		if (-1== id)
+		{
+			Landmark_list::instance()->add(map);
 		}
 	}
 
 }
 
-std::tuple<int,int,double> Landmark_list::get(int mapid ,int areaid,const point &pt)
+std::tuple<int,int,double> Landmark_list::get_landmark(int mapid ,int areaid,const point &pt)
 {
 	int32_t id = -1;
 	double dis = DBL_MAX;
 	point p;
-	for(const auto &lm : m_v)	
+	auto m_v = Landmark_list::instance()->m_map;
+	auto it_s = m_v.begin();
+	while(it_s!=m_v.end())	
 	{
+		auto lm = it_s->second;
 		if(lm->area_id == areaid)
 		{
 			double tmp = pt.dist(*lm);
@@ -99,6 +138,7 @@ std::tuple<int,int,double> Landmark_list::get(int mapid ,int areaid,const point
 				p=*lm;
 			}
 		}
+		it_s++;
 	}
 	if(id==-1)
 	  return std::make_tuple(0,0,0);
@@ -120,8 +160,8 @@ DIRECTION_TYPE Landmark_list::GetDirectionType(point card_point, point landmark_
 		y_offset = 0;
 
 	std::shared_ptr<map_direction> pMapDirectoryInfo = nullptr;
-	auto it = m_map.find(map_id);		
-	if(it == m_map.end())
+	auto it = m_map_direction.find(map_id);
+	if(it == m_map_direction.end())
 	{
 		return NODIRECTORY;
 	}

+ 10 - 6
landmark.h

@@ -2,9 +2,11 @@
 #define __LAND_MARK_HPP__
 #include <string>
 #include <vector>
+#include <mutex>
 #include <map>
 #include <memory>
 #include <tuple>
+#include "write-copy.h"
 #include "point.h"
 enum DIRECTION_TYPE{
 	NODIRECTORY = 0,
@@ -42,17 +44,19 @@ struct map_direction
 	int map_id;
 	int north_angle;
 };
-struct Landmark_list
+struct Landmark_list:single_base<Landmark_list, int, std::shared_ptr<LandmarkInfo>>
 {
-	std::vector<std::shared_ptr<LandmarkInfo>> m_v;
-	std::map<int,std::shared_ptr<map_direction>> m_map;
-	static Landmark_list * instance();
+	//std::vector<std::shared_ptr<LandmarkInfo>> m_v;
+	std::map<int,std::shared_ptr<map_direction>> m_map_direction;
+	//static Landmark_list * instance();
 	void init_from_db();
-	void init_landmarkInfo();
+	void init_landmarkInfo(int id = -1);
+	
 	void init_mapDirection();
 	//landmarkId landmark_direction  landmark_dis
-	std::tuple<int,int,double> get(int mapid,int areaid,const point &pt);
+	std::tuple<int,int,double> get_landmark(int mapid,int areaid,const point &pt);
 	DIRECTION_TYPE GetDirectionType(point card_point, point landmark_point, int map_id);
+	std::mutex m_mutex;
 };
 #endif
 

+ 24 - 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>
@@ -101,6 +103,14 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
             int id = std::stoi(szParam);
             deal_call_edit_persons_dynamic_thre(id,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());
@@ -316,6 +326,20 @@ void module_meta_date_changed::deal_call_edit_persons_dynamic_thre(int area_id,E
 {
     area_list::instance()->init_area_persons_dynamic_thre_from_db(area_id);
 }
+// 修改地标信息
+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(id);
+	}
+}
 
 void module_meta_date_changed::init_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 deal_call_edit_persons_dynamic_thre(int area_id,EDIT_TYPE_ID edit_type_id);

+ 3 - 0
websocket/constdef.h

@@ -72,6 +72,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"
 //设置区域中时间段人员超员阈值等数据