Prechádzať zdrojové kódy

增加修改基础数据1

daiyueteng 6 rokov pred
rodič
commit
4692c14df5

+ 6 - 0
CMakeLists.txt

@@ -54,6 +54,10 @@ set(SRC_YASL "ant.cpp" "ant.h" "base64.cpp" "base64.h" "card.cpp" "card.h" "cloc
     "landmark.h" "landmark.cpp" "area.h" "area.cpp"
     "site_area.h" "site_area.cpp"
     "special_area.h" "special_area.cpp"
+    "cardMgr.h" "cardMgr.cpp"
+    "geo_hash.h" "geo_hash.cpp"
+    "bindmorecard.h" "bindmorecard.cpp"
+    "common.h"
     )
 
 set(SRC_MODULE
@@ -76,6 +80,8 @@ set(SRC_MODULE
     "module_service/module_mine.h"
     "module_service/module_over_speed_vehicle.h"
     "module_service/module_other_alarm.h"
+
+    "module_service/module_meta_date_changed.cpp" "module_service/module_meta_date_changed.h"
     )
 
 add_executable(${PROJECT_NAME} "main.cpp" ${SRC_YASL}  ${SRC_MODULE})

+ 1 - 1
CMakeLists.txt.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.7.0, 2018-10-11T16:29:55. -->
+<!-- Written by QtCreator 4.7.0, 2018-10-20T21:16:35. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 504 - 206
ant.cpp

@@ -169,239 +169,537 @@ void sit_list::read_sit_list(const char*fname)
 
 }
 #endif
-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 );
+//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)
+//	{
+//		auto & sit = *(sit_.second);
+//		if(sit.m_id==-1)
+//			continue;
+
+//		if(sit.m_ant[0]==sit.m_ant[1])
+//		{
+//			log_warn("%d分站天线坐标相等.",sit.m_id);
+//		}
+
+//		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);
+//	}
+//}
+
+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";
+
+     if(-1 == id)
+     {
+         sql.append(";");
+     }
+     else
+     {
+         sql.append(" AND reader_id=");
+         sql.append(std::to_string(id));
+         sql.append(";");
+
+         std_debug("修改path sql=%s", sql.c_str());
+         log_info("修改path sql=%s", sql.c_str());
+     }
+
+     std::string Error;
+     YADB::CDBResultSet DBRes;
+     sDBConnPool.Query(sql.c_str(),DBRes,Error);
+     int nCount = DBRes.GetRecordCount( Error );
+     if (nCount < 1)
+     {
+         log_error("修改path失败,数据库中找不到(dat_reader_path_tof_n): 分站id=%d", id);
+         return ;
+     }
+
+     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(-1!=id)//清空path
+         {
+            sit_.clear_path();
+            log_info( "修改path 清空path,分站id=%d\n", id );
+            std_debug( "修改path 清空path,分站id=%d\n", id );
+         }
+
+         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);
+         }
+     }
+
+     if(-1==id)
+     {
+         log_info( "read_ant_path. The record count=%ld\n", nCount );
+         for(auto&_s:sit_list::instance()->m_map)
+         {
+             _s.second->deal_path();
+         }
+     }
+     else
+     {
+         auto sit_ptr=sit_list::instance()->get(id);
+         if(sit_ptr)
+         {
+             sit_ptr->deal_path();
+             log_info( "修改path成功,分站id=%d\n", id );
+             std_debug( "修改path成功,分站id=%d\n", id );
+         }
+     }
+}
 
-            double y= 0;
-            DBRes.GetField( "y",y, Error );
+void sit_list::init_site(int id)
+{
+     std::string sql = "SELECT reader_id, reader_type_id, dat_reader.map_id, \
+             area_id, device_type_id, dimension, dat_map.scale\
+             FROM dat_reader, dat_map where \
+             dat_reader.map_id=dat_map.map_id and state=0";
+
+     if(-1 == id)
+     {
+         sql.append(";");
+     }
+     else
+     {
+         sql.append(" AND reader_id=");
+         sql.append(std::to_string(id));
+         sql.append(";");
+
+         std_debug("增加或修改分站 sql=%s", sql.c_str());
+         log_info("增加或修改分站 sql=%s", sql.c_str());
+     }
+
+     std::string Error;
+     YADB::CDBResultSet DBRes;
+     sDBConnPool.Query(sql.c_str(),DBRes,Error);
+     int nCount = DBRes.GetRecordCount( Error );
+     if (nCount < 1)
+     {
+         log_error("增加或修改失败,数据库中找不到: 分站id=%d", id);
+         return ;
+     }
+
+     log_info( "增加或修改 init_site. 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)
+         {
+             site_ptr = std::make_shared<site>(reader_id);
+             sit_list::instance()->add(reader_id,site_ptr);
+         }
+
+         int reader_type_id  = 0;
+         DBRes.GetField( "reader_type_id",reader_type_id, Error );
+
+         int map_id  = 0;
+         DBRes.GetField( "map_id",map_id, Error );
+
+         int area_id  = 0;
+         DBRes.GetField( "area_id",area_id, Error );
+
+         int device_type_id  = 0;
+         DBRes.GetField( "device_type_id",device_type_id, Error );
+
+         int dimension  = 0;
+         DBRes.GetField( "dimension",dimension, Error );
+
+         double scale= 0;
+         DBRes.GetField( "scale",scale, Error );
+
+         site_ptr->m_reader_type_id = reader_type_id;
+         site_ptr->m_map_id = map_id;
+         site_ptr->m_area_id = area_id;
+
+         site_ptr->m_device_type_id = device_type_id;
+
+         site_ptr->m_dimension = dimension;
+         site_ptr->m_scale = scale;
+     }
+}
 
-            double z= 0;
-            DBRes.GetField( "z",z, Error );
+void sit_list::read_sit_list(int id)
+{
+    std::string 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::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);
-        }
+            id=10;
+    if(-1 == id)
+    {
+        sql.append(";");
     }
-	sit_list::instance()->add(map);
-	for(auto&sit_:map)
-	{
-		auto & sit = *(sit_.second);
-		if(sit.m_id==-1)
-			continue;
-
-		if(sit.m_ant[0]==sit.m_ant[1])
-		{
-			log_warn("%d分站天线坐标相等.",sit.m_id);
-		}
-
-		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)
+    else
     {
-        log_info( "init_ant_path. The record count=%ld\n", nCount );
+        sql.append(" AND antenna_id=");
+        sql.append(std::to_string(id));
+        sql.append(";");
 
-        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);
-			}
-        }
+        std_debug("基础数据 增加或修改天线 sql=%s", sql.c_str());
+        log_info("基础数据 增加或修改天线 sql=%s", sql.c_str());
     }
-	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);
-	}
-}
-
-
-void sit_list::init_site()
-{
-    const char *sql = "SELECT reader_id, reader_type_id, dat_reader.map_id, \
-            area_id, device_type_id, dimension, dat_map.scale\
-            FROM dat_reader, dat_map where \
-            dat_reader.map_id=dat_map.map_id and state=0;";
 
     std::string Error;
     YADB::CDBResultSet DBRes;
-    sDBConnPool.Query(sql,DBRes,Error);
-    uint64_t nCount = DBRes.GetRecordCount( Error );
-    if (nCount > 0)
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    int nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
     {
-        log_info( "init_site. The record count=%ld\n", nCount );
+        log_error("基础数据 增加或修改失败,数据库中找不到: 天线id=%d", id);
+        return ;
+    }
 
-        while ( DBRes.GetNextRecod(Error) )
-        {
-            int reader_id  = 0;
-            DBRes.GetField( "reader_id",reader_id, Error );
+    std::unordered_map<int,std::shared_ptr<site>> map;
+    while ( DBRes.GetNextRecod(Error) )
+    {
+        int antenna_id = 0;
+        DBRes.GetField( "antenna_id",antenna_id, Error );
 
-            auto site_ptr=sit_list::instance()->get(reader_id);
-            if(nullptr==site_ptr)
-            {
-                site_ptr = std::make_shared<site>(reader_id);
-                sit_list::instance()->add(reader_id,site_ptr);
-            }
+        int reader_id  = 0;
+        DBRes.GetField( "reader_id",reader_id, Error );
 
-            int reader_type_id  = 0;
-            DBRes.GetField( "reader_type_id",reader_type_id, Error );
+        int idx=0;
+        DBRes.GetField( "idx",idx, Error );
 
-            int map_id  = 0;
-            DBRes.GetField( "map_id",map_id, Error );
+        int antid = idx-1;
+        if(antid >= 2)
+          continue;
 
-            int area_id  = 0;
-            DBRes.GetField( "area_id",area_id, Error );
+        double x= 0;
+        DBRes.GetField( "x",x, Error );
 
-            int device_type_id  = 0;
-            DBRes.GetField( "device_type_id",device_type_id, Error );
+        double y= 0;
+        DBRes.GetField( "y",y, Error );
 
-            int dimension  = 0;
-            DBRes.GetField( "dimension",dimension, Error );
+        double z= 0;
+        DBRes.GetField( "z",z, Error );
 
-            double scale= 0;
-            DBRes.GetField( "scale",scale, Error );
+        if(-1 == id)
+        {
+            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].m_id = antenna_id;
+            site_ptr->m_ant[antid].set(x,-y);
+            log_info("reand_ant..%d,%d,%.2f,%.2f",reader_id,antid,x,y);
+        }
+        else
+        {
+            auto site_ptr = sit_list::instance()->get(reader_id);
+            if(site_ptr)
+            {
+                site_ptr->m_ant[antid].set(x,-y);
 
-            site_ptr->m_reader_type_id = reader_type_id;
-            site_ptr->m_map_id = map_id;
-            site_ptr->m_area_id = area_id;
+                site_ptr->set_ex();
+            }
 
-            site_ptr->m_device_type_id = device_type_id;
+            log_info("基础数据 增加或修改天线成功:天线id:%d,分站id:%d",id,reader_id);
+            std_debug("基础数据 增加或修改天线成功:天线id:%d,分站id:%d",id,reader_id);
+        }
+    }
 
-            site_ptr->m_dimension = dimension;
-            site_ptr->m_scale = scale;
+    if(-1 == id)
+    {
+        log_info( "init_antenna. The record count=%ld\n", nCount );
+        sit_list::instance()->add(map);
+        for(auto&sit_:map)
+        {
+            sit_.second->set_ex();
         }
     }
 }
 
