|
@@ -225,6 +225,117 @@ 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)
|
|
|
+ {
|
|
|
+ SArea_Persons_Thre &d = it.second;
|
|
|
+ if (sz_cur_time >= d.start_time && sz_cur_time <= d.end_time)
|
|
|
+ {
|
|
|
+ return d.thre_value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return m_limit_person_count;
|
|
|
+}
|
|
|
+
|
|
|
+// 判断区域中是否有时间段超员设定
|
|
|
+bool area::is_time_person_thre()
|
|
|
+{
|
|
|
+ return m_area_persons_thre.size() > 0;
|
|
|
+}
|
|
|
+
|
|
|
+int area::update_persons_thre()
|
|
|
+{
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ log_info("area::init_persons_thre : areaid=%d count=%d",m_id,m_area_persons_thre.size());
|
|
|
+}
|
|
|
+
|
|
|
+/////////////////// area_list //////////////////////////////////////////////////
|
|
|
area_list::area_list()
|
|
|
{
|
|
|
}
|
|
@@ -567,6 +678,66 @@ std::vector<std::shared_ptr<area>> area_list::get_area(const std::shared_ptr<sit
|
|
|
//区域覆盖不完全地图,很多车辆人行驶在地图外,如何确认.
|
|
|
return std::move(ret);
|
|
|
}
|
|
|
+// 区域时间段超员设置
|
|
|
+void area_list::init_area_persons_dynamic_thre_from_db(int area_id/* = -1*/)
|
|
|
+{
|
|
|
+ std::string sql = "SELECT area_id,adpt_id,start_time,end_time,thre_value from dat_area_persons_dynamic_thre ";
|
|
|
+ if (area_id > -1 )
|
|
|
+ {
|
|
|
+ sql.append(" where area_id=");
|
|
|
+ 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;
|
|
|
+ sDBConnPool.Query(sql.c_str(),DBRes,Error);
|
|
|
+ int nCount = DBRes.GetRecordCount( Error );
|
|
|
+ if (nCount < 1)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ MAP_AREA_PERSONS_THRE map_thre;
|
|
|
+ std::shared_ptr<area> tmp_area = nullptr;
|
|
|
+ while ( DBRes.GetNextRecod(Error) )
|
|
|
+ {
|
|
|
+ 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("thre_value", td.thre_value, Error);
|
|
|
+
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ if (nullptr != tmp_area )
|
|
|
+ {
|
|
|
+ tmp_area->init_persons_thre();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+/////////////////////////////////////////////////////////////////////
|
|
|
area_hover::area_hover(const std::shared_ptr<area>&area,const point&pt)
|
|
|
:m_area(area)
|
|
|
{
|