1
0

bindmorecard.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include "bindmorecard.h"
  2. #include <boost/algorithm/string/split.hpp>
  3. #include <boost/algorithm/string/classification.hpp>
  4. #include <config_file.h>
  5. #include "db_api/CDBSingletonDefine.h"
  6. #include "event.h"
  7. #include "db_tool.h"
  8. #include "common_tool.h"
  9. #include "tool_time.h"
  10. extern config_file config;
  11. RemoteCardFactory::RemoteCardFactory(cardMgr * owner)
  12. :CardFactory(owner)
  13. {
  14. int remote_hours = config.get("BindMoreCard.timeAlarm_remote",1);
  15. m_remote_slot =(int)((remote_hours*60 *60*1000)/TIME_WIN_MILLISEC);
  16. std_info("remote:%d",m_remote_slot);
  17. }
  18. CloserCardFactory::CloserCardFactory(cardMgr * owner)
  19. :CardFactory(owner)
  20. {
  21. int closer_hours = config.get("BindMoreCard.timeAlarm_closer",3);
  22. m_closer_slot =(int)((closer_hours*60*60*1000)/TIME_WIN_MILLISEC);
  23. std_info("closer:%d",m_closer_slot);
  24. }
  25. void CardFactory::handle_event(std::map<uint64_t,std::string> m)
  26. {
  27. for(const auto &x:m)
  28. {
  29. std::vector<std::string> vs;
  30. boost::split(vs,x.second,boost::is_any_of(","));
  31. std::uint64_t c1 =std::stoul( vs[0].substr(0,vs[0].find('&')));
  32. std::uint64_t c2 =std::stoul(vs[0].substr(vs[0].find('&')+1));
  33. std::string card1=tool_other::get_string_cardid(c1);
  34. std::string card2=tool_other::get_string_cardid(c2);
  35. std::string sc=card1+'&'+card2;
  36. std::string s1=card1.substr(3);
  37. std::string s2=card2.substr(3);
  38. std::string ss=s1>s2?s1+s2:s2+s1;
  39. uint32_t uc = std::stoul(ss);
  40. //create event;
  41. //limit_value === start_time;
  42. //cur_value === end_time;
  43. write_data(vs,card1,card2);
  44. create_event(uc,std::stof(vs[1])*1000,std::stof(vs[2])*1000,sc);
  45. }
  46. }
  47. void CloserCardFactory::create_event(uint32_t key,double lv,double cv,const std::string &desc)
  48. {
  49. log_info("creeat_event_closer:%s--%u,%f,%f",desc.c_str(),key,lv,cv);
  50. event_tool::instance()->handle_event(OT_MORE_CARD,ET_UWB_MORE_CARD,key,lv,cv,true,DT_COMMON,desc);
  51. }
  52. void RemoteCardFactory::create_event(uint32_t key,double lv,double cv,const std::string &desc)
  53. {
  54. log_info("creeat_event_remote:%s--%u,%f,%f",desc.c_str(),key,lv,cv);
  55. event_tool::instance()->handle_event(OT_MORE_CARD,ET_UWB_MORE_CARD,key,lv,cv,false,DT_COMMON,desc);
  56. }
  57. void CloserCardFactory::write_data(std::vector<std::string> &v,const std::string & card1,const std::string &card2)
  58. {
  59. std::stringstream ss;
  60. ss<<"REPLACE INTO uwb_more_card_info(uwb_cardone,uwb_cardtwo,uwb_timestamp,uwb_totaldis,uwb_ctindex) VALUES ";
  61. for (auto it = v.begin()+3;it != v.end()-1;it++)
  62. {
  63. std::vector<std::string> vt;
  64. boost::split(vt,*it,boost::is_any_of("&"));
  65. time_t time_T = atol(vt[0].c_str());
  66. std::string strTime = tool_time::to_str(time_T);
  67. ss<<"('"<<card1<<"','"<<card2<<"','"<<strTime<<"',"<<vt[1]<<","<<vt[2]<<"),";
  68. }
  69. std::string sql = ss.str();
  70. sql.pop_back();
  71. sql+=";";
  72. log_info("LemonHash_sql..%s",sql.c_str());
  73. db_tool::PushAsync(sql.c_str());
  74. }