+//void sit_list::init_site()
+//{
+//    const char *sql = "SELECT reader_id, reader_type_id, dat_reader.map_id, \
+//            area_id, device_type_id, dimension, dat_map.scale\
+//            FROM dat_reader, dat_map where \
+//            dat_reader.map_id=dat_map.map_id and state=0;";
+
+//    std::string Error;
+//    YADB::CDBResultSet DBRes;
+//    sDBConnPool.Query(sql,DBRes,Error);
+//    uint64_t nCount = DBRes.GetRecordCount( Error );
+//    if (nCount > 0)
+//    {
+//        log_info( "init_site. 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)
+//            {
+//                site_ptr = std::make_shared<site>(reader_id);
+//                sit_list::instance()->add(reader_id,site_ptr);
+//            }
+
+//            int reader_type_id  = 0;
+//            DBRes.GetField( "reader_type_id",reader_type_id, Error );
+
+//            int map_id  = 0;
+//            DBRes.GetField( "map_id",map_id, Error );
+
+//            int area_id  = 0;
+//            DBRes.GetField( "area_id",area_id, Error );
+
+//            int device_type_id  = 0;
+//            DBRes.GetField( "device_type_id",device_type_id, Error );
+
+//            int dimension  = 0;
+//            DBRes.GetField( "dimension",dimension, Error );
+
+//            double scale= 0;
+//            DBRes.GetField( "scale",scale, Error );
+
+//            site_ptr->m_reader_type_id = reader_type_id;
+//            site_ptr->m_map_id = map_id;
+//            site_ptr->m_area_id = area_id;
+
+//            site_ptr->m_device_type_id = device_type_id;
+
+//            site_ptr->m_dimension = dimension;
+//            site_ptr->m_scale = scale;
+//        }
+//    }
+//}
+
 algo_config site::g_config[]=
 {
 	{ "tof-1",  1, 2, 0.1, 1 },

+ 73 - 7
ant.h

@@ -59,6 +59,7 @@ struct algo_config
 //
 struct ant :point
 {
+    int m_id;
     std::vector<path> m_path;
     path & operator[](int i)
     {
@@ -264,6 +265,58 @@ struct site:point
     {
         return m_ant[i];
     }
+
+    void set_ex()
+    {
+        if(-1 == m_id)
+        {
+            return;
+        }
+
+        if(m_ant[0]==m_ant[1])
+        {
+            log_warn("%d分站天线坐标相等.", m_id);
+        }
+
+        set( (m_ant[0].x+m_ant[1].x)/2,(m_ant[0].y+m_ant[1].y)/2);
+    }
+
+    void deal_path()
+    {
+        if(m_id==-1)
+            return;
+        swap();
+        if((path(0).empty() && path(1).empty()))
+            return;
+        m_path_empty=false;
+
+        for(auto &a: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",sit_ptr->to_string().c_str());
+        log_info("%s",to_string().c_str());
+        //std_info("%f----%f",sit_ptr->x,sit_ptr->y);
+    }
+
+    void delete_antenna(int antidx)
+    {
+        m_ant[antidx].m_path.clear();
+        m_ant[antidx].m_id=0;
+        point pt;
+        m_ant[antidx].set(pt);
+    }
+
+    void clear_path()
+    {
+        m_ant[0].m_path.clear();
+        m_ant[1].m_path.clear();
+    }
 };
 
 
@@ -271,19 +324,32 @@ struct sit_list:single_base<sit_list,int,std::shared_ptr<site>>
 {
     void load()
     {
-        read_sit_list();
-        read_ant_path();
+        read_sit_list(-1);
+        read_ant_path(-1);
     }
 
-    void load_from_db()
+//    void load_from_db()
+//    {
+//        load();
+//        init_site(-1);
+//    }
+
+    ///id=-1为初始化所有
+    void load_from_db(int id)
     {
         load();
-        init_site();
+        init_site(id);
     }
 
-    void read_sit_list();
-    void read_ant_path();
-    void init_site();
+//    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
 

+ 359 - 105
area.cpp

@@ -72,144 +72,398 @@ area_list::area_list()
 {
 }
 
-void area_list::init_monkeycar_area()
-{
-	std::unordered_map<int,std::shared_ptr<area>> map;
-	const char *sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path, c.scale,\
-						over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, over_speed_vehicle, is_attendance ,b.monkeycar_coordinate,b.monkeycar_speed \
-						FROM dat_area a ,dat_monkeycar_base_info b ,dat_map c\
-						where a.area_id = b.monkeycar_areaid and a.map_id = c.map_id;";
-	std::string Error;
-	YADB::CDBResultSet DBRes;
-	sDBConnPool.Query(sql,DBRes,Error);
-	if(!Error.empty())
-		log_error("monkeycar area init Error,%s",Error.c_str());
-	int nCount = DBRes.GetRecordCount( Error );
-	if (nCount > 0)
-	{
-		log_info( "init_monkey area. The record count=%d", nCount );
-
-		while ( DBRes.GetNextRecod(Error) )
-		{
-			int area_id  = 0;
-			DBRes.GetField( "area_id",area_id, Error );
-
-			int map_id  = 0;
-			DBRes.GetField( "map_id",map_id, Error );
-
-			unsigned int area_type_id  = 0;
-			DBRes.GetField( "area_type_id",area_type_id, Error );
+//void area_list::init_monkeycar_area()
+//{
+//	std::unordered_map<int,std::shared_ptr<area>> map;
+//	const char *sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path, c.scale,\
+//						over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, over_speed_vehicle, is_attendance ,b.monkeycar_coordinate,b.monkeycar_speed \
+//						FROM dat_area a ,dat_monkeycar_base_info b ,dat_map c\
+//						where a.area_id = b.monkeycar_areaid and a.map_id = c.map_id;";
+//	std::string Error;
+//	YADB::CDBResultSet DBRes;
+//	sDBConnPool.Query(sql,DBRes,Error);
+//	if(!Error.empty())
+//		log_error("monkeycar area init Error,%s",Error.c_str());
+//	int nCount = DBRes.GetRecordCount( Error );
+//	if (nCount > 0)
+//	{
+//		log_info( "init_monkey area. The record count=%d", nCount );
+
+//		while ( DBRes.GetNextRecod(Error) )
+//		{
+//			int area_id  = 0;
+//			DBRes.GetField( "area_id",area_id, Error );
+
+//			int map_id  = 0;
+//			DBRes.GetField( "map_id",map_id, Error );
+
+//			unsigned int area_type_id  = 0;
+//			DBRes.GetField( "area_type_id",area_type_id, Error );
 			
-			int over_count_person = 0;
-			DBRes.GetField( "over_count_person",over_count_person, Error );
+//			int over_count_person = 0;
+//			DBRes.GetField( "over_count_person",over_count_person, Error );
 
-			int over_count_vehicle = 0;
-			DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
+//			int over_count_vehicle = 0;
+//			DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
 
-			int over_time_person = 0;
-			DBRes.GetField( "over_time_person",over_time_person, Error );
+//			int over_time_person = 0;
+//			DBRes.GetField( "over_time_person",over_time_person, Error );
 
-			int over_time_vehicle = 0;
-			DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
+//			int over_time_vehicle = 0;
+//			DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
 
-			std::string path;
-			DBRes.GetField( "path",path, Error );
+//			std::string path;
+//			DBRes.GetField( "path",path, Error );
 			
-			float monkeycar_speed = 0;
-			DBRes.GetField( "monkeycar_speed",monkeycar_speed, Error );
+//			float monkeycar_speed = 0;
+//			DBRes.GetField( "monkeycar_speed",monkeycar_speed, Error );
 
-			std::string monkeycar_coor;
-			DBRes.GetField( "monkeycar_coordinate",monkeycar_coor, Error );
+//			std::string monkeycar_coor;
+//			DBRes.GetField( "monkeycar_coordinate",monkeycar_coor, Error );
 
-			float scale=0;
-			DBRes.GetField( "scale",scale, Error );
+//			float scale=0;
+//			DBRes.GetField( "scale",scale, Error );
 
 
-			log_info("init_area : id:%d,path:%s",area_id, path.c_str());
+//			log_info("init_area : id:%d,path:%s",area_id, path.c_str());
 
-			std::shared_ptr<db_area>  da = std::make_shared<db_area>(); 
-			da->m_default_speed = monkeycar_speed;
-			da->m_point = init_path(monkeycar_coor);
+//			std::shared_ptr<db_area>  da = std::make_shared<db_area>();
+//			da->m_default_speed = monkeycar_speed;
+//			da->m_point = init_path(monkeycar_coor);
 		
-			std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person,over_time_person,scale,map_id,area_type_id);
+//			std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person,over_time_person,scale,map_id,area_type_id);
 
-			ap->m_bound=init_path(path);
-			for(const auto &p : ap->m_bound)
-			  log_info("point:monkey:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
-			for(const auto &p : da->m_point)
-			  log_info("point:monkey_coor:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+//			ap->m_bound=init_path(path);
+//			for(const auto &p : ap->m_bound)
+//			  log_info("point:monkey:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+//			for(const auto &p : da->m_point)
+//			  log_info("point:monkey_coor:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
 
-			map.insert({area_id,ap});
-		}
-	}
+//			map.insert({area_id,ap});
+//		}
+//	}
 	
-	area_list::instance()->add(map);
+//	area_list::instance()->add(map);
+//}
+
+void area_list::init_monkeycar_area(int id)
+{
+    std::string sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path, c.scale,\
+            over_count_person, over_count_vehicle, over_time_person, over_time_vehicle,\
+            over_speed_vehicle, is_attendance ,b.monkeycar_coordinate,b.monkeycar_speed \
+            FROM dat_area a ,dat_monkeycar_base_info b ,dat_map c\
+            where a.area_id = b.monkeycar_areaid and a.map_id = c.map_id";
+
+    if(-1 == id)
+    {
+        sql.append(";");
+    }
+    else
+    {
+        sql.append(" AND a.area_id=");
+        sql.append(std::to_string(id));
+        sql.append(";");
+
+        std_debug("基础数据 monkeycar area 增加或修改区域 sql=%s", sql.c_str());
+        log_info("基础数据 monkeycar area 增加或修改区域 sql=%s", sql.c_str());
+    }
+
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    int nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
+    {
+        log_error("基础数据 monkeycar area 增加或修改失败,数据库中找不到: area_id=%d", id);
+        return ;
+    }
+
+    std::unordered_map<int,std::shared_ptr<area>> map;
+    while ( DBRes.GetNextRecod(Error) )
+    {
+        int area_id  = 0;
+        DBRes.GetField( "area_id",area_id, Error );
+
+        int map_id  = 0;
+        DBRes.GetField( "map_id",map_id, Error );
+
+        unsigned int area_type_id  = 0;
+        DBRes.GetField( "area_type_id",area_type_id, Error );
+
+        int over_count_person = 0;
+        DBRes.GetField( "over_count_person",over_count_person, Error );
+
+        int over_count_vehicle = 0;
+        DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
+
+        int over_time_person = 0;
+        DBRes.GetField( "over_time_person",over_time_person, Error );
+
+        int over_time_vehicle = 0;
+        DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
+
+        std::string path;
+        DBRes.GetField( "path",path, Error );
+
+        double monkeycar_speed = 0;
+        DBRes.GetField( "monkeycar_speed",monkeycar_speed, Error );
+
+        std::string monkeycar_coor;
+        DBRes.GetField( "monkeycar_coordinate",monkeycar_coor, Error );
+
+        double scale=0;
+        DBRes.GetField( "scale",scale, Error );
+
+        log_info("monkeycar area init_area : id:%d,path:%s",area_id, path.c_str());
+
+        if(-1 == id)
+        {
+            std::shared_ptr<db_area>  da = std::make_shared<db_area>();
+            da->m_default_speed = monkeycar_speed;
+            da->m_point = init_path(monkeycar_coor);
+
+            std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person,
+                                       over_time_person,scale,map_id,area_type_id);
+
+            ap->m_bound=init_path(path);
+            for(const auto &p : ap->m_bound)
+              log_info("point:monkey:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+            for(const auto &p : da->m_point)
+              log_info("point:monkey_coor:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+
+            map.insert({area_id,ap});
+        }
+        else
+        {
+            auto tmp_ptr = area_list::instance()->get(id);
+            if(tmp_ptr)
+            {
+                //待补充
+            }
+            else
+            {
+                std::shared_ptr<db_area>  da = std::make_shared<db_area>();
+                da->m_default_speed = monkeycar_speed;
+                da->m_point = init_path(monkeycar_coor);
+
+                std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person,
+                                           over_time_person,scale,map_id,area_type_id);
+
+                ap->m_bound=init_path(path);
+                for(const auto &p : ap->m_bound)
+                  log_info("point:monkey:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+                for(const auto &p : da->m_point)
+                  log_info("point:monkey_coor:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+
+                area_list::instance()->add(id, ap);
+            }
+
+            log_info("基础数据 monkeycar area增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,\
+                     scale:%.2f,map_id:%d,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
+                     id,over_count_person, over_time_person,scale,map_id,area_type_id,
+                     over_count_vehicle,over_time_vehicle);
+            std_debug("基础数据 monkeycar area增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,\
+                      scale:%.2f,map_id:%d,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
+                      id,over_count_person, over_time_person,scale,map_id,area_type_id,
+                      over_count_vehicle,over_time_vehicle);
+        }
+    }
+
+    if(-1 == id)
+    {
+        log_info( "monkeycar area init_area. The record count=%d\n", nCount );
+        area_list::instance()->add(map);
+    }
 }
-void area_list::init_from_db()
+
+void area_list::init_from_db(int id)
 {
-	std::unordered_map<int,std::shared_ptr<area>> map;
-	const char *sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path,b.scale, \
-						over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, over_speed_vehicle, is_attendance \
-						FROM dat_area a,dat_map b\
-						where a.map_id = b.map_id and  area_id not in (select monkeycar_areaid from dat_monkeycar_base_info);";
-	std::string Error;
-	YADB::CDBResultSet DBRes;
-	sDBConnPool.Query(sql,DBRes,Error);
-	if(!Error.empty())
-		log_error("monkeycar area init Error,%s",Error.c_str());
-	int nCount = DBRes.GetRecordCount( Error );
-	if (nCount > 0)
-	{
-		log_info( "init_area. The record count=%d\n", nCount );
+    std::string sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path,b.scale, \
+            over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, \
+            over_speed_vehicle, is_attendance \
+            FROM dat_area a,dat_map b\
+            where a.map_id = b.map_id and  area_id not in \
+            (select monkeycar_areaid from dat_monkeycar_base_info)";
+
+    if(-1 == id)
+    {
+        sql.append(";");
+    }
+    else
+    {
+        sql.append(" AND s.area_id=");
+        sql.append(std::to_string(id));
+        sql.append(";");
+
+        std_debug("基础数据 增加或修改区域 sql=%s", sql.c_str());
+        log_info("基础数据 增加或修改区域 sql=%s", sql.c_str());
+    }
+
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    int nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
+    {
+        log_error("基础数据 增加或修改失败,数据库中找不到: area_id=%d", id);
+        return ;
+    }
+
+    std::unordered_map<int,std::shared_ptr<area>> map;
+    while ( DBRes.GetNextRecod(Error) )
+    {
+        int area_id  = 0;
+        DBRes.GetField( "area_id",area_id, Error );
+
+        int map_id  = 0;
+        DBRes.GetField( "map_id",map_id, Error );
+
+        unsigned int area_type_id  = 0;
+        DBRes.GetField( "area_type_id",area_type_id, Error );
+
+        int over_count_person = 0;
+        DBRes.GetField( "over_count_person",over_count_person, Error );
+
+        int over_count_vehicle = 0;
+        DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
+
+        int over_time_person = 0;
+        DBRes.GetField( "over_time_person",over_time_person, Error );
+
+        int over_time_vehicle = 0;
+        DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
+
+        std::string path;
+        DBRes.GetField( "path",path, Error );
+
+        double scale = 0;
+        DBRes.GetField( "scale",scale, Error );
+
+        log_info("init_area : id:%d,path:%s",area_id, path.c_str());
+
+        if(-1 == id)
+        {
+            std::shared_ptr<area> ap = std::make_shared<area>(area_id,over_count_person,over_time_person,
+                                                              scale,map_id,area_type_id);
 
-		while ( DBRes.GetNextRecod(Error) )
-		{
-			int area_id  = 0;
-			DBRes.GetField( "area_id",area_id, Error );
+            ap->m_limit_vehicle_second = over_time_vehicle;
+            ap->m_limit_vehicle_count = over_count_vehicle;
 
-			int map_id  = 0;
-			DBRes.GetField( "map_id",map_id, Error );
+            ap->m_bound=init_path(path);
+            for(const auto &p : ap->m_bound)
+              log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+
+            map.insert({area_id,ap});
+        }
+        else
+        {
+            auto tmp_ptr = area_list::instance()->get(id);
+            if(tmp_ptr)
+            {
+                tmp_ptr->update(over_count_person, over_time_person,scale,map_id,area_type_id,
+                                over_count_vehicle,over_time_vehicle);
+                tmp_ptr->m_bound=init_path(path);
+            }
+            else
+            {
+                std::shared_ptr<area> ap = std::make_shared<area>(area_id,over_count_person,over_time_person,
+                                                                  scale,map_id,area_type_id);
+
+                ap->m_limit_vehicle_second = over_time_vehicle;
+                ap->m_limit_vehicle_count = over_count_vehicle;
+
+                ap->m_bound=init_path(path);
+                for(const auto &p : ap->m_bound)
+                  log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+
+                area_list::instance()->add(id, ap);
+            }
+
+            log_info("基础数据 增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,scale:%.2f,map_id:%d\
+                     ,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
+                     id,over_count_person, over_time_person,scale,map_id,area_type_id,
+                     over_count_vehicle,over_time_vehicle);
+            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);
+        }
+    }
+
+    if(-1 == id)
+    {
+        log_info( "init_area. The record count=%d\n", nCount );
+        area_list::instance()->add(map);
+
+        init_monkeycar_area(-1);
+    }
+}
 
-			unsigned int area_type_id  = 0;
-			DBRes.GetField( "area_type_id",area_type_id, Error );
+//void area_list::init_from_db()
+//{
+//	std::unordered_map<int,std::shared_ptr<area>> map;
+//	const char *sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path,b.scale, \
+//						over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, over_speed_vehicle, is_attendance \
+//						FROM dat_area a,dat_map b\
+//						where a.map_id = b.map_id and  area_id not in (select monkeycar_areaid from dat_monkeycar_base_info);";
+//	std::string Error;
+//	YADB::CDBResultSet DBRes;
+//	sDBConnPool.Query(sql,DBRes,Error);
+//	if(!Error.empty())
+//		log_error("monkeycar area init Error,%s",Error.c_str());
+//	int nCount = DBRes.GetRecordCount( Error );
+//	if (nCount > 0)
+//	{
+//		log_info( "init_area. The record count=%d\n", nCount );
+
+//		while ( DBRes.GetNextRecod(Error) )
+//		{
+//			int area_id  = 0;
+//			DBRes.GetField( "area_id",area_id, Error );
+
+//			int map_id  = 0;
+//			DBRes.GetField( "map_id",map_id, Error );
+
+//			unsigned int area_type_id  = 0;
+//			DBRes.GetField( "area_type_id",area_type_id, Error );
 			
-			int over_count_person = 0;
-			DBRes.GetField( "over_count_person",over_count_person, Error );
+//			int over_count_person = 0;
+//			DBRes.GetField( "over_count_person",over_count_person, Error );
 
-			int over_count_vehicle = 0;
-			DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
+//			int over_count_vehicle = 0;
+//			DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
 
-			int over_time_person = 0;
-			DBRes.GetField( "over_time_person",over_time_person, Error );
+//			int over_time_person = 0;
+//			DBRes.GetField( "over_time_person",over_time_person, Error );
 
-			int over_time_vehicle = 0;
-			DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
+//			int over_time_vehicle = 0;
+//			DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
 
-			std::string path;
-			DBRes.GetField( "path",path, Error );
+//			std::string path;
+//			DBRes.GetField( "path",path, Error );
 		
-			double scale = 0;
-			DBRes.GetField( "scale",scale, Error );
+//			double scale = 0;
+//			DBRes.GetField( "scale",scale, Error );
 
-			log_info("init_area : id:%d,path:%s",area_id, path.c_str());
+//			log_info("init_area : id:%d,path:%s",area_id, path.c_str());
 			
-            std::shared_ptr<area> ap = std::make_shared<area>(area_id,over_count_person,over_time_person,scale,map_id,area_type_id);
+//            std::shared_ptr<area> ap = std::make_shared<area>(area_id,over_count_person,over_time_person,scale,map_id,area_type_id);
 
-            ap->m_limit_vehicle_second = over_time_vehicle;
-            ap->m_limit_vehicle_count = over_count_vehicle;
+//            ap->m_limit_vehicle_second = over_time_vehicle;
+//            ap->m_limit_vehicle_count = over_count_vehicle;
 
-			ap->m_bound=init_path(path);
-			for(const auto &p : ap->m_bound)
-			  log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
+//			ap->m_bound=init_path(path);
+//			for(const auto &p : ap->m_bound)
+//			  log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
 
-			map.insert({area_id,ap});
-		}
-	}
+//			map.insert({area_id,ap});
+//		}
+//	}
 	
-	area_list::instance()->add(map);
+//	area_list::instance()->add(map);
 
-	init_monkeycar_area();
-}
+//	init_monkeycar_area();
+//}
 std::vector<point> area_list::init_path(std::string &str)
 {
 	if(str.empty())

+ 18 - 2
area.h

@@ -52,6 +52,18 @@ struct area
         return m_person_count + m_vehicle_count;
     }
 
+    void  update(int limit_count_person, int limit_time_person,double scale,int32_t mapid,
+                     int32_t type,int limit_count_vehicle, int limit_time_vehicle)
+    {
+        m_area_type=type;
+        m_limit_person_second=limit_time_person;
+        m_limit_person_count=limit_count_person;
+        m_scale=scale;
+        m_mapid=mapid;
+        m_limit_vehicle_count=limit_count_vehicle;
+        m_limit_vehicle_second=limit_time_vehicle;
+    }
+
     std::vector<point> m_bound;
 public:
     //std::atomic<int> m_card_count;
@@ -79,8 +91,12 @@ struct area_list:single_base<area_list,int,std::shared_ptr<area>>
 
     std::shared_ptr<area> get_area(const point&pt);
     std::vector<point> init_path(std::string  &str);
-    void init_from_db();
-    void init_monkeycar_area();
+    //void init_from_db();
+    //void init_monkeycar_area();
+    ///id=-1为初始化所有
+    void init_from_db(int id);
+    ///id=-1为初始化所有
+    void init_monkeycar_area(int id);
 };
 
 struct area_hover

+ 353 - 111
card.cpp

@@ -424,148 +424,390 @@ uint64_t card_list::getId(uint32_t cardid,uint64_t type)
 {
 	return type<<32|cardid;
 }
-void card_list::init_vehicle()
+
+void card_list::init_staffer(int32_t id)
 {
-	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_staffer. The record count=%d\n", nCount );
+    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 \
+            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";
+
+    int type = CT_PERSON;
+    std::string card_id_str = card_list::to_id64_str(type, static_cast<uint32_t>(id));
+    if(-1 == id)
+    {
+        sql.append(";");
+    }
+    else
+    {
+        sql.append(" AND s.card_id = '");
+        sql.append(card_id_str);
+        sql.append("';");
 
-		while ( DBRes.GetNextRecod(Error) )
-		{
-			unsigned int vehicle_id  = 0;
-			DBRes.GetField( "vehicle_id",vehicle_id, Error );
+        std_debug("基础数据 增加或修改人卡 sql=%s", sql.c_str());
+        log_info("基础数据 增加或修改人卡 sql=%s", sql.c_str());
+    }
+
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    int nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
+    {
+        log_error("增加或修改失败,数据库中找不到: card_id=%s", card_id_str.c_str());
+        return ;
+    }
 
-			std::string card_id;
-			DBRes.GetField( "card_id",card_id, Error );
+    std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
+    while ( DBRes.GetNextRecod(Error) )
+    {
+        unsigned int staff_id  = 0;
+        DBRes.GetField( "staff_id",staff_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 );
+        std::string card_id;
+        DBRes.GetField( "card_id",card_id, Error );
 
-			int dept_id = 0;
-			DBRes.GetField( "dept_id",dept_id, Error );
+        uint32_t vsid = atoi(card_id.substr(3).c_str());
 
-			int group_id = 0;
-			DBRes.GetField( "group_id",group_id, Error );
+        unsigned int card_type_id  = 0;
+        DBRes.GetField( "card_type_id",card_type_id, Error );
 
-			int vehicle_type_id = 0;
-			DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
+        int dept_id = 0;
+        DBRes.GetField( "dept_id",dept_id, Error );
 
-			int vehicle_level_id = 0;
-			DBRes.GetField( "vehicle_level_id",vehicle_level_id, Error );
+        int group_id = 0;
+        DBRes.GetField( "group_id",group_id, Error );
 
-			int need_display = 0;
-			DBRes.GetField( "need_display",need_display, Error );
+        int occupation_id = 0;
+        DBRes.GetField( "occupation_id",occupation_id, Error );
 
-			int power_alarm = 0;
-			DBRes.GetField( "power_alarm",power_alarm, Error );
+        int occupation_level_id = 0;
+        DBRes.GetField( "occupation_level_id",occupation_level_id, Error );
 
-			int vehicle_category_id = 0;
-			DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
+        int need_display = 0;
+        DBRes.GetField( "need_display",need_display, Error );
 
-			int bigger_car_flag= 0;
-			DBRes.GetField( "bigger_car_flag",bigger_car_flag, Error );
+        //for now;
+        staff_id = vsid;
 
-			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);
+        if(-1 == id)
+        {
+            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,type);
+            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});
+        }
+        else
+        {
+            auto card_id64 = card_list::to_id64(type, static_cast<uint32_t>(id));
+            auto card_ptr = card_list::instance()->get(card_id64);
+            if(card_ptr)
+            {
+                person* tmp_ptr= static_cast<person*>(card_ptr.get());
+                tmp_ptr->m_display = static_cast<uint16_t>(need_display);
+                tmp_ptr->m_deptid = dept_id;
+                //group_id
+                //occ_id
+                tmp_ptr->m_level_id = occupation_level_id;
+                //worktype_id
+            }
+            else
+            {
+                auto clb = std::make_shared<person>(strategy,staff_id,need_display,card_type_id,dept_id,occupation_level_id);
+                card_list::instance()->add(card_id64, clb);
+            }
+
+            log_info("基础数据 增加或修改人卡成功:卡id:%d,卡type:%d dept_id:%d,need_display:%d,occupation_level_id:%d",
+                     id,type,dept_id,need_display,occupation_level_id);
+            std_debug("基础数据 增加或修改人卡成功:卡id:%d,卡type:%d dept_id:%d,need_display:%d,occupation_level_id:%d",
+                     id,type,dept_id,need_display,occupation_level_id);
+        }
+    }
+
+    if(-1 == id)
+    {
+        log_info( "init_staffer. The record count=%d\n", nCount );
+        card_list::instance()->add(map);
+    }
 }
 
-void card_list::init_staffer()
+void card_list::init_vehicle(int32_t id)
 {
-	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 );
+    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,\
+                        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";
+
+    int type = CT_VEHICLE;
+    std::string card_id_str = card_list::to_id64_str(type, static_cast<uint32_t>(id));
+    if(-1 == id)
+    {
+        sql.append(";");
+    }
+    else
+    {
+        sql.append(" AND ve.card_id ='");
+        sql.append(card_id_str);
+        sql.append("';");
 
-		while ( DBRes.GetNextRecod(Error) )
-		{
-			unsigned int staff_id  = 0;
-			DBRes.GetField( "staff_id",staff_id, Error );
+        std_debug("基础数据 增加或修改车卡 sql=%s", sql.c_str());
+        log_info("基础数据 增加或修改车卡 sql=%s", sql.c_str());
+    }
+
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    int nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
+    {
+        log_error("增加或修改失败,数据库中找不到: card_id=%s", card_id_str.c_str());
+        return ;
+    }
+
+    std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
+    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;
+
+        if(-1 == id)
+        {
+            auto 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,type);
+            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});
+        }
+        else
+        {
+            auto card_id64 = card_list::to_id64(type, static_cast<uint32_t>(id));
+            auto card_ptr = card_list::instance()->get(card_id64);
+            if(card_ptr)
+            {
+                car* tmp_ptr= static_cast<car*>(card_ptr.get());
+                tmp_ptr->m_display = static_cast<uint16_t>(need_display);
+                tmp_ptr->m_deptid = dept_id;
+                tmp_ptr->m_vehicle_category_id = vehicle_category_id;
+                tmp_ptr->m_vehicle_type_id = vehicle_type_id;
+                tmp_ptr->m_level_id = vehicle_level_id;
+            }
+            else
+            {
+                auto clb = std::make_shared<car>(strategy,id,need_display,card_type_id,dept_id,
+                                                 vehicle_category_id, vehicle_type_id,vehicle_level_id);
+                card_list::instance()->add(card_id64, clb);
+            }
+
+            log_info("基础数据 增加或修改车卡成功:卡id:%d,卡type:%d dept_id:%d,need_display:%d,categoryid:%d",
+                     id,type,dept_id,need_display,vehicle_category_id);
+            std_debug("基础数据 增加或修改车卡成功:卡id:%d,卡type:%d dept_id:%d,need_display:%d,categoryid:%d",
+                     id,type,dept_id,need_display,vehicle_category_id);
+        }
+    }
+
+    if(-1 == id)
+    {
+        log_info( "init_vehicle. The record count=%d\n", nCount );
+        card_list::instance()->add(map);
+    }
+}
+
+//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 );
 
