Browse Source

reader_error && IDSDK && common function

lixioayao 6 years ago
parent
commit
71a8aed0ad

+ 26 - 314
ant.cpp

@@ -1,10 +1,9 @@
-
 #include <stdio.h>
 #include <string.h>
 #include <math.h>
 #include "ant.h"
 #include "db_api/CDBSingletonDefine.h"
-
+#include "ya_event.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
@@ -18,333 +17,46 @@ site::site(int id)
     ,m_id(id)
     ,m_path_empty(true)
 {
-
+	m_time=time(0);
 }
 const algo_config&site::config()const
 {
 	return g_config[index()];
 }
-
-#if 0 
-static int str_split(char*s,char**rc)
-{
-	char**o=rc;
-
-	for(;*s;)
-	{
-		*o=strtok_r(s,",",&s);
-		o++;
-	}
-
-	return o-rc;
-}
-void sit_list::read_ant_path(const char*fname)
-{
-	FILE*fp=fopen(fname,"r");
-	char buf[512],*p;
-	int t,id,pid;
-	char* s[20];
-	while((p=fgets(buf,sizeof(buf),fp)))
-	{
-		t=str_split(buf,&s[0]);
-		if(t<9)
-			continue;
-
-		id=atoi(s[0]);
-		auto s_ = sit_list::instance()->get(id);
-		if(s_==nullptr)
-			continue;
-
-		pid=atoi(s[1]);
-		if(pid>2)
-          continue;
-        point p1(atof(s[2]),-atof(s[3]));
-        point p2(atof(s[5]),-atof(s[6]));
-		auto &sit_ = *s_; 
-        if(pid == 0)
-        {
-            line_v l(p1,p2);
-            {
-                point px = l.line::projection(sit_);
-                sit_.set(px);
-                for(int i=0;i<2;i++)
-                {
-                    path p;
-                    p.m_slope[0] = atof(s[8]);
-                    p.m_line[0] = line_v(px,l[i]);
-                    sit_.m_ant[i].m_path.push_back(p);
-                }
-            }
-        }
-        else 
-        {
-            ant &a = pid<0?sit_.m_ant[0]:sit_.m_ant[1];
-            if(a.m_path.size()!=0)
-            {
-                path &p = a.m_path[0];
-                p.m_line[abs(pid)-1] = line_v(p1,p2);
-                p.m_slope[abs(pid)-1] = atof(s[8]);
-            }
-            else
-            {
-                path p;
-                p.m_line[abs(pid)-1] = line_v(p1,p2);
-                p.m_slope[abs(pid)-1] = atof(s[8]);
-                a.m_path.push_back(p);
-            }
-            if(abs(pid)==1)
-				 sit_.set(p1);
-        }
-	}
-	fclose(fp);
-
-	for(auto&_s:sit_list::instance()->m_map)
-	{
-		auto & s = *(_s.second);
-		if(s.m_id==-1)
-			continue;
-        s.swap();
-		if((s.path(0).empty() && s.path(1).empty()))
-			continue;
-        s.m_path_empty=false; 
-
-        for(auto &a:s.m_ant)
-        for(auto &p:a.m_path)
-        {
-            if(!p.m_line[0].empty())
-            {
-                point px = p.m_line[0].line::projection(a);
-                p.m_line[0]=line_v(px,p.m_line[0][1]);
-            }
-        }
-        //std_info("%s",s.to_string().c_str());
-        log_info("%s",s.to_string().c_str());
-        //std_info("%f----%f",s.x,s.y);
-	}
-}
-
-//1, 101, 1, '101-1', 4727, 75, 0, 0, '2017-08-29 10:21:14'
-void sit_list::read_sit_list(const char*fname)
+bool visit_site_status::visit(std::shared_ptr<site> s)
 {
-	FILE*fp=fopen(fname,"r");
-	char buf[512];
-	int t,id;
-	char* s[20];
-	while(fgets(buf,sizeof(buf),fp))
+	time_t now = time(0);
+	int diff = now - s->m_time;
+	if(diff > READER_TIMEOUT)	
 	{
-		t=str_split(buf,&s[0]);
-		if(t<8)
-			continue;
-
-		id=atoi(s[1]);
-
-		int antid=atoi(s[2])-1;
-		if(antid>=2)
-			continue;
-		auto tmp = m_instance->get(id);
-		if(tmp==nullptr)
-			tmp = std::make_shared<site>(id);
-		tmp->m_ant[antid].set(atof(s[4]),-atof(s[5]));
-		sit_list::instance()->add(id,tmp);
-		//std_info("211111 id=%dsize = %d",id,instance()->m_map.size());
-		//m_list[id].m_id=id;
-		//m_list[id].m_ant[antid].set(atof(s[4]),-atof(s[5]));
-	}
-	
-	for(auto&sit_:sit_list::instance()->m_map)
-	{
-		auto & sit = *(sit_.second);
-		if(sit.m_id==-1)
-			continue;
-
-		if(sit.m_ant[0]==sit.m_ant[1])
+        auto ev_ptr = event_list::instance()->get_event_reader(s->m_id,ET_READER_ERROR);
+		if(!ev_ptr)
 		{
-			log_warn("%d分站天线坐标相等.",sit.m_id);
+			auto ev_ptr = event_list::create_event_reader(s->m_id,ET_READER_ERROR);
+            event_list::copy_event(s, ev_ptr);
+            ev_ptr->m_limit_value = READER_TIMEOUT;
+            ev_ptr->m_cur_value = diff;
+            //保存到数据库
+            event_list::save_event(ev_ptr);
+			event_list::instance()->add(ev_ptr->get_list_id(),ev_ptr);
+			log_info("reader_error_create: %d,diff:%d",s->m_id,diff);
 		}
-
-		sit.set( (sit.m_ant[0].x+sit.m_ant[1].x)/2,(sit.m_ant[0].y+sit.m_ant[1].y)/2);
 	}
-
-	fclose(fp);
-
-}
-#endif
-#if 0
-void sit_list::read_sit_list()
-{
-	std::unordered_map<int,std::shared_ptr<site>> map;
-	const char *sql = "SELECT antenna_id, a.reader_id, idx, a.x, a.y, a.z, a.angle \
-						FROM dat_antenna a, dat_reader r \
-						WHERE a.reader_id = r.reader_id;";
-    std::string Error;
-    YADB::CDBResultSet DBRes;
-    sDBConnPool.Query(sql,DBRes,Error);
-    uint64_t nCount = DBRes.GetRecordCount( Error );
-    if (nCount > 0)
-    {
-        log_info( "init_antenna. The record count=%ld\n", nCount );
-
-        while ( DBRes.GetNextRecod(Error) )
-        {
-            int reader_id  = 0;
-            DBRes.GetField( "reader_id",reader_id, Error );
-
-         	int idx=0;
-            DBRes.GetField( "idx",idx, Error );
-
-			int antid = idx-1;
-			if(antid >= 2)
-			  continue;
-
-            double x= 0;
-            DBRes.GetField( "x",x, Error );
-
-            double y= 0;
-            DBRes.GetField( "y",y, Error );
-
-            double z= 0;
-            DBRes.GetField( "z",z, Error );
-
-			std::shared_ptr<site> site_ptr=nullptr;
-		    auto it = map.find(reader_id);
-            if(it==map.end())
-            {
-                site_ptr = std::make_shared<site>(reader_id);
-				map.insert({reader_id,site_ptr});
-            }
-			else
-			  site_ptr=it->second;
-			site_ptr->m_ant[antid].set(x,-y);
-			log_info("reand_ant..%d,%d,%.2f,%.2f",reader_id,antid,x,y);
-        }
-    }
-	sit_list::instance()->add(map);
-	for(auto&sit_:map)
+	else
 	{
-		auto & sit = *(sit_.second);
-		if(sit.m_id==-1)
-			continue;
-
-		if(sit.m_ant[0]==sit.m_ant[1])
+        auto ev_ptr = event_list::instance()->get_event_reader(s->m_id,ET_READER_ERROR);
+        if(ev_ptr && !ev_ptr->is_end())
 		{
-			log_warn("%d分站天线坐标相等.",sit.m_id);
+			event_list::copy_event(s, ev_ptr);
+			ev_ptr->m_cur_value = diff;
+			ev_ptr->m_status = ES_END;
+            //保存到数据库
+            event_list::save_event(ev_ptr);
+			log_info("reader_error_delete: %d,diff:%d",s->m_id,diff);
 		}
-
-		sit.set( (sit.m_ant[0].x+sit.m_ant[1].x)/2,(sit.m_ant[0].y+sit.m_ant[1].y)/2);
-	}
-
-}
-void sit_list::read_ant_path()
-{
-	std::unordered_map<int,std::shared_ptr<site>> map;
-	const char *sql = "SELECT reader_id,tof_flag,b_x,b_y,b_z,e_x,e_y,e_z,spacing_ratio FROM dat_reader_path_tof_n;";
-    std::string Error;
-    YADB::CDBResultSet DBRes;
-    sDBConnPool.Query(sql,DBRes,Error);
-    uint64_t nCount = DBRes.GetRecordCount( Error );
-	if(nCount<=0)
-	   log_error("init_ant_path error :%s",Error.c_str());
-    if (nCount > 0)
-    {
-        log_info( "init_ant_path. The record count=%ld\n", nCount );
-
-        while ( DBRes.GetNextRecod(Error) )
-        {
-            int reader_id  = 0;
-            DBRes.GetField( "reader_id",reader_id, Error );
-
-			auto site_ptr=sit_list::instance()->get(reader_id);
-			if(nullptr==site_ptr)
-				continue;
-
-         	int pid=0;
-            DBRes.GetField( "tof_flag",pid, Error );
-
-            double b_x= 0;
-            DBRes.GetField( "b_x",b_x, Error );
-
-            double b_y= 0;
-            DBRes.GetField( "b_y",b_y, Error );
-
-            double b_z= 0;
-            DBRes.GetField( "b_z",b_z, Error );
-
-			double e_x= 0;
-            DBRes.GetField( "e_x",e_x, Error );
-
-            double e_y= 0;
-            DBRes.GetField( "e_y",e_y, Error );
-
-            double e_z= 0;
-            DBRes.GetField( "e_z",e_z, Error );
-
-			double spacing_ratio = 0;
-            DBRes.GetField( "spacing_ratio",spacing_ratio, Error );
-			log_info("ant_path:%d,%.2f,%.2f,%.2f,%.2f",reader_id,b_x,b_y,e_x,e_y);
-			point p1(b_x,-b_y);
-			point p2(e_x,-e_y);
-			auto &sit_ = *site_ptr;
-			if(pid == 0)
-			{
-				line_v l(p1,p2);
-				{
-					point px = l.line::projection(sit_);
-					sit_.set(px);
-					for(int i=0;i<2;i++)
-					{
-						path p;
-						p.m_slope[0] = spacing_ratio;
-						p.m_line[0] = line_v(px,l[i]);
-						sit_.m_ant[i].m_path.push_back(p);
-					}
-				}
-			}
-			else
-			{
-				ant &a = pid<0?sit_.m_ant[0]:sit_.m_ant[1];
-				if(a.m_path.size()!=0)
-				{
-					path &p = a.m_path[0];
-					p.m_line[abs(pid)-1] = line_v(p1,p2);
-					p.m_slope[abs(pid)-1] = spacing_ratio;
-				}
-				else
-				{
-					path p;
-					p.m_line[abs(pid)-1] = line_v(p1,p2);
-					p.m_slope[abs(pid)-1] = spacing_ratio;
-					a.m_path.push_back(p);
-				}
-				if(abs(pid)==1)
-					sit_.set(p1);
-			}
-        }
-    }
-	for(auto&_s:sit_list::instance()->m_map)
-	{
-		auto & s = *(_s.second);
-		if(s.m_id==-1)
-			continue;
-        s.swap();
-		if((s.path(0).empty() && s.path(1).empty()))
-			continue;
-        s.m_path_empty=false;
-
-        for(auto &a:s.m_ant)
-        for(auto &p:a.m_path)
-        {
-            if(!p.m_line[0].empty())
-            {
-                point px = p.m_line[0].line::projection(a);
-                p.m_line[0]=line_v(px,p.m_line[0][1]);
-            }
-        }
-        //std_info("%s",s.to_string().c_str());
-        log_info("%s",s.to_string().c_str());
-        //std_info("%f----%f",s.x,s.y);
 	}
+	return true;
 }
