|
@@ -1,7 +1,3 @@
|
|
|
-//
|
|
|
-// Created by Administrator on 2019/3/5.
|
|
|
-//
|
|
|
-
|
|
|
#include "forbid_staff_down_mine.h"
|
|
|
#include "log.h"
|
|
|
#include "tool_time.h"
|
|
@@ -12,14 +8,10 @@ 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 ";
|
|
|
sql += " where status = 1 and end_time > now() ";
|
|
|
if (id != -1)
|
|
|
- {
|
|
|
sql += " and id = " + std::to_string(id) + ";";
|
|
|
- }
|
|
|
else
|
|
|
- {
|
|
|
sql += ";";
|
|
|
- m_map.clear();
|
|
|
- }
|
|
|
+
|
|
|
std::string Error;
|
|
|
YADB::CDBResultSet DBRes;
|
|
|
sDBConnPool.Query(sql.c_str(),DBRes,Error);
|
|
@@ -29,13 +21,6 @@ void forbid_staff_down_mine::init_forbid_staff(int id /* = -1*/)
|
|
|
log_error("增加或修改失败,数据库中找不到: sql", sql.c_str());
|
|
|
return ;
|
|
|
}
|
|
|
- forbid_staff_down_mine::instance()->update_forbid_data(DBRes,true);
|
|
|
-}
|
|
|
-
|
|
|
-//更新数据
|
|
|
-void forbid_staff_down_mine::update_forbid_data(YADB::CDBResultSet & DBRes,bool bInsert)
|
|
|
-{
|
|
|
- std::string Error;
|
|
|
while ( DBRes.GetNextRecod(Error) )
|
|
|
{
|
|
|
int key = 0;
|
|
@@ -53,22 +38,24 @@ void forbid_staff_down_mine::update_forbid_data(YADB::CDBResultSet & DBRes,bool
|
|
|
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 != nullptr)
|
|
|
+ //如果存在则查找更新。查找不到则插入
|
|
|
+ if (s)
|
|
|
{
|
|
|
- if(!bInsert)
|
|
|
+ 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;
|
|
|
- log_info("Check Forbid_staff_down_mine DBID:%d Staff:%d State:%d Time:%s -> %s . "
|
|
|
+ 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());
|
|
|
- continue;
|
|
|
- }
|
|
|
+ break;
|
|
|
}
|
|
|
+ if (f) continue;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -85,16 +72,11 @@ void forbid_staff_down_mine::update_forbid_data(YADB::CDBResultSet & DBRes,bool
|
|
|
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());
|
|
|
+ ,key,staff_id,state,start_time.c_str(),end_time.c_str());
|
|
|
s->forbidList.push_back(info);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-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);
|
|
@@ -103,8 +85,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;
|