Ver Fonte

区域时间段超员设置及功能--优化数据加载

chensongchao há 5 anos atrás
pai
commit
41e9f0d649
5 ficheiros alterados com 46 adições e 140 exclusões
  1. 23 48
      area.cpp
  2. 6 8
      area.h
  3. 7 3
      area_persons_thre_time.cpp
  4. 3 4
      area_persons_thre_time.h
  5. 7 77
      module_service/area_business_count_checker.cpp

+ 23 - 48
area.cpp

@@ -85,9 +85,9 @@ area::area(int id,int limit_count_person, int limit_time_person,double scale,int
 	 ,m_frozen_count(0)
      ,m_is_work_area(0)
     {
+		m_default_limit_person_count = limit_count_person;
 		m_area_business_list=area_business::get_instance_list(m_biz_type,id);
-
-		m_persons_thre_time = std::make_shared<area_persons_thre_time>(limit_count_person);
+		m_persons_thre_time = std::make_shared<area_persons_thre_time>();
     }
 void area::clear()
 {
@@ -229,44 +229,15 @@ bool area::in_area(const std::shared_ptr<site>&s,const std::shared_ptr<card_loca
 }
 
 //
-int area::get_limit_person_count()
+bool area::get_limit_person_count()
 {
 	int count = m_persons_thre_time->get_limit_person_count();
 	if (count != m_limit_person_count.load())
 	{
 		m_limit_person_count = count;
+		return true;
 	}
-	if(m_persons_thre_time->m_web_checkdata)
-	{
-		m_persons_thre_time->m_web_checkdata = false;
-	}
-	return m_limit_person_count.load();
-}
-
-// 判断区域中是否有时间段超员设定
-bool area::is_time_person_thre()
-{
-    return m_persons_thre_time->get_count() > 0;
-}
-
-bool area::is_limit_person_count_check(int & limit_person_count)
-{
-	bool ret = false;
-	int count = m_persons_thre_time->get_limit_person_count();
-	if (count != m_limit_person_count.load())
-	{
-		std_info("is_limit_person_count_check :area=%d,m_limit_person_count=%d->%d"
-				,m_id,m_limit_person_count.load(),count);
-		m_limit_person_count = count;
-		ret = true;
-	}
-	limit_person_count = m_limit_person_count;
-	if(m_persons_thre_time->m_web_checkdata)
-	{
-		ret = true;
-		m_persons_thre_time->m_web_checkdata = false;
-	}
-	return ret;
+	return false;
 }
 
 /////////////////// area_list //////////////////////////////////////////////////
@@ -622,7 +593,6 @@ void area_list::init_area_persons_dynamic_thre_from_db(int area_id/* = -1*/)
 		sql.append(std::to_string(area_id));
 	}
 	sql.append(" order by area_id asc,start_time asc ;");
-	log_info("加载区域:%d 时间段人员超员设置sql: %s",area_id, sql.c_str());
 
 	std::string Error;
 	YADB::CDBResultSet DBRes;
@@ -632,8 +602,7 @@ void area_list::init_area_persons_dynamic_thre_from_db(int area_id/* = -1*/)
 	{
 		return;
 	}
-	MAP_AREA_PERSONS_THRE map_thre;
-	std::shared_ptr<area> tmp_area = nullptr;
+	std::map<int, std::shared_ptr<area_persons_thre_time>> map_thre;
 	while ( DBRes.GetNextRecod(Error) )
 	{
 		SArea_Persons_Thre td;
@@ -644,22 +613,28 @@ void area_list::init_area_persons_dynamic_thre_from_db(int area_id/* = -1*/)
 		DBRes.GetField("thre_value", td.thre_value, Error);
 		td.start_time = tool_time::time_to_day_seconds(td.sz_start_time);
 		td.end_time = tool_time::time_to_day_seconds(td.sz_end_time);
-		if (nullptr == tmp_area || tmp_area->m_id != td.area_id)
+		auto it = map_thre.find(td.area_id);
+		if (it == map_thre.end())
 		{
-			tmp_area = area_list::instance()->get(td.area_id);
-			if (nullptr == tmp_area)
-			{
-				continue;
-			}
-			tmp_area->m_persons_thre_time->clear_persons_thre();
+			std::shared_ptr<area_persons_thre_time> p = std::make_shared<area_persons_thre_time>();
+			p->add_persons_thre(td);
+			map_thre[td.area_id] = p;
+		}
+		else
+		{
+			it->second->add_persons_thre(td);
 		}
-		tmp_area->m_persons_thre_time->add_persons_thre(td);
 	}
-	if (area_id > 0 && nullptr == tmp_area && tmp_area->m_id == area_id)
+	for( auto &it : map_thre)
 	{
-		//标记web修改
-		tmp_area->m_persons_thre_time->m_web_checkdata = true;
+		std::shared_ptr<area> a = area_list::instance()->get(it.first);
+		if (nullptr != a)
+		{
+			it.second->set_default_person_count_limit(a->m_default_limit_person_count);
+			a->m_persons_thre_time = it.second;
+		}
 	}
+	log_info("加载区域:%d 时间段人员超员设置sql: %s",area_id, sql.c_str());
 }
 /////////////////////////////////////////////////////////////////////
 area_hover::area_hover(const std::shared_ptr<area>&area,const point&pt)

