소스 검색

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

lixioayao 6 년 전
부모
커밋
417947a307
8개의 변경된 파일193개의 추가작업 그리고 169개의 파일을 삭제
  1. 4 1
      ant.cpp
  2. 147 132
      area.cpp
  3. 3 5
      area.h
  4. 11 24
      card_path.cpp
  5. 0 3
      main.cpp
  6. 9 2
      module_service/area_business_person_dwell_checker.cpp
  7. 1 1
      websocket/constdef.h
  8. 18 1
      znet.cpp

+ 4 - 1
ant.cpp

@@ -6,6 +6,7 @@
 #include "event.h"
 #include "tool_time.h"
 #include "area.h"
+#include "card_path.h"
 //template<> std::shared_ptr<sit_list> single_base<sit_list, int, std::shared_ptr<site>>::m_instance=std::make_shared<sit_list>();
 
 int site::index()const
@@ -45,7 +46,7 @@ void sit_list::read_ant_path(int id)
      }
      else
      {
-         sql.append(" AND reader_id=");
+         sql.append(" where reader_id=");
          sql.append(std::to_string(id));
          sql.append(";");
 
@@ -158,6 +159,8 @@ void sit_list::read_ant_path(int id)
              log_info( "修改path成功,分站id=%d\n", id );
          }
      }
+
+	 card_path::init();
 }
 
 void sit_list::init_site(int id)

+ 147 - 132
area.cpp

@@ -29,8 +29,8 @@
 
 struct underground_area:area
 {
-    underground_area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type)
-        :area(id,limit_count_person,limit_time_person,scale,mapid,type)
+    underground_area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t biz_type)
+        :area(id,limit_count_person,limit_time_person,scale,mapid,biz_type)
 	{
 	}
     virtual bool in_area(const std::shared_ptr<site>&s,const std::shared_ptr<card_location_base>&c, const point & p,int &sarid)
@@ -41,8 +41,8 @@ struct underground_area:area
 
 struct special_area:area
 {
-    special_area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type)
-        :area(id,limit_count_person,limit_time_person,scale,mapid,type)
+    special_area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t biz_type)
+        :area(id,limit_count_person,limit_time_person,scale,mapid,biz_type)
 	{}
     virtual bool in_area(const std::shared_ptr<site>&s,const std::shared_ptr<card_location_base>&c, const point & p,int &sarid)
 	{
@@ -66,9 +66,9 @@ struct special_area:area
 
 };
 
-area::area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type)
+area::area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t b_type)
      :m_id(id)
-     ,m_area_type(type)
+     ,m_biz_type(b_type)
      ,m_limit_person_min(limit_time_person)
      ,m_limit_person_count(limit_count_person)
      ,m_scale(scale)
@@ -78,7 +78,7 @@ area::area(int id,int limit_count_person, int limit_time_person,double scale,int
      ,m_person_show_count(0)
      ,m_vehicle_show_count(0)
     {
-		m_area_business_list=area_business::get_instance_list(m_area_type,id);
+		m_area_business_list=area_business::get_instance_list(m_biz_type,id);
 		m_event_person_count = false;
 		m_event_vehicle_count = false;
 		m_event_person_show_count = false;
@@ -106,9 +106,10 @@ void area::change_business(uint32_t new_bits)
 {
 	worker*w=worker::instance();
 
-	uint32_t del=((m_area_type^new_bits)|m_area_type)^m_area_type;
-	uint32_t add=((m_area_type^new_bits)|new_bits)^new_bits;
-    log_info("change_area_business:%d,b_type:%d,area_type:%d [del:%d, add:%d]",m_id,new_bits,m_area_type,del,add);
+	uint32_t del=((m_biz_type^new_bits)|m_biz_type)^m_biz_type;
+	uint32_t add=((m_biz_type^new_bits)|new_bits)^new_bits;
+    log_info("change_area_business:area_id:%d,b_type:%d,area_type:%d [del:%d, add:%d]",m_id,new_bits,m_biz_type,del,add);
+
 	if(del==0 && add==0)
 		return;
 
@@ -134,6 +135,8 @@ void area::change_business(uint32_t new_bits)
 
 	add_frozen_count(w->num_thread()+1);
 
+	this->m_biz_type=new_bits;
+
 	w->broadcast(t);
 }
 
@@ -291,7 +294,7 @@ void area_list::init_monkeycar_area(int id)
             da->m_default_speed = monkeycar_speed;
             da->m_point = init_path(monkeycar_coor,area_id);
             std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person, over_time_person,scale,map_id,b_type);
-            ap->update(over_count_person, over_time_person,scale,map_id,b_type, over_count_vehicle,over_time_vehicle);
+            ap->update(over_count_person, over_time_person,scale,map_id,over_count_vehicle,over_time_vehicle);
 
             ap->m_bound=init_path(path,area_id);
             for(const auto &p : ap->m_bound)
@@ -303,22 +306,31 @@ void area_list::init_monkeycar_area(int id)
         }
         else
         {
-			//这里后续需要把猴车得信息传递过去
-            std::shared_ptr<db_area>  da = std::make_shared<db_area>();
-            da->m_default_speed = monkeycar_speed;
-            da->m_point = init_path(monkeycar_coor,area_id);
-			std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person, over_time_person,scale,map_id,b_type);
-			if(auto area_=area_list::instance()->get(id))
-				area_=ap;
-			else
-				area_list::instance()->add(area_id,ap);
 
