sys_setting.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "sys_setting.h"
  2. #include "db/db_api/CDBSingletonDefine.h"
  3. #include "log.h"
  4. #include <config_file.h>
  5. extern config_file config;
  6. SSys_setting CYaSetting::m_sys_setting;
  7. service_position_ptr ios_service::m_ios_service;
  8. /*
  9. * 从数据库的dat_setting表初始化系统阈值,
  10. * 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值
  11. */
  12. bool CYaSetting::Init_sys_setting()
  13. {
  14. {
  15. m_sys_setting.rav_disable=config.get("service.rav_disable","");
  16. log_info("rav_disable:%s",m_sys_setting.rav_disable.c_str());
  17. }
  18. std::string Error;
  19. YADB::CDBResultSet DBRes;
  20. std::string sql = "select setting_id, name, type, value from dat_setting;";
  21. sDBConnPool.Query(sql.c_str(),DBRes,Error);
  22. int nCount = DBRes.GetRecordCount( Error );
  23. if (nCount > 0)
  24. {
  25. while ( DBRes.GetNextRecod(Error) )
  26. {
  27. std::string strVal = "";
  28. std::string val="";
  29. DBRes.GetField("name",strVal, Error );
  30. #define D_GetValue(K,N,X,PS) \
  31. if(strVal==N)\
  32. {DBRes.GetField("value",val, Error);\
  33. log_info("init_setting:%s,%s",N,val.c_str());\
  34. K = atoi(val.c_str())*X;}\
  35. D_GetValue(m_sys_setting.over_count_person,"over_count_person",1,"人员井下超员")
  36. D_GetValue(m_sys_setting.over_count_vehicle,"over_count_vehicle",1,"车辆井下超员")
  37. D_GetValue(m_sys_setting.over_time_person,"over_time_person",60,"人员井下超时")
  38. D_GetValue(m_sys_setting.over_time_vehicle,"over_time_vehicle",60,"车辆井下超时")
  39. D_GetValue(m_sys_setting.over_speed,"over_speed",1,"车辆超速限值")
  40. D_GetValue(m_sys_setting.att_starttime_offset_staff,"att_starttime_offset_staff",60,"考勤开始时间向前偏移分钟数")
  41. D_GetValue(m_sys_setting.att_endtime_offset_staff,"att_endtime_offset_staff",60,"车辆考勤开始时间向前偏移分钟数")
  42. D_GetValue(m_sys_setting.att_starttime_offset_vehicle,"att_starttime_offset_vehicle",60,"车辆考勤结束时间向后偏移分钟数")
  43. D_GetValue(m_sys_setting.att_endtime_offset_vehicle,"att_endtime_offset_vehicle",60,"车辆考勤结束时间向后偏移分钟数")
  44. D_GetValue(m_sys_setting.att_person_thre_hour,"att_person_thre_hour",60*60,"")
  45. D_GetValue(m_sys_setting.rear_end_d,"rear_end_distance",1,"")
  46. D_GetValue(m_sys_setting.rear_end_t,"rear_end_time",1,"")
  47. D_GetValue(m_sys_setting.geofault_warn_dis,"geofault_warn",1,"")
  48. D_GetValue(m_sys_setting.light_group_count, "light_group_count", 1, "")
  49. #undef D_GetValue
  50. if(strVal == "anti_collision"){
  51. val = "";
  52. DBRes.GetField("value", val, Error);
  53. log_info("init_setting: anti_collision:%s", val.c_str());
  54. m_sys_setting.init_anti_coll_value(val);
  55. }
  56. }
  57. log_info("init_setting:rear_end_d:%f, rear_end_t:%ld, over_count_person:%u, over_count_vehicle:%u, over_time_person:%u, over_time_vehicle:%u, over_speed:%f, light_group_count:%d",
  58. m_sys_setting.rear_end_d,
  59. m_sys_setting.rear_end_t,
  60. m_sys_setting.over_count_person,
  61. m_sys_setting.over_count_vehicle,
  62. m_sys_setting.over_time_person,
  63. m_sys_setting.over_time_vehicle,
  64. m_sys_setting.over_speed,
  65. m_sys_setting.light_group_count
  66. );
  67. }
  68. return true;
  69. }
  70. void ios_service::start_service_position(const int& port)
  71. {
  72. m_ios_service = service_position_ptr(new service_position_ptr::element_type());
  73. m_ios_service->set_port(port);
  74. m_ios_service->start();
  75. }