Browse Source

fix conficit

lixioayao 5 years ago
parent
commit
68e6e1bc22

+ 1 - 1
area.cpp

@@ -729,7 +729,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

+ 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
 

+ 28 - 3
module_service/area_business_card_enter_or_leave.cpp

@@ -20,17 +20,41 @@ void area_business_card_enter_or_leave::on_enter(const std::shared_ptr<area_hove
     char sql[LENGTH_SQL]{0};
     std::string start_time = tool_time::to_str(a->m_enter_time/1000);
     const auto &p=a->m_enter_point;
-    snprintf(sql,LENGTH_SQL,"INSERT INTO his_location_area (obj_id,card_type_id,ident,area_id,map_id,enter_time,start_point) \
+    // 根据区域无法区分是否井上分站[分站创建的区域没有代入区域类型-导致都是井上区域] 只能通过分站区分
+    if (nullptr == c->get_area_tool()->m_site || !c->get_area_tool()->m_site->is_up_site())
+    {
+        snprintf(sql, LENGTH_SQL, "INSERT INTO his_location_area (obj_id,card_type_id,ident,area_id,map_id,enter_time,start_point) \
 	                         VALUES ('%d','%lu','%d',%d,%d,'%s','%.2f,%.2f');",
-				c->m_cid,c->m_type,c->m_id, a->id(),a->mapid(),start_time.c_str(),p.x,p.y);
-
+                 c->m_cid, c->m_type, c->m_id, a->id(), a->mapid(), start_time.c_str(), p.x, p.y);
+    }
+    else
+    {
+        // 井上分站时,插入时把离开时间也写入 防止员工出井后最后一个区域没有leave_time
+        snprintf(sql, LENGTH_SQL, "INSERT INTO his_location_area (obj_id,card_type_id,ident,area_id,map_id,enter_time,leave_time,start_point) \
+	                         VALUES ('%d','%lu','%d',%d,%d,'%s','%s','%.2f,%.2f');",
+                 c->m_cid, c->m_type, c->m_id, a->id(), a->mapid(), start_time.c_str(),start_time.c_str(), p.x, p.y);
+    }
     db_tool::PushAsync(sql);
 }
 
 void area_business_card_enter_or_leave::on_hover(const std::shared_ptr<area_hover>&a,
                                                  const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 {
+    // 根据区域无法区分是否井上分站[分站创建的区域没有代入区域类型-导致都是井上区域] 只能通过分站区分
+    if (nullptr != c->get_area_tool()->m_site && c->get_area_tool()->m_site->is_up_site())
+    {
+        // 井上分站时,员工在行走过程中更新时间
+        char sql[LENGTH_SQL]{0};
+        std::string start_time = tool_time::to_str(a->m_enter_time/1000);
+        std::string end_time = tool_time::to_str(tool_time::now_to_seconds());
+        const auto &ep=a->m_last_point;
+        snprintf(sql,LENGTH_SQL,"UPDATE his_location_area SET leave_time='%s',end_point='%.2f,%.2f' \
+	                         WHERE  enter_time='%s' AND obj_id=%d AND area_id=%d;",
+                 end_time.c_str(),ep.x,ep.y,
+                 start_time.c_str(),c->m_cid,a->id());
 
+        db_tool::PushAsync(sql);
+    }
 }
 //出区域则入库
 void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hover>&a,
@@ -47,6 +71,7 @@ void area_business_card_enter_or_leave::on_leave(const std::shared_ptr<area_hove
 				start_time.c_str(),c->m_cid,a->id());
 
     log_info("card_enter_leave:%s",sql);
+
     db_tool::PushAsync(sql);
 }
 

+ 41 - 4
module_service/module_meta_date_changed.cpp

@@ -11,6 +11,9 @@
 #include"card.h"
 #include"area.h"
 #include "forbid_staff_down_mine.h"
+#include "landmark.h"
+#include <three_rates.h>
+#include"area_business_geofault.h"
 #include <boost/format.hpp>
 #include <boost/tokenizer.hpp>
 #include <boost/algorithm/string/split.hpp>
@@ -94,6 +97,19 @@ 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 if (JSON_KEY_NAME_COALFACE==name|| JSON_KEY_NAME_COALFACE_VEHICLE == name || 
+			JSON_KEY_NAME_DRIVING_FACE == name || JSON_KEY_NAME_DRIVINGFACE_VEHICLE == name )
+		{			
+			three_rates::get_instance()->update_db_data(name, szParam, edit_type_id);
+		}
         else
         {
             log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
@@ -248,7 +264,7 @@ void module_meta_date_changed::deal_call_edit_map(int id, EDIT_TYPE_ID edit_type
             return;
         }
 
-        //update_map_info(id);
+        update_map_info(id);
     }
     else if(ET_DELETE == edit_type_id)
     {
@@ -303,6 +319,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(id);
+	}
+}
+
 void module_meta_date_changed::init_setting()
 {
     //pRes = getMysqlRes("select setting_id, name, type, value from dat_setting;");
@@ -448,10 +479,16 @@ void module_meta_date_changed::update_map_info(int id)
         log_error("修改地图失败,数据库中找不到: map_id=%d", id);
         return ;
     }
-
     double scale  = 0;
-    DBRes.GetField( "scale",scale, Error );
-
+    if (DBRes.GetNextRecod(Error))
+    {
+        DBRes.GetField("scale", scale, Error);
+    }
+    if (scale < 1e-4)
+    {
+        log_error("修改地图,数据库地图比例尺错误: map_id=%d,scale=%.2f", id,scale);
+        return;
+    }
     auto area = area_list::instance()->m_map;
     for(auto& it : area)
     {

+ 2 - 0
module_service/module_meta_date_changed.h

@@ -65,6 +65,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();

+ 9 - 0
websocket/constdef.h

@@ -72,6 +72,15 @@
 #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_COALFACE "coalface"
+#define JSON_KEY_NAME_COALFACE_VEHICLE "coalface_vehicle"
+#define JSON_KEY_NAME_DRIVING_FACE "drivingface"
+#define JSON_KEY_NAME_DRIVINGFACE_VEHICLE "drivingface_vehicle"
+
 //禁止指定人员下井
 #define JSON_KEY_NAME_FORBID_PERSON_DOWN_MINE "rt_person_forbid_down_mine"