-#endif
 void sit_list::read_ant_path(int id)
 {
      std::string sql = "SELECT reader_id,tof_flag,b_x,b_y,b_z,e_x,e_y,e_z,spacing_ratio FROM dat_reader_path_tof_n";

+ 15 - 31
ant.h

@@ -12,9 +12,9 @@
 #include "line.h"
 #include "point.h"
 #include "write-copy.h"
-class client;
 #include"net-service.h"
 #include"common.h"
+class client;
 struct path
 {
     std::array<line_v,2>	m_line;
@@ -110,40 +110,36 @@ struct site:point
     int      m_algo;			//TOF:0,TDOA:1
     int      m_num_dims;	    //1维:0,2维:1,3维:2
     double  m_scale = 2.0;  // 地图比例尺
-
     point    m_position;
-    int index()const;
-    const algo_config&config()const;
-    int id()const
-    {
-        return m_id;
-    }
-    site(int id=-1);
-
     mutable double m_height=1.5;
     int m_id;
     bool m_path_empty;
     std::array<ant,2> m_ant;
-
     mutable double m_ant_dist=0;
     mutable double m_ant_dist_sum_new=0;
     mutable int m_ant_dist_cnt_new=0;
-
     ///分站位置 READER_TYPE_ID
     int m_reader_type_id = 0;
     int m_map_id = 0;
     int m_area_id = 0;
-
     /// 设备类型,分站、通信分站、交通灯等
     int m_device_type_id=0;
-
     /// 指定分站定位类型:一维定位,二维定位,三维定位
     int m_dimension=0;
-
     std::shared_ptr<client> m_clt=nullptr;
+	time_t m_time;
+
+    site(int id=-1);
+    int index()const;
+    const algo_config&config()const;
+    int id()const
+    {
+        return m_id;
+	}
     void set_client(std::shared_ptr<client>& clt)
     {
         m_clt = clt;
+		m_time=time(0);
     }
 
     std::shared_ptr<client> get_client()
@@ -318,8 +314,10 @@ struct site:point
         m_ant[1].m_path.clear();
     }
 };
