Browse Source

区域时间段超员设置及功能--优化·

chensongchao 5 years ago
parent
commit
8e72fe21b8

+ 3 - 3
Makefile.am

@@ -22,13 +22,13 @@ SRC_MAIN= ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_ar
 		  landmark.cpp line_fit.cpp  message.cpp message_file.cpp mine.cpp \
 		  net-service.cpp point.cpp  special_area.cpp tdoa_sync.cpp visit.cpp \
 		  web-client.cpp worker.cpp event.cpp znet.cpp ya_setting.cpp area_business.cpp\
-		  forbid_staff_down_mine.cpp bulletin_broad_show.cpp
+		  forbid_staff_down_mine.cpp bulletin_broad_show.cpp area_persons_thre_time.cpp
 
 AM_SOURCES=$(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN) $(SRC_MAIN_EVENT)
 
-AM_CPPFLAGS=-Wall -pthread -m64 -g  -std=c++11 -I${prefix}/include -I/usr/local/mysql/include -Iwebsocket -Iwebsocket/sio -I./db  -Imodule_service
+AM_CPPFLAGS=-Wall -pthread -m64 -g -std=c++11 -I${prefix}/include -I/usr/local/mysql/include -Iwebsocket -Iwebsocket/sio -I./db  -Imodule_service
 
-AM_LDFLAGS=-Wall -pthread -m64 -g  -std=c++11  -L${prefix}/lib  -L/usr/local/mysql/lib
+AM_LDFLAGS=-Wall -pthread -m64 -g -std=c++11  -L${prefix}/lib  -L/usr/local/mysql/lib
 
 yals_SOURCES=${AM_SOURCES} main.cpp
 yals_CPPFLAGS=${AM_CPPFLAGS}

+ 34 - 110
area.cpp

@@ -12,6 +12,7 @@
 #include "monkey_car/monkeycar_area.h"
 #include "landmark.h"
 #include "area_business.h"
+#include "area_persons_thre_time.h"
 
 #include <boost/algorithm/string/split.hpp>
 #include <boost/algorithm/string/classification.hpp>
@@ -85,6 +86,8 @@ area::area(int id,int limit_count_person, int limit_time_person,double scale,int
      ,m_is_work_area(0)
     {
 		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);
     }
 void area::clear()
 {
@@ -225,114 +228,45 @@ bool area::in_area(const std::shared_ptr<site>&s,const std::shared_ptr<card_loca
     }
 }
 
-void area::add_persons_thre(const SArea_Persons_Thre & thre)
-{
-	m_area_persons_thre[thre.db_id] = thre;
-}
-void area::del_persons_thre(int thre_db_id)
-{
-	m_area_persons_thre.erase(thre_db_id);
-}
-void area::clear_persons_thre()
-{
-	m_area_persons_thre.clear();
-}
 //
 int area::get_limit_person_count()
 {
-	return get_limit_person_count(tool_time::now_to_seconds());
-}
-int area::get_limit_person_count(uint64_t cur_time)
-{
-	std::string sz_cur_time = tool_time::to_str_time(cur_time);
-	for (auto it : m_area_persons_thre)
+	int count = m_persons_thre_time->get_limit_person_count();
+	if (count != m_limit_person_count.load())
 	{
-		SArea_Persons_Thre &d = it.second;
-		if (sz_cur_time >= d.start_time && sz_cur_time <= d.end_time)
-		{
-			return d.thre_value;
-		}
+		m_limit_person_count = count;
 	}
-	return m_limit_person_count;
+	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_area_persons_thre.size() > 0;
+    return m_persons_thre_time->get_count() > 0;
 }
 
