123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //
- // Created by Administrator on 2019/1/17.
- //
- #include "common_data.h"
- #include "db_api/CDBSingletonDefine.h"
- #include "log.h"
- common_data::common_data()
- {
- m_map_scale = 2;
- }
- common_data::~common_data()
- {
- }
- void common_data::init_data()
- {
- init_data_workface();
- init_data_bind_card_vechicle();
- init_data_bind_card_workface();
- init_data_map();
- m_map_scale = 2;
- m_cur_map_id = 0;
- }
- /*初始化工作面*/
- int common_data::init_data_workface()
- {
- const char * sql = "SELECT work_face_id, work_face_type,name,map_id,area_id,lastUpdate FROM dat_work_face;";
- std::string Error = "";
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(sql,DBRes,Error))
- {
- logn_error(2,"TR-init_data_workface Query exist error, error: %s", Error.c_str());
- return 1;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- m_workface.clear();
- while ( DBRes.GetNextRecod(Error) )
- {
- std::shared_ptr<WorkfaceDBData> p = std::make_shared<WorkfaceDBData>();
- DBRes.GetField( "work_face_id",p->workface_id, Error );
- DBRes.GetField( "work_face_type",p->workface_type, Error );
- DBRes.GetField( "name",p->workface_name, Error );
- DBRes.GetField( "map_id",p->map_id, Error );
- DBRes.GetField( "area_id",p->area_id, Error );
- DBRes.GetField( "lastUpdate",p->lastUpdateTime, Error );
- m_workface.insert(make_pair(p->workface_id,p));
- }
- }
- return 0;
- }
- /*初始化车卡对应车卡ID*/
- int common_data::init_data_bind_card_vechicle()
- {
- const char * sql = "SELECT vehicle_id, card_id FROM dat_vehicle_extend;";
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(sql,DBRes,Error))
- {
- logn_error(2,"TR-init_data_bind_card_vechicle Query exist error, error: %s", Error.c_str());
- return 1;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- m_card_vehicle.clear();
- while ( DBRes.GetNextRecod(Error) )
- {
- int vehicle_id = 0;
- std::string card_id = "";
- DBRes.GetField( "vehicle_id",vehicle_id, Error );
- DBRes.GetField( "card_id",card_id, Error );
- m_card_vehicle.insert(make_pair(card_id,vehicle_id));
- m_vehicle_card.insert(make_pair(vehicle_id,card_id));
- }
- }
- return 0;
- }
- /*初始化车卡对应工作面 */
- int common_data::init_data_bind_card_workface()
- {
- const char * sql = "SELECT b.coalface_id as face_id , a.card_id FROM dat_vehicle_extend a, dat_coalface_vehicle b "
- "where a.vehicle_id = b.vehicle_id "
- "UNION "
- "SELECT b.drivingface_id as face_id , a.card_id FROM dat_vehicle_extend a, dat_drivingface_vehicle b "
- "where a.vehicle_id = b.vehicle_id;";
- std::string Error;
- YADB::CDBResultSet DBRes;
- if (0 == sDBConnPool.Query(sql,DBRes,Error))
- {
- logn_error(2,"TR-init_data_bind_card_workface Query exist error, error: %s", Error.c_str());
- return 1;
- }
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount > 0)
- {
- m_card_workface.clear();
- while ( DBRes.GetNextRecod(Error) )
- {
- int face_id = 0;
- std::string card_id = "";
- DBRes.GetField( "face_id",face_id, Error );
- DBRes.GetField( "card_id",card_id, Error );
- card_id = "00" + card_id;
- m_card_workface.insert(make_pair(card_id,face_id));
- }
- }
- return 0;
- }
- /*
- * 初始化地图信息,主要获得地图的比例尺数据
- */
- void common_data::init_data_map()
- {
- const char* sql = "select map_id,scale from dat_map_gis;";
- YADB::CDBResultSet DBRes;
- std::string szError;
- if (0 == sDBConnPool.Query(sql,DBRes,szError))
- {
- logn_error(2,"TR-init_data_bind_card_workface Query exist error, error: %s", szError.c_str());
- return ;
- }
- int nCount = DBRes.GetRecordCount( szError );
- if (nCount > 0)
- {
- m_map_list.clear();
- while (DBRes.GetNextRecod(szError))
- {
- map_info mapinfo;
- int map_id;
- double map_scale;
- DBRes.GetField("map_id",map_id, szError);
- DBRes.GetField("scale", map_scale, szError);
- mapinfo.m_map_id = map_id;
- mapinfo.m_map_scale = map_scale;
- m_map_list[map_id] = mapinfo;
- }
- }
- }
- /*根据卡ID获取工作面ID */
- int common_data::get_workface_id(std::string card_id)
- {
- auto it = m_card_workface.find(card_id);
- if (it != m_card_workface.end())
- {
- return it->second;
- }
- return -1;
- }
- /*根据卡ID获取车ID */
- int common_data::get_vechicle_id(std::string card_id)
- {
- auto it = m_card_vehicle.find(card_id);
- if (it != m_card_vehicle.end())
- {
- return it->second;
- }
- return -1;
- }
- /*根据车ID获取卡ID
- * return "" : 表示不存在
- * */
- std::string common_data::get_card_id(int vechicle_id)
- {
- auto it = m_vehicle_card.find(vechicle_id);
- if (it != m_vehicle_card.end())
- {
- return it->second;
- }
- return "";
- }
- /*获取工作面的DB数据* */
- std::shared_ptr<WorkfaceDBData> common_data::get_workface(int work_face_id)
- {
- auto it = m_workface.find(work_face_id);
- if (it != m_workface.end())
- {
- return it->second;
- }
- return nullptr;
- }
- /*设置当前的地图ID*/
- void common_data::set_map_id(int map_id)
- {
- if (map_id == m_cur_map_id)
- {
- return;
- }
- auto it = m_map_list.find(map_id);
- if (it == m_map_list.end())
- {
- return;
- }
- m_cur_map_id = map_id;
- m_map_scale = it->second.m_map_scale;
- }
|