Browse Source

修改禁止人员下井,新增最下系统定时加载数据

chensongchao 6 năm trước cách đây
mục cha
commit
f13831b7aa
2 tập tin đã thay đổi với 31 bổ sung18 xóa
  1. 24 14
      forbid_staff_down_mine.cpp
  2. 7 4
      forbid_staff_down_mine.h

+ 24 - 14
forbid_staff_down_mine.cpp

@@ -7,9 +7,12 @@
 #include "tool_time.h"
 #include "db_api/CDBSingletonDefine.h"
 
+std::string forbid_staff_down_mine::m_updateTime = "";
+
 void forbid_staff_down_mine::init_forbid_staff(int id /* = -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";
+    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 end_time > now() ";
     if (id != -1)
     {
         sql += " and id = " + std::to_string(id) + ";";
@@ -28,11 +31,11 @@ void forbid_staff_down_mine::init_forbid_staff(int id /* = -1*/)
         log_error("增加或修改失败,数据库中找不到: sql", sql.c_str());
         return ;
     }
-    update_forbid_data(DBRes);
+    forbid_staff_down_mine::instance()->update_forbid_data(DBRes,true);
 }
 
 //更新数据
-void forbid_staff_down_mine::update_forbid_data(YADB::CDBResultSet & DBRes)
+void forbid_staff_down_mine::update_forbid_data(YADB::CDBResultSet & DBRes,bool bInsert)
 {
     std::string Error;
     while ( DBRes.GetNextRecod(Error) )
@@ -51,20 +54,25 @@ void forbid_staff_down_mine::update_forbid_data(YADB::CDBResultSet & DBRes)
         DBRes.GetField("oper_time", create_time, Error);
         std::string update_time;
         DBRes.GetField("lastupdate", update_time, Error);
-        updatetime(create_time);
-        updatetime(update_time);
+        forbid_staff_down_mine::updatetime(create_time);
+        forbid_staff_down_mine::updatetime(update_time);
 
         std::shared_ptr<SForbidStaffList> s = forbid_staff_down_mine::instance()->get(staff_id);
         if (s != nullptr)
         {
-            for (SForbidStaffInfo &info : s->forbidList)
+            if(!bInsert)
             {
-                if (info.db_id == key) //已有记录,修改完成
+                for (SForbidStaffInfo &info : s->forbidList)
                 {
-                    info.start_time = tool_time::to_time(start_time);
-                    info.end_time = tool_time::to_time(end_time);
-                    info.state = state;
-                    continue;
+                    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;
+                        log_info("Check Forbid_staff_down_mine DBID:%d Staff:%d State:%d Time:%s -> %s . "
+                                ,key,staff_id,state,start_time.c_str(),end_time.c_str());
+                        continue;
+                    }
                 }
             }
         }
@@ -80,6 +88,9 @@ void forbid_staff_down_mine::update_forbid_data(YADB::CDBResultSet & DBRes)
         info.start_time = tool_time::to_time(start_time);
         info.end_time = tool_time::to_time(end_time);
         info.state = state;
+
+        log_info("Init Forbid_staff_down_mine DBID:%d Staff:%d State:%d Time:%s -> %s . "
+        ,key,staff_id,state,start_time.c_str(),end_time.c_str());
         s->forbidList.push_back(info);
     }
 }
@@ -98,7 +109,7 @@ void forbid_staff_down_mine::on_load_data()
         return ;
     }
 
-    update_forbid_data(DBRes);
+    forbid_staff_down_mine::instance()->update_forbid_data(DBRes,false);
 }
 
 void forbid_staff_down_mine::del_forbid_staff(int staff_id)
@@ -150,8 +161,7 @@ void forbid_staff_down_mine::updatetime(const std::string & t)
 {
     if (t.length() > 0 && t > m_updateTime)
     {
+        log_info("forbid_staff_down_mine::updatetime :LastTime: %s -> t:%s ",t.c_str(),m_updateTime.c_str());
         m_updateTime = t;
-
-        std_info("forbid_staff_down_mine(%x)::updatetime : t:%s updateTime: %s",this,t.c_str(),m_updateTime.c_str());
     }
 }

+ 7 - 4
forbid_staff_down_mine.h

@@ -38,6 +38,8 @@ struct SForbidStaffList
 struct forbid_staff_down_mine
         :single_base<forbid_staff_down_mine,int,std::shared_ptr<SForbidStaffList>>
 {
+public:
+    ~forbid_staff_down_mine(){}
 public:
     // 根据数据库中的自增长id
     void init_forbid_staff(int id = -1);
@@ -50,12 +52,13 @@ public:
     bool IsForbid(int staff_id,time_t cur_time);
     //重新加载数据更新时间> m_updateTime
     void on_load_data();
-private:
+
+public:
     //更新数据
-    void update_forbid_data(YADB::CDBResultSet & DBRes);
-    void updatetime(const std::string & t);
+    void update_forbid_data(YADB::CDBResultSet & DBRes,bool bInsert);
+    static void updatetime(const std::string & t);
     //数据中最新时间
-    std::string m_updateTime = "";
+    static std::string m_updateTime;
 };