+ 6 - 8
area.h

@@ -104,8 +104,11 @@ public:
     int    m_biz_type=0;
     int    m_area_type=0;
 
-	//人卡超时及超员数量(阀值)
+	// 人卡超时及超员数量(阀值)
     int m_limit_person_min;
+    // 区域表中人员超员的(阀值)
+    int m_default_limit_person_count;
+    // 当前人员超员的(阀值)
     std::atomic<int> m_limit_person_count;
     //是否人卡超员已有告警
     bool m_event_person_count;
@@ -141,13 +144,8 @@ public:
 	//区域时间段超员限制
     std::shared_ptr<area_persons_thre_time> m_persons_thre_time;
 
-    // 获取区域当前超员的阈值,区域可能有时间段限制
-    int get_limit_person_count();
-    // 判断当前时间是超员限制值是否改变,
-    // out limit_person_count: 改变后的值
-    bool is_limit_person_count_check(int & limit_person_count);
-    // 判断区域中是否有时间段超员设定
-    bool is_time_person_thre();
+    // 判断区域当前超员的阈值,是否变化 true:有变化
+    bool get_limit_person_count();
 };
 
 struct area_list:single_base<area_list,int,std::shared_ptr<area>>

+ 7 - 3
area_persons_thre_time.cpp

@@ -5,11 +5,15 @@
 #include "area_persons_thre_time.h"
 #include "tool_time.h"
 
-area_persons_thre_time::area_persons_thre_time(int _limit)
-    :m_default_limit_person_limit(_limit)
+area_persons_thre_time::area_persons_thre_time()
 {
-    m_web_checkdata = false;
 }
+
+void area_persons_thre_time::set_default_person_count_limit(int _limit)
+{
+    m_default_limit_person_limit = _limit;
+};
+
 void area_persons_thre_time::add_persons_thre(const SArea_Persons_Thre & thre)
 {
     m_area_persons_thre[thre.db_id] = thre;

+ 3 - 4
area_persons_thre_time.h

@@ -35,16 +35,15 @@ typedef std::map<int,SArea_Persons_Thre> MAP_AREA_PERSONS_THRE;
 
 struct area_persons_thre_time
 {
-    area_persons_thre_time(int _limit);
+    area_persons_thre_time();
     MAP_AREA_PERSONS_THRE m_area_persons_thre;
     int m_default_limit_person_limit;
 
-    // web修改数据
-    std::atomic<bool> m_web_checkdata;
-
     void add_persons_thre(const SArea_Persons_Thre & thre);
     void del_persons_thre(int thre_db_id);
     void clear_persons_thre();
+    //设置默认值
+    void set_default_person_count_limit(int _limit);
 
     //记录数量
     int get_count() const;

+ 7 - 77
module_service/area_business_count_checker.cpp

@@ -50,7 +50,7 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 		return ;
 	if (c->is_person())
 	{
-        int limit_val=a->m_area->get_limit_person_count();
+        int limit_val=a->m_area->m_limit_person_count;
         int aid=a->m_area->id();
         if(limit_val<=0)
         {
@@ -63,21 +63,6 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 		    a->m_area->m_person_show_count ++ ;
 
         _add_person_count_event(a,limit_val,"person_count_enter");
-        /*int pc=a->m_area->m_person_count.load();
-        int pc_=a->m_area->m_person_show_count.load();
-	    EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON ;
-        if(pc>limit_val){
-            lock();
-		    event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,pc,a->m_area->m_event_person_count=true,DT_NORMAL);
-            unlock();
-		    log_info("person_count_enter:%d,v_count:%d limit:%d",aid,pc,limit_val);
-        }
-        if(pc_>limit_val){
-            lock();
-		    event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,pc_,a->m_area->m_event_person_show_count=true,DT_SPECIAL);
-            unlock();
-		    log_info("person_count_enter_show:%d,v_count:%d limit:%d",aid,pc_,limit_val);
-        }*/
 	}
 	else if (c->is_vehicle())
 	{
@@ -94,21 +79,6 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 		    a->m_area->m_vehicle_show_count ++ ;
 
         _add_vehicle_count_event(a,limit_val);
-        /*int vc=a->m_area->m_vehicle_count.load();
-        int vc_=a->m_area->m_vehicle_show_count.load();
-		EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_VEHICLE : EVENT_TYPE::ET_AREA_OVER_COUNT_VEHICLE ;
-        if(vc>limit_val){
-            lock();
-		    event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,vc,a->m_area->m_event_vehicle_count=true,DT_NORMAL);
-            unlock();
-		    log_info("vehicle_count_enter:%d,v_count:%d limit:%d",aid,vc,limit_val);
-        }
-        if(vc_>limit_val){
-            lock();
-		    event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,vc_,a->m_area->m_event_vehicle_show_count=true,DT_SPECIAL);
-            unlock();
-		    log_info("vehicle_count_enter_show:%d,v_count:%d limit:%d",aid,vc_,limit_val);
-        }*/
 	}
     c->update_display();
 }
@@ -124,16 +94,11 @@ void area_business_count_checker::on_hover(const std::shared_ptr<area_hover>&a,
           on_leave(a,c,ptr);
         c->update_display();
         ptr=nullptr;
-        return;
     }
 
-    if (c->is_person() && a->m_area->is_time_person_thre())
+    if (c->is_person() && a->m_area->get_limit_person_count())
     {
-        int limit_val = 0;
-        if (!a->m_area->is_limit_person_count_check(limit_val) || limit_val <= 0)
-        {
-            return;
-        }
+        int limit_val = a->m_area->m_limit_person_count;
         _remove_person_count_event(a,limit_val,"area_business_count_checker::on_hover");
         _add_person_count_event(a,limit_val,"area_business_count_checker::on_hover");
     }
@@ -164,25 +129,7 @@ void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
             if(flag)
 		        a->m_area->m_person_show_count -- ;
         }
-        int limit_val=a->m_area->get_limit_person_count();
-        _remove_person_count_event(a,limit_val,"person_count_leave");
-        /*int pc=a->m_area->m_person_count.load();
-        int pc_=a->m_area->m_person_show_count.load();
-        int aid=a->m_area->id();
-	    EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON ;
-		if(a->m_area->m_event_person_count&& pc <= limit_val){
-            lock();
-			event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,pc,a->m_area->m_event_person_count=false,DT_NORMAL);
-            unlock();
-		    log_info("person_count_leave:%d,v_count:%d limit:%d",aid,pc,limit_val);
-        }
-		if(a->m_area->m_event_person_show_count&& pc_ <= limit_val){
-            lock();
-			event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,pc_,a->m_area->m_event_person_show_count=false,DT_SPECIAL);
-            unlock();
-		    log_info("person_count_leave_show:%d,v_count:%d limit:%d",aid,pc,limit_val);
-        }
-         */
+        _remove_person_count_event(a , a->m_area->m_limit_person_count ,"person_count_leave");
 	}
 	else if (c->is_vehicle())
 	{
@@ -194,24 +141,7 @@ void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
             if(flag)
 		        a->m_area->m_vehicle_show_count -- ;
         }