-			std::string card_id;
-			DBRes.GetField( "card_id",card_id, Error );
+//			int group_id = 0;
+//			DBRes.GetField( "group_id",group_id, Error );
 
-			uint32_t vsid = atoi(card_id.substr(3).c_str());
+//			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 );
 			
-			unsigned int card_type_id  = 0;
-			DBRes.GetField( "card_type_id",card_type_id, 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 dept_id = 0;
+//			DBRes.GetField( "dept_id",dept_id, Error );
 
-			int group_id = 0;
-			DBRes.GetField( "group_id",group_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_id = 0;
+//			DBRes.GetField( "occupation_id",occupation_id, Error );
 
-			int occupation_level_id = 0;
-			DBRes.GetField( "occupation_level_id",occupation_level_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 );
+//			int need_display = 0;
+//			DBRes.GetField( "need_display",need_display, Error );
 
-			//for now;
-			staff_id = vsid;
+//			//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});
-		}
-	}
+//			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);
-}
+//	card_list::instance()->add(map);
+//}
 
 void card_list::init_card_from_db()
 {
-	init_staffer();	
-	init_vehicle();
+    init_staffer(-1);
+    init_vehicle(-1);
 }
 
 void card_list::load_his_card_postion_from_db()

+ 6 - 2
card.h

