12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "bindmorecard.h"
- #include <boost/algorithm/string/split.hpp>
- #include <boost/algorithm/string/classification.hpp>
- #include <config_file.h>
- #include "db_api/CDBSingletonDefine.h"
- #include "event.h"
- #include "db_tool.h"
- #include "common_tool.h"
- #include "tool_time.h"
- extern config_file config;
- RemoteCardFactory::RemoteCardFactory(cardMgr * owner)
- :CardFactory(owner)
- {
- int remote_hours = config.get("BindMoreCard.timeAlarm_remote",1);
- m_remote_slot =(int)((remote_hours*60 *60*1000)/TIME_WIN_MILLISEC);
- std_info("remote:%d",m_remote_slot);
- }
- CloserCardFactory::CloserCardFactory(cardMgr * owner)
- :CardFactory(owner)
- {
- int closer_hours = config.get("BindMoreCard.timeAlarm_closer",3);
- m_closer_slot =(int)((closer_hours*60*60*1000)/TIME_WIN_MILLISEC);
- std_info("closer:%d",m_closer_slot);
- }
- void CardFactory::handle_event(std::map<uint64_t,std::string> m)
- {
- for(const auto &x:m)
- {
- std::vector<std::string> vs;
- boost::split(vs,x.second,boost::is_any_of(","));
- std::uint64_t c1 =std::stoul( vs[0].substr(0,vs[0].find('&')));
- std::uint64_t c2 =std::stoul(vs[0].substr(vs[0].find('&')+1));
- std::string card1=tool_other::get_string_cardid(c1);
- std::string card2=tool_other::get_string_cardid(c2);
- std::string sc=card1+'&'+card2;
- std::string s1=card1.substr(3);
- std::string s2=card2.substr(3);
- std::string ss=s1>s2?s1+s2:s2+s1;
- uint32_t uc = std::stoul(ss);
- //create event;
- //limit_value === start_time;
- //cur_value === end_time;
- write_data(vs,card1,card2);
- create_event(uc,std::stof(vs[1])*1000,std::stof(vs[2])*1000,sc);
- }
- }
- void CloserCardFactory::create_event(uint32_t key,double lv,double cv,const std::string &desc)
- {
- log_info("creeat_event_closer:%s--%u,%f,%f",desc.c_str(),key,lv,cv);
- event_tool::instance()->handle_event(OT_MORE_CARD,ET_UWB_MORE_CARD,key,lv,cv,true,DT_COMMON,desc);
- }
- void RemoteCardFactory::create_event(uint32_t key,double lv,double cv,const std::string &desc)
- {
- log_info("creeat_event_remote:%s--%u,%f,%f",desc.c_str(),key,lv,cv);
- event_tool::instance()->handle_event(OT_MORE_CARD,ET_UWB_MORE_CARD,key,lv,cv,false,DT_COMMON,desc);
- }
- void CloserCardFactory::write_data(std::vector<std::string> &v,const std::string & card1,const std::string &card2)
- {
- std::stringstream ss;
- ss<<"REPLACE INTO uwb_more_card_info(uwb_cardone,uwb_cardtwo,uwb_timestamp,uwb_totaldis,uwb_ctindex) VALUES ";
- for (auto it = v.begin()+3;it != v.end()-1;it++)
- {
- std::vector<std::string> vt;
- boost::split(vt,*it,boost::is_any_of("&"));
- time_t time_T = atol(vt[0].c_str());
- std::string strTime = tool_time::to_str(time_T);
- ss<<"('"<<card1<<"','"<<card2<<"','"<<strTime<<"',"<<vt[1]<<","<<vt[2]<<"),";
- }
- std::string sql = ss.str();
- sql.pop_back();
- sql+=";";
- log_info("LemonHash_sql..%s",sql.c_str());
- db_tool::PushAsync(sql.c_str());
- }
|