-int area::update_persons_thre()
+bool area::is_limit_person_count_check(int & limit_person_count)
 {
-	uint32_t cur_time = tool_time::now_to_seconds();
-	std::string sz_cur_time = tool_time::to_str_time(cur_time);
-	for (auto &it : m_area_persons_thre)
+	bool ret = false;
+	int count = m_persons_thre_time->get_limit_person_count();
+	if (count != m_limit_person_count.load())
 	{
-		SArea_Persons_Thre &d = it.second;
-		int t_state = d.in_time_state;
-		if (sz_cur_time < d.start_time)
-		{
-			d.in_time_state = EIN_TIME_STATE::NotYet;
-            log_info("area::update_persons_thre : Init areaid=%d db_id=%d time=%s -> %s val=%d "
-                    ,m_id,d.db_id,d.start_time.c_str(),sz_cur_time.c_str(),d.thre_value);
-        }
-		else if (sz_cur_time >= d.start_time && sz_cur_time <= d.end_time)
-		{
-            d.in_time_state = EIN_TIME_STATE::Middle;
-			if (t_state == EIN_TIME_STATE::NotYet)
-			{
-				d.check_state_time =cur_time;
-				log_info("area::update_persons_thre : areaid=%d db_id=%d time=%s -> %s val=%d state=%d -> %d"
-						,m_id,d.db_id,d.start_time.c_str(),d.end_time.c_str(),d.thre_value,t_state,d.in_time_state);
-				return d.in_time_state;
-			}
-		}
-		else
-		{
-            d.in_time_state = EIN_TIME_STATE::Overtime;
-			if (t_state == EIN_TIME_STATE::Middle)
-			{
-                d.check_state_time =cur_time;
-				log_info("area::update_persons_thre : areaid=%d db_id=%d time=%s -> %s val=%d state=%d -> %d"
-						,m_id,d.db_id,d.start_time.c_str(),d.end_time.c_str(),d.thre_value,t_state,d.in_time_state);
-
-				return d.in_time_state;
-			}
-		}
+		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;
 	}
-	return EIN_TIME_STATE::NotYet;
-}
-
-void area::init_persons_thre()
-{
-	std::string sz_cur_time = tool_time::to_str_time(tool_time::now_to_seconds());
-	for (auto &it : m_area_persons_thre)
+	limit_person_count = m_limit_person_count;
+	if(m_persons_thre_time->m_web_checkdata)
 	{
-		SArea_Persons_Thre &d = it.second;
-		if (sz_cur_time < d.start_time)
-		{
-			d.in_time_state = EIN_TIME_STATE::NotYet;
-		}
-		else if (sz_cur_time >= d.start_time && sz_cur_time <= d.end_time)
-		{
-			if (d.old_in_time_state == EIN_TIME_STATE::Middle)
-			{
-				d.in_time_state = EIN_TIME_STATE::Middle;
-			}
-		}
-		else
-		{
-			d.in_time_state = EIN_TIME_STATE::Overtime;
-			if (d.old_in_time_state == EIN_TIME_STATE::Middle)
-			{
-				d.in_time_state = EIN_TIME_STATE::Middle;
-			}
-		}
-
-		log_info("area::init_persons_thre : areaid=%d time=%s -> %s val=%d state=%d -> %d"
-				,m_id,d.start_time.c_str(),d.end_time.c_str(),d.thre_value,d.old_in_time_state,d.in_time_state);
+		ret = true;
+		m_persons_thre_time->m_web_checkdata = false;
 	}
-	log_info("area::init_persons_thre : areaid=%d count=%d",m_id,m_area_persons_thre.size());
+	return ret;
 }
 
 /////////////////// area_list //////////////////////////////////////////////////
@@ -705,37 +639,27 @@ void area_list::init_area_persons_dynamic_thre_from_db(int area_id/* = -1*/)
 		SArea_Persons_Thre td;
 		DBRes.GetField("area_id", td.area_id, Error);
 		DBRes.GetField("adpt_id", td.db_id, Error);
-		DBRes.GetField("start_time", td.start_time, Error);
-		DBRes.GetField("end_time", td.end_time, Error);
+		DBRes.GetField("start_time", td.sz_start_time, Error);
+		DBRes.GetField("end_time", td.sz_end_time, Error);
 		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)
 		{
-			if (nullptr != tmp_area )
-			{
-				tmp_area->init_persons_thre();
-			}
 			tmp_area = area_list::instance()->get(td.area_id);
 			if (nullptr == tmp_area)
 			{
 				continue;
 			}
-			map_thre = tmp_area->m_area_persons_thre;
-			tmp_area->clear_persons_thre();
+			tmp_area->m_persons_thre_time->clear_persons_thre();
 		}
