special_area.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "special_area.h"
  2. #include "db_api/CDBSingletonDefine.h"
  3. #include "log.h"
  4. special_area_list * special_area_list::instance()
  5. {
  6. static special_area_list spl;
  7. return &spl;
  8. }
  9. int32_t special_area_list::get_special_id(uint32_t cardid,const point p,int32_t categoryid)
  10. {
  11. int32_t f = -1;
  12. for(const auto s:m_v)
  13. {
  14. if(p.x<=std::max(s.start_point.x,s.end_point.x)
  15. &&p.x>=std::min(s.start_point.x,s.end_point.x)
  16. &&p.y<=std::max(s.start_point.y,s.end_point.y)
  17. &&p.y>=std::min(s.start_point.y,s.end_point.y))
  18. //&&p.z<=std::max(s.start_point.z,s.end_point.z)
  19. //&&p.z>=std::min(s.start_point.z,s.end_point.z))
  20. {
  21. if(!s.car_type.empty())
  22. if(s.car_type.find(std::to_string(categoryid)) == std::string::npos)
  23. continue;
  24. if(m_m.find(s.special_area_id) != m_m.end())
  25. {
  26. auto v=m_m[s.special_area_id];
  27. if(std::find(v.begin(),v.end(),cardid)==v.end())
  28. continue;
  29. }
  30. f=s.special_area_id;
  31. }
  32. }
  33. return f;
  34. }
  35. void special_area_list::init_from_db()
  36. {
  37. init_special_area_entry();
  38. init_special_card();
  39. }
  40. void special_area_list::init_special_area_entry()
  41. {
  42. const char * sql = "SELECT serial_num, start_point_x, start_point_y, start_point_z, end_point_x, end_point_y, \
  43. end_point_z, special_area_id,car_type FROM dat_special_area_entry;";
  44. std::string Error;
  45. YADB::CDBResultSet DBRes;
  46. sDBConnPool.Query(sql,DBRes,Error);
  47. int nCount = DBRes.GetRecordCount( Error );
  48. if (nCount > 0)
  49. {
  50. log_info( "init_special_area. The record count=%d\n", nCount );
  51. while ( DBRes.GetNextRecod(Error) )
  52. {
  53. double start_x=0;
  54. DBRes.GetField( "start_point_x",start_x, Error );
  55. double start_y=0;
  56. DBRes.GetField( "start_point_y",start_y, Error );
  57. double start_z=0;
  58. DBRes.GetField( "start_point_z",start_z, Error );
  59. double end_x=0;
  60. DBRes.GetField( "end_point_x",end_x, Error );
  61. double end_y=0;
  62. DBRes.GetField( "end_point_y",end_y, Error );
  63. double end_z=0;
  64. DBRes.GetField( "end_point_z",end_z, Error );
  65. int areaid = 0;
  66. DBRes.GetField( "special_area_id",areaid, Error );
  67. std::string categoryid;
  68. DBRes.GetField( "car_type",categoryid, Error );
  69. m_v.emplace_back(start_x,start_y,start_z,end_x,end_y,end_z,areaid,categoryid);
  70. log_info("special area .....areaid:%d,categoryid:%s",areaid,categoryid.c_str());
  71. }
  72. }
  73. }
  74. void special_area_list::init_special_card()
  75. {
  76. const char * sql = "SELECT b.vehicle_id,a.special_area FROM dat_special_card a , dat_vehicle b WHERE a.card_name = b.name;";
  77. std::string Error;
  78. YADB::CDBResultSet DBRes;
  79. sDBConnPool.Query(sql,DBRes,Error);
  80. int nCount = DBRes.GetRecordCount( Error );
  81. if (nCount > 0)
  82. {
  83. log_info( "init_special_card. The record count=%d\n", nCount );
  84. while ( DBRes.GetNextRecod(Error) )
  85. {
  86. int vehicle_id = 0;
  87. DBRes.GetField( "vehicle_id",vehicle_id, Error );
  88. int areaid=0;
  89. DBRes.GetField( "special_area",areaid, Error );
  90. auto iter = m_m.find(areaid);
  91. if(iter != m_m.end())
  92. iter->second.push_back(vehicle_id);
  93. else
  94. m_m[areaid].push_back(vehicle_id);
  95. log_info("special card .....areaid:%d,categoryid:%d %d ..... %d",areaid,vehicle_id,m_m.size(),m_m[areaid].size());
  96. }
  97. }
  98. }