-        int limit_val=a->m_area->m_limit_vehicle_count;
-        _remove_vehicle_count_event(a,limit_val);
-        /*int pc=a->m_area->m_vehicle_count.load();
-        int pc_=a->m_area->m_vehicle_show_count.load();
-        int aid=a->m_area->id();
-		EVENT_TYPE ev = a->m_area->is_mine()?EVENT_TYPE::ET_OVER_COUNT_VEHICLE : EVENT_TYPE::ET_AREA_OVER_COUNT_VEHICLE ;
-		if(a->m_area->m_event_vehicle_count&& pc <= limit_val){
-            lock();
-			event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,pc,a->m_area->m_event_vehicle_count=false,DT_NORMAL);
-            unlock();
-		    log_info("vehicle_count_leave:%d,v_count:%d limit:%d",aid,pc,limit_val);
-        }
-		if(a->m_area->m_event_vehicle_show_count&& pc_ <= limit_val){
-            lock();
-			event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,pc_,a->m_area->m_event_vehicle_show_count=false,DT_SPECIAL);
-            unlock();
-		    log_info("vehicle_count_leave_show:%d,v_count:%d limit:%d",aid,pc,limit_val);
-        }*/
+        _remove_vehicle_count_event(a,a->m_area->m_limit_vehicle_count);
 	}
 }
 
@@ -223,14 +153,14 @@ void area_business_count_checker::_add_person_count_event(const std::shared_ptr<
     int pc = a->m_area->m_person_count.load();
     int pc_ = a->m_area->m_person_show_count.load();
     EVENT_TYPE ev = a->m_area->is_mine() ? EVENT_TYPE::ET_OVER_COUNT_PERSON : EVENT_TYPE::ET_AREA_OVER_COUNT_PERSON;
-    if(pc >= limit_val )
+    if(pc > limit_val )
     {
         lock();
         event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,pc,a->m_area->m_event_person_count=true,DT_NORMAL);
         unlock();
         log_info("%s:%d,v_count:%d limit:%d",desc.c_str(),aid,pc,limit_val);
     }
-    if(pc_ >= limit_val )
+    if(pc_ > limit_val )
     {
         lock();
         event_tool::instance()->handle_event(OT_AREA,ev,aid,limit_val,pc_,a->m_area->m_event_person_show_count=true,DT_SPECIAL);