-		auto iter = map_thre.find(td.db_id);
-		if (iter != map_thre.end())
-		{
-			td.old_in_time_state = iter->second.in_time_state;
-			td.check_state_time = iter->second.check_state_time;
-		}
-		tmp_area->add_persons_thre(td);
+		tmp_area->m_persons_thre_time->add_persons_thre(td);
 	}
-	if (nullptr != tmp_area )
+	if (area_id > 0 && nullptr == tmp_area && tmp_area->m_id == area_id)
 	{
-		tmp_area->init_persons_thre();
+		//标记web修改
+		tmp_area->m_persons_thre_time->m_web_checkdata = true;
 	}
-
 }
 /////////////////////////////////////////////////////////////////////
 area_hover::area_hover(const std::shared_ptr<area>&area,const point&pt)

+ 6 - 45
area.h

@@ -18,40 +18,7 @@ struct area_business;
 struct business_data;
 struct card_location_base;
 struct site;
-
-
-//区域时间段超员设置
-enum EIN_TIME_STATE
-{
-    NotYet   = 0,       //时间未到
-    Middle   = 1,       //时间过程中
-    Overtime = 2        //时间已过
-};
-
-struct SArea_Persons_Thre
-{
-    int db_id;
-    int area_id;
-    int thre_value;
-    int old_in_time_state;
-    int in_time_state;        //EIN_TIME_STATE
-    uint32_t check_state_time;//修改in_time_state时间
-    std::string start_time;
-    std::string end_time;
-
-    SArea_Persons_Thre()
-    {
-        db_id = 0;
-        area_id = 0;
-        thre_value = 0;
-        start_time = "";
-        end_time = "";
-        old_in_time_state = EIN_TIME_STATE::NotYet;
-        in_time_state = EIN_TIME_STATE::NotYet;
-    }
-};
-
-typedef std::map<int,SArea_Persons_Thre> MAP_AREA_PERSONS_THRE;
+struct area_persons_thre_time;
 
 /*
 	每个区域对应一个area对象。
@@ -139,7 +106,7 @@ public:
 
 	//人卡超时及超员数量(阀值)
     int m_limit_person_min;
-    int m_limit_person_count;
+    std::atomic<int> m_limit_person_count;
     //是否人卡超员已有告警
     bool m_event_person_count;
     bool m_event_person_show_count;
@@ -172,21 +139,15 @@ public:
 	std::vector<area_business*> m_area_business_list;
 
 	//区域时间段超员限制
-    MAP_AREA_PERSONS_THRE m_area_persons_thre;
-    void add_persons_thre(const SArea_Persons_Thre & thre);
-    void del_persons_thre(int thre_db_id);
-    void clear_persons_thre();
+    std::shared_ptr<area_persons_thre_time> m_persons_thre_time;
 
-    // 获取区域cur_time超员的阈值,区域可能有时间段限制
-    int get_limit_person_count(uint64_t cur_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();
-    // 更新区域时间段超员设置 return false:没有更新的记录
-    int update_persons_thre();
-    void init_persons_thre();
 };
 
 struct area_list:single_base<area_list,int,std::shared_ptr<area>>

+ 60 - 0
area_persons_thre_time.cpp

@@ -0,0 +1,60 @@
+//
+// Created by songchao.chen on 2019/7/4.
+//
+
+#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)
+{
+    m_web_checkdata = false;
+}
+void area_persons_thre_time::add_persons_thre(const SArea_Persons_Thre & thre)
+{
+    m_area_persons_thre[thre.db_id] = thre;
+}
+
+void area_persons_thre_time::del_persons_thre(int thre_db_id)
+{
+    m_area_persons_thre.erase(thre_db_id);
+}
+
+void area_persons_thre_time::clear_persons_thre()
+{
+    m_area_persons_thre.clear();
+}
+
+//记录数量
+int area_persons_thre_time::get_count() const
+{
+    return (int)m_area_persons_thre.size();
+}
+
+int area_persons_thre_time::get_limit_person_count(uint64_t cur_time)
+{
+    int cur_sec = tool_time::time_to_day_seconds(cur_time);
+
+    //std::string sz_cur_time = tool_time::to_str_time(cur_time);
+    for (auto it : m_area_persons_thre)
+    {
+        SArea_Persons_Thre &d = it.second;
+        /*if (sz_cur_time >= d.sz_start_time && sz_cur_time <= d.sz_end_time)
+        {
+            return d.thre_value;
+        }*/
+        if (cur_sec >= d.start_time && cur_sec <= d.end_time)
+        {
+            return d.thre_value;
+        }
+        if(d.start_time > d.end_time)  //隔天 (23:00:00 -- 02:00:00
+        {
+            if ((cur_sec >= d.start_time && cur_sec <= 3600 * 24)
+             || (cur_sec >= 0 && cur_sec <= d.end_time))
+            {
+                return d.thre_value;
+            }
+        }
+    }
+    return m_default_limit_person_limit;
+}

