|
@@ -1,24 +1,15 @@
|
|
|
-//
|
|
|
-// 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";
|
|
|
+ std::string sql = "select id,staff_id,start_time,end_time,status,oper_time,lastupdate from rt_person_forbid_down_mine where status = 1 and end_time > now() ";
|
|
|
if (id != -1)
|
|
|
- {
|
|
|
sql += " and id = " + std::to_string(id) + ";";
|
|
|
- }
|
|
|
else
|
|
|
- {
|
|
|
- m_map.clear();
|
|
|
- }
|
|
|
+ sql += ";";
|
|
|
std::string Error;
|
|
|
YADB::CDBResultSet DBRes;
|
|
|
sDBConnPool.Query(sql.c_str(),DBRes,Error);
|
|
@@ -28,59 +19,62 @@ void forbid_staff_down_mine::init_forbid_staff(int id /* = -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);
|
|
|
+ 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::shared_ptr<SForbidStaffList> s = nullptr;
|
|
|
- if (id != -1)
|
|
|
+ std::string create_time;
|
|
|
+ DBRes.GetField("oper_time", create_time, Error);
|
|
|
+ std::string update_time;
|
|
|
+ DBRes.GetField("lastupdate", update_time, Error);
|
|
|
+ std::shared_ptr<SForbidStaffList> s = forbid_staff_down_mine::instance()->get(staff_id);
|
|
|
+ //如果存在则查找更新。查找不到则插入
|
|
|
+ if (s)
|
|
|
{
|
|
|
- s = forbid_staff_down_mine::instance()->get(s_id);
|
|
|
- if (s != nullptr)
|
|
|
+ bool f=false;
|
|
|
+ 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;
|
|
|
- }
|
|
|
+ f=true;
|
|
|
+ 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());
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+ if(f)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;
|
|
|
+
|
|
|
+ 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);
|
|
|
- forbid_staff_down_mine::instance()->add(s_id,s);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void forbid_staff_down_mine::del_forbid_staff(int staff_id)
|
|
|
-{
|
|
|
- forbid_staff_down_mine::instance()->remove(staff_id);
|
|
|
-}
|
|
|
-
|
|
|
void forbid_staff_down_mine::del_forbid_data(int id,int staff_id)
|
|
|
{
|
|
|
auto s = forbid_staff_down_mine::instance()->get(staff_id);
|
|
@@ -89,8 +83,7 @@ void forbid_staff_down_mine::del_forbid_data(int id,int staff_id)
|
|
|
log_info(" remove Forbid Staff:%d Down mine.DBID=%d",s->staff_id,id);
|
|
|
for(auto it = s->forbidList.begin(); it != s->forbidList.end() ; ++it)
|
|
|
{
|
|
|
- SForbidStaffInfo & info = *it;
|
|
|
- if (info.db_id == id)
|
|
|
+ if ((*it).db_id == id)
|
|
|
{
|
|
|
s->forbidList.erase(it);
|
|
|
break;
|
|
@@ -106,7 +99,7 @@ void forbid_staff_down_mine::del_forbid_data(int id,int staff_id)
|
|
|
//是否禁止状态
|
|
|
bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
|
|
|
{
|
|
|
- auto flist = m_map;
|
|
|
+ auto flist = forbid_staff_down_mine::instance()->m_map;
|
|
|
auto it = flist.find(staff_id);
|
|
|
if (it != flist.end())
|
|
|
{
|
|
@@ -119,4 +112,4 @@ bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
-}
|
|
|
+}
|