123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- void card_list::init_vehicle(int64_t id64)
- {
- std::string strategy = config.get("car.strategy","car1");
- std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, \
- ve.dept_id, ve.group_id, v.vehicle_type_id, vt.vehicle_level_id, \
- vt.is_railroad AS vt_is_railroad,ve.need_display ,ve.power_alarm,\
- vt.vehicle_category_id,v.bigger_car_flag,vc.over_speed \
- FROM dat_vehicle_extend ve \
- LEFT JOIN dat_vehicle v ON ve.vehicle_id = v.vehicle_id \
- LEFT JOIN dat_card c ON ve.card_id = c.card_id \
- LEFT JOIN dat_dept d ON ve.dept_id = d.dept_id \
- LEFT JOIN dat_group g ON ve.group_id = g.group_id \
- LEFT JOIN dat_vehicle_type vt ON v.vehicle_type_id = vt.vehicle_type_id \
- LEFT JOIN dat_vehicle_category vc ON vc.vehicle_category_id = vt.vehicle_category_id \
- WHERE c.state_id = 0";
- std::string card_id_str = tool_other::to13str(id64);
- if(-1 == id64)
- {
- sql.append(";");
- }
- else
- {
- sql.append(" AND ve.card_id ='");
- sql.append(card_id_str);
- sql.append("';");
- std_debug("基础数据 增加或修改车卡 sql=%s", sql.c_str());
- log_info("基础数据 增加或修改车卡 sql=%s", sql.c_str());
- }
- std::string Error;
- YADB::CDBResultSet DBRes;
- sDBConnPool.Query(sql.c_str(),DBRes,Error);
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount < 1)
- {
- log_error("增加或修改失败,数据库中找不到: card_id=%s", card_id_str.c_str());
- return ;
- }
- std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
- while ( DBRes.GetNextRecod(Error) )
- {
- unsigned int vehicle_id = 0;
- DBRes.GetField( "vehicle_id",vehicle_id, Error );
- std::string card_id;
- DBRes.GetField( "card_id",card_id, Error );
- uint32_t vsid = atoi(card_id.substr(3).c_str());
- unsigned int card_type_id = 0;
- DBRes.GetField( "card_type_id",card_type_id, Error );
- int dept_id = 0;
- DBRes.GetField( "dept_id",dept_id, Error );
- int group_id = 0;
- DBRes.GetField( "group_id",group_id, Error );
- int vehicle_type_id = 0;
- DBRes.GetField( "vehicle_type_id",vehicle_type_id, Error );
- int vehicle_level_id = 0;
- DBRes.GetField( "vehicle_level_id",vehicle_level_id, Error );
- int need_display = 0;
- DBRes.GetField( "need_display",need_display, Error );
- int power_alarm = 0;
- DBRes.GetField( "power_alarm",power_alarm, Error );
- int vehicle_category_id = 0;
- DBRes.GetField( "vehicle_category_id",vehicle_category_id, Error );
- int bigger_car_flag= 0;
- DBRes.GetField( "bigger_car_flag",bigger_car_flag, Error );
- double over_speed= 0;
- DBRes.GetField( "over_speed",over_speed, Error );
- //for now
- //vehicle_id = vsid;
- if(-1 == id64)
- {
- auto clb = std::make_shared<car>(strategy,vsid,need_display,card_type_id,
- dept_id,vehicle_category_id, vehicle_type_id,vehicle_level_id,vehicle_id);
- uint64_t cardid = getId(vsid,card_type_id);
- log_info("cardId:%llu,id:%d dept_id:%d,need_display:%d-cardid:%s,categoryid:%d,vchile_id:%d,type:%d",
- cardid,vsid,dept_id,need_display,card_id.c_str(),vehicle_category_id,vehicle_id,card_type_id);
- map.insert({cardid,clb});
- }
- else
- {
- auto card_id64 = card_list::to_id64(card_type_id, tool_other::id64_to_id(card_id));
- auto card_ptr = card_list::instance()->get(card_id64);
- if(card_ptr)
- {
- car* tmp_ptr= static_cast<car*>(card_ptr.get());
- tmp_ptr->m_display = static_cast<uint16_t>(need_display);
- tmp_ptr->m_deptid = dept_id;
- tmp_ptr->m_vehicle_category_id = vehicle_category_id;
- tmp_ptr->m_vehicle_type_id = vehicle_type_id;
- tmp_ptr->m_level_id = vehicle_level_id;
- }
- else
- {
- auto clb = std::make_shared<car>(strategy,vsid,need_display,card_type_id,dept_id,
- vehicle_category_id, vehicle_type_id,vehicle_level_id,vehicle_id);
- card_list::instance()->add(card_id64, clb);
- }
- log_info("基础数据 增加或修改车卡成功:卡id:%ld, dept_id:%d,need_display:%d,categoryid:%d",
- id64,dept_id,need_display,vehicle_category_id);
- std_debug("基础数据 增加或修改车卡成功:卡id:%ld, dept_id:%d,need_display:%d,categoryid:%d",
- id64,dept_id,need_display,vehicle_category_id);
- }
- }
- if(-1 == id64)
- {
- log_info( "init_vehicle. The record count=%d\n", nCount );
- card_list::instance()->add(map);
- }
- }
|