+ 56 - 0
area_persons_thre_time.h

@@ -0,0 +1,56 @@
+//
+// Created by songchao.chen on 2019/7/4.
+// 区域中设定时间段人员超时限制
+//
+
+#ifndef WORKSPACE_AREA_PERSONS_THRE_TIME_H
+#define WORKSPACE_AREA_PERSONS_THRE_TIME_H
+
+#include <string>
+#include <map>
+#include <atomic>
+
+struct SArea_Persons_Thre
+{
+    int db_id;
+    int area_id;
+    int thre_value;
+    std::string sz_start_time;
+    std::string sz_end_time;
+    int start_time;
+    int end_time;
+    SArea_Persons_Thre()
+    {
+        db_id = 0;
+        area_id = 0;
+        thre_value = 0;
+        start_time = 0;
+        end_time = 0;
+        sz_start_time = "";
+        sz_end_time = "";
+    }
+};
+
+typedef std::map<int,SArea_Persons_Thre> MAP_AREA_PERSONS_THRE;
+
+struct area_persons_thre_time
+{
+    area_persons_thre_time(int _limit);
+    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();
+
+    //记录数量
+    int get_count() const;
+    // 获取区域cur_time超员的阈值,区域可能有时间段限制
+    int get_limit_person_count(uint64_t cur_time = 0);
+};
+
+
+#endif //WORKSPACE_AREA_PERSONS_THRE_TIME_H

+ 110 - 54
module_service/area_business_count_checker.cpp

@@ -61,7 +61,9 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 		    a->m_area->m_person_count ++;
         if(c->m_display)
 		    a->m_area->m_person_show_count ++ ;
-        int pc=a->m_area->m_person_count.load();
+
+        _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){
@@ -75,7 +77,7 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 		    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())
 	{
@@ -90,7 +92,9 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 		    a->m_area->m_vehicle_count ++ ;
         if(c->m_display)
 		    a->m_area->m_vehicle_show_count ++ ;
-        int vc=a->m_area->m_vehicle_count.load();
+
+        _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){
@@ -104,7 +108,7 @@ void area_business_count_checker::on_enter(const std::shared_ptr<area_hover>&a,
 		    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();
 }
@@ -125,54 +129,13 @@ void area_business_count_checker::on_hover(const std::shared_ptr<area_hover>&a,
 
     if (c->is_person() && a->m_area->is_time_person_thre())
     {
-
-        int aid = a->m_area->id();
-        int in_time_state = a->m_area->update_persons_thre();
-        if (in_time_state == EIN_TIME_STATE::NotYet)
+        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->get_limit_person_count();
-        if (limit_val <= 0) {
-            log_warn("on_enter_area_id:%d,limit_person_count is 0.so should not run area_business_count_checker...",
-                     aid);
-            return;
-        }
-        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 (in_time_state == EIN_TIME_STATE::Middle)
-        {
-            //时间已到
-            if(pc>limit_val && !a->m_area->m_event_person_count){
-                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_hover_enter:%d,v_count:%d limit:%d",aid,pc,limit_val);
-            }
-            if(pc_>limit_val && !a->m_area->m_event_person_show_count){
-                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_hover_enter:%d,v_count:%d limit:%d",aid,pc_,limit_val);
-            }
-        }
-        else if(in_time_state == EIN_TIME_STATE::Overtime)
-        {
-            //时间已过
-            if(pc <= limit_val && a->m_area->m_event_person_count){
-                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_hover_leave:%d,v_count:%d limit:%d",aid,pc,limit_val);
-            }
-            if(pc_ <= limit_val && a->m_area->m_event_person_show_count){
-                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_hover_leave:%d,v_count:%d limit:%d",aid,pc_,limit_val);
-            }
-        }
+        _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");
     }
 }
 
@@ -201,9 +164,10 @@ void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
             if(flag)
 		        a->m_area->m_person_show_count -- ;
         }