-            ap->m_bound=init_path(path,area_id);
-            ap->update(over_count_person, over_time_person,scale,map_id,b_type, over_count_vehicle,over_time_vehicle);
-            for(const auto &p : ap->m_bound)
-              log_info("point:monkey:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
-            for(const auto &p : da->m_point)
-              log_info("point:monkey_coor:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+			auto tmp_ptr = area_list::instance()->get(id);
+			bool newobj=false;
+
+			if(!tmp_ptr)
+			{
+				std::shared_ptr<db_area>  da = std::make_shared<db_area>();
+				da->m_default_speed = monkeycar_speed;
+				da->m_point = init_path(monkeycar_coor,area_id);
+				tmp_ptr=std::make_shared<monkey_area>(da,area_id,over_count_person, over_time_person,scale,map_id,b_type);
+
+				newobj=true;
+			}
+
+			tmp_ptr->m_bound=init_path(path,area_id);
+            tmp_ptr->update(over_count_person, over_time_person,scale,map_id, over_count_vehicle,over_time_vehicle);
+
+			if(newobj)
+			{
+				area_list::instance()->add(id, tmp_ptr);
+			}
+			else
+			{
+				tmp_ptr->change_business(b_type);
+			}
 
             log_info("基础数据 monkeycar area增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,\
                      scale:%.2f,map_id:%d,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
@@ -352,134 +364,137 @@ std::shared_ptr<area>  area_list::create(int type,int id,int limit_count_person,
 }
 void area_list::init_from_db(int id/*=-1*/)
 {
-    std::string sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path,b.scale, \
-            over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, \
-            over_speed_vehicle, is_attendance,business_type, a.is_work_area\
-            FROM dat_area a,dat_map b\
-            where a.map_id = b.map_id and  area_id not in \
-			  (select monkeycar_base_info_id from dat_monkeycar_base_info)";
-
-    if(-1 == id)
-    {
-        sql.append(";");
-    }
-    else
-    {
-        sql.append(" AND a.area_id=");
-        sql.append(std::to_string(id));
-        sql.append(";");
+	do{
+		std::string sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path,b.scale, \
+						   over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, \
+						   over_speed_vehicle, is_attendance,business_type, a.is_work_area\
+						   FROM dat_area a,dat_map b\
+						   where a.map_id = b.map_id and  area_id not in \
+						   (select monkeycar_base_info_id from dat_monkeycar_base_info)";
+
+		if(-1 == id)
+		{
+			sql.append(";");
+		}
+		else
+		{
+			sql.append(" AND a.area_id=");
+			sql.append(std::to_string(id));
+			sql.append(";");
 
-        log_info("基础数据 增加或修改区域 sql=%s", sql.c_str());
-    }
+			log_info("基础数据 增加或修改区域 sql=%s", sql.c_str());
+		}
 
-    std::string Error;
-    YADB::CDBResultSet DBRes;
-    sDBConnPool.Query(sql.c_str(),DBRes,Error);
-    int nCount = DBRes.GetRecordCount( Error );
-    if (nCount < 1)
-    {
-        log_error("基础数据 增加或修改失败,数据库中找不到: area_id=%d:%s", id,sql.c_str());
-        return ;
-    }
+		std::string Error;
+		YADB::CDBResultSet DBRes;
+		sDBConnPool.Query(sql.c_str(),DBRes,Error);
+		int nCount = DBRes.GetRecordCount( Error );
+		if (nCount < 1)
+		{
+			log_error("基础数据 增加或修改失败,数据库中找不到: area_id=%d:%s", id,sql.c_str());
+			break;
+		}
 
-    std::unordered_map<int,std::shared_ptr<area>> map;
-    while ( DBRes.GetNextRecod(Error) )
-    {
-        int area_id  = 0;
-        DBRes.GetField( "area_id",area_id, Error );
+		std::unordered_map<int,std::shared_ptr<area>> map;
+		while ( DBRes.GetNextRecod(Error) )
+		{
+			int area_id  = 0;
+			DBRes.GetField( "area_id",area_id, Error );
 
-        int map_id  = 0;
-        DBRes.GetField( "map_id",map_id, Error );
+			int map_id  = 0;
+			DBRes.GetField( "map_id",map_id, Error );
 
-        unsigned int area_type_id  = 0;
-        DBRes.GetField( "area_type_id",area_type_id, Error );
+			unsigned int area_type_id  = 0;
+			DBRes.GetField( "area_type_id",area_type_id, Error );
 
-        int over_count_person = 0;
-        DBRes.GetField( "over_count_person",over_count_person, Error );
+			int over_count_person = 0;
+			DBRes.GetField( "over_count_person",over_count_person, Error );
 
-        int over_count_vehicle = 0;
-        DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
+			int over_count_vehicle = 0;
+			DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
 
-        int over_time_person = 0;
-        DBRes.GetField( "over_time_person",over_time_person, Error );
+			int over_time_person = 0;
+			DBRes.GetField( "over_time_person",over_time_person, Error );
 
-        int over_time_vehicle = 0;
-        DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
+			int over_time_vehicle = 0;
+			DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
 
-        std::string over_speed_vehicle;
-        DBRes.GetField( "over_speed_vehicle",over_speed_vehicle, Error );
+			std::string over_speed_vehicle;
+			DBRes.GetField( "over_speed_vehicle",over_speed_vehicle, Error );
 
-        std::string path;
-        DBRes.GetField( "path",path, Error );
+			std::string path;
+			DBRes.GetField( "path",path, Error );
 
-        double scale = 0;
-        DBRes.GetField( "scale",scale, Error );
+			double scale = 0;
+			DBRes.GetField( "scale",scale, Error );
 
-		uint32_t b_type =0;
-        DBRes.GetField( "business_type",b_type, Error );
+			uint32_t b_type =0;
+			DBRes.GetField( "business_type",b_type, Error );
 
-        int is_work_area = 0;
-        DBRes.GetField( "is_work_area",is_work_area, Error );
+			int is_work_area = 0;
+			DBRes.GetField( "is_work_area",is_work_area, Error );
 
-        log_info("init_area : id:%d,path:%s..speed:%s",area_id, path.c_str(),over_speed_vehicle.c_str());
-        std::map<int,double> map_;
-        auto vp=init_path(over_speed_vehicle,area_id);
-        for(const auto &v:vp)
-            map_.insert({v.x,v.y});
-        if(-1 == id)
-        {
-            std::shared_ptr<area> ap = create(area_type_id,area_id,over_count_person,over_time_person, scale,map_id,b_type);
-            ap->m_limit_vehicle_min = over_time_vehicle;
-            ap->m_limit_vehicle_count = over_count_vehicle;
-            ap->m_speed=std::move(map_);
-            ap->m_is_work_area = is_work_area;
+			log_info("init_area : id:%d,path:%s..speed:%s",area_id, path.c_str(),over_speed_vehicle.c_str());
+			std::map<int,double> map_;
+			auto vp=init_path(over_speed_vehicle,area_id);
+			for(const auto &v:vp)
+				map_.insert({v.x,v.y});
+			if(-1 == id)
+			{
+				std::shared_ptr<area> ap = create(area_type_id,area_id,over_count_person,over_time_person, scale,map_id,b_type);
+				ap->m_limit_vehicle_min = over_time_vehicle;
+				ap->m_limit_vehicle_count = over_count_vehicle;
+				ap->m_speed=std::move(map_);
+				ap->m_is_work_area = is_work_area;
+
+				ap->m_bound=init_path(path,area_id);
+				for(const auto &p : ap->m_bound)
+					log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+				map.insert({area_id,ap});
+			}
+			else
+			{
+				auto tmp_ptr = area_list::instance()->get(id);
+				bool newobj=false;
 
-            ap->m_bound=init_path(path,area_id);
-            for(const auto &p : ap->m_bound)
-              log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
-            map.insert({area_id,ap});
-        }
-        else
-        {
-            auto tmp_ptr = area_list::instance()->get(id);
-			bool newobj=false;
-			
-            if(!tmp_ptr)
-            {
-				tmp_ptr = create(area_type_id,area_id,over_count_person,over_time_person, scale,map_id,b_type);
-				newobj=true;
-            }
+				if(!tmp_ptr)
+				{
+					tmp_ptr = create(area_type_id,area_id,over_count_person,over_time_person, scale,map_id,b_type);
+					newobj=true;
+				}
 
-            tmp_ptr->update(over_count_person, over_time_person,scale,map_id,b_type, over_count_vehicle,over_time_vehicle);
-            tmp_ptr->m_speed=std::move(map_);
-            tmp_ptr->m_bound=init_path(path,area_id);
-            tmp_ptr->m_is_work_area = is_work_area;
+				tmp_ptr->update(over_count_person, over_time_person,scale,map_id, over_count_vehicle,over_time_vehicle);
+				tmp_ptr->m_speed=std::move(map_);
+				tmp_ptr->m_bound=init_path(path,area_id);
+				tmp_ptr->m_is_work_area = is_work_area;
 
-            for(const auto &p : tmp_ptr->m_bound)
-                log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+				for(const auto &p : tmp_ptr->m_bound)
+					log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
 
-            log_info("基础数据 增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,scale:%.2f,map_id:%d\
-                     ,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d,b_type:%d",
-                     id,over_count_person, over_time_person,scale,map_id,area_type_id,
-                     over_count_vehicle,over_time_vehicle,b_type);
+				log_info("基础数据 增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,scale:%.2f,map_id:%d\
+						,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
+						id,over_count_person, over_time_person,scale,map_id,area_type_id,
+						over_count_vehicle,over_time_vehicle);
 
-			if(newobj)
-			{
-				area_list::instance()->add(id, tmp_ptr);
-			}
-			else
-			{
-				tmp_ptr->change_business(b_type);
+				if(newobj)
+				{
+					area_list::instance()->add(id, tmp_ptr);
+				}
+				else
+				{
+					tmp_ptr->change_business(b_type);
+				}
 			}
-        }
-    }
+		}
 
-    if(-1 == id)
-    {
-        log_info( "init_area. The record count=%d\n", nCount );
-        area_list::instance()->add(map);
-    }
-    init_monkeycar_area(id);
+		if(-1 == id)
+		{
+			log_info( "init_area. The record count=%d\n", nCount );
+			area_list::instance()->add(map);
+		}
+	}while(0);
+
+	init_monkeycar_area(id);
 }
 
 std::vector<point> area_list::init_path(std::string &str_0,int area_id)

+ 3 - 5
area.h

@@ -23,7 +23,7 @@ struct site;
 */
 struct area
 {
-    area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t type);
+    area(int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t b_type);
 
   	virtual void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c);
 	virtual	void on_enter(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c);
@@ -50,10 +50,8 @@ struct area
     virtual ~area()
     {}
     double get_speed(int vehicle_category_id) {return m_speed[vehicle_category_id];}
-    void  update(int limit_count_person, int limit_time_person,double scale,int32_t mapid,
-                     int32_t type,int limit_count_vehicle, int limit_time_vehicle)
+    void  update(int limit_count_person, int limit_time_person,double scale,int32_t mapid, int limit_count_vehicle, int limit_time_vehicle)
     {
-        m_area_type=type;
         m_limit_person_min=limit_time_person;
         m_limit_person_count=limit_count_person;
         m_scale=scale;
@@ -103,7 +101,7 @@ public:
 		7:禁区[进入时长]
 		8:猴车区域
 	*/
-    int m_area_type;
+    int    m_biz_type=0;
 
 	//人卡超时及超员数量(阀值)
     int m_limit_person_min;

+ 11 - 24
card_path.cpp

@@ -822,33 +822,20 @@ struct graph
 	}
 };
 
-
-std::atomic<int> g_init_flag(0);
-graph g_graph;
-
+safe_shared_ptr<graph> g_graph(std::make_shared<graph>());
 }//namespace
 
 void card_path::init()
 {
-    //Ensure only ont thread can init path.
-	int expect=0;
-	if(g_init_flag.compare_exchange_strong(expect,1))
-	{
-		handle_path hp;
-		//std::vector<base_path> opath=init_path(sites,v_list);
-		sit_list::instance()->accept(hp);
-		std::vector<base_path> opath=init_path(hp.ret,hp.v);
-		g_graph.init(hp.v,opath);
+	std::shared_ptr<graph> local_graph=std::make_shared<graph>();
 
-		++g_init_flag;
-	}
-    //if != 2 then wait here until init over.
-	while(g_init_flag.load()!=2)
-	{
-		std::this_thread::sleep_for (std::chrono::seconds(1));
-	}
-}
+	handle_path hp;
+	sit_list::instance()->accept(hp);
+	std::vector<base_path> opath=init_path(hp.ret,hp.v);
+	local_graph->init(hp.v,opath);
 
+	g_graph.set(local_graph);
+}
 
 card_path&card_path::inst()
 {
@@ -858,17 +845,17 @@ card_path&card_path::inst()
 
 std::vector<point> card_path::find_path(const point&from,const point&to)const
 {
-	return g_graph.find(from,to);
+	return g_graph.get()->find(from,to);
 }
 
 bool card_path::is_at_path(const point&pt)const
 {
-	return g_graph.is_at_path(pt);
+	return g_graph.get()->is_at_path(pt);
 }
 
 std::vector<line_v>  card_path::find_possible_path(const point&from,double dist) const
 {
-	return std::move(g_graph.find_possible_path(from,dist));
+	return std::move(g_graph.get()->find_possible_path(from,dist));
 }
 
 #ifdef __DEBUG__

+ 0 - 3
main.cpp

@@ -182,9 +182,6 @@ int main(int argc ,char * argv[])
     Init_Setting is;
     is.init();
 
-	card_path::init();
-//	test_find_path(point(4600,-75),point(4727,-90));
-
     module_mgr::start();
     web_connect::start_beatheart_monitor();
     atexit(&cleanup);

+ 9 - 2
module_service/area_business_person_dwell_checker.cpp

@@ -22,17 +22,23 @@ void area_business_person_dwell_checker::on_enter(const std::shared_ptr<area_hov
 							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data>&ptr)
 {
     log_info("area_business_person_dwell_checker::on_enter : In Area=%d Card = %d  ",a->m_area->id(),c->m_id);
+
+	if( a->m_area->m_limit_person_min == 0 )
+	{
+		log_warn("区域area_id=%d超时值设置为0,不会检查超时。",a->m_area->m_id);
+	}
 }
 
 //判断是否超时
 void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hover>&a,
 							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 {
-    if(!c->is_person()||a->m_enter_time==0)
+    if(!c->is_person()||a->m_enter_time==0||a->m_area->m_limit_person_min==0)
       return;
 
 	int limit_val = a->m_area->m_limit_person_min*60;
 	int cur_val = ( tool_time::now_to_seconds() - a->m_enter_time / 1000);
+
 	EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON : EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
 	if (limit_val < cur_val)
     {
@@ -48,8 +54,9 @@ void area_business_person_dwell_checker::on_hover(const std::shared_ptr<area_hov
 void area_business_person_dwell_checker::on_leave(const std::shared_ptr<area_hover>&a,
 							const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr)
 {
-    if(!c->is_person())
+    if(!c->is_person()||a->m_enter_time==0||a->m_area->m_limit_person_min==0)
       return;
+
     EVENT_TYPE evType = a->m_area->is_mine() ? EVENT_TYPE::ET_CARD_OVER_TIME_PERSON:EVENT_TYPE::ET_CARD_AREA_OVER_TIME_PERSON;
     if(c->get_event_flag(evType))
     {

+ 1 - 1
websocket/constdef.h

@@ -53,7 +53,7 @@
 #define JSON_KEY_NAME "name"
 #define JSON_KEY_NAME_MAP "map"
 #define JSON_KEY_NAME_AREA "area"
-#define JSON_KEY_NAME_PATH "path"
+#define JSON_KEY_NAME_PATH "reader_path_tof_n"
 #define JSON_KEY_NAME_READER "reader"
 #define JSON_KEY_NAME_CARD "card"
 #define JSON_KEY_NAME_STAFF "staff"

+ 18 - 1
znet.cpp

@@ -626,7 +626,24 @@ struct main_loop:io_context
 
 		block_sig(SIGPIPE);
 		signal_w sint(*this,SIGINT),term(*this,SIGTERM);
-		ev::dynamic_loop::run(0);
+
+
+		while(!check_stop_flag())
+		{
+			try
+			{
+			ev::dynamic_loop::run(0);
+			}
+			catch(const std::exception&e)
+			{
+				log_error("捕获到异常:%s",e.what());
+			}
+			catch(...)
+			{
+				log_error("捕获到未知异常");
+			}
+		}
+
 		_1.stop();
 		close_all();