|
@@ -13,9 +13,12 @@ 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) + ";";
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ m_map.clear();
|
|
|
+ }
|
|
|
std::string Error;
|
|
|
YADB::CDBResultSet DBRes;
|
|
|
sDBConnPool.Query(sql.c_str(),DBRes,Error);
|
|
@@ -41,84 +44,77 @@ void forbid_staff_down_mine::init_forbid_staff(int id /* = -1*/)
|
|
|
|
|
|
if (id != -1)
|
|
|
{
|
|
|
- auto s = get(id);
|
|
|
+ auto s = forbid_staff_down_mine::instance()->get(s_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;
|
|
|
+ for (SForbidStaffInfo &info : s->forbidList)
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- std::shared_ptr<SForbidStaffInfo> s = std::make_shared<SForbidStaffInfo>();
|
|
|
+ std::shared_ptr<SForbidStaffList> s = std::make_shared<SForbidStaffList>();
|
|
|
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;
|
|
|
- forbid_staff_down_mine::instance()->add(key,s);
|
|
|
-
|
|
|
- m_forbidlist[s_id].push_back(key);
|
|
|
+ SForbidStaffInfo info ;
|
|
|
+ info.staff_id = s_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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
- forbid_staff_down_mine::instance()->remove(key);
|
|
|
- }
|
|
|
- m_forbidlist.erase(it);
|
|
|
- }
|
|
|
+ forbid_staff_down_mine::instance()->remove(staff_id);
|
|
|
}
|
|
|
|
|
|
-void forbid_staff_down_mine::del_forbid_data(int id)
|
|
|
+void forbid_staff_down_mine::del_forbid_data(int id,int staff_id)
|
|
|
{
|
|
|
- auto s = forbid_staff_down_mine::instance()->get(id);
|
|
|
+ auto s = forbid_staff_down_mine::instance()->get(staff_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())
|
|
|
+ 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)
|
|
|
{
|
|
|
- for (auto key : it->second)
|
|
|
- {
|
|
|
- if(key == id)
|
|
|
- {
|
|
|
- it->second.remove(id);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (it->second.size() == 0)
|
|
|
+ SForbidStaffInfo & info = *it;
|
|
|
+ if (info.db_id == id)
|
|
|
{
|
|
|
- m_forbidlist.erase(it);
|
|
|
+ s->forbidList.erase(it);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+ if(s->forbidList.size() == 0)
|
|
|
+ {
|
|
|
+ forbid_staff_down_mine::instance()->remove(staff_id);
|
|
|
+ }
|
|
|
}
|
|
|
- forbid_staff_down_mine::instance()->remove(id);
|
|
|
}
|
|
|
|
|
|
//是否禁止状态
|
|
|
bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
|
|
|
{
|
|
|
- auto flist = m_forbidlist;
|
|
|
+ auto flist = m_map;
|
|
|
auto it = flist.find(staff_id);
|
|
|
if (it != flist.end())
|
|
|
{
|
|
|
- for (auto key : it->second)
|
|
|
+ for (auto &info : it->second->forbidList)
|
|
|
{
|
|
|
- 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)
|
|
|
+ if (info.state == 1 && cur_time > info.start_time && cur_time < info.end_time)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //del_forbid_staff(staff_id); //容易引起多线程问题 已过禁止时间 或者记录失效 删除
|
|
|
return false;
|
|
|
}
|