123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- #include <memory>
- #include <unordered_map>
- #include "log.h"
- #include "config_file.h"
- #include "db_api/CDBResultSet.h"
- #include "db_api/CDBSingletonDefine.h"
- #include "../card_base.h"
- #include "../card_person.h"
- #include "../common.h"
- #include "../common_tool.h"
- extern config_file config;
- namespace db_card
- {
- std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_car(const std::string & lszId64)
- {
- std::string sql = "SELECT ve.vehicle_id, ve.card_id, c.card_type_id, cf.freq_value, \
- 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, ve.enable_anti_collision \
- 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 \
- LEFT JOIN dat_card_freq cf on cf.freq_id = c.freq_id \
- WHERE c.state_id = 0";
- std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
- if("" == lszId64)
- {
- sql.append(";");
- }
- else
- {
- sql.append(" AND ve.card_id ='");
- sql.append(lszId64);
- sql.append("';");
- }
- std::string Error;
- YADB::CDBResultSet DBRes;
- sDBConnPool.Query(sql.c_str(),DBRes,Error);
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount < 1)
- {
- log_error("增加或修改失败,数据库中找不到: sql=%s", sql.c_str());
- return 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 );
- double freq = 0;
- DBRes.GetField("freq_value", freq, 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 );
- uint32_t type = tool_other::card_id_to_type(card_id);
- if(type != card_type_id)
- {
- log_error("init_vehicle_card error.Type is not matching..");
- continue;
- }
- std::string strategy;
- if(card_type_id ==CT_VEHICLE)
- strategy = config.get("car.strategy","CS_1");
- else if(vehicle_type_id==VT_COAL_CUTTER)
- strategy = config.get("coalface.strategy","WS_1");
- else
- strategy = config.get("person.strategy","PS_1");
- auto clb = card_location_base::make_car(strategy,vsid,need_display,card_type_id,
- dept_id,vehicle_category_id, vehicle_type_id,vehicle_level_id,vehicle_id);
- uint64_t cardid = tool_other::type_id_to_u64(card_type_id,vsid);
- clb->m_freq = freq;
- int anti_collision = 0;
- DBRes.GetField("enable_anti_collision", anti_collision, Error);
- clb->m_enable_anti_collision = ((anti_collision == 1) ? true : false);
-
- map.insert({cardid,clb});
- log_info("cardId:%s,id:%d dept_id:%d,need_display:%d-cardid:%s,categoryid:%d,vchile_id:%d,type:%d,vehicle_type_id:%d, anti_collision:%d",
- card_id.c_str(),
- vsid,
- dept_id,
- need_display,
- card_id.c_str(),
- vehicle_category_id,
- vehicle_id,
- card_type_id,
- vehicle_type_id,
- anti_collision
- );
- }
- return map;
- }
- std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> load_person(const std::string & lszId64,const std::string&strategy)
- {
- std::string sql = "SELECT s.staff_id, s.card_id, c.card_type_id, cf.freq_value, s.dept_id, s.group_id, s.occupation_id, \
- ol.occupation_level_id,s.worktype_id,s.need_display,s.work_line\
- ,ds.name as staffer_name,dd.name as dept_name\
- FROM dat_staff_extend s \
- LEFT JOIN dat_staff ds ON ds.staff_id = s.staff_id \
- LEFT JOIN dat_dept dd ON dd.dept_id = s.dept_id \
- LEFT JOIN dat_card c ON s.card_id = c.card_id \
- LEFT JOIN dat_occupation o ON s.occupation_id = o.occupation_id \
- LEFT JOIN dat_occupation_level ol ON ol.occupation_level_id = o.occupation_level_id \
- LEFT JOIN dat_card_freq cf on cf.freq_id = c.freq_id \
- WHERE s.duty_id = 0 AND c.state_id = 0";
- std::unordered_map<uint64_t,std::shared_ptr<card_location_base>> map;
- if("" == lszId64)
- {
- sql.append(";");
- }
- else
- {
- sql.append(" AND s.card_id = '");
- sql.append(lszId64);
- sql.append("';");
- }
- std::string Error;
- YADB::CDBResultSet DBRes;
- sDBConnPool.Query(sql.c_str(),DBRes,Error);
- int nCount = DBRes.GetRecordCount( Error );
- if (nCount < 1)
- {
- log_error("增加或修改失败,数据库中找不到: sql=%s", sql.c_str());
- return map;
- }
- while ( DBRes.GetNextRecod(Error) )
- {
- unsigned int staff_id = 0;
- DBRes.GetField( "staff_id",staff_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 );
- double freq = 0;
- DBRes.GetField("freq_value", freq, Error);
- int dept_id = 0;
- DBRes.GetField( "dept_id",dept_id, Error );
- int group_id = 0;
- DBRes.GetField( "group_id",group_id, Error );
- int occupation_id = 0;
- DBRes.GetField( "occupation_id",occupation_id, Error );
- int occupation_level_id = 0;
- DBRes.GetField( "occupation_level_id",occupation_level_id, Error );
- int need_display = 0;
- DBRes.GetField( "need_display",need_display, Error );
- int work_line = 0;
- DBRes.GetField( "work_line",work_line, Error );
- std::string staffer_name;
- DBRes.GetField( "staffer_name",staffer_name, Error );
- std::string dept_name;
- DBRes.GetField( "dept_name",dept_name, Error );
- int worktype_id;
- DBRes.GetField( "worktype_id",worktype_id, Error );
- uint32_t type = tool_other::card_id_to_type(card_id);
- if(type != card_type_id)
- {
- log_error("init_staffer_card error.Type is not matching..");
- continue;
- }
- std::shared_ptr<card_location_base> clb =
- std::make_shared<person>(strategy, vsid, need_display, card_type_id, dept_id, occupation_level_id, staff_id, work_line, staffer_name, dept_name, worktype_id);
- uint64_t cardid = tool_other::type_id_to_u64(card_type_id,vsid);
- clb->m_freq = freq;
- log_info("Init_card.cardId:%llu,id:%d dept_id:%d,need_display:%d,card:%s:work_line:%d,staff_id:%d,type:%d,staffer_name:%s,dept_name:%s",
- cardid, vsid, dept_id, need_display, card_id.c_str(), work_line, staff_id, card_type_id,staffer_name.c_str(), dept_name.c_str());
- map.insert({cardid,clb});
- }
- return map;
- }
- }
|