瀏覽代碼

修改禁止人员下井功能 数据初始化问题
最小系统重新加载数据

chensongchao 6 年之前
父節點
當前提交
66e4b9b892
共有 9 個文件被更改,包括 219 次插入62 次删除
  1. 1 1
      Makefile.am
  2. 6 3
      card_base.cpp
  3. 55 20
      forbid_staff_down_mine.cpp
  4. 9 0
      forbid_staff_down_mine.h
  5. 43 38
      main.cpp
  6. 61 0
      min_system.cpp
  7. 40 0
      min_system.h
  8. 1 0
      ya_setting.cpp
  9. 3 0
      ya_setting.h

+ 1 - 1
Makefile.am

@@ -22,7 +22,7 @@ SRC_MAIN= ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_ar
 		  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\
-		  forbid_staff_down_mine.cpp
+		  forbid_staff_down_mine.cpp min_system.cpp
 
 AM_SOURCES=$(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN) $(SRC_MAIN_EVENT)
 

+ 6 - 3
card_base.cpp

@@ -18,6 +18,7 @@
 #include "common_tool.h"
 #include "ant.h"
 #include "area.h"
+#include "ya_setting.h"
 
 extern config_file config;
 
@@ -168,9 +169,11 @@ void card_location_base::put_three_rates(card_pos & cp)
 		cp.reader_y = _areatool->m_site->y;
 		cp.reader_id = _areatool->m_site->m_id;
 	}
-
-	log_info("three_rates:type:%d,id:%d,cid:%d",cp.type,cp.id,cp.identifier_id);
-	three_rates::get_instance()->put(cp);
+	if (!CYaSetting::g_minSystem)
+	{
+		log_info("three_rates:type:%d,id:%d,cid:%d",cp.type,cp.id,cp.identifier_id);
+		three_rates::get_instance()->put(cp);
+	}
 }
 
 bool card_location_base::is_person() const

+ 55 - 20
forbid_staff_down_mine.cpp

@@ -5,18 +5,18 @@
 #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";
+    std::string sql = "select id,staff_id,start_time,end_time,status,oper_time,lastupdate from rt_person_forbid_down_mine where status = 1";
     if (id != -1)
     {
         sql += " and id = " + std::to_string(id) + ";";
     }
     else
     {
+        sql += ";";
         m_map.clear();
     }
     std::string Error;
@@ -28,54 +28,79 @@ void forbid_staff_down_mine::init_forbid_staff(int id /* = -1*/)
         log_error("增加或修改失败,数据库中找不到: sql", sql.c_str());
         return ;
     }
+    update_forbid_data(DBRes);
+}
 
+//更新数据
+void forbid_staff_down_mine::update_forbid_data(YADB::CDBResultSet & DBRes)
+{
+    std::string Error;
     while ( DBRes.GetNextRecod(Error) )
     {
         int key = 0;
         DBRes.GetField("id", key, Error);
-        unsigned int s_id = 0;
-        DBRes.GetField("staff_id", s_id, Error);
+        unsigned int staff_id = 0;
+        DBRes.GetField("staff_id", staff_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);
+        std::string create_time;
+        DBRes.GetField("oper_time", create_time, Error);
+        std::string update_time;
+        DBRes.GetField("lastupdate", update_time, Error);
+        updatetime(create_time);
+        updatetime(update_time);
 
-        std::shared_ptr<SForbidStaffList> s = nullptr;
-        if (id != -1)
+        std::shared_ptr<SForbidStaffList> s = forbid_staff_down_mine::instance()->get(staff_id);
+        if (s != nullptr)
         {
-            s = forbid_staff_down_mine::instance()->get(s_id);
-            if (s != nullptr)
+            for (SForbidStaffInfo &info : s->forbidList)
             {
-                for (SForbidStaffInfo &info : s->forbidList)
+                if (info.db_id == key) //已有记录,修改完成
                 {
-                    if (info.db_id == key) //已有记录,修改完成
-                    {
-                        info.start_time = tool_time::to_time(start_time);
-                        info.end_time = tool_time::to_time(end_time);
-                        info.state = state;
-                        return;
-                    }
+                    info.start_time = tool_time::to_time(start_time);
+                    info.end_time = tool_time::to_time(end_time);
+                    info.state = state;
+                    continue;
                 }
             }
         }
-        if (s == nullptr)
+        else
         {
             s = std::make_shared<SForbidStaffList>();
+            forbid_staff_down_mine::instance()->add(staff_id,s);
         }
-        s->staff_id = s_id;
+        s->staff_id = staff_id;
         SForbidStaffInfo info ;
-        info.staff_id = s_id;
+        info.staff_id = staff_id;
         info.db_id = key;
         info.start_time = tool_time::to_time(start_time);
         info.end_time = tool_time::to_time(end_time);
         info.state = state;
         s->forbidList.push_back(info);
-        forbid_staff_down_mine::instance()->add(s_id,s);
     }
 }
 
