123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //
- // 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)
- {
- sql += " and id = " + std::to_string(id) + ";";
- }
- else
- {
- m_map.clear();
- }
- 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);
- std::shared_ptr<SForbidStaffList> s = nullptr;
- if (id != -1)
- {
- s = forbid_staff_down_mine::instance()->get(s_id);
- if (s != nullptr)
- {
- 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;
- return;
- }
- }
- }
- }
- if (s == nullptr)
- {
- s = std::make_shared<SForbidStaffList>();
- }
- s->staff_id = s_id;
- 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)
- {
- 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);
- if (s != nullptr)
- {
- 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)
- {
- s->forbidList.erase(it);
- break;
- }
- }
- if(s->forbidList.size() == 0)
- {
- forbid_staff_down_mine::instance()->remove(staff_id);
- }
- }
- }
- //是否禁止状态
- bool forbid_staff_down_mine::IsForbid(int staff_id,time_t cur_time)
- {
- auto flist = m_map;
- auto it = flist.find(staff_id);
- if (it != flist.end())
- {
- for (auto &info : it->second->forbidList)
- {
- if (info.state == 1 && cur_time > info.start_time && cur_time < info.end_time)
- {
- return true;
- }
- }
- }
- return false;
- }
|