@@ -92,8 +92,12 @@ struct card_location_base:card
 
 struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_base>>
 {
-    void init_staffer();
-    void init_vehicle();
+    ///id=-1为初始化所有卡
+    void init_staffer(int32_t id);
+    ///id=-1为初始化所有卡
+    void init_vehicle(int32_t id);
+    //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();

+ 19 - 2
common_tool.h

@@ -153,8 +153,13 @@ public:
     static std::string to13str(std::string& str)
     {
         uint64_t tmp = std::stoull(str);
+        return to13str(tmp);
+    }
+
+    static std::string to13str(uint64_t data)
+    {
         char ss[20]={0};
-        sprintf(ss, "%013ld", tmp);
+        sprintf(ss, "%013ld", data);
 
         return std::string(ss);
     }
@@ -168,6 +173,18 @@ public:
     {
         return std::stoi(to13str(str).substr(0, 3));
     }
+
+//    static uint32_t id64_to_id(uint64_t card_id)
+//    {
+//        return static_cast<uint32_t>(card_id);
+//    }
+
+//    static int id64_to_type(uint64_t card_id)
+//    {
+//        return static_cast<int32_t>(card_id>>32);
+//    }
+
+
 };
 
 
@@ -198,7 +215,7 @@ public:
         auto end = mine_tool_ptr->m_attendance_start_time;
         if(!mine_tool_ptr->is_attendance())//考勤结束时间
         {
-            end = std::chrono::system_clock::time_point(std::chrono::milliseconds(card_ptr->m_time));
+            end = std::chrono::system_clock::now();
         }
 
         std::string start_str = tool_time::to_str(start);