+//重新加载数据更新时间> m_updateTime
+void forbid_staff_down_mine::on_load_data()
+{
+    std::string sql = "select id,staff_id,start_time,end_time,status,oper_time,lastupdate from rt_person_forbid_down_mine";
+    sql += " where status = 1 and (oper_time > '" + m_updateTime + "' or lastupdate > '" + m_updateTime + "') ;";
+    std::string Error;
+    YADB::CDBResultSet DBRes;
+    sDBConnPool.Query(sql.c_str(),DBRes,Error);
+    int nCount = DBRes.GetRecordCount( Error );
+    if (nCount < 1)
+    {
+        return ;
+    }
+
+    update_forbid_data(DBRes);
+}
+
 void forbid_staff_down_mine::del_forbid_staff(int staff_id)
 {
     forbid_staff_down_mine::instance()->remove(staff_id);
@@ -119,4 +144,14 @@ bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
         }
     }
     return false;
+}
+
+void forbid_staff_down_mine::updatetime(const std::string & t)
+{
+    if (t.length() > 0 && t > m_updateTime)
+    {
+        m_updateTime = t;
+
+        std_info("forbid_staff_down_mine(%x)::updatetime : t:%s updateTime: %s",this,t.c_str(),m_updateTime.c_str());
+    }
 }

+ 9 - 0
forbid_staff_down_mine.h

@@ -10,6 +10,7 @@
 #include <string>
 #include <map>
 #include <list>
+#include "db_api/CDBResultSet.h"
 
 struct SForbidStaffInfo
 {
@@ -47,6 +48,14 @@ public:
 
     //是否禁止状态
     bool IsForbid(int staff_id,time_t cur_time);
+    //重新加载数据更新时间> m_updateTime
+    void on_load_data();
+private:
+    //更新数据
+    void update_forbid_data(YADB::CDBResultSet & DBRes);
+    void updatetime(const std::string & t);
+    //数据中最新时间
+    std::string m_updateTime = "";
 };
 
 

+ 43 - 38
main.cpp

@@ -22,6 +22,7 @@
 #include "ya_setting.h"
 #include "websocket/web_connect.h"
 #include "forbid_staff_down_mine.h"
+#include "min_system.h"
 
 config_file config;
 void handlereader(uint32_t readerid,bool duration,uint32_t t)
