Jelajahi Sumber

web实时修改人员及车辆信息,调试。新增禁止指定人员下井web更改通知采集服务器
调试采集服务器关于禁止指定人员下井所有功能。

chensongchao 6 tahun lalu
induk
melakukan
345b916eed

+ 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)
 

+ 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;
 	}
 }
 

+ 123 - 0
forbid_staff_down_mine.cpp

@@ -0,0 +1,123 @@
+//
+// 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;
+        this->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) {
+            this->remove(key);
+        }
+        m_forbidlist.erase(it);
+    }
+}
+
+void forbid_staff_down_mine::del_forbid_data(int id)
+{
+    auto s = this->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);
+            }
+        }
+    }
+    this->remove(id);
+}
+
+//是否禁止状态
+bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
+{
+    auto it = m_forbidlist.find(staff_id);
+    if (it != m_forbidlist.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

+ 12 - 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)
@@ -49,7 +50,10 @@ struct Init_Setting
         std::vector<std::string> url_list;
         url_list.push_back(url);
         if(!wsClientMgr_init(url_list,send_interval))
-		  exit(0);
+        {
+            std_info("连接Web Server 失败,采集服务器无法启动!");
+            exit(0);
+        }
         YADB::_DB_POOL_SETTING_ DBSetting;
 
         DBSetting.Host = config.get("db.host","127.0.0.1");
@@ -59,13 +63,17 @@ 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);
+        }
 		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);
@@ -110,6 +118,7 @@ struct Init_Setting
             std_error("数据库线程池创建失败,Err=%s", szError.c_str());
 			flag = false;
         }
+        std_info("数据库线程池创建成功");
 		return flag;
     }
 

+ 39 - 22
module_service/module_meta_date_changed.cpp

@@ -10,6 +10,7 @@
 #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>
@@ -34,7 +35,8 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
     std::string op_type="";
     tool_map::try_get_value(op_type, JSON_KEY_OP_TYPE, data);
 
-    if(-1 != id && !op_type.empty())
+    //printf("Recv Web Data : name=%s,edit_type=%s id =%lld , %s ...\n",name.c_str(),op_type.c_str(),id,szParam.c_str());
+    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))
@@ -85,6 +87,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());
@@ -138,41 +144,39 @@ void module_meta_date_changed::clear_card(std::shared_ptr<card_location_base> ca
     }
 }
 /*
-     * 修改车及卡的数据
-     * 在 ET_INSERT | ET_DELETE id64 = 卡ID =10000001198
-     * ET_UPDATE  id64 = 卡ID;员工ID或者车ID=10000001198;101  分号间隔
-     */
+ * 修改车及卡的数据
+ * id64 = ;员工ID或者车ID;卡ID=101;10000001198  分号间隔
+ */
 void module_meta_date_changed::deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id)
 {
-    // 在 ET_INSERT | ET_DELETE id64 = 卡ID =10000001198
-    //ET_UPDATE  id64 = 卡ID;员工ID或者车ID=10000001198;101  分号间隔
+    // id64 = ;员工ID或者车ID;卡ID=101;10000001198  分号间隔
+
+    std::vector<std::string> vecSegTag;
+    boost::split(vecSegTag, id64, boost::is_any_of(";"));
+    if (vecSegTag.size() == 1)  //数据发生错误
+    {
+        log_errno("Web Send Data Error!(%s)", id64.c_str());
+        return;
+    }
+    std::string lsz_card_id = vecSegTag[1];
+    int64_t card_id = std::stoll(lsz_card_id);
+    int cid = std::stoi(vecSegTag[0].c_str());
     if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
     {
-        int64_t card_id = std::stoll(id64);
         if (ET_UPDATE == edit_type_id)
         {
-            std::vector<std::string> vecSegTag;
-            boost::split(vecSegTag, id64,boost::is_any_of(";"));
-            if (vecSegTag.size() == 1)  //数据发生错误
-            {
-                log_errno("Web Send Data Error!(%s)",id64.c_str());
-                return;
-            }
-            auto c = card_list::instance()->get_card_by_cid(std::stoi(vecSegTag[1].c_str()));
-            if (nullptr != c && tool_other::type_id_to_str(c->m_type,c->m_id) != tool_other::to13str(vecSegTag[0]))
+            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);
             }
-            card_id = std::stoll(vecSegTag[0]);
         }
         card_list::instance()->init_vehicle(card_id);
     }
     else
     {
-        std::string card_id = id64;
-        auto str = tool_other::to13str(card_id);
-        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));
     }
 }
 
@@ -189,7 +193,7 @@ void module_meta_date_changed::deal_call_edit_card(std::string & id64, EDIT_TYPE
             if (nullptr != c)
             {
                 char id[100] = {0};
-                sprintf(id,"%s;%d",lsz.c_str(),c->m_cid);
+                sprintf(id,"%d;%s",c->m_cid,card_id64_str.c_str());
                 lsz = id;
             }
         }
@@ -320,6 +324,19 @@ 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;");

+ 4 - 2
module_service/module_meta_date_changed.h

@@ -45,8 +45,7 @@ public:
 private:
     /*
      * 修改车及卡的数据
-     * 在 ET_INSERT | ET_DELETE id64 = 卡ID =10000001198
-     * ET_UPDATE  id64 = 卡ID;员工ID或者车ID=10000001198;101  分号间隔
+     * id64 = ;员工ID或者车ID;卡ID=101;10000001198  分号间隔
      */
     void deal_call_edit_vehicle_or_staff(const std::string & id64, EDIT_TYPE_ID edit_type_id);
 
@@ -70,6 +69,9 @@ 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();
 

+ 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"