+ 99 - 100
main.cpp

@@ -21,142 +21,141 @@
 config_file config;
 struct Init_Setting
 {
-	void init()
-	{
-		std::string url=config.get("service.websocket_url","ws://127.0.0.1:8086");
-		int32_t send_interval =config.get("service.interval_send_json_postion",1);
-		std_info("json_interval:%d",send_interval);
-		std::vector<std::string> url_list;
-		url_list.push_back(url);
-		wsClientMgr_init(url_list,send_interval);//init websocket
+    void init()
+    {
+        std::string url=config.get("service.websocket_url","ws://127.0.0.1:8086");
+        int32_t send_interval =config.get("service.interval_send_json_postion",1);
+        std_info("json_interval:%d",send_interval);
+        std::vector<std::string> url_list;
+        url_list.push_back(url);
+        wsClientMgr_init(url_list,send_interval);//init websocket
 
-		YADB::_DB_POOL_SETTING_ DBSetting;
+        YADB::_DB_POOL_SETTING_ DBSetting;
 
         DBSetting.Host = config.get("db.host","192.168.0.102");
-		DBSetting.User = config.get("db.user","root");
+        DBSetting.User = config.get("db.user","root");
         DBSetting.PWD = config.get("db.passwd","root");
-		DBSetting.DBName = config.get("db.dbname","yaxt");
-		DBSetting.CharSet = config.get("db.charset","utf8");
-		DBSetting.TimeOut = config.get("db.conn_timeout",5);
-		DBSetting.PoolSize = config.get("db.conn_timeout",30);
-		_mysql_init(DBSetting);
+        DBSetting.DBName = config.get("db.dbname","yaxt");
+        DBSetting.CharSet = config.get("db.charset","utf8");
+        DBSetting.TimeOut = config.get("db.conn_timeout",5);
+        DBSetting.PoolSize = config.get("db.conn_timeout",30);
+        _mysql_init(DBSetting);
 
-		sit_list::instance()->load_from_db();
+        sit_list::instance()->load_from_db(-1);
 
-		card_list::instance()->init_card_from_db();
+        card_list::instance()->init_card_from_db();
 
-		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);
+        area_list::instance()->init_from_db(-1);
+        std_info("here....");
+        //test
+        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);
-		std_info("test landmark:id:%d,dir:%d,dis:%.2f",std::get<0>(a),std::get<1>(a),std::get<2>(a));
+        Landmark_list::instance()->init_from_db();
+        auto a = Landmark_list::instance()->get(5,id,pt);
+        std_info("test landmark:id:%d,dir:%d,dis:%.2f",std::get<0>(a),std::get<1>(a),std::get<2>(a));
 
-		special_area_list::instance()->init_from_db();
-		auto s = special_area_list::instance()->get_special_id(1013,point(4727,-254),2);
-		std_info("test special_area:%d",s);
+        special_area_list::instance()->init_from_db();
+        auto s = special_area_list::instance()->get_special_id(1013,point(4727,-254),2);
+        std_info("test special_area:%d",s);
 
         card_list::instance()->load_his_card_postion_from_db();
         event_list::instance()->load_his_data_from_db();
-	}
-
-	void _mysql_init(YADB::_DB_POOL_SETTING_ &dps)
-	{
-		std::string Error;
-	
-		//创建连接池
-		if ( !sDBConnPool.Create( dps, Error ) )
-		{
-			log_error("数据库线程池创建失败,Err=%s\n", Error.c_str());
-		}
-	}
-
-	void wsClientMgr_init(const std::vector<std::string>&uri_list,int32_t st)
-	{
-		std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE> MsgFuncList;
-	
+    }
+
+    void _mysql_init(YADB::_DB_POOL_SETTING_ &dps)
+    {
+        std::string Error;
+
+        //创建连接池
+        if ( !sDBConnPool.Create( dps, Error ) )
+        {
+            log_error("数据库线程池创建失败,Err=%s\n", Error.c_str());
+        }
+    }
+
+    void wsClientMgr_init(const std::vector<std::string>&uri_list,int32_t st)
+    {
+        std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE> MsgFuncList;
+
         //MsgFuncList.insert( std::make_pair( "req_all_data", On_req_all_data ) );
         //MsgFuncList.insert( std::make_pair( "req_all_person_on_car", On_req_all_person_on_car ) );
 
         module_mgr::init(config, MsgFuncList);
 
-		swsClientMgr.Build( uri_list, MsgFuncList );
-	
-		//连接服务器
-		if ( swsClientMgr.connect() != 0 )
-		{
-			log_error("web socket init failed.");
-			std_error("web socket init failed.");
-			return;
-		}
-	
-		//登录
-		swsClientMgr.login();
-		//init thread...
-		YA::_THREAD_CONFIG_ Config;
-		Config.SendInterval = st;
-		swsTimerThrd.Init( Config );
-		swsTimerThrd.Start();
-	}
-	
+        swsClientMgr.Build( uri_list, MsgFuncList );
+
+        //连接服务器
+        if ( swsClientMgr.connect() != 0 )
+        {
+            log_error("web socket init failed.");
+            std_error("web socket init failed.");
+            return;
+        }
+
+        //登录
+        swsClientMgr.login();
+        //init thread...
+        YA::_THREAD_CONFIG_ Config;
+        Config.SendInterval = st;
+        swsTimerThrd.Init( Config );
+        swsTimerThrd.Start();
+    }
+
 };
 
 
