load_c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. void card_list::init_vehicle(int64_t id64)
  2. {
  3. std::string strategy = config.get("car.strategy","car1");
  4. std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
  5. ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
  6. vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
  7. vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
  8. FROM dat_vehicle_extend ve \
  9. LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
  10. LEFT JOIN dat_card c ON ve.card_id = c.card_id \
  11. LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
  12. LEFT JOIN dat_group g ON ve.group_id = g.group_id \
  13. LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
  14. LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
  15. WHERE c.state_id = 0";
  16. std::string card_id_str = tool_other::to13str(id64);
  17. if(-1 == id64)
  18. {
  19. sql.append(";");
  20. }
  21. else
  22. {
  23. sql.append(" AND ve.card_id ='");
  24. sql.append(card_id_str);
  25. sql.append("';");
  26. std_debug("基础数据 增加或修改车卡 sql=%s", sql.c_str());
  27. log_info("基础数据 增加或修改车卡 sql=%s", sql.c_str());
  28. }
  29. std::string Error;
  30. YADB::CDBResultSet DBRes;
  31. sDBConnPool.Query(sql.c_str(),DBRes,Error);
  32. int nCount = DBRes.GetRecordCount( Error );
  33. if (nCount < 1)
  34. {
  35. log_error("增加或修改失败,数据库中找不到: card_id=%s", card_id_str.c_str());
  36. return ;
  37. }
  38. std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
  39. while ( DBRes.GetNextRecod(Error) )
  40. {
  41. unsigned int vehicle_id = 0;
  42. DBRes.GetField( "vehicle_id",vehicle_id, Error );
  43. std::string card_id;
  44. DBRes.GetField( "card_id",card_id, Error );
  45. uint32_t vsid = atoi(card_id.substr(3).c_str());
  46. unsigned int card_type_id = 0;
  47. DBRes.GetField( "card_type_id",card_type_id, Error );
  48. int dept_id = 0;
  49. DBRes.GetField( "dept_id",dept_id, Error );
  50. int group_id = 0;
  51. DBRes.GetField( "group_id",group_id, Error );
  52. int vehicle_type_id = 0;
  53. DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
  54. int vehicle_level_id = 0;
  55. DBRes.GetField( "vehicle_level_id",vehicle_level_id, Error );
  56. int need_display = 0;
  57. DBRes.GetField( "need_display",need_display, Error );
  58. int power_alarm = 0;
  59. DBRes.GetField( "power_alarm",power_alarm, Error );
  60. int vehicle_category_id = 0;
  61. DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
  62. int bigger_car_flag= 0;
  63. DBRes.GetField( "bigger_car_flag",bigger_car_flag, Error );
  64. double over_speed= 0;
  65. DBRes.GetField( "over_speed",over_speed, Error );
  66. //for now
  67. //vehicle_id = vsid;
  68. if(-1 == id64)
  69. {
  70. auto clb = std::make_shared<car>(strategy,vsid,need_display,card_type_id,
  71. dept_id,vehicle_category_id, vehicle_type_id,vehicle_level_id,vehicle_id);
  72. uint64_t cardid = getId(vsid,card_type_id);
  73. log_info("cardId:%llu,id:%d dept_id:%d,need_display:%d-cardid:%s,categoryid:%d,vchile_id:%d,type:%d",
  74. cardid,vsid,dept_id,need_display,card_id.c_str(),vehicle_category_id,vehicle_id,card_type_id);
  75. map.insert({cardid,clb});
  76. }
  77. else
  78. {
  79. auto card_id64 = card_list::to_id64(card_type_id, tool_other::id64_to_id(card_id));
  80. auto card_ptr = card_list::instance()->get(card_id64);
  81. if(card_ptr)
  82. {
  83. car* tmp_ptr= static_cast<car*>(card_ptr.get());
  84. tmp_ptr->m_display = static_cast<uint16_t>(need_display);
  85. tmp_ptr->m_deptid = dept_id;
  86. tmp_ptr->m_vehicle_category_id = vehicle_category_id;
  87. tmp_ptr->m_vehicle_type_id = vehicle_type_id;
  88. tmp_ptr->m_level_id = vehicle_level_id;
  89. }
  90. else
  91. {
  92. auto clb = std::make_shared<car>(strategy,vsid,need_display,card_type_id,dept_id,
  93. vehicle_category_id, vehicle_type_id,vehicle_level_id,vehicle_id);
  94. card_list::instance()->add(card_id64, clb);
  95. }
  96. log_info("基础数据 增加或修改车卡成功:卡id:%ld, dept_id:%d,need_display:%d,categoryid:%d",
  97. id64,dept_id,need_display,vehicle_category_id);
  98. std_debug("基础数据 增加或修改车卡成功:卡id:%ld, dept_id:%d,need_display:%d,categoryid:%d",
  99. id64,dept_id,need_display,vehicle_category_id);
  100. }
  101. }
  102. if(-1 == id64)
  103. {
  104. log_info( "init_vehicle. The record count=%d\n", nCount );
  105. card_list::instance()->add(map);
  106. }
  107. }