123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include <cmath>
- #include "card_tool.h"
- #include "log.h"
- #include "db/db_tool.h"
- #include "sstream"
- card_tool::card_tool()
- :m_staff_num(0)
- ,m_record_staffer_timeval(0)
- {}
- card_tool* card_tool::inst()
- {
- static card_tool ct;
- return &ct;
- }
- void card_tool::fetch_add()
- {
- m_staff_num++;
- }
- void card_tool::reset()
- {
- m_staff_num=0;
- }
- void card_tool::record_stffer_num()
- {
- static uint32_t min_num=0,max_num=0;
- std::time_t t = time(NULL);
- char ti[64] = { 0 };
- strftime(ti,sizeof(ti),"%Y/%m/%d %H:%M:%S",localtime(&t));
- std::string sti(ti);
- int minute = atoi(sti.substr(sti.find_first_of(':')+1,2).c_str());
- if(m_record_staffer_timeval==0)
- {
- min_num=max_num=m_staff_num;
- m_record_staffer_timeval = t;
- }
- if(t-m_record_staffer_timeval>=120 && minute%2 == 0)
- {
- std::stringstream ss;
- ss<< "INSERT INTO his_staff_number(max_num,min_num,ave_num) VALUES("<<max_num<<','<<min_num<<','<<std::lround((max_num+min_num)/2)<<");";
- logn_info(2,"staff_number:%s",ss.str().c_str());
- db_tool::PushAsync(ss.str().c_str());
- min_num=max_num=m_staff_num;
- m_record_staffer_timeval = t;
- }
- else
- {
- if (min_num>m_staff_num) min_num = m_staff_num;
- if (max_num < m_staff_num) max_num = m_staff_num;
- }
- reset();
- return;
- }
|