123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- //
- // 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";
- if (id != -1)
- {
- m_map.clear();
- sql += " and id = " + std::to_string(id) + ";";
- }
- std::string Error;
- YADB::CDBResultSet DBRes;
- sDBConnPool.Query(sql.c_str(),DBRes,Error);
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount < 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);
- 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);
- if (id != -1)
- {
- auto s = get(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;
- }
- }
- std::shared_ptr<SForbidStaffInfo> s = std::make_shared<SForbidStaffInfo>();
- 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);
- }
- }
- 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);
- }
- }
- void forbid_staff_down_mine::del_forbid_data(int id)
- {
- auto s = forbid_staff_down_mine::instance()->get(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())
- {
- for (auto key : it->second)
- {
- if(key == id)
- {
- it->second.remove(id);
- break;
- }
- }
- if (it->second.size() == 0)
- {
- m_forbidlist.erase(it);
- }
- }
- }
- 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 it = flist.find(staff_id);
- if (it != flist.end())
- {
- for (auto key : it->second)
- {
- 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)
- {
- return true;
- }
- }
- }
- //del_forbid_staff(staff_id); //容易引起多线程问题 已过禁止时间 或者记录失效 删除
- return false;
- }
|