-void cleanup() 
-{ 
+void cleanup()
+{
     module_mgr::stop();
 }
 
 void usage(char ** argv)
 {
-	std::string cmd(argv[1]);
-	if(cmd=="--help" || cmd == "-H")
-	{
-		printf("用法:yals [选项]文件...\n");
-		printf("选项:\n");
-		printf("--help			显示此帮助说明\n");
-		printf("-v|--version		显示采集程序版本信息\n");
-	}
-	else if(cmd == "--version" || cmd == "-v")
-	{
-		printf("yals (采集程序) 0.1.0\n");
-	}
-	else
-	{
-		printf("Unknown option:%s\n",cmd.c_str());
-		printf( "usage:yals [--version][--help][-v][-H]\n");
-	}
+    std::string cmd(argv[1]);
+    if(cmd=="--help" || cmd == "-H")
+    {
+        printf("用法:yals [选项]文件...\n");
+        printf("选项:\n");
+        printf("--help			显示此帮助说明\n");
+        printf("-v|--version		显示采集程序版本信息\n");
+    }
+    else if(cmd == "--version" || cmd == "-v")
+    {
+        printf("yals (采集程序) 0.1.0\n");
+    }
+    else
+    {
+        printf("Unknown option:%s\n",cmd.c_str());
+        printf( "usage:yals [--version][--help][-v][-H]\n");
+    }
 
 
 }
 
 int main(int argc ,char * argv[])
 {
-	if(argc >1)
-	{
-		usage(argv);
-		return 0;
-	}
+    if(argc >1)
+    {
+        usage(argv);
+        return 0;
+    }
     log_init("../etc/log.ini");
     if(config.open("../etc/config.ini"))
-		return -1;
-	Init_Setting is;
-	is.init();
-	
-	atexit(&cleanup);
+        return -1;
+    Init_Setting is;
+    is.init();
 
-	card_path::init();
+    atexit(&cleanup);
+
+    card_path::init();
 
     module_mgr::start();
 
-	net_service mh;
-	int port=config.get("service.port",4000);
-	service_handle::instance(&mh)->run(port);
+    net_service mh;
+    int port=config.get("service.port",4000);
+    service_handle::instance(&mh)->run(port);
 
-	return 0;
+    return 0;
 }
-

+ 8 - 2
module_service/module_area.h

@@ -28,6 +28,8 @@ public:
     {
         if(0==c->id() || 0==c->mapid())
         {
+            log_error("(0==c->id() || 0==c->mapid()), card_id=%d, 卡type=%d,areaid=%d,mapid=%d",
+                      card_id, type, c->id(), c->mapid());
             return;
         }
 
@@ -38,7 +40,7 @@ public:
             return;
         }
 
-        c->m_enter_time = card_ptr->m_time/1000;
+        c->m_enter_time = tool_time::now_to_seconds();
 
         if(card_ptr->is_person())//统计人卡
         {
@@ -64,6 +66,8 @@ public:
     {
         if(0==c->id() || 0==c->mapid())
         {
+            log_error("(0==c->id() || 0==c->mapid()), card_id=%d, 卡type=%d,areaid=%d,mapid=%d",
+                      card_id, type, c->id(), c->mapid());
             return;
         }
 
@@ -92,6 +96,8 @@ public:
     {
         if(0==c->id() || 0==c->mapid())
         {
+            log_error("(0==c->id() || 0==c->mapid()), card_id=%d, 卡type=%d,areaid=%d,mapid=%d",
+                      card_id, type, c->id(), c->mapid());
             return;
         }
 
@@ -156,7 +162,7 @@ public:
         }
 
         std::string start_str = tool_time::to_str_ex(static_cast<uint64_t>(area_hover_ptr->m_enter_time) *1000);
-        std::string end_str = tool_time::to_str_ex(card_ptr->m_time);
+        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(),

+ 3 - 3
module_service/module_area_over_count.h

@@ -51,7 +51,7 @@ public:
             auto ev_ptr = event_list::instance()->get_event_area(area_ptr->id(), ev_type);
             if(ev_ptr)
             {
-                event_list::copy_event(card_ptr, ev_ptr);
+                event_list::copy_event(area_ptr, ev_ptr);
 
                 ev_ptr->m_limit_value=limit;
                 ev_ptr->m_cur_value=cur_value;
@@ -60,7 +60,7 @@ public:
             {
                 ev_ptr = event_list::create_event_area(area_ptr->id(), ev_type);
 
-                event_list::copy_event(card_ptr, ev_ptr);
+                event_list::copy_event(area_ptr, ev_ptr);
 
                 ev_ptr->m_limit_value=limit;
                 ev_ptr->m_cur_value=cur_value;
@@ -113,7 +113,7 @@ public:
                     return;
                 }
 
-                event_list::copy_event(card_ptr, ev_ptr);
+                event_list::copy_event(area_ptr, ev_ptr);
 
                 ev_ptr->m_limit_value=limit;
                 ev_ptr->m_cur_value=cur_value;

+ 0 - 2
module_service/module_area_timeout.h

@@ -27,8 +27,6 @@ private:
 public:
     void on_enter(std::shared_ptr<card_location_base> card_ptr,std::shared_ptr<area_hover>&c)
     {
-//        c->m_enter_time = card_ptr->m_time/1000;
-
 //        EVENT_TYPE ev_type = card_ptr->is_person() ? ET_CARD_AREA_OVER_TIME_PERSON : ET_AREA_OVER_COUNT_VEHICLE;
 //        //中途服务器宕机处理
 //        if(auto ev_ptr = event_list::instance()->get(card_ptr->m_id, ev_type))

+ 51 - 65
module_service/module_attendance_person.h

@@ -21,6 +21,7 @@
 #include"site_area.h"
 #include"module_const.h"
 #include"module_area.h"
+#include "module_meta_date_changed.h"
 
 /**
  * @brief 主要是针对人卡进行考勤,人卡从井上切换到井下为考勤开始,人卡从井下切换到井上为考勤结束
@@ -41,51 +42,20 @@ public:
      */
     void enter_site(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<site> site_ptr)
     {
-        auto site_area_ptr = card_ptr->get_site_area();
-        auto mine_tool_ptr = card_ptr->get_mine_tool();
-
         // 从井下切换到井上为考勤结束
         if(site_ptr->is_up_site())
         {
-            if(mine_tool_ptr->is_attendance())
-            {
-                //考勤结束
-                mine_tool_ptr->m_stat_attendance=AS_NOT_ATTENDANCE;
-
-                //作为一条结束考勤记录保存到数据库
-                tool_db::save_attendance(card_ptr);
-
-                rapidjson::Document doc(rapidjson::kObjectType);
-                rapidjson::Value datas(rapidjson::kArrayType);
-                rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
-
-                to_json_card_up_one(card_ptr, datas, allocator);
-                person_card_clear(card_ptr);
-
-                //升井json发给web
-                if(datas.Size() > 0)
-                {
-                    doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
-                    //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
-                    doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
-
-                    tool_other::send_json(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
-                }
-
-                log_info("人卡考勤结束:卡id=%d,卡type=%d,分站id=%d,分站reader_type_id=%d,stat_attendance=%d",
-                         card_ptr->m_id, card_ptr->m_type,
-                         site_ptr->m_id,site_ptr->m_reader_type_id,mine_tool_ptr->m_stat_attendance);
-            }
+            up_mine(card_ptr, site_ptr);
         }
         else// 从井上切换到井下为考勤开始
         {
+            auto mine_tool_ptr = card_ptr->get_mine_tool();
             if(!mine_tool_ptr->is_attendance())
             {
                 //考勤开始
                 mine_tool_ptr->m_stat_attendance=AS_ATTENDANCE;
 
-                mine_tool_ptr->m_attendance_start_time=
-                        std::chrono::system_clock::time_point(std::chrono::milliseconds(card_ptr->m_time));
+                mine_tool_ptr->m_attendance_start_time=std::chrono::system_clock::now();
 
                 //作为一条开始考勤记录保存到数据库
                 tool_db::save_attendance(card_ptr);
@@ -107,6 +77,51 @@ public:
 
 //    }
 
+    ///升井或收到web的删除卡命令  site_ptr==nullptr表示收到web的删除卡命令
+    static void up_mine(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<site> site_ptr)
+    {
+        auto mine_tool_ptr = card_ptr->get_mine_tool();
+        if(!mine_tool_ptr->is_attendance())
+        {
+            return;
+        }
+
+        //考勤结束
+        mine_tool_ptr->m_stat_attendance=AS_NOT_ATTENDANCE;
+
+        //作为一条结束考勤记录保存到数据库
+        tool_db::save_attendance(card_ptr);
+
+        rapidjson::Document doc(rapidjson::kObjectType);
+        rapidjson::Value datas(rapidjson::kArrayType);
+        rapidjson::Document::AllocatorType& allocator=doc.GetAllocator();
+
+        to_json_card_up_one(card_ptr, datas, allocator);
+        module_meta_date_changed::clear_card(card_ptr);
+
+        //升井json发给web
+        if(datas.Size() > 0)
+        {
+            doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_UP_MINE, allocator);
+            //doc.AddMember(JSON_ROOT_KEY_VERSION,INTERFACE_VERSION, allocator);
+            doc.AddMember(JSON_ROOT_KEY_DATA, datas, allocator);
+
+            tool_other::send_json(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
+        }
+
+        if(site_ptr)
+        {
+            log_info("人卡考勤结束:卡id=%d,卡type=%d,分站id=%d,分站reader_type_id=%d,stat_attendance=%d",
+                     card_ptr->m_id, card_ptr->m_type,
+                     site_ptr->m_id,site_ptr->m_reader_type_id,mine_tool_ptr->m_stat_attendance);
+        }
+        else
+        {
+            log_info("收到web的删除卡命令,人卡考勤结束:卡id=%d,卡type=%d, stat_attendance=%d",
+                     card_ptr->m_id, card_ptr->m_type, mine_tool_ptr->m_stat_attendance);
+        }
+    }
+
     /**
      * @brief 手工升井函数
      */
@@ -159,7 +174,7 @@ public:
                 }
 
                 to_json_card_up_one(card_ptr, datas, allocator);
-                person_card_clear(card_ptr);
+                module_meta_date_changed::clear_card(card_ptr);
             }
             else
             {
@@ -179,35 +194,6 @@ public:
     }
 
 private:
-    ///3.人卡升井要清除卡相关信息,区域相关,分站相关,考勤相关,清除定时器,
-    ///速度,状态 呼救 呼叫 告警相关。即保留基础信息,其他的重置。
-    static void person_card_clear(std::shared_ptr<card_location_base> card_ptr)
-    {
-		//删除
-		card_ptr->del_card_pos();
-        // 升井 删除所有报警信息
-        for(int i=0; i < CARD_EVENT_COUNT_MAX; i++ )
-        {
-            if (i == EVENT_TYPE::ET_CARD_LOW_POWER_SERIOUS)
-            {
-                continue;
-            }
-
-            auto ev_ptr = event_list::instance()->get_event_card(
-                        card_ptr->m_id, card_ptr->m_type, static_cast<EVENT_TYPE>(i));
-            if(ev_ptr && !ev_ptr->is_end()) //
-            {
-                event_list::copy_event(card_ptr, ev_ptr);
-
-                ev_ptr->m_status = ES_END;
-
-                event_list::save_event(ev_ptr);
-            }
-        }
-
-        card_ptr->clear();
-    }
-
     ///升井json
     static void to_json_card_up_one(std::shared_ptr<card_location_base> card_ptr,
                                        rapidjson::Value& out_datas, rapidjson::Document::AllocatorType& allocator)
@@ -239,7 +225,7 @@ private:
         //接收时间戳
         data.PushBack(0, allocator);
         //工作时长
-        t = tool_time::now_to_ms() - tool_time::to_ms(mine_tool_ptr->m_attendance_start_time);	//转为ms
+        t = tool_time::elapse_ms(mine_tool_ptr->m_attendance_start_time);	//转为ms
         data.PushBack(t, allocator);
 
         //地图编号

+ 33 - 16
module_service/module_attendance_vehicle.h

@@ -17,6 +17,7 @@
 #include <set>
 #include "module_const.h"
 #include "common_tool.h"
+#include"module_meta_date_changed.h"
 
 /**
  * @brief 车辆进入某些特定区域,结束考勤;从特定区域进入其他区域,开始考勤, 单例
@@ -32,34 +33,21 @@ private:
 public:
     void on_enter(std::shared_ptr<card_location_base> card_ptr, std::shared_ptr<area_hover>&c)
     {
-        auto mine_tool_ptr = card_ptr->get_mine_tool();
-
         auto area_ptr = c->m_area;
 
         //从考勤状态转换为结束考勤
         if(is_not_attendance_area(area_ptr->m_id, card_ptr->get_vehicle_type_id()))
         {
-            if(mine_tool_ptr->is_attendance())
-            {
-                //考勤结束
-                mine_tool_ptr->m_stat_attendance=AS_NOT_ATTENDANCE;
-
-                //作为一条结束考勤记录保存到数据库
-                tool_db::save_attendance(card_ptr);
-
-                log_info("车卡考勤结束:卡id=%d,卡type=%d,区域id=%d, stat_attendance=%d",
-                          card_ptr->m_id, card_ptr->m_type,
-                          area_ptr->m_id,mine_tool_ptr->m_stat_attendance);
-            }
+            save_attendance(card_ptr, area_ptr);
         }
         else//没在考勤状态转换为考勤状态
         {
+            auto mine_tool_ptr = card_ptr->get_mine_tool();
             if(!mine_tool_ptr->is_attendance())
             {
                 //考勤开始
                 mine_tool_ptr->m_stat_attendance=AS_ATTENDANCE;
-                mine_tool_ptr->m_attendance_start_time=
-                        std::chrono::system_clock::time_point(std::chrono::milliseconds(card_ptr->m_time));
+                mine_tool_ptr->m_attendance_start_time=std::chrono::system_clock::now();
 
                 //作为一条开始考勤记录保存到数据库
                 tool_db::save_attendance(card_ptr);
@@ -95,6 +83,7 @@ public:
         {
             log_info( "init_attendance_area_from_db. The record count=%ld\n", nCount );
 
+            m_map.clear();
             while ( DBRes.GetNextRecod(Error) )
             {
                 int area_id  = 0;
@@ -111,6 +100,34 @@ public:
         }
     }
 
+    ///area_ptr==nullptr 表示接收到 web的删除卡命令
+    static void save_attendance(std::shared_ptr<card_location_base>& card_ptr, std::shared_ptr<area> area_ptr)
+    {
+        auto mine_tool_ptr = card_ptr->get_mine_tool();
+        if(!mine_tool_ptr->is_attendance())
+        {
+            return;
+        }
+
+        //考勤结束
+        mine_tool_ptr->m_stat_attendance=AS_NOT_ATTENDANCE;
+
+        //作为一条结束考勤记录保存到数据库
+        tool_db::save_attendance(card_ptr);
+
+        if(area_ptr)
+        {
+            log_info("车卡考勤结束:卡id=%d,卡type=%d,区域id=%d, stat_attendance=%d",
+                      card_ptr->m_id, card_ptr->m_type,
+                      area_ptr->m_id,mine_tool_ptr->m_stat_attendance);
+        }
+        else
+        {
+            log_info("收到web的删除卡命令,车卡考勤结束:卡id=%d,卡type=%d,stat_attendance=%d",
+                      card_ptr->m_id, card_ptr->m_type,mine_tool_ptr->m_stat_attendance);
+        }
+    }
+
 private:
     bool is_not_attendance_area(int area_id, int vehicle_type_id)
     {

+ 210 - 0
module_service/module_meta_date_changed.cpp

@@ -0,0 +1,210 @@
+#include "module_meta_date_changed.h"
+#include"module_attendance_person.h"
+#include"module_attendance_vehicle.h"
+#include"ant.h"
+
+
+void module_meta_date_changed::deal_call_edit_vehicle(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        card_list::instance()->init_vehicle(id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        remove_card(static_cast<uint32_t>(id), CT_VEHICLE);
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_staff(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        card_list::instance()->init_staffer(id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        remove_card(static_cast<uint32_t>(id), CT_PERSON);
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_card(int id64, EDIT_TYPE_ID edit_type_id)
+{
+    std::string card_id64_str = tool_other::to13str(static_cast<uint64_t>(id64));
+    int type = tool_other::id64_to_type(card_id64_str);
+    int id = static_cast<int32_t>(tool_other::id64_to_id(card_id64_str));
+
+    if(CT_PERSON==type)
+    {
+        deal_call_edit_staff(id, edit_type_id);
+    }
+    else if(CT_VEHICLE==type)
+    {
+        deal_call_edit_vehicle(id, edit_type_id);
+    }
+    else
+    {
+        log_error("基础数据 删除卡type不对:type=%d", type);
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_area(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        if(is_monkeycar_area(id))
+        {
+            area_list::instance()->init_monkeycar_area(id);
+        }
+        else
+        {
+            area_list::instance()->init_from_db(id);
+        }
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        auto area_ptr = area_list::instance()->get(id);
+        if(!area_ptr)
+        {
+            log_info("区域已经删除:areaid=%d", id);
+            return;
+        }
+        //删除告警
+        delete_area_event(area_ptr);
+        area_list::instance()->remove(id);
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_reader(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        sit_list::instance()->init_site(id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        //删除告警
+
+        sit_list::instance()->remove(id);
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_antenna(int id,EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        sit_list::instance()->read_sit_list(id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        delete_antenna(id);
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_path(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id)
+    {
+        log_error("path不支持增加操作");
+        std_debug("path不支持增加操作");
+    }
+    else if(ET_UPDATE == edit_type_id)
+    {
+        sit_list::instance()->read_ant_path(id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        auto sit_ptr = sit_list::instance()->get(id);
+        if(sit_ptr)
+        {
+            sit_ptr->clear_path();
+        }
+
+        log_info("path删除成功,分站id=%d", id);
+        std_debug("path删除成功,分站id=%d", id);
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_map(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        if(!is_cur_map(id))
+        {
+            log_info("修改的不是当前使用的地图,要修改地图id=%d,当前使用地图id=%d", id, cur_map_id());
+            return;
+        }
+
+        update_map_info(id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        if(is_cur_map(id))
+        {
+            log_error("删除了当前使用的地图");
+            return;
+        }
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_light(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+    }
+}
+
+void module_meta_date_changed::deal_call_edit_lights_group(int id, EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+    }
+}
+
+void module_meta_date_changed::init_setting()
+{
+//pRes = getMysqlRes("select setting_id, name, type, value from dat_setting;");
+}
+
+void module_meta_date_changed::remove_card(uint32_t id, int32_t type)
+{
+    uint64_t card_id = card_list::to_id64(type, id);
+    auto card_ptr = card_list::instance()->get(card_id);
+    if(!card_ptr)
+    {
+        log_error("基础数据, 在全局列表中删除卡,全局列表中已经不存在此卡, id=%d, type=%d", id, type);
+        return;
+    }
+
+    if(card_ptr->is_person())
+    {
+        module_attendance_person::up_mine(card_ptr, nullptr);
+    }
+    else
+    {
+        clear_card_vehicle(card_ptr);
+    }
+
+    // 避免状态重置
+    card_list::instance()->remove(card_id);
+    log_info("基础数据, 在全局列表中删除卡成功, id=%d, type=%d", id, type);
+}
+
+void module_meta_date_changed::clear_card_vehicle(std::shared_ptr<card_location_base> card_ptr)
+{
+    module_attendance_vehicle::save_attendance(card_ptr, nullptr);
+
+    auto area_hover_ptr = card_ptr->get_area_hover();
+    if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
+    {
+        module_area::save_his_area_location_leave(card_ptr);
+    }
+
+    module_meta_date_changed::clear_card(card_ptr);
+}

+ 326 - 0
module_service/module_meta_date_changed.h

@@ -0,0 +1,326 @@
+#ifndef MODULE_META_DATE_CHANGED_H
+#define MODULE_META_DATE_CHANGED_H
+/**
+ * @brief 简要说明
+ * @author 戴月腾
+ * @date 2018-10-18
+ */
+
+#include"module_const.h"
+
+
+
+enum EDIT_TYPE_ID
+{
+    ET_INSERT = 0, // 新增
+    ET_UPDATE,	   // 修改
+    ET_DELETE      // 删除
+};
+
+class module_meta_date_changed:public singleton_base<module_meta_date_changed>
+{
+private:
+    friend class singleton_base<module_meta_date_changed>;
+    module_meta_date_changed()
+    {
+    }
+
+    ///已经实现的:'card', 'staff', 'vehicle', 'vehicle_extend', 'staff_extend', 'area', 'reader',
+    /// map antenna  path
+    ///提供了接口未实现的: setting  light  lights_group
+    ///下面的是暂时不要处理的
+    ///'drivingface', 'drivingface_render', 'dat_drivingface_warning_point',
+    ///'rules', 'drivingface_vehicle', 'dat_handup_vehicle', 'lights_binding'
+public:
+    ///基础数据
+    void accept(sio::message::ptr const& data)
+    {
+        std::string name="";
+        if(!tool_map::try_get_value(name, JSON_KEY_NAME, data))
+        {
+            log_error("web发来的数据: 基础数据找不到name字段");
+            return;
+        }
+
+        std_debug("基础数据 receive meta_data_changed: %s", name.c_str());
+
+        int id=-1;
+        tool_map::try_get_value(id, JSON_KEY_ID, data);
+
+        std::string op_type="";
+        tool_map::try_get_value(op_type, JSON_KEY_OP_TYPE, data);
+
+        if(-1 != id && !op_type.empty())
+        {
+            EDIT_TYPE_ID edit_type_id;
+            if(!try_get_edit_type_id(op_type, edit_type_id))
+            {
+                log_error("web发来的数据: 基础数据op_type字段错误:op_type=%s", op_type.c_str());
+                return;
+            }
+
+            if(JSON_KEY_NAME_VEHICLE == name || JSON_KEY_NAME_VEHICLE_EXTEND == name)
+            {
+                deal_call_edit_vehicle(id, edit_type_id);
+            }
+            else if(JSON_KEY_NAME_STAFF == name || JSON_KEY_NAME_STAFF_EXTEND == name)
+            {
+                deal_call_edit_staff(id, edit_type_id);
+            }
+            else if(JSON_KEY_NAME_CARD == name)
+            {
+                deal_call_edit_card(id, edit_type_id);
+            }
+            else if(JSON_KEY_NAME_AREA == name)
+            {
+                deal_call_edit_area(id, edit_type_id);
+            }
+            else if(JSON_KEY_NAME_READER == name)
+            {
+                deal_call_edit_reader(id, edit_type_id);
+            }
+            else if ("antenna" == name)
+            {
+                deal_call_edit_antenna(id,edit_type_id);
+            }
+            else if(JSON_KEY_NAME_PATH == name)
+            {
+                deal_call_edit_path(id, edit_type_id);
+            }
+            else if(JSON_KEY_NAME_MAP == name)
+            {
+                deal_call_edit_map(id, edit_type_id);
+            }
+            else if (JSON_KEY_NAME_LIGHT == name)
+            {
+                deal_call_edit_light(id,edit_type_id);///待实现
+            }
+            else if ("lights_group" == name)
+            {
+                deal_call_edit_lights_group(id,edit_type_id);///待实现
+            }
+            else
+            {
+                log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
+            }
+        }
+        else
+        {
+            if(JSON_KEY_NAME_SETTING == name)
+            {
+                //阈值限制接口
+                init_setting(); ///待实现
+            }
+            else
+            {
+                log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
+            }
+        }
+    }
+
+    ///3.清除卡相关信息,区域相关,分站相关,考勤相关,清除定时器,
+    ///速度,状态 呼救 呼叫 告警相关。即保留基础信息,其他的重置。
+    static void clear_card(std::shared_ptr<card_location_base> card_ptr)
+    {
+        //删除
+        card_ptr->del_card_pos();
+        // 升井 删除所有报警信息
+        for(int i=0; i < CARD_EVENT_COUNT_MAX; i++ )
+        {
+            if (i == EVENT_TYPE::ET_CARD_LOW_POWER_SERIOUS)
+            {
+                continue;
+            }
+
+            auto ev_ptr = event_list::instance()->get_event_card(
+                        card_ptr->m_id, card_ptr->m_type, static_cast<EVENT_TYPE>(i));
+            if(ev_ptr && !ev_ptr->is_end()) //
+            {
+                event_list::copy_event(card_ptr, ev_ptr);
+
+                ev_ptr->m_status = ES_END;
+
+                event_list::save_event(ev_ptr);
+            }
+        }
+
+        card_ptr->clear();
+    }
+
+private:
+    void deal_call_edit_vehicle(int id, EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_staff(int id, EDIT_TYPE_ID edit_type_id);
+
+    ///id64格式为10000006666
+    void deal_call_edit_card(int id64, EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_reader(int id, EDIT_TYPE_ID edit_type_id);
+
+    ///待实现
+    void deal_call_edit_path(int id, EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_antenna(int id,EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_area(int id, EDIT_TYPE_ID edit_type_id);
+
+    void deal_call_edit_map(int id, EDIT_TYPE_ID edit_type_id);
+
+    ///待实现
+    void deal_call_edit_light(int id,EDIT_TYPE_ID edit_type_id);
+
+    ///待实现
+    void deal_call_edit_lights_group(int id,EDIT_TYPE_ID edit_type_id);
+
+    ///待实现
+    void init_setting();
+
+    void remove_card(uint32_t id, int32_t type);
+
+    bool try_get_edit_type_id(const std::string& op_type, EDIT_TYPE_ID& out_edit_type_id)
+    {
+        if(JSON_KEY_OP_TYPE_UPDATE == op_type)
+        {
+            out_edit_type_id = ET_UPDATE;
+        }
+        else if(JSON_KEY_OP_TYPE_DELETE == op_type)
+        {
+            out_edit_type_id = ET_DELETE;
+        }
+        else if(JSON_KEY_OP_TYPE_INSERT == op_type)
+        {
+            out_edit_type_id = ET_INSERT;
+        }
+        else
+        {
+            return false;
+        }
+
+        return true;
+    }
+
+    bool is_monkeycar_area(int area_id)
+    {
+        char sql[1024] = {'\0'};
+        sprintf(sql,"select monkeycar_areaid from dat_monkeycar_base_info where monkeycar_areaid=%d;", area_id);
+        std::string Error;
+        YADB::CDBResultSet DBRes;
+        sDBConnPool.Query(sql,DBRes,Error);
+        int64_t nCount = DBRes.GetRecordCount( Error );
+
+        log_info("monkeycar_area区域查询:nCount=%d,sql=%s", nCount, sql);
+        std_debug("monkeycar_area区域查询:nCount=%d,sql=%s", nCount, sql);
+
+        return  (nCount > 0);
+    }
+
+    ///删除区域所有报警信息
+    static void delete_area_event(std::shared_ptr<area> area_ptr)
+    {
+        for(int i=0; i < CARD_EVENT_COUNT_MAX; i++ )
+        {
+            auto ev_ptr = event_list::instance()->get_event_area(area_ptr->id(), static_cast<EVENT_TYPE>(i));
+            if(ev_ptr && !ev_ptr->is_end()) //
+            {
+                event_list::copy_event(area_ptr, ev_ptr);
+
+                ev_ptr->m_status = ES_END;
+
+                event_list::save_event(ev_ptr);
+            }
+        }
+    }
+
+    void delete_antenna(int id)
+    {
+        int sitid=-8;
+        auto map = sit_list::instance()->m_map;
+        for(auto&it:map)
+        {
+            auto sit_ptr = it.second;
+            if(sit_ptr->m_ant[0].m_id == id)
+            {
+                sitid=sit_ptr->m_id;
+                sit_ptr->delete_antenna(0);
+                break;
+            }
+            if(sit_ptr->m_ant[1].m_id == id)
+            {
+                sitid=sit_ptr->m_id;
+                sit_ptr->delete_antenna(1);
+                break;
+            }
+        }
+
+        if(sitid==-8)
+        {
+            std_debug("天线已经删除了,在分站列表中找不到该天线:天线id=%d", id);
+            log_info("天线已经删除了,在分站列表中找不到该天线:天线id=%d", id);
+        }
+        else
+        {
+            std_debug("删除天线成功:天线id=%d,分站id=%d", id, sitid);
+            log_info("删除天线成功:天线id=%d,分站id=%d", id, sitid);
+        }
+    }
+
+    bool is_cur_map(int id)
+    {
+        return cur_map_id()==id;
+    }
+
+    int cur_map_id()
+    {
+        auto tmp = area_list::instance()->m_map;
+        for(auto&it:tmp)
+        {
+            if(0!=it.second->m_mapid)
+            {
+                return it.second->m_mapid;
+            }
+        }
+
+        return -1;
+    }
+
+    void update_map_info(int id)
+    {
+        std::string sql = "SELECT scale FROM dat_map WHERE map_id=";
+
+        sql.append(std::to_string(id));
+        sql.append(";");
+
+        std_debug("修改地图 sql=%s", sql.c_str());
+        log_info("修改地图 sql=%s", sql.c_str());
+
+        std::string Error;
+        YADB::CDBResultSet DBRes;
+        sDBConnPool.Query(sql.c_str(),DBRes,Error);
+        int nCount = DBRes.GetRecordCount( Error );
+        if (nCount < 1)
+        {
+            log_error("修改地图失败,数据库中找不到: map_id=%d", id);
+            return ;
+        }
+
+        double scale  = 0;
+        DBRes.GetField( "scale",scale, Error );
+
+        auto area = area_list::instance()->m_map;
+        for(auto& it : area)
+        {
+            it.second->m_scale = scale;
+        }
+
+        auto site = sit_list::instance()->m_map;
+        for(auto& it : site)
+        {
+            it.second->m_scale = scale;
+        }
+    }
+
+    ///收到web的删除车卡命令  保存考勤 入库  清理卡
+    void clear_card_vehicle(std::shared_ptr<card_location_base> card_ptr);
+};
+
+#endif // MODULE_META_DATE_CHANGED_H

+ 17 - 13
module_service/module_over_speed_vehicle.h

@@ -108,25 +108,29 @@ public:
         sDBConnPool.Query(sql,DBRes,Error);
         if(!Error.empty())
             log_error("init_vehicle_category Error,%s",Error.c_str());
-        uint64_t nCount = DBRes.GetRecordCount( Error );
-        if (nCount > 0)
+        int64_t nCount = DBRes.GetRecordCount( Error );
+        if (nCount < 1)
         {
-            log_info( "init_vehicle_category. The record count=%ld\n", nCount );
+            log_error("错误,init_vehicle_category. The record count=%ld\n", nCount );
+            return;
+        }
 
-            while ( DBRes.GetNextRecod(Error) )
-            {
-                int vehicle_category_id  = 0;
-                DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
+        log_info( "init_vehicle_category. The record count=%ld\n", nCount );
 
-                double over_speed = 0;
-                DBRes.GetField( "over_speed",over_speed, Error );
+        _vehicle_category_map.clear();
+        while ( DBRes.GetNextRecod(Error) )
+        {
+            int vehicle_category_id  = 0;
+            DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
 
-                _vehicle_category_map.insert({vehicle_category_id,over_speed});
-            }
+            double over_speed = 0;
+            DBRes.GetField( "over_speed",over_speed, Error );
 
-            for(const auto &p : _vehicle_category_map)
-                std_debug("dat_vehicle_category:category_id:%d--over_speed:%.2f",p.first,p.second);
+            _vehicle_category_map.insert({vehicle_category_id,over_speed});
         }
+
+        for(const auto &p : _vehicle_category_map)
+            std_debug("dat_vehicle_category:category_id:%d--over_speed:%.2f",p.first,p.second);
     }
 
 private:

+ 6 - 1
module_service/module_web.cpp

@@ -4,6 +4,7 @@
 #include"module_call.h"
 #include"module_area.h"
 #include"module_attendance_person.h"
+#include"module_meta_date_changed.h"
 
 void module_web::accept( int ID, std::string const& name,
                          sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp )
@@ -40,7 +41,11 @@ void module_web::accept( int ID, std::string const& name,
             return;
         }
 
-        if(JSON_CMD_VALUE_DEAL_HELP == cmd) // 处理呼救信息
+        if(JSON_CMD_VALUE_META_DATA_CHANGED == cmd)///基础数据
+        {
+            module_meta_date_changed::instance()->accept(data_value);
+        }
+        else if(JSON_CMD_VALUE_DEAL_HELP == cmd) // 处理呼救信息
         {
             module_call_help::instance()->accept_web_deal_help(data_value);
         }

+ 10 - 2
ya_event.h

@@ -164,8 +164,7 @@ public:
     {
         ev_ptr->x = card_ptr->x;
         ev_ptr->y = card_ptr->y;
-        ev_ptr->m_cur_time = std::chrono::system_clock::time_point(std::chrono::milliseconds(card_ptr->m_time));
-                //std::chrono::system_clock::now();
+        ev_ptr->m_cur_time = std::chrono::system_clock::now();
         ev_ptr->m_is_display = card_ptr->m_display;
 
         auto hover = card_ptr->get_area_hover();
@@ -180,6 +179,15 @@ public:
         }
     }
 
+    static void copy_event(const std::shared_ptr<area> area_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 =  area_ptr->id();
+        ev_ptr->m_map_id = area_ptr->mapid();
+    }
+
     std::shared_ptr<ya_event> get_event_card(uint32_t card_id, int card_type, EVENT_TYPE ev_type)
     {
         return base::get(to_list_id(ev_type, OT_CARD, card_type, card_id));