sys_setting.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. D_GetValue(m_sys_setting.site_no_position_time, "site_no_position_time", 60, "基站长时间无定位阈值(分钟数)");
  50. #undef D_GetValue
  51. if(strVal == "anti_collision"){
  52. val = "";
  53. DBRes.GetField("value", val, Error);
  54. log_info("init_setting: anti_collision:%s", val.c_str());
  55. m_sys_setting.init_anti_coll_value(val);
  56. }
  57. }
  58. 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, site_no_position_time: %d",
  59. m_sys_setting.rear_end_d,
  60. m_sys_setting.rear_end_t,
  61. m_sys_setting.over_count_person,
  62. m_sys_setting.over_count_vehicle,
  63. m_sys_setting.over_time_person,
  64. m_sys_setting.over_time_vehicle,
  65. m_sys_setting.over_speed,
  66. m_sys_setting.light_group_count,
  67. m_sys_setting.site_no_position_time
  68. );
  69. }
  70. Init_map_setting();
  71. return true;
  72. }
  73. bool CYaSetting::Init_map_setting()
  74. {
  75. m_sys_setting.mp_sid_solution.clear();
  76. m_sys_setting.mp_sids_index.clear();
  77. std::string Error;
  78. YADB::CDBResultSet DBRes;
  79. std::string sql = "select site_list, solution from dat_map_zhurong;";
  80. sDBConnPool.Query(sql.c_str(), DBRes, Error);
  81. int nCount = DBRes.GetRecordCount(Error);
  82. if (nCount > 0)
  83. {
  84. while (DBRes.GetNextRecod(Error))
  85. {
  86. std::string strVal = "";
  87. std::string val = "";
  88. DBRes.GetField("site_list", strVal, Error);
  89. std::vector<std::string> vt_sid;
  90. boost::split(vt_sid, strVal, boost::is_any_of(","));
  91. int nSolution = 0;
  92. DBRes.GetField("solution", nSolution, Error);
  93. int nResultIndex = 1;
  94. for (auto iter0 = vt_sid.begin(); iter0 != vt_sid.end(); iter0++)
  95. {
  96. m_sys_setting.mp_sid_solution.insert(std::make_pair(atoi(iter0->c_str()), nSolution));
  97. for (auto iter1 = iter0 + 1; iter1 != vt_sid.end(); ++iter1)
  98. {
  99. for (auto iter2 = iter1 + 1; iter2 != vt_sid.end(); ++iter2, ++nResultIndex)
  100. {
  101. if (nSolution == 0)
  102. {
  103. m_sys_setting.mp_sids_index.insert(std::make_pair(*iter0 + ',' + *iter1 + ',' + *iter2, 0));
  104. }
  105. else
  106. {
  107. m_sys_setting.mp_sids_index.insert(std::make_pair(*iter0 + ',' + *iter1 + ',' + *iter2, nResultIndex));
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. return true;
  115. }
  116. void ios_service::start_service_position(const int& port)
  117. {
  118. m_ios_service = service_position_ptr(new service_position_ptr::element_type());
  119. m_ios_service->set_port(port);
  120. m_ios_service->start();
  121. }