Browse Source

Merge branch 'master' of chensongchao/ya-serv into master

liheting 6 years ago
parent
commit
44111b2029

+ 2 - 1
Makefile.am

@@ -21,7 +21,8 @@ SRC_MAIN= ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_ar
     	  card.cpp card_message_handle.cpp cardMgr.cpp card_path.cpp card_person.cpp crc.cpp geo_hash.cpp \
 		  landmark.cpp line_fit.cpp loc_point.cpp loc_tool.cpp message.cpp message_file.cpp mine.cpp \
 		  net-service.cpp point.cpp select_tool.cpp  special_area.cpp tdoa_sync.cpp visit.cpp \
-		  web-client.cpp worker.cpp event.cpp znet.cpp ya_setting.cpp area_business.cpp
+		  web-client.cpp worker.cpp event.cpp znet.cpp ya_setting.cpp area_business.cpp\
+		  forbid_staff_down_mine.cpp
 
 AM_SOURCES=$(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN) $(SRC_MAIN_EVENT)
 

+ 27 - 10
card.cpp

@@ -18,20 +18,20 @@
 #include "mine_business.h"
 
 extern config_file config;
-void card_list::init_staffer(int64_t id64)
+void card_list::init_staffer(const std::string & lszId64)
 {
     std::string strategy = config.get("person.strategy","PS_1");
 
 	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> 
-		map=std::move(db_card::load_person(id64,strategy));
+		map=std::move(db_card::load_person(lszId64,strategy));
 
 	if(map.empty())
 	{
-		log_error("增加或修改失败,数据库中找不到: card_id=%013lld", id64);
+		log_error("增加或修改失败,数据库中找不到: card_id=%", lszId64.c_str());
 		return ;
 	}
 
-	if(-1 == id64)
+	if("" == lszId64)
 	{
 		log_info( "init_staffer. The record count=%d\n", map.size() );
 		card_list::instance()->add(map);
@@ -39,6 +39,7 @@ void card_list::init_staffer(int64_t id64)
 	else
 	{
 		auto db_person=map.begin()->second;
+        uint64_t id64 = map.begin()->first;
 		auto card_ptr = card_list::instance()->get(id64);
 		if(card_ptr)
 		{
@@ -68,18 +69,18 @@ void card_list::init_staffer(int64_t id64)
 }
 
 
-void card_list::init_vehicle(int64_t id64)
+void card_list::init_vehicle(const std::string & lszId64)
 {
 	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> 
-		map=std::move(db_card::load_car(id64));
+		map=std::move(db_card::load_car(lszId64));
 
 	if(map.empty())
 	{
-		log_error("增加或修改失败,数据库中找不到: card_id=%013lld", id64);
+		log_error("增加或修改失败,数据库中找不到: card_id=%s", lszId64.c_str());
 		return ;
 	}
 
-	if(-1 == id64)
+	if("" == lszId64)
 	{
 		log_info( "init_vehicle. The record count=%d\n", map.size() );
 		card_list::instance()->add(map);
@@ -87,6 +88,7 @@ void card_list::init_vehicle(int64_t id64)
 	else
 	{
 		car* db_car= static_cast<car*>(map.begin()->second.get());
+        uint64_t id64 = map.begin()->first;
 		auto card_ptr = card_list::instance()->get(id64);
 		if(card_ptr)
 		{
@@ -109,8 +111,8 @@ void card_list::init_vehicle(int64_t id64)
 
 void card_list::init_card_from_db()
 {
-    init_staffer(-1);
-    init_vehicle(-1);
+    init_staffer("");
+    init_vehicle("");
 }
 
 void card_list::load_his_card_postion_from_db()
@@ -357,11 +359,26 @@ void card_list::on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_
 	c->on_message(loop,loc,is_history);
 }
 
+//获取卡数据  //标识id 人staff_id 车 vehicle_id
+std::shared_ptr<card_location_base> card_list::get_card_by_cid(int cid)
+{
+    auto t_map = m_map;
+    for(std::pair<int,std::shared_ptr<card_location_base>> me:t_map)
+    {
+        if ((int)me.second->m_cid == cid)
+        {
+            return me.second;
+        }
+    }
+    return nullptr;
+}
+
 bool card_list_visit::visit(std::shared_ptr<card_location_base> c)
 {
 	c->get_card(_flag);
 	return true;	
 }
 
+
 //template<> std::shared_ptr<card_list> single_base<card_list, uint64_t, std::shared_ptr<card_location_base>>::m_instance=std::make_shared<card_list>();
 

+ 6 - 4
card.h

@@ -14,9 +14,9 @@ struct card_list_visit:visitor<std::shared_ptr<card_location_base>>
 
 struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_base>>
 {
-    ///id64=-1为初始化所有卡, id格式为:10000001016
-    void init_staffer(int64_t id64);
-    void init_vehicle(int64_t id64);
+    ///lszId64=为初始化所有卡, lszId64格式为:0010000001016
+    void init_staffer(const std::string & lszId64);
+    void init_vehicle(const std::string & lszId64);
     void on_message(zloop<task*> *loop,const message_locinfo&loc,bool is_history);
     void init_card_from_db();
 
@@ -24,6 +24,8 @@ struct card_list:single_base<card_list,uint64_t,std::shared_ptr<card_location_ba
     void load_his_card_postion_staff();
     void load_his_card_postion_from_db();
 
+    //获取卡数据  //标识id 人staff_id 车 vehicle_id
+    std::shared_ptr<card_location_base> get_card_by_cid(int cid);
     ~card_list(){}
 };
-#endif
+#endif

+ 2 - 2
card_base.cpp

@@ -56,7 +56,6 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 	m_ct = loc.m_card_ct;
 	m_time = loc.m_time_stamp;
 	auto site_ptr = sit_list::instance()->get(loc.m_site_id);
-
 	if(!site_ptr)
 	{
 		return;
@@ -67,6 +66,8 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 		auto area_tool=get_area_tool();
 		area_tool->set(site_ptr);
 		area_tool->on_point(shared_from_this(),point(1,1));
+
+		this->site_hover(loc.m_site_id);
 	}
 	else
 	{
@@ -74,7 +75,6 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 		{
 			log_warn("接收到分站%d的数据,CT=%d,但是分站路径为空",site_ptr->id(),loc.m_card_ct);
 		}
-
 		m_message_handle->on_message(loop,loc,is_history);
 	}
 }

+ 3 - 8
card_message_handle.cpp

@@ -154,17 +154,12 @@ void card_message_handle::on_message(zloop<task*> * loop,const message_locinfo&l
 		log_warn("%s","当前代码没有处理历史消息记录。");
 		return;
 	}
-	//
-	m_card->site_hover(loc.m_site_id);
-
+	STATUS_CARD c_status = STATUS_POWER_NOMARL;
 	if(loc.m_batty_status == 2)
 	{
-		m_card->do_status(STATUS_POWER_LOWER_SERIOUS);
-	}
-	else
-	{
-		m_card->do_status(STATUS_POWER_NOMARL);
+		c_status = STATUS_POWER_LOWER_SERIOUS;
 	}
+	m_card->do_status(c_status);
 
 	if(loc.m_callinfo & 0x80)
 	{

+ 19 - 17
card_person.cpp

@@ -15,6 +15,7 @@
 #include "mine_business.h"
 #include"common_tool.h"
 #include"db/db_tool.h"
+#include "forbid_staff_down_mine.h"
 
 person::person(const std::string &type,uint32_t cardid,uint16_t needdisplay,int16_t t,int32_t deptid,int32_t level_id,uint32_t cid,int wl,const std::string &sname,const std::string &dname,int worketype_id)
 	:card_location_base(type,cardid,needdisplay,t,deptid,level_id,cid)
@@ -57,26 +58,27 @@ void person::site_hover(int sid)
 //虹膜识别入库功能	
 void person::IKSDK_DB(int sid)
 {
-	auto sit_ptr = sit_list::instance()->get(sid);
-	if(nullptr == sit_ptr)
-	  return;
-	if(sit_ptr->m_reader_type_id == READER_TYPE_ID_UP)
+	printf("person::IKSDK_DB : card=%d,Sid=%d \n",m_id,sid);
+	time_t now = time(0);
+	if(now - m_iris_recognition_timeval > 5)
 	{
-		time_t now = time(0);
-		if(now - m_iris_recognition_timeval > 5)
+		if (forbid_staff_down_mine::instance()->IsForbid(m_cid,now))
 		{
-			int f=0;
-			if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_LOW_POWER_SERIOUS))
-			  f=1;
-			std::string card_id = tool_other::type_id_to_str(m_type,m_id);
-			std::string st	    = tool_time::to_str(now);
-			char nsql[256]={0};
-			const char*sql="REPLACE INTO his_att_interface (staff_id,card_id,reader_id,staff_name,dept_name,upt_time,low_power_warn) VALUES (%d,%s,%d,'%s','%s','%s',%d);";
-			snprintf(nsql,256,sql,m_cid,card_id.c_str(),sid,m_stafferName.c_str(),m_deptName.c_str(),st.c_str(),f);
-			db_tool::PushAsync(nsql);
-			logn_info(2,"%s",nsql);
-			m_iris_recognition_timeval = now;
+			log_info("Staff:%d forbid down mine",m_cid); //禁止指定人员下井
+			return;
 		}
+		int f=0;
+		if(event_list::instance()->get_event_card(m_id, m_type, ET_CARD_LOW_POWER_SERIOUS)) {
+			f = 1;
+		}
+		std::string card_id = tool_other::type_id_to_str(m_type,m_id);
+		std::string st	    = tool_time::to_str(now);
+		char nsql[256]={0};
+		const char*sql="REPLACE INTO his_att_interface (staff_id,card_id,reader_id,staff_name,dept_name,upt_time,low_power_warn) VALUES (%d,%s,%d,'%s','%s','%s',%d);";
+		snprintf(nsql,256,sql,m_cid,card_id.c_str(),sid,m_stafferName.c_str(),m_deptName.c_str(),st.c_str(),f);
+		db_tool::PushAsync(nsql);
+		logn_info(2,"%s",nsql);
+		m_iris_recognition_timeval = now;
 	}
 }
 

+ 6 - 9
db/db_card.cpp

@@ -13,7 +13,7 @@
 extern config_file config;
 namespace db_card
 {
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(int64_t id64)
+	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(const std::string & lszId64)
 	{
 		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, \
@@ -30,16 +30,14 @@ namespace db_card
 
 		std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
 
-		std::string card_id_str = tool_other::to13str(id64);
-
-		if(-1 == id64)
+		if("" == lszId64)
 		{
 			sql.append(";");
 		}
 		else
 		{
 			sql.append(" AND ve.card_id ='");
-			sql.append(card_id_str);
+			sql.append(lszId64);
 			sql.append("';");
 		}
 
@@ -110,7 +108,7 @@ namespace db_card
 		return map;
 	}
 
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(int64_t id64,const std::string&strategy)
+	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(const std::string & lszId64,const std::string&strategy)
 	{
 		std::string sql = "SELECT s.staff_id, s.card_id, c.card_type_id, s.dept_id, s.group_id, s.occupation_id, \
 						   ol.occupation_level_id,s.worktype_id,s.need_display,s.work_line\
@@ -124,15 +122,14 @@ namespace db_card
 						   WHERE s.duty_id = 0 AND c.state_id = 0";
 
 		std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
-		std::string card_id_str = tool_other::to13str(id64);
-		if(-1 == id64)
+		if("" == lszId64)
 		{
 			sql.append(";");
 		}
 		else
 		{
 			sql.append(" AND s.card_id = '");
-			sql.append(card_id_str);
+			sql.append(lszId64);
 			sql.append("';");
 		}
 

+ 3 - 3
db/db_card.h

@@ -7,9 +7,9 @@ struct card_location_base;
 
 namespace db_card
 {
-
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(int64_t id64,const std::string&); 
-	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(int64_t id64); 
+	//const std::string & lszId64 = 0010000001102
+	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(const std::string & lszId64,const std::string&);
+	std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(const std::string & lszId64);
 
 }
 

+ 124 - 0
forbid_staff_down_mine.cpp

@@ -0,0 +1,124 @@
+//
+// Created by Administrator on 2019/3/5.
+//
+
+#include "forbid_staff_down_mine.h"
+#include "log.h"
+#include "tool_time.h"
+#include "db_api/CDBResultSet.h"
+#include "db_api/CDBSingletonDefine.h"
+
+void forbid_staff_down_mine::init_forbid_staff(int id /* = -1*/)
+{
+    std::string sql = "select id,staff_id,start_time,end_time,status from rt_person_forbid_down_mine where status = 1";
+    if (id != -1)
+    {
+        m_map.clear();
+        sql += " and id = " + std::to_string(id) + ";";
+    }
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    int nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
+    {
+        log_error("增加或修改失败,数据库中找不到: sql", sql.c_str());
+        return ;
+    }
+
+    while ( DBRes.GetNextRecod(Error) )
+    {
+        int key = 0;
+        DBRes.GetField("id", key, Error);
+        unsigned int s_id = 0;
+        DBRes.GetField("staff_id", s_id, Error);
+        std::string start_time;
+        DBRes.GetField("start_time", start_time, Error);
+        std::string end_time;
+        DBRes.GetField("end_time", end_time, Error);
+        int state;
+        DBRes.GetField("status", state, Error);
+
+        if (id != -1)
+        {
+            auto s = get(id);
+            if (s != nullptr)
+            {
+                s->staff_id = s_id;
+                s->start_time = tool_time::to_time(start_time);
+                s->end_time = tool_time::to_time(end_time);
+                s->state = state;
+                continue;
+            }
+        }
+
+        std::shared_ptr<SForbidStaffInfo> s = std::make_shared<SForbidStaffInfo>();
+        s->staff_id = s_id;
+        s->start_time = tool_time::to_time(start_time);
+        s->end_time = tool_time::to_time(end_time);
+        s->state = state;
+        forbid_staff_down_mine::instance()->add(key,s);
+
+        m_forbidlist[s_id].push_back(key);
+    }
+}
+
+void forbid_staff_down_mine::del_forbid_staff(int staff_id)
+{
+    auto it = m_forbidlist.find(staff_id);
+    if (it != m_forbidlist.end()) {
+        for (auto key : it->second) {
+            forbid_staff_down_mine::instance()->remove(key);
+        }
+        m_forbidlist.erase(it);
+    }
+}
+
+void forbid_staff_down_mine::del_forbid_data(int id)
+{
+    auto s = forbid_staff_down_mine::instance()->get(id);
+    if (s != nullptr)
+    {
+        log_info(" remove Forbid Staff:%d Down mine.",s->staff_id);
+        auto it = m_forbidlist.find(s->staff_id);
+        if (it != m_forbidlist.end())
+        {
+            for (auto key : it->second)
+            {
+                if(key == id)
+                {
+                    it->second.remove(id);
+                    break;
+                }
+            }
+            if (it->second.size() == 0)
+            {
+                m_forbidlist.erase(it);
+            }
+        }
+    }
+    forbid_staff_down_mine::instance()->remove(id);
+}
+
+//是否禁止状态
+bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
+{
+    auto flist = m_forbidlist;
+    auto it = flist.find(staff_id);
+    if (it != flist.end())
+    {
+        for (auto key : it->second)
+        {
+            std::shared_ptr<SForbidStaffInfo> s = get(key);
+            if (nullptr == s) {
+                continue;
+            }
+            if (s->state == 1 && cur_time > s->start_time && cur_time < s->end_time)
+            {
+                return true;
+            }
+        }
+    }
+    //del_forbid_staff(staff_id);  //容易引起多线程问题 已过禁止时间 或者记录失效 删除
+    return false;
+}

+ 49 - 0
forbid_staff_down_mine.h

@@ -0,0 +1,49 @@
+//
+// Created by Administrator on 2019/3/5.
+// 禁止制定人员下井
+//
+
+#ifndef WORKSPACE_FORBID_STAFF_DOWN_MINE_H
+#define WORKSPACE_FORBID_STAFF_DOWN_MINE_H
+
+#include "write-copy.h"
+#include <string>
+#include <map>
+#include <list>
+
+struct SForbidStaffInfo
+{
+    int staff_id;
+    time_t start_time;
+    time_t end_time;
+    int state;          //状态 0 = 无效 1 = 有效
+    SForbidStaffInfo()
+    {
+        staff_id = 0;
+        start_time = 0;
+        end_time = 0;
+        state = 0;
+    }
+};
+
+struct forbid_staff_down_mine
+        :single_base<forbid_staff_down_mine,int,std::shared_ptr<SForbidStaffInfo>>
+{
+public:
+    // 根据数据库中的自增长id
+    void init_forbid_staff(int id = -1);
+    // 根据数据库中的自增长id
+    void del_forbid_data(int id);
+    // 根据员工ID
+    void del_forbid_staff(int staff_id);
+
+    //是否禁止状态
+    bool IsForbid(int staff_id,time_t cur_time);
+
+private:
+    typedef std::map <int ,std::list<int>> ForbidStaffList;
+    ForbidStaffList m_forbidlist;
+};
+
+
+#endif //WORKSPACE_FORBID_STAFF_DOWN_MINE_H

+ 14 - 3
main.cpp

@@ -21,6 +21,7 @@
 #include "main_test.h"
 #include "ya_setting.h"
 #include "websocket/web_connect.h"
+#include "forbid_staff_down_mine.h"
 
 config_file config;
 void handlereader(uint32_t readerid,bool duration,uint32_t t)
@@ -51,21 +52,29 @@ struct Init_Setting
         DBSetting.CharSet = config.get("db.charset","utf8");
         DBSetting.TimeOut = config.get("db.conn_timeout",5);
         DBSetting.PoolSize = config.get("db.pool_size",30);
+        DBSetting.Port = config.get("db.port",3306);
         if(!_mysql_init(DBSetting))
-		  exit(0);
-         
+        {
+            std_info("连接DB[%s:%s] 失败,采集服务器无法启动!",DBSetting.Host.c_str(),DBSetting.User.c_str());
+            exit(0);
+        }
+
         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);
         if(!wsClientMgr_init(url_list,send_interval))
-		  exit(0);
+        {
+            std_info("连接webServer[%s] 失败,采集服务器无法启动!",url.c_str());
+            exit(0);
+        }
 
 		CYaSetting::Init_sys_setting();
         sit_list::instance()->load_from_db();
         card_list::instance()->init_card_from_db();
         area_list::instance()->init_from_db();
+        forbid_staff_down_mine::instance()->init_forbid_staff();
         //point pt(3348,100);
         //int id = area_list::instance()->get_area(pt)->id();
         //std_info("test area:%d",id);
@@ -99,6 +108,7 @@ struct Init_Setting
 		ip.driving_face_alarm = Handle_ThreeRates_Event_Callback;
 		three_rates::get_instance()->init(ip,dbs);
 		three_rates::get_instance()->start();
+        std_info("加载三率模块成功");
 	}
 
     bool _mysql_init(YADB::_DB_POOL_SETTING_ &dps)
@@ -112,6 +122,7 @@ struct Init_Setting
             std_error("数据库线程池创建失败,Err=%s", szError.c_str());
 			flag = false;
         }
+        std_info("数据库线程池创建成功");
 		return flag;
     }
 

+ 84 - 43
module_service/module_meta_date_changed.cpp

@@ -10,7 +10,11 @@
 #include"ant.h"
 #include"card.h"
 #include"area.h"
-
+#include "forbid_staff_down_mine.h"
+#include <boost/format.hpp>
+#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string.hpp>
 
 ///基础数据
 void module_meta_date_changed::accept(sio::message::ptr const& data)
@@ -25,11 +29,13 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
 
     int64_t id=-1;
     tool_map::try_get_value(id, JSON_KEY_ID, data);
+    std::string szParam = "0";
+    tool_map::try_get_value(szParam,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())
+    if((-1 != id || szParam != "0") && !op_type.empty())
     {
         EDIT_TYPE_ID edit_type_id;
         if(!try_get_edit_type_id(op_type, edit_type_id))
@@ -37,20 +43,20 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
             log_error("web发来的数据: 基础数据op_type字段错误:op_type=%s", op_type.c_str());
             return;
         }
-
-		log_info("基础数据 receive meta_data_changed: %s, id=%d, op_type=%d", name.c_str(), id, edit_type_id);
+		log_info("基础数据 receive meta_data_changed: %s, id=%d-%s, op_type=%d"
+		        , name.c_str(), id,szParam.c_str() , edit_type_id);
 
         if(JSON_KEY_NAME_VEHICLE == name || JSON_KEY_NAME_VEHICLE_EXTEND == name)
         {
-            deal_call_edit_vehicle(id, edit_type_id);
+            deal_call_edit_vehicle_or_staff(szParam, edit_type_id);
         }
         else if(JSON_KEY_NAME_STAFF == name || JSON_KEY_NAME_STAFF_EXTEND == name)
         {
-            deal_call_edit_staff(id, edit_type_id);
+            deal_call_edit_vehicle_or_staff(szParam, edit_type_id);
         }
         else if(JSON_KEY_NAME_CARD == name)
         {
-            deal_call_edit_card(id, edit_type_id);
+            deal_call_edit_card(szParam, edit_type_id);
         }
         else if(JSON_KEY_NAME_AREA == name)
         {
@@ -80,6 +86,10 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
         {
             deal_call_edit_lights_group(id,edit_type_id);///待实现
         }
+        else if (JSON_KEY_NAME_FORBID_PERSON_DOWN_MINE == name)
+        {
+            deal_call_edit_forbid_person_down_mine(id,edit_type_id);
+        }
         else
         {
             log_error("web发来的数据: 基础数据name字段错误:name=%s", name.c_str());
@@ -132,48 +142,61 @@ void module_meta_date_changed::clear_card(std::shared_ptr<card_location_base> ca
         //        }
     }
 }
-
-
-void module_meta_date_changed::deal_call_edit_vehicle(int64_t id64, EDIT_TYPE_ID edit_type_id)
+/*
+ * 修改车及卡的数据
+ * id64 = ;员工ID或者车ID;卡ID=101;0010000001198  分号间隔
+ */
+void module_meta_date_changed::deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id)
 {
-    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
-    {
-        card_list::instance()->init_vehicle(id64);
-    }
-    else if(ET_DELETE == edit_type_id)
+    std::vector<std::string> vecSegTag;
+    boost::split(vecSegTag, id64, boost::is_any_of(";"));
+    if (vecSegTag.size() == 1)  //数据发生错误
     {
-        auto str = tool_other::to13str(id64);
-
-        remove_card(tool_other::id64_to_id(str), tool_other::id64_to_type(str));
+        log_errno("Web Send Data Error!(%s)", id64.c_str());
+        return;
     }
-}
-
-void module_meta_date_changed::deal_call_edit_staff(int64_t id64, EDIT_TYPE_ID edit_type_id)
-{
+    std::string lsz_card_id = vecSegTag[1];
+    int cid = std::stoi(vecSegTag[0].c_str());
     if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
     {
-        card_list::instance()->init_staffer(id64);
+        if (ET_UPDATE == edit_type_id)
+        {
+            auto c = card_list::instance()->get_card_by_cid(cid);
+            if (nullptr != c && tool_other::type_id_to_str(c->m_type,c->m_id) != lsz_card_id)
+            {
+                //如果修改了卡号,则删除原来的卡的数据
+                remove_card(c);
+            }
+        }
+        int c_type = tool_other::id64_to_type(lsz_card_id);
+        if (tool_other::is_vehicle(c_type))
+        {
+            card_list::instance()->init_vehicle(lsz_card_id);
+        }
+        else if (tool_other::is_person(c_type))
+        {
+            card_list::instance()->init_staffer(lsz_card_id);
+        }
     }
-    else if(ET_DELETE == edit_type_id)
+    else
     {
-        auto str = tool_other::to13str(id64);
-
-        remove_card(tool_other::id64_to_id(str), tool_other::id64_to_type(str));
+        remove_card(tool_other::id64_to_id(lsz_card_id), tool_other::id64_to_type(lsz_card_id));
     }
 }
 
-void module_meta_date_changed::deal_call_edit_card(int64_t id64, EDIT_TYPE_ID edit_type_id)
+void module_meta_date_changed::deal_call_edit_card(std::string & id64, EDIT_TYPE_ID edit_type_id)
 {
-    std::string card_id64_str = tool_other::to13str(static_cast<uint64_t>(id64));
+    std::string card_id64_str = tool_other::to13str(id64);
     int type = tool_other::id64_to_type(card_id64_str);
-
-    if(tool_other::is_person(type))
-    {
-        deal_call_edit_staff(id64, edit_type_id);
-    }
-    else if(tool_other::is_vehicle(type))
+    if(tool_other::is_person(type) || tool_other::is_vehicle(type))
     {
-        deal_call_edit_vehicle(id64, edit_type_id);
+        auto c = card_list::instance()->get(tool_other::card_id_to_u64(card_id64_str));
+        if (nullptr == c) {
+            log_info("web edit card:%s Not bind staff or vehicle. editType:%d", card_id64_str.c_str(), edit_type_id);
+            return ;
+        }
+        std::string lsz = std::to_string(c->m_cid) + ";" + card_id64_str;
+        deal_call_edit_vehicle_or_staff(lsz,edit_type_id);
     }
     else
     {
@@ -300,21 +323,40 @@ void module_meta_date_changed::deal_call_edit_lights_group(int id, EDIT_TYPE_ID
     }
 }
 
+// 禁止指定人员下井 id = (rt_person_forbid_down_mine)数据库中自增长ID
+void module_meta_date_changed::deal_call_edit_forbid_person_down_mine(int id,EDIT_TYPE_ID edit_type_id)
+{
+    if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
+    {
+        forbid_staff_down_mine::instance()->init_forbid_staff(id);
+    }
+    else if(ET_DELETE == edit_type_id)
+    {
+        forbid_staff_down_mine::instance()->del_forbid_data(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)
-{
+void module_meta_date_changed::remove_card(uint32_t id, int32_t type) {
     uint64_t card_id = tool_other::type_id_to_u64(type, id);
     auto card_ptr = card_list::instance()->get(card_id);
-    if(!card_ptr)
-    {
+    if (!card_ptr) {
         log_error("基础数据, 在全局列表中删除卡,全局列表中已经不存在此卡, id=%d, type=%d", id, type);
         return;
     }
-
+    remove_card(card_ptr);
+}
+void module_meta_date_changed::remove_card(std::shared_ptr<card_location_base> card_ptr)
+{
+    if (!card_ptr)
+    {
+        return;
+    }
+    log_info("基础数据, 在全局列表中删除卡成功, id=%d, type=%d",card_ptr->m_type, card_ptr->m_id);
     //    auto area_hover_ptr = card_ptr->get_area_hover();
     //    if(area_hover_ptr && 0!=area_hover_ptr->id() && 0!=area_hover_ptr->mapid())
     //    {
@@ -331,11 +373,10 @@ void module_meta_date_changed::remove_card(uint32_t id, int32_t type)
 
     //        module_meta_date_changed::clear_card(card_ptr);
     //    }
-
     module_meta_date_changed::clear_card(card_ptr);
     // 避免状态重置
+    uint64_t card_id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
     card_list::instance()->remove(card_id);
-    log_info("基础数据, 在全局列表中删除卡成功, id=%d, type=%d", id, type);
 }
 
 bool module_meta_date_changed::try_get_edit_type_id(const std::string& op_type, EDIT_TYPE_ID& out_edit_type_id)

+ 10 - 6
module_service/module_meta_date_changed.h

@@ -43,14 +43,14 @@ public:
     static void clear_card(std::shared_ptr<card_location_base> card_ptr);
 
 private:
-    ///id64格式为:10000001016
-    void deal_call_edit_vehicle(int64_t id64, EDIT_TYPE_ID edit_type_id);
-
-    ///id64格式为:10000001016
-    void deal_call_edit_staff(int64_t id64, EDIT_TYPE_ID edit_type_id);
+    /*
+     * 修改车及卡的数据
+     * id64 = ;员工ID或者车ID;卡ID=101;0010000001198  分号间隔
+     */
+    void deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id);
 
     ///id64格式为10000006666
-    void deal_call_edit_card(int64_t id64, EDIT_TYPE_ID edit_type_id);
+    void deal_call_edit_card(std::string & id64, EDIT_TYPE_ID edit_type_id);
 
     void deal_call_edit_reader(int id, EDIT_TYPE_ID edit_type_id);
 
@@ -69,10 +69,14 @@ private:
     ///待实现
     void deal_call_edit_lights_group(int id,EDIT_TYPE_ID edit_type_id);
 
+    // 禁止指定人员下井
+    void deal_call_edit_forbid_person_down_mine(int id,EDIT_TYPE_ID edit_type_id);
+
     ///待实现
     void init_setting();
 
     void remove_card(uint32_t id, int32_t type);
+    void remove_card(std::shared_ptr<card_location_base> card_ptr);
 
     bool try_get_edit_type_id(const std::string& op_type, EDIT_TYPE_ID& out_edit_type_id);
 

+ 3 - 0
websocket/constdef.h

@@ -71,6 +71,9 @@
 #define JSON_KEY_NAME_DRIVINGFACE "drivingface_vehicle"
 #define JSON_KEY_NAME_DRIVINGFACE_WARNING_POINT "dat_drivingface_warning_point"
 #define JSON_KEY_NAME_HAND_UP "dat_handup_vehicle"
+//禁止指定人员下井
+#define JSON_KEY_NAME_FORBID_PERSON_DOWN_MINE "rt_person_forbid_down_mine"
+
 
 #define JSON_KEY_CALL_CARD_CALL_TYPE "call_type_id"
 #define JSON_KEY_CALL_CARD_CALL_TIME_OUT "call_time_out"