#ifndef __WORKTIME_RATE_H #define __WORKTIME_RATE_H #define LENGTH_SQL 2000 #include "three_rates.h" #include #include #include #include class BanShift { public: int shift_id; int shift_type_id; uint32_t start_time; uint32_t end_time; BanShift() {} BanShift(int sid,int tid, uint32_t stime, uint32_t etime) { shift_id = sid; shift_type_id = tid; start_time = stime%(24*3600); end_time = etime%(24*3600); } }; typedef std::map> BanShiftMap; class worktime { public: worktime(); ~worktime(); /* *@brief Load shift From dat_shift */ void init_shift(); /* *@brief when the card enter work_area record the date in DB *@param [in] const card_pos &pos \n *@param [in] const area_data &Area \n */ void enter_area(std::shared_ptr &card_ptr, std::shared_ptr &area_ptr); /* *@brief when the card leave work_area record the date in DB *@param [in] const card_pos &pos \n *@param [in] const area_data &Area \n */ void leave_area(std::shared_ptr &card_ptr, std::shared_ptr &area_ptr); private: /* *@brief Get current time for shitf *return shift_id *param [in] struct tm* current_time \n *param [in] int shift_type = 1 \n */ int _get_shift_id( time_t time); bool _get_start_worktime(int staff_id, time_t& out_time); BanShiftMap _shitf_map; //"%Y-%m-%d %H:%M:%S" static time_t to_time(std::string str) { time_t t_; tm tm_={0}; strptime(str.c_str(), "%Y-%m-%d %H:%M:%S", &tm_); //将字符串转换为tm时间 t_ = mktime(&tm_); //将tm时间转换为秒时间 return t_; } //%H:%M:%S" static uint32_t to_time_short(std::string str) { tm tm_; strptime(str.c_str(), "%H:%M:%S", &tm_); //将字符串转换为tm时间 //t_ = mktime(&tm_); //将tm时间转换为秒时间 return tm_.tm_hour*3600 + tm_.tm_min*60 + tm_.tm_sec; } static uint32_t to_time_short(std::time_t time) { std::string str = to_str(time); tm tm_; strptime(str.c_str(), "%Y-%m-%d %H:%M:%S", &tm_); //将字符串转换为tm时间 //t_ = mktime(&tm_); //将tm时间转换为秒时间 return tm_.tm_hour*3600 + tm_.tm_min*60 + tm_.tm_sec; } //"%Y-%m-%d %H:%M:%S" static std::string to_str(const std::time_t &time) { char _time[25] = {0}; struct tm local_time; localtime_r(&time, &local_time); strftime(_time, 22, "%Y-%m-%d %H:%M:%S", &local_time); return std::string(_time); } uint32_t now_to_seconds() { return static_cast( std::chrono::duration_cast (std::chrono::system_clock::now().time_since_epoch()).count() ); } }; #endif//__WORKTIME_RATE_H