@@ -42,34 +43,42 @@ void Handle_ThreeRates_Event_Callback(const int evType, const int evId, uint64_t
 
 struct Init_Setting
 {
-    void init()
-    {
-        YADB::_DB_POOL_SETTING_ DBSetting;
-        DBSetting.Host = config.get("db.host","127.0.0.1");
-        DBSetting.User = config.get("db.user","root");
-        DBSetting.PWD = config.get("db.passwd","123456");
-        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.pool_size",30);
-        DBSetting.Port = config.get("db.port",3306);
-        if(!_mysql_init(DBSetting))
+    void init() {
+        //是否最小系统
+        CYaSetting::g_minSystem = config.get("minsystem", 0);
+        if (CYaSetting::g_minSystem)
         {
-            std_info("连接DB[%s:%s] 失败,采集服务器无法启动!",DBSetting.Host.c_str(),DBSetting.User.c_str());
+            s_min_system.initSystem(&config);
+        }
+        YADB::_DB_POOL_SETTING_ DBSetting;
+        DBSetting.Host = config.get("db.host", "127.0.0.1");
+        DBSetting.User = config.get("db.user", "root");
+        DBSetting.PWD = config.get("db.passwd", "123456");
+        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.pool_size", 30);
+        DBSetting.Port = config.get("db.port", 3306);
+        if (!_mysql_init(DBSetting)) {
+            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))
+        if (!CYaSetting::g_minSystem)
         {
-            std_info("连接webServer[%s] 失败,采集服务器无法启动!",url.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))
+            {
+                std_info("连接webServer[%s] 失败,采集服务器无法启动!", url.c_str());
+                exit(0);
+            }
+
+            //三率模块
+            init_three_rates(DBSetting);
         }
-
 		if(0)
 		{
 			std::vector<char> b(1024*1024);
@@ -93,28 +102,24 @@ struct Init_Setting
 		mine_business::inst()->load();
         event_list::instance()->load_his_data_from_db();
         card_list::instance()->load_his_card_postion_from_db();
-        db_para dp;	
-        dp.Host=DBSetting.Host;
-        dp.User=DBSetting.User;
-        dp.PWD=DBSetting.PWD ;
-        dp.DBName=DBSetting.DBName;
-        dp.CharSet=DBSetting.CharSet ;
-        dp.TimeOut=DBSetting.TimeOut;
-        dp.PoolSize=DBSetting.PoolSize;
-		init_three_rates(dp);
-
-
         log_info("Init_Setting::init  Success. \n" );
-
     }
 
-	void init_three_rates(const db_para& dbs)
+	void init_three_rates(const YADB::_DB_POOL_SETTING_ & dbset)
 	{
-		log_info("init three_rates ...................");
+        db_para dps;
+        dps.Host = dbset.Host;
+        dps.User = dbset.User;
+        dps.PWD = dbset.PWD;
+        dps.DBName = dbset.DBName;
+        dps.CharSet = dbset.CharSet;
+        dps.TimeOut = dbset.TimeOut;
+        dps.PoolSize = dbset.PoolSize;
+
 		init_para ip;
 		ip.send_pt = handlereader;
 		ip.driving_face_alarm = Handle_ThreeRates_Event_Callback;
-		three_rates::get_instance()->init(ip,dbs);
+		three_rates::get_instance()->init(ip,dps);
 		three_rates::get_instance()->start();
         std_info("加载三率模块成功");
 	}

+ 61 - 0
min_system.cpp

@@ -0,0 +1,61 @@
+//
+// Created by Administrator on 2019/3/15.
+//
+
+#include "min_system.h"
+#include "ya_setting.h"
+#include "forbid_staff_down_mine.h"
+#include <ev++.h>
+#include "card.h"
+#include "log.h"
+#include "config_file.h"
+
+min_system::min_system ()
+{
+    m_thread.reset(new std::thread(std::bind(&min_system::run,this)));
+    m_lastTimer = time(nullptr) ;
+    m_interval_time = 30;
+}
+
+void min_system::initSystem(config_file * config)
+{
+    std_info("当前系统: 采集最小系统,和虹膜考勤系统相关! 初始化最小系统");
+    if (config)
+    {
+        m_interval_time = config->get("min_system_interval_time",60);
+    }
+}
+
+//定时重新加载相关数据
+void min_system::on_timer_load()
+{
+    if (!CYaSetting::g_minSystem)
+    {
+        return ;
+    }
+    forbid_staff_down_mine::instance()->on_load_data();
+}
+
+void min_system::run()
+{
+    ev::timer timer_1s(*this);
+
+    timer_1s.set<min_system,&min_system::on_time>(this);
+    timer_1s.start(m_interval_time,m_interval_time);
+
+    ev::dynamic_loop::run(0);
+    //log_info("worker_thread exit....");
+}
+
+void min_system::on_time()
+{
+    std_info("min_system::on_time ");
+    time_t cur_time = time(nullptr);
+    s_min_system.on_timer_load();
+    if (cur_time - s_min_system.m_lastTimer > 60 * 60)
+    {
+        card_list::instance()->init_staffer("");
+    }
+    s_min_system.m_lastTimer = time(nullptr);
+}
+

+ 40 - 0
min_system.h

@@ -0,0 +1,40 @@
+//
+// Created by Administrator on 2019/3/15.
+//
+
+#ifndef WORKSPACE_MIN_SYSTEM_H
+#define WORKSPACE_MIN_SYSTEM_H
+
+#include <boost/serialization/singleton.hpp>
+#include <thread>
+#include "zloop.h"
+struct task;
+struct config_file;
+
+class min_system: zloop<task*>
+{
+public:
+    min_system();
+    ~min_system(){};
+
+    void initSystem(config_file * config);
+private:
+    void run();
+    //定时时间处理 每分钟
+    void on_time();
+
+    //定时重新加载相关数据
+    void on_timer_load();
+private:
+    std::unique_ptr<std::thread> m_thread;
+    // 上传加载时间
+    time_t m_lastTimer;
+    // 间隔多久加载一次 (秒)
+    int m_interval_time;
+};
+
+//单件相关定义
+typedef boost::serialization::singleton<min_system> singleton_min_system ;
+#define s_min_system singleton_min_system::get_mutable_instance()
+
+#endif //WORKSPACE_MIN_SYSTEM_H

+ 1 - 0
ya_setting.cpp

@@ -3,6 +3,7 @@
 #include "log.h"
 
 SSys_setting CYaSetting::m_sys_setting;
+bool CYaSetting::g_minSystem  = false;
 /*
 * 从数据库的dat_setting表初始化系统阈值,
 * 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值

+ 3 - 0
ya_setting.h

@@ -55,6 +55,9 @@ public:
     static SSys_setting m_sys_setting;
     static bool Init_sys_setting();
 
+    //是否最小系统
+    //最小系统 用于 和虹膜考勤系统相关---只负责考勤定位不用其他功能
+    static bool g_minSystem ;
 };
 
 #endif