-        int pc=a->m_area->m_person_count.load();
-        int pc_=a->m_area->m_person_show_count.load();
         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){
@@ -218,6 +182,7 @@ void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
             unlock();
 		    log_info("person_count_leave_show:%d,v_count:%d limit:%d",aid,pc,limit_val);
         }
+         */
 	}
 	else if (c->is_vehicle())
 	{
@@ -229,9 +194,10 @@ void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
             if(flag)
 		        a->m_area->m_vehicle_show_count -- ;
         }
-        int pc=a->m_area->m_vehicle_count.load();
-        int pc_=a->m_area->m_vehicle_show_count.load();
         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){
@@ -245,7 +211,97 @@ void area_business_count_checker::on_leave(const std::shared_ptr<area_hover>&a,
 			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);
-        }
+        }*/
 	}
 }
 
+//添加人员告警
+void area_business_count_checker::_add_person_count_event(const std::shared_ptr<area_hover>&a
+        ,int limit_val,const std::string &desc)
+{
+    int aid = a->m_area->id();
+    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("%s:%d,v_count:%d limit:%d",desc.c_str(),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("%s:%d,v_count:%d limit:%d",desc.c_str(),aid,pc_,limit_val);
+    }
+}
+//移除人员告警
+void area_business_count_checker::_remove_person_count_event(const std::shared_ptr<area_hover>&a
+        ,int limit_val,const std::string &desc)
+{
+    int aid = a->m_area->id();
+    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 && a->m_area->m_event_person_count)
+    {
+        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("%s :%d,v_count:%d limit:%d",desc.c_str(),aid,pc,limit_val);
+    }
+    if(pc_ <= limit_val && a->m_area->m_event_person_show_count)
+    {
+        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("%s :%d,v_count:%d limit:%d",desc.c_str(),aid,pc_,limit_val);
+    }
+}
+
+//添加车数量超出限制告警
+void area_business_count_checker::_add_vehicle_count_event(const std::shared_ptr<area_hover>&a
+        ,int limit_val,const std::string &desc)
+{
+    int aid = a->m_area->id();
+    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);
+    }
+}
+//移除车数量超出告警
+void area_business_count_checker::_remove_vehicle_count_event(const std::shared_ptr<area_hover>&a
+        ,int limit_val,const std::string &desc)
+{
+    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);
+    }
+}

+ 11 - 0
module_service/area_business_count_checker.h

@@ -22,6 +22,17 @@ struct area_business_count_checker:area_business
 	void on_hover(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
 	//减少计数
 	void on_leave(const std::shared_ptr<area_hover>&a,const std::shared_ptr<card_location_base>&c,std::shared_ptr<business_data> ptr);
+
+private:
+    //添加人数超出限制告警
+    void _add_person_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc);
+    //移除人数超出限制告警
+    void _remove_person_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc);
+    //添加车数量超出限制告警
+    void _add_vehicle_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc = "");
+    //移除车数量超出告警
+    void _remove_vehicle_count_event(const std::shared_ptr<area_hover>&a,int limit_val,const std::string &desc = "");
+
 private:
 	std::atomic<int> m_mutex;
 	void lock()

+ 20 - 0
tool_time.h

@@ -139,6 +139,26 @@ public:
 
         return std::string(_time);
     }
+
+    static int time_to_day_seconds(uint64_t t)
+    {
+        std::time_t _time = t;
+        if (_time == 0)
+        {
+            _time = tool_time::now_to_seconds();
+        }
+        struct tm local_time;
+        localtime_r(&_time, &local_time);
+        return local_time.tm_hour * 3600 + local_time.tm_min * 60 + local_time.tm_sec;
+    }
+    //t 格式:05:02:02
+    static int time_to_day_seconds(const std::string &t)
+    {
+        int hour = 0,min = 0,sec = 0;
+        sscanf(t.c_str(), "%d:%d:%d", &hour,&min,&sec);
+        return hour * 3600 + min * 60 + sec;
+    }
+
     static int get_hour()
     {
         time_t tt = time(0);