-
-
+struct visit_site_status:visitor<std::shared_ptr<site>>
+{
+	bool visit(std::shared_ptr<site> s);
+};
 struct sit_list:single_base<sit_list,int,std::shared_ptr<site>>
 {
     void load()
@@ -327,28 +325,14 @@ struct sit_list:single_base<sit_list,int,std::shared_ptr<site>>
         read_sit_list(-1);
         read_ant_path(-1);
     }
-
-//    void load_from_db()
-//    {
-//        load();
-//        init_site(-1);
-//    }
-
     ///id=-1为初始化所有
     void load_from_db(int id=-1)
     {
         load();
         init_site(id);
     }
-
-//    void read_sit_list();
-//    void read_ant_path();
-    //void init_site();
-    ///id=-1为初始化所有
     void read_sit_list(int id);
-    ///id=-1为初始化所有
     void read_ant_path(int id);
-    ///id=-1为初始化所有
     void init_site(int id);
 };
 #endif

+ 0 - 5
area.cpp

@@ -293,7 +293,6 @@ void area_list::init_from_db(int id/*=-1*/)
         sql.append(std::to_string(id));
         sql.append(";");
 
-        std_debug("基础数据 增加或修改区域 sql=%s", sql.c_str());
         log_info("基础数据 增加或修改区域 sql=%s", sql.c_str());
     }
 
@@ -381,10 +380,6 @@ void area_list::init_from_db(int id/*=-1*/)
                      ,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);
-            std_debug("基础数据 增加或修改区域成功:区域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);
         }
     }
 

+ 5 - 5
autom4te.cache/requests

@@ -81,8 +81,8 @@
                         'configure.ac'
                       ],
                       {
-                        'AM_PROG_F77_C_O' => 1,
                         '_LT_AC_TAGCONFIG' => 1,
+                        'AM_PROG_F77_C_O' => 1,
                         'm4_pattern_forbid' => 1,
                         'AC_CANONICAL_TARGET' => 1,
                         'AC_CONFIG_LIBOBJ_DIR' => 1,
@@ -149,10 +149,10 @@
                         'AC_FC_PP_SRCEXT' => 1,
                         'AH_OUTPUT' => 1,
                         'AM_PROG_CC_C_O' => 1,
-                        'AC_FUNC_MKTIME' => 1,
-                        'AM_CONDITIONAL' => 1,
-                        'AC_CANONICAL_SYSTEM' => 1,
                         'AM_XGETTEXT_OPTION' => 1,
+                        'AC_CANONICAL_SYSTEM' => 1,
+                        'AM_CONDITIONAL' => 1,
+                        'AC_FUNC_MKTIME' => 1,
                         'AC_CONFIG_HEADERS' => 1,
                         'AC_TYPE_UINT16_T' => 1,
                         'AM_POT_TOOLS' => 1,
@@ -226,8 +226,8 @@
                         'AC_CONFIG_MACRO_DIR_TRACE' => 1,
                         'AM_SET_DEPDIR' => 1,
                         '_AM_DEPENDENCIES' => 1,
-                        'AM_PROG_INSTALL_SH' => 1,
                         'm4_include' => 1,
+                        'AM_PROG_INSTALL_SH' => 1,
                         '_AC_AM_CONFIG_HEADER_HOOK' => 1,
                         'AU_DEFUN' => 1,
                         'AM_MAKE_INCLUDE' => 1

+ 68 - 185
card.cpp

@@ -203,19 +203,16 @@ struct person:card_location_base, card_area
 {
 	std::weak_ptr<monkey_person> m_monkeyPerson;
 	int m_workLine=0;
-	person(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid,int wl)
+	time_t m_iris_recognition_timeval=0;
+	std::string m_stafferName,m_deptName;
+	person(std::string type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid,int wl,std::string sname,std::string dname)
         :card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
-		 ,m_workLine(wl)
+		 ,m_workLine(wl),m_iris_recognition_timeval(0),m_stafferName(sname),m_deptName(dname)
 	{
         m_message_handle.reset(new card_message_handle(this));
 		m_his_location_card.reset(new location_staff(m_id,m_type));
 	}
 
-	void on_message(zloop<task*> * loop,const message_locinfo&loc,bool is_history)
-	{
-		m_message_handle->on_message(loop,loc,is_history);
-	}
-
     void clear()
     {
         //m_site_area.reset(new site_area_hover);
@@ -228,11 +225,35 @@ struct person:card_location_base, card_area
 	virtual void site_hover(int sid)
 	{
         if(m_time<=0)
-        {
             return;
-        }
-		log_info("__thread_id site_hover:%d,%x  [%x]",m_id,std::this_thread::get_id(),m_site_area.get());
         m_site_area->on_point(m_id,sid,nullptr, m_type);
+		IKSDK_DB(sid);
+	}
+	//虹膜识别入库功能	
+	void IKSDK_DB(int sid)
+	{
+		auto sit_ptr = sit_list::instance()->get(sid);
+		if(nullptr == sit_ptr)
+		  return;
+		if(sit_ptr->m_reader_type_id == READER_TYPE_ID_UP)
+		{
+			time_t now = time(0);
+			if(now - m_iris_recognition_timeval > 5)
+			{
+				int f=0;
+				if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_LOW_POWER_SERIOUS))
+				  f=1;
+				std::string card_id = tool_other::type_id_to_str(m_type,m_id);
+				std::string st	    = tool_time::to_str(now);
+				char nsql[256]={0};
+				const char*sql="REPLACE INTO his_att_interface (staff_id,card_id,reader_id,staff_name,dept_name,upt_time,low_power_warn) VALUES (%d,%s,%d,'%s','%s','%s',%d);";
+				snprintf(nsql,256,sql,m_cid,card_id.c_str(),sid,m_stafferName.c_str(),m_deptName.c_str(),st.c_str(),f);
+				tool_db::PushAsync(nsql);
+				log_info("%s",nsql);
+				logn_info(2,"%s",nsql);
+				m_iris_recognition_timeval = now;
+			}
+		}
 	}
 
     virtual std::shared_ptr<area_hover> get_area_hover()
@@ -340,9 +361,7 @@ struct car:card_location_base,card_area
 	virtual void site_hover(int sid)
 	{
         if(m_time<=0)
-        {
             return;
-        }
         m_site_area->on_point(m_id,sid,0, m_type);
 	}
 
@@ -451,17 +470,14 @@ private:
 
 loc_tool_main one_ct_message_handle::m_loc_tool;
 
-uint64_t card_list::getId(uint32_t cardid,uint64_t type)
-{
-	return type<<32|cardid;
-}
-
 void card_list::init_staffer(int64_t id64)
 {
-    std::string strategy = config.get("person.strategy","person1");
-    std::string sql = "SELECT staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
-            ol.occupation_level_id,s.worktype_id,s.need_display,s.work_line\
+    std::string strategy = config.get("person.strategy","PS_1");
+    std::string sql = "SELECT s.staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
+            ol.occupation_level_id,s.worktype_id,s.need_display,s.work_line,ds.name as staffer_name,dd.name as dept_name\
             FROM dat_staff_extend s \
+			LEFT JOIN dat_staff ds ON ds.staff_id = s.staff_id \
+			LEFT JOIN dat_dept dd ON dd.dept_id = s.dept_id \
             LEFT JOIN dat_card c ON s.card_id = c.card_id \
             LEFT JOIN dat_occupation o ON s.occupation_id = o.occupation_id \
             LEFT JOIN dat_occupation_level ol ON ol.occupation_level_id = o.occupation_level_id \
@@ -523,21 +539,26 @@ void card_list::init_staffer(int64_t id64)
 		
         int work_line = 0;
         DBRes.GetField( "work_line",work_line, Error );
-        //for now;
-        //staff_id = vsid;
+		
+		std::string staffer_name;
+        DBRes.GetField( "staffer_name",staffer_name, Error );
+
+		std::string dept_name;
+        DBRes.GetField( "dept_name",dept_name, Error );
+
 
         if(-1 == id64)
         {
             std::shared_ptr<card_location_base> clb =
-                    std::make_shared<person>(strategy,vsid,need_display,card_type_id,dept_id,occupation_level_id,staff_id,work_line);
-            uint64_t cardid = getId(vsid,card_type_id);
-            log_info("cardId:%llu,id:%d dept_id:%d,need_display:%d,card:%s:work_line:%d,staff_id:%d,type:%d",
-                     cardid,vsid,dept_id,need_display,card_id.c_str(),work_line,staff_id,card_type_id);
+                    std::make_shared<person>(strategy,vsid,need_display,card_type_id,dept_id,occupation_level_id,staff_id,work_line,staffer_name,dept_name);
+            uint64_t cardid = tool_other::type_id_to_u64(vsid,card_type_id);
+            log_info("cardId:%llu,id:%d dept_id:%d,need_display:%d,card:%s:work_line:%d,staff_id:%d,type:%d,staffer_name:%s,dept_name:%s",
+                     cardid,vsid,dept_id,need_display,card_id.c_str(),work_line,staff_id,card_type_id,staffer_name.c_str(),dept_name.c_str());
             map.insert({cardid,clb});
         }
         else
         {
-            auto card_id64 = card_list::to_id64(card_type_id, tool_other::id64_to_id(card_id));
+            auto card_id64 = tool_other::type_id_to_u64(card_type_id, tool_other::id64_to_id(card_id));
             auto card_ptr = card_list::instance()->get(card_id64);
             if(card_ptr)
             {
@@ -551,7 +572,7 @@ void card_list::init_staffer(int64_t id64)
             }
             else
             {
-                auto clb = std::make_shared<person>(strategy,vsid,need_display,card_type_id,dept_id,occupation_level_id,staff_id,work_line);
+                auto clb = std::make_shared<person>(strategy,vsid,need_display,card_type_id,dept_id,occupation_level_id,staff_id,work_line,staffer_name,dept_name);
                 card_list::instance()->add(card_id64, clb);
             }
 
@@ -571,7 +592,6 @@ void card_list::init_staffer(int64_t id64)
 
 void card_list::init_vehicle(int64_t id64)
 {
-    std::string strategy = config.get("car.strategy","car1");
     std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
                         ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
                         vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
@@ -650,7 +670,15 @@ void card_list::init_vehicle(int64_t id64)
 
         double over_speed= 0;
         DBRes.GetField( "over_speed",over_speed, Error );
-
+		std::string strategy;	
+		if(card_type_id == CT_VEHICLE)
+		{
+			strategy = config.get("car.strategy","CS_1");
+		}
+		else if(card_type_id == CT_COAL_CUTTER || CT_HEADING_MACHINE == card_type_id)
+		{
+			strategy = config.get("coal_wining.strategy","WS_1");
+		}
         //for now
         //vehicle_id = vsid;
 
@@ -658,14 +686,14 @@ void card_list::init_vehicle(int64_t id64)
         {
             auto clb = std::make_shared<car>(strategy,vsid,need_display,card_type_id,
                                              dept_id,vehicle_category_id, vehicle_type_id,vehicle_level_id,vehicle_id);
-            uint64_t cardid = getId(vsid,card_type_id);
+            uint64_t cardid = tool_other::type_id_to_u64(vsid,card_type_id);
             log_info("cardId:%llu,id:%d dept_id:%d,need_display:%d-cardid:%s,categoryid:%d,vchile_id:%d,type:%d",
                      cardid,vsid,dept_id,need_display,card_id.c_str(),vehicle_category_id,vehicle_id,card_type_id);
             map.insert({cardid,clb});
         }
         else
         {
-            auto card_id64 = card_list::to_id64(card_type_id, tool_other::id64_to_id(card_id));
+            auto card_id64 = tool_other::type_id_to_u64(card_type_id, tool_other::id64_to_id(card_id));
             auto card_ptr = card_list::instance()->get(card_id64);
             if(card_ptr)
             {
@@ -694,147 +722,9 @@ void card_list::init_vehicle(int64_t id64)
     {
         log_info( "init_vehicle. The record count=%d\n", nCount );
         card_list::instance()->add(map);
-    }
-}
-#if 0
-void card_list::init_vehicle()
-{
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
-	std::string strategy = config.get("car.strategy","car1");
-	const char *sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
-						ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
-						vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
-						vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
-						FROM dat_vehicle_extend ve \
-						LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
-						LEFT JOIN dat_card c ON ve.card_id = c.card_id \
-						LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
-						LEFT JOIN dat_group g ON ve.group_id = g.group_id \
-						LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
-						LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
-						WHERE c.card_type_id = 2 AND c.state_id = 0;";
-	std::string Error;
-	YADB::CDBResultSet DBRes;
-	sDBConnPool.Query(sql,DBRes,Error);
-	int nCount = DBRes.GetRecordCount( Error );
-	if (nCount > 0)
-	{
         log_info( "init_vehicle. The record count=%d\n", nCount );
-
-		while ( DBRes.GetNextRecod(Error) )
-		{
-			unsigned int vehicle_id  = 0;
-			DBRes.GetField( "vehicle_id",vehicle_id, Error );
-
-			std::string card_id;
-			DBRes.GetField( "card_id",card_id, Error );
-
-			uint32_t vsid = atoi(card_id.substr(3).c_str());
-  		
-			unsigned int card_type_id  = 0;
-			DBRes.GetField( "card_type_id",card_type_id, Error );
-
-			int dept_id = 0;
-			DBRes.GetField( "dept_id",dept_id, Error );
-
-			int group_id = 0;
-			DBRes.GetField( "group_id",group_id, Error );
-
-			int vehicle_type_id = 0;
-			DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
-
-			int vehicle_level_id = 0;
-			DBRes.GetField( "vehicle_level_id",vehicle_level_id, Error );
-
-			int need_display = 0;
-			DBRes.GetField( "need_display",need_display, Error );
-
-			int power_alarm = 0;
-			DBRes.GetField( "power_alarm",power_alarm, Error );
-
-			int vehicle_category_id = 0;
-			DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
-
-			int bigger_car_flag= 0;
-			DBRes.GetField( "bigger_car_flag",bigger_car_flag, Error );
-
-			double over_speed= 0;
-			DBRes.GetField( "over_speed",over_speed, Error );
-  		
-			//for now
-			vehicle_id = vsid;
-
-            std::shared_ptr<card_location_base> clb = std::make_shared<car>(strategy,vehicle_id,
-                  need_display,card_type_id,dept_id,vehicle_category_id, vehicle_type_id,vehicle_level_id);
-			uint64_t cardid = getId(vehicle_id,2);
-			log_info("cardId:%llu,vehicle_id:%d dept_id:%d,need_display:%d---cardid:%s,categoryid:%d",cardid,vehicle_id,dept_id,need_display,card_id.c_str(),vehicle_category_id);
-			map.insert({cardid,clb});
-		}
-	}
-  
-	card_list::instance()->add(map);
-}
-
-void card_list::init_staffer()
-{
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
-	std::string strategy = config.get("person.strategy","person1");
-	const char *sql = "SELECT staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
-						ol.occupation_level_id,s.worktype_id,s.need_display \
-						FROM dat_staff_extend s \
-						LEFT JOIN dat_card c ON s.card_id = c.card_id \
-						LEFT JOIN dat_occupation o ON s.occupation_id = o.occupation_id \
-						LEFT JOIN dat_occupation_level ol ON ol.occupation_level_id = o.occupation_level_id \
-						WHERE c.card_type_id = 1 AND s.duty_id = 0 AND c.state_id = 0;";
-	std::string Error;
-	YADB::CDBResultSet DBRes;
-	sDBConnPool.Query(sql,DBRes,Error);
-	int nCount = DBRes.GetRecordCount( Error );
-	if (nCount > 0)
-	{
-		log_info( "init_staffer. The record count=%d\n", nCount );
-
-		while ( DBRes.GetNextRecod(Error) )
-		{
-			unsigned int staff_id  = 0;
-			DBRes.GetField( "staff_id",staff_id, Error );
-
-			std::string card_id;
-			DBRes.GetField( "card_id",card_id, Error );
-
-			uint32_t vsid = atoi(card_id.substr(3).c_str());
-  		
-			unsigned int card_type_id  = 0;
-			DBRes.GetField( "card_type_id",card_type_id, Error );
-  		
-			int dept_id = 0;
-			DBRes.GetField( "dept_id",dept_id, Error );
-
-			int group_id = 0;
-			DBRes.GetField( "group_id",group_id, Error );
-
-			int occupation_id = 0;
-			DBRes.GetField( "occupation_id",occupation_id, Error );
-
-			int occupation_level_id = 0;
-			DBRes.GetField( "occupation_level_id",occupation_level_id, Error );
-
-			int need_display = 0;
-			DBRes.GetField( "need_display",need_display, Error );
-
-			//for now;
-			staff_id = vsid;
-
-			std::shared_ptr<card_location_base> clb = std::make_shared<person>(strategy,staff_id,need_display,card_type_id,dept_id,occupation_level_id);
-			uint64_t cardid = getId(staff_id,1);
-			log_info("cardId:%llu,staff_id:%d dept_id:%d,need_display:%d--c-ard:%s",cardid,staff_id,dept_id,need_display,card_id.c_str());
-			map.insert({cardid,clb});
-		}
-	}
-  
-	card_list::instance()->add(map);
+    }
 }
-#endif
 void card_list::init_card_from_db()
 {
     init_staffer(-1);
@@ -905,7 +795,7 @@ void card_list::load_his_card_postion_vehicle()
             uint32_t id = tool_other::id64_to_id(card_id);
             int type = tool_other::id64_to_type(card_id);
 
-            auto temp_ptr = card_list::instance()->get(card_list::to_id64(type, id));
+            auto temp_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
             if(!temp_ptr || !temp_ptr->is_vehicle())
             {
                 log_error("全局卡列表中找不到卡,卡id=%d,卡type=%d", id, type);
@@ -1027,7 +917,7 @@ void card_list::load_his_card_postion_staff()
             uint32_t id = tool_other::id64_to_id(card_id);
             int type = tool_other::id64_to_type(card_id);
 
-            auto temp_ptr = card_list::instance()->get(card_list::to_id64(type, id));
+            auto temp_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
             if(!temp_ptr || !temp_ptr->is_person())
             {
                 log_error("全局卡列表中找不到卡,卡id=%d,卡type=%d", id, type);
@@ -1115,8 +1005,8 @@ void card_list::load_his_card_postion_staff()
 void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history)
 {
 	//std::shared_ptr<card_location_base>c=get(loc.m_card_id);
-	uint64_t cardid = getId(loc.m_card_id,loc.m_card_type);
-	const auto c=get(cardid);
+	uint64_t cardid = tool_other::type_id_to_u64(loc.m_card_id,loc.m_card_type);
+	const auto c=card_list::instance()->get(cardid);
 	if(c==nullptr)
 	{
 		log_warn("数据库中未定义该卡的信息,card_id=%d", loc.m_card_id);
@@ -1136,13 +1026,6 @@ struct local_visit:visitor<std::shared_ptr<card_location_base>>
 	}
 };
 
-// TODO : 停止进程
-void card_list::onStopRun()
-{
-    card_list::instance()->m_bflag = true; 
-    card_list::instance()->m_pThread->join();
-}
-
 void card_list::onTimer()
 {
 	local_visit lv;
@@ -1177,9 +1060,9 @@ void card_location_base::on_location(const std::vector<point>&vp,const std::vect
 		x = pt.x;
 		y = pt.y;
 
-		//Msg m;
-		//m.type=m_type;m.x=(int)x;m.y=(int)y;m.cmd=CMD_HANDLE;m.cardid=m_type<<32|m_id;
-		//cardMgr::instance()->tryPut(m);
+		Msg m;
+		m.type=m_type;m.x=(int)x;m.y=(int)y;m.cmd=CMD_HANDLE;m.cardid=m_type<<32|m_id;
+		cardMgr::instance()->tryPut(m);
 		double acc = lm[0].m_acc;
 		log_info("useful:card_id:%d,ct:%d,timestamp:%llu, loc_point,x:%.2f,y:%.2f acc:%.2f",m_id,m_ct,m_time,pt.x,pt.y,acc);
 		do_business(pt,acc);

+ 2 - 29
card.h

@@ -40,7 +40,7 @@ struct card:point
 	uint64_t time_(){return m_time;}
 	uint32_t m_id;				//卡号
 	uint32_t m_cid;				//标识id 人staff_id 车 vehicle_id
-	uint64_t  m_type;			//类型
+	uint64_t m_type;			//类型
 	uint16_t m_display;			//1显示0不显示,往前端推送
 	double   m_speed;			//速度
 	int      m_is_attendance;	//井上井下状态  0初始状态 1 井上 2 井下
@@ -56,14 +56,11 @@ struct card_location_base:card
     std::unique_ptr<smooth_tool> m_smo_tool;
 	std::unique_ptr<card_message_handle> m_message_handle;
 	std::unique_ptr<location_card> m_his_location_card;
-  //  ev::dynamic_loop * m_loop = nullptr;
- //   ev::timer m_timer;
 
     card_location_base()=default;
     card_location_base(std::string type,uint32_t id,uint16_t dis,int16_t t,int32_t,int32_t,uint32_t );
 
 	virtual void do_business(const point &pt,double acc)=0;
-//	virtual void set(ev::dynamic_loop * loop)=0;
 	virtual void on_timer()=0;
 	virtual void site_hover(int sid)=0;
     virtual std::shared_ptr<area_hover> get_area_hover()=0;
@@ -93,11 +90,7 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
 {
     ///id64=-1为初始化所有卡, id格式为:10000001016
     void init_staffer(int64_t id64);
-    ///id64=-1为初始化所有卡, id格式为:10000001016
     void init_vehicle(int64_t id64);
-    //void init_staffer();
-    //void init_vehicle();
-    uint64_t getId(uint32_t cardid,uint64_t);
     void on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history);
     void init_card_from_db();
 
@@ -106,33 +99,13 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
     void load_his_card_postion_from_db();
 
 	std::unique_ptr<std::thread> m_pThread;
+
 	bool m_bflag=false;
 	void run()
 	{
 		m_pThread.reset(new std::thread(std::bind(&card_list::onTimer,this)));
 	}
-	// TODO : 停止进程
-	void onStopRun(); 
-	
 	void onTimer();
-    /// (类型<<32)|卡号
-	//公用函数最好不要使用成员函数,改成公共函数。
-    static uint64_t to_id64(int32_t type, uint32_t id)
-    {
-        return (static_cast<uint64_t>(type)<<32)|id;
-    }
-
-    static std::string to_id64_str(int32_t type, uint32_t id)
-    {
-        char sql[15] = {'\0'};
-        sprintf(sql, "%03d%010d", type, id);
-
-        return std::string(sql);
-    }
-
     ~card_list(){m_bflag=true;}
 };
-
 #endif
-
-

+ 1 - 0
common.h

@@ -3,6 +3,7 @@
 
 #define LENGTH_SQL 2000
 #define SPEED_COUNT_LIMIT 5
+#define READER_TIMEOUT 20
 
 /**
  * @brief 分站位置 1井上,2井下

+ 12 - 3
common_tool.h

@@ -146,7 +146,7 @@ class tool_other
 public:
     static void send_json(const std::string& cmd, const std::string& data)
     {
-        log_info("发送json: cmd=%s, data=%s\n", cmd.c_str(), data.c_str());
+        //log_info("发送json: cmd=%s, data=%s\n", cmd.c_str(), data.c_str());
         swsClientMgr.send(cmd, data);
     }
 
@@ -173,7 +173,16 @@ public:
     {
         return std::stoi(to13str(str).substr(0, 3));
     }
-
+	static std::string type_id_to_str(int32_t type,uint32_t id)  
+	{
+        char sql[15] = {0};
+        snprintf(sql, 15,"%03d%010d", type, id);
+        return std::string(sql);
+	}
+	static uint64_t type_id_to_u64(uint64_t type,uint32_t id)
+	{
+		return type<<32|id;
+	}
     static bool is_person(int32_t type)
     {
         return CT_PERSON == type;
@@ -243,7 +252,7 @@ public:
         }
 
         sprintf(sql, "CALL %s(%s, %d, '%s', '%s', %d, %d, %.3f);", call.c_str(),
-                card_list::to_id64_str(card_ptr->m_type, card_ptr->m_id).c_str(),
+                tool_other::type_id_to_str(card_ptr->m_type, card_ptr->m_id).c_str(),
                 card_ptr->m_id, start_str.c_str(), end_str.c_str(),
                 landmarkid, landmarkdirect, landmarkdist);
 

+ 4 - 4
main.cpp

@@ -51,12 +51,13 @@ struct Init_Setting
 
         card_list::instance()->init_card_from_db();
 
+        std_info("here....");
         area_list::instance()->init_from_db();
         std_info("here....");
         //test
-        //point pt(3348,100);
-        //int id = area_list::instance()->get_area(pt)->id();
-        //std_info("test area:%d",id);
+        point pt(3348,100);
+        int id = area_list::instance()->get_area(pt)->id();
+        std_info("test area:%d",id);
 
         Landmark_list::instance()->init_from_db();
         //auto a = Landmark_list::instance()->get(5,id,pt);
@@ -186,7 +187,6 @@ int main(int argc ,char * argv[])
     service_handle::instance(&mh)->run(port);
     
     sDBConnPool.Close();
-    card_list::instance()->onStopRun();
 
     sleep(1);
     printf("YA-SERV Server Exit ...\n");

+ 6 - 6
mine.h

@@ -13,12 +13,12 @@
 #include "common.h"
 struct mine_tool
 {
-    mine_tool():
-        m_over_speed_count(0)
-      ,m_normal_speed_count(0)
-      ,m_status_call(0)
-      ,m_stat_attendance(AS_INIT)
-      ,m_attendance_start_time(std::chrono::seconds(0))
+    mine_tool()
+		:m_over_speed_count(0)
+		,m_normal_speed_count(0)
+		,m_status_call(0)
+		,m_stat_attendance(AS_INIT)
+		,m_attendance_start_time(std::chrono::seconds(0))
     {
 
     }

+ 5 - 5
module_service/module_area.h

@@ -33,7 +33,7 @@ public:
             return;
         }
 
-        auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
+        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
         if(!card_ptr)
         {
             log_error("卡不存在card_id=%d", card_id);
@@ -71,7 +71,7 @@ public:
             return;
         }
 
-        auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
+        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
         if(!card_ptr)
         {
             log_error("卡不存在card_id=%d", card_id);
@@ -101,7 +101,7 @@ public:
             return;
         }
 
-        auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
+        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
         if(!card_ptr)
         {
             log_error("卡不存在card_id=%d", card_id);
@@ -142,7 +142,7 @@ public:
         std::string start_str = tool_time::to_str_ex(static_cast<uint64_t>(area_hover_ptr->m_enter_time) *1000);
 
         sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
-                card_list::to_id64_str(card_ptr->m_type, card_ptr->m_id).c_str(),
+                tool_other::type_id_to_str(card_ptr->m_type, card_ptr->m_id).c_str(),
                 card_ptr->m_id, area_hover_ptr->id(), area_hover_ptr->mapid(), start_str.c_str(), start_str.c_str());
 
         tool_db::PushAsync(sql);
@@ -165,7 +165,7 @@ public:
         std::string end_str = tool_time::to_str_ex(tool_time::now_to_ms());
 
         sprintf(sql, "CALL %s(%s, %d, %d, %d, '%s','%s');", call.c_str(),
-                card_list::to_id64_str(card_ptr->m_type, card_ptr->m_id).c_str(),
+                tool_other::type_id_to_str(card_ptr->m_type, card_ptr->m_id).c_str(),
                 card_ptr->m_id, area_hover_ptr->id(), area_hover_ptr->mapid(), start_str.c_str(), end_str.c_str());
 
         tool_db::PushAsync(sql);

+ 2 - 2
module_service/module_attendance_person.h

@@ -152,7 +152,7 @@ public:
             }
 
             uint32_t id = tool_other::id64_to_id(s_card_id);
-            auto card_ptr = card_list::instance()->get(card_list::to_id64(type, id));
+            auto card_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
             if(card_ptr && card_ptr->is_person())
             {
                 std_debug("手工升井,处理,卡id=%d,卡type=%d", id, type);
@@ -209,7 +209,7 @@ private:
 
         rapidjson::Value data(rapidjson::kArrayType);
         //卡号
-        std::string id = card_list::to_id64_str(card_ptr->m_type, card_ptr->m_id);
+        std::string id = tool_other::type_id_to_str(card_ptr->m_type, card_ptr->m_id);
         tool_json::push_back(data, id, allocator);
 
         //x,y坐标

+ 2 - 2
module_service/module_call.h

@@ -104,12 +104,12 @@ private:
 
         uint64_t to_id64()
         {
-            return card_list::to_id64(cardtype, cardid);
+            return tool_other::type_id_to_u64(cardtype, cardid);
         }
 
         std::string to_id64_str()
         {
-            return card_list::to_id64_str(cardtype, cardid);
+            return tool_other::type_id_to_str(cardtype, cardid);
         }
 
         bool is_timeout()

+ 1 - 1
module_service/module_call_help.h

@@ -70,7 +70,7 @@ public:
         uint32_t id = tool_other::id64_to_id(s_card_id);
         int type = tool_other::id64_to_type(s_card_id);
 
-        auto card_ptr = card_list::instance()->get(card_list::to_id64(type, id));
+        auto card_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
         if(card_ptr)
         {
             log_info("处理呼救,card_id=%d, type=%d,  ev_id=%d", id, type, ev_id);

+ 1 - 1
module_service/module_meta_date_changed.cpp

@@ -177,7 +177,7 @@ void module_meta_date_changed::init_setting()
 
 void module_meta_date_changed::remove_card(uint32_t id, int32_t type)
 {
-    uint64_t card_id = card_list::to_id64(type, id);
+    uint64_t card_id = tool_other::type_id_to_u64(type, id);
     auto card_ptr = card_list::instance()->get(card_id);
     if(!card_ptr)
     {

+ 2 - 2
module_service/module_mgr.h

@@ -59,7 +59,7 @@ public:
 
     static void do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
     {
-        auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
+        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
         if(!card_ptr)
         {
             log_error("卡不存在card_id=%d", card_id);
@@ -109,7 +109,7 @@ public:
 //                    uint32_t id = tool_other::id64_to_id(card_id);
 //                    int32_t type = tool_other::id64_to_type(card_id);
 
-//                    auto card_ptr = card_list::instance()->get(card_list::to_id64(type, id));
+//                    auto card_ptr = card_list::instance()->get(tool_other::type_id_to_u64(type, id));
 //                    if(card_ptr)
 //                    {
 //                        std::string start_time;

+ 1 - 1
module_service/module_mine.h

@@ -20,7 +20,7 @@ private:
 public:
     static void on_point(uint32_t card_id,int32_t type, int vehicle_category_id)
     {
-        auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
+        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
         if(!card_ptr)
         {
             log_error("卡不存在card_id=%d", card_id);

+ 2 - 2
module_service/module_site.h

@@ -31,7 +31,7 @@ public:
      */
     static void enter_site(uint32_t card_id,int enter_site,int32_t type)
     {
-        auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
+        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
         if(!card_ptr)
         {
             log_error("卡不存在card_id=%ld, type=%ld", card_id, type);
@@ -63,7 +63,7 @@ public:
      */
     static void leave_site(uint32_t card_id,int enter_site, int32_t type)
     {
-        auto card_ptr=card_list::instance()->get(card_list::to_id64(type, card_id));
+        auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
         if(!card_ptr)
         {
             log_error("卡不存在card_id=%ld, type=%ld", card_id, type);

+ 6 - 2
net-service.cpp

@@ -29,9 +29,13 @@ net_service::~net_service()
 		m_loc_worker->stop();
 }
 
+void net_service::on_timer()
+{
+	visit_site_status vss;
+	sit_list::instance()->accept(vss);
+}
 void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t len)
 {
-	//clt->send(std::move(v));
 	logn_bin(1,"",data,len);//输出二进制日志
 
 	zistream is(data,len-2);
@@ -43,7 +47,7 @@ void net_service::on_message(std::shared_ptr<client> clt,const char*data,size_t
 			{
 				uint32_t site_id;
 				is>>site_id>>skip(12);
-               auto site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
+                auto site_ptr = sit_list::instance()->get(static_cast<int32_t>(site_id));
                 if(!site_ptr)
                 {
                     log_error("在全局分站列表中找不到分站:分站id=%d", site_id);

+ 1 - 0
net-service.h

@@ -15,6 +15,7 @@ struct net_service:service_callback
 	net_service();
 	~net_service();
 	void on_message(std::shared_ptr<client> clt,const char*data,size_t len);
+	void on_timer();
 };
 
 #endif

+ 8 - 6
select_tool.h

@@ -1141,25 +1141,27 @@ struct select_tool_manage
 {
    void create_tool(const std::string &s,std::unique_ptr <select_tool> &set,std::unique_ptr <smooth_tool> &smt)
    {
-        if(!s.compare(std::string{"person1"}))
+        if(!s.compare(std::string{"PS_1"}))
         {
 			set.reset(new select_tool_person_1());
 			smt.reset(new smooth_tool_person_1(set));
         }
-        else if(!s.compare(std::string{"person2"}))
+        else if(!s.compare(std::string{"PS_2"}))
         {
 			set.reset(new select_tool_person_2());
 			smt.reset(new smooth_tool_person_1(set));
         }
-        else if(!s.compare(std::string{"car1"}))
+        else if(!s.compare(std::string{"CS_1"}))
         {
 			set.reset(new select_tool_car_1());
 			smt.reset(new smooth_tool_car_1(set));
         }
-        else if(!s.compare(std::string{"drivingface1"}))
+        else if(!s.compare(std::string{"WS_1"}))
         {
-			set.reset(new select_tool_drivingface_car_1());
-			smt.reset(new smooth_tool_drivingface_car_1(set));
+			set.reset(new select_tool_person_1());
+			smt.reset(new smooth_tool_person_1(set));
+			//set.reset(new select_tool_drivingface_car_1());
+			//smt.reset(new smooth_tool_drivingface_car_1(set));
         }
    }
    static select_tool_manage * instance();

+ 3 - 3
site_area.cpp

@@ -19,7 +19,10 @@ void site_area_hover::on_point(uint32_t card_id,int site_id,const point*pt,int32
 	else
 	{
 		if(m_site_id==site_id) 
+		{
+			m_last_time=time(0);
 			return;
+		}
         int last_id = m_site_id;
         m_site_id = site_id;
 
@@ -32,7 +35,6 @@ void site_area_hover::on_point(uint32_t card_id,int site_id,const point*pt,int32
         //m_site_id=site_id;
         m_enter_time=m_last_time=time(nullptr);
 
-		log_info("---thread_id onpoint:%d,%x",card_id,std::this_thread::get_id());
         m_enter_point.set(0,0);
         m_last_point.set(0,0);
 	}
@@ -47,5 +49,3 @@ void site_area_hover::leave_site(uint32_t card_id,int enter_site,int32_t type)
 {
     module_site::leave_site(card_id, enter_site, type);
 }
-
-

+ 1 - 4
write-copy.h

@@ -5,7 +5,6 @@
 #include <algorithm>
 #include <memory>
 #include <mutex>
-
 #include "visit.h"
 
 template<typename T,typename K,typename V> 
@@ -21,9 +20,7 @@ struct write_copy_base:acceptor<V>
 
 	std::unordered_map<K,V> m_map;
 	write_copy_base()
-	{
-	
-	}
+	{}
 
 	V get(K k)const
 	{

+ 21 - 2
ya_event.h

@@ -32,7 +32,7 @@ enum EVENT_STATUS
 enum EVENT_TYPE{ // 事件类型
     ET_AREA_OVER_COUNT_PERSON = 3,	// 区域人员超员
     ET_AREA_OVER_COUNT_VEHICLE = 4,	// 区域车辆超员
-
+	ET_READER_ERROR = 6,
     ET_CARD_LOW_POWER_SERIOUS = 12, // 电量极低
 
     ET_CARD_AREA_OVER_TIME_PERSON = 15, // 人员区域超时
@@ -154,6 +154,10 @@ public:
         return create_event(OT_AREA, area_id, 0, ev_type);
     }
 
+    static event_ptr create_event_reader(int reader_id, EVENT_TYPE ev_type)
+    {
+        return create_event(OT_DEVICE_READER, reader_id, 0, ev_type);
+    }
     ///创建与卡有关的警告,需要卡类型
     static event_ptr create_event_card(uint32_t card_id, int32_t card_type, EVENT_TYPE ev_type)
     {
@@ -187,6 +191,17 @@ public:
         ev_ptr->m_area_id =  area_ptr->id();
         ev_ptr->m_map_id = area_ptr->mapid();
     }
+    static void copy_event(const std::shared_ptr<site> site_ptr, event_ptr ev_ptr)
+    {
+        ev_ptr->m_cur_time = std::chrono::system_clock::now();
+        ev_ptr->m_is_display = true;
+
+        ev_ptr->m_area_id =  site_ptr->m_area_id;
+        ev_ptr->m_map_id = site_ptr->m_map_id;
+        ev_ptr->x = site_ptr->x;
+        ev_ptr->y = site_ptr->y;
+    }
+
 
     std::shared_ptr<ya_event> get_event_card(uint32_t card_id, int card_type, EVENT_TYPE ev_type)
     {
@@ -198,6 +213,10 @@ public:
         return base::get(to_list_id(ev_type, OT_AREA, 0, static_cast<uint32_t>(area_id)));
     }
 
+    std::shared_ptr<ya_event> get_event_reader(int32_t reader_id, EVENT_TYPE ev_type)
+    {
+        return base::get(to_list_id(ev_type,OT_DEVICE_READER, 0, static_cast<uint32_t>(reader_id)));
+    }
     void load_his_data_from_db();
 
     static void save_event(const event_ptr ev_ptr)
@@ -291,7 +310,7 @@ private:
 
         ev_ptr->m_ev_type = ev_type;
         ev_ptr->m_obj_type = obj_type;
-        ev_ptr->m_obj_id = card_list::to_id64_str(type, static_cast<uint32_t>(obj_id) );
+        ev_ptr->m_obj_id = tool_other::type_id_to_str(type, obj_id);
 
         return ev_ptr;
     }

+ 8 - 1
znet.cpp

@@ -29,13 +29,17 @@ struct io_context: zloop<std::shared_ptr<client>> ,service_handle
 {
 private:
 	service_callback&m_serv;
+	ev::timer m_timer;
 public:
 	
 	std::vector<std::shared_ptr<client>> m_thread_clts;
 	io_context(service_callback&serv)
 		:m_serv(serv)
+		,m_timer(*this)
 	{
 		m_thread_clts.reserve(2048);
+		m_timer.set<io_context,&io_context::on_timer>(this);
+		m_timer.start(20,2);
 	}
 
 	virtual ~io_context()
@@ -50,7 +54,10 @@ public:
 			i->send(std::move(tmp));
 		}
 	}
-
+	void on_timer()
+	{
+		m_serv.on_timer();	
+	}
 	void on_connect(std::shared_ptr<client> clt)
 	{
 		if(clt->handle()>=(int)m_thread_clts.size())

+ 1 - 0
znet.h

@@ -77,6 +77,7 @@ struct service_callback:service_handle
 	}
 
 	virtual void on_message(std::shared_ptr<client> clt,const char*data,size_t len)=0;
+	virtual void on_timer()=0;
 
 	virtual ~service_callback(){}
 };