1
0
zhuyf 3 лет назад
Родитель
Сommit
5ab4153628
2 измененных файлов с 183 добавлено и 0 удалено
  1. 81 0
      sys_setting.cpp
  2. 102 0
      sys_setting.h

+ 81 - 0
sys_setting.cpp

@@ -0,0 +1,81 @@
+#include "sys_setting.h"
+#include "db/db_api/CDBSingletonDefine.h"
+#include "log.h"
+#include <config_file.h>
+
+extern config_file config;
+SSys_setting CYaSetting::m_sys_setting;
+service_position_ptr ios_service::m_ios_service;
+
+/*
+* 从数据库的dat_setting表初始化系统阈值,
+* 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值
+*/
+bool CYaSetting::Init_sys_setting()
+{
+    {
+        m_sys_setting.rav_disable=config.get("service.rav_disable","");
+        log_info("rav_disable:%s",m_sys_setting.rav_disable.c_str());
+    }
+	std::string Error;
+	YADB::CDBResultSet DBRes;
+	std::string sql = "select setting_id, name, type, value from dat_setting;";
+	sDBConnPool.Query(sql.c_str(),DBRes,Error);
+	int nCount = DBRes.GetRecordCount( Error );
+	if (nCount > 0)
+	{
+		while ( DBRes.GetNextRecod(Error) )
+		{
+			std::string strVal = "";
+			std::string val="";
+			DBRes.GetField("name",strVal, Error );
+#define D_GetValue(K,N,X,PS) \
+			if(strVal==N)\
+			{DBRes.GetField("value",val, Error);\
+			log_info("init_setting:%s,%s",N,val.c_str());\
+			K = atoi(val.c_str())*X;}\
+
+			D_GetValue(m_sys_setting.over_count_person,"over_count_person",1,"人员井下超员")
+			D_GetValue(m_sys_setting.over_count_vehicle,"over_count_vehicle",1,"车辆井下超员")
+			D_GetValue(m_sys_setting.over_time_person,"over_time_person",60,"人员井下超时")
+			D_GetValue(m_sys_setting.over_time_vehicle,"over_time_vehicle",60,"车辆井下超时")
+			D_GetValue(m_sys_setting.over_speed,"over_speed",1,"车辆超速限值")
+			D_GetValue(m_sys_setting.att_starttime_offset_staff,"att_starttime_offset_staff",60,"考勤开始时间向前偏移分钟数")
+			D_GetValue(m_sys_setting.att_endtime_offset_staff,"att_endtime_offset_staff",60,"车辆考勤开始时间向前偏移分钟数")
+			D_GetValue(m_sys_setting.att_starttime_offset_vehicle,"att_starttime_offset_vehicle",60,"车辆考勤结束时间向后偏移分钟数")
+			D_GetValue(m_sys_setting.att_endtime_offset_vehicle,"att_endtime_offset_vehicle",60,"车辆考勤结束时间向后偏移分钟数")
+			D_GetValue(m_sys_setting.att_person_thre_hour,"att_person_thre_hour",60*60,"")
+			D_GetValue(m_sys_setting.rear_end_d,"rear_end_distance",1,"")
+			D_GetValue(m_sys_setting.rear_end_t,"rear_end_time",1,"")
+			D_GetValue(m_sys_setting.geofault_warn_dis,"geofault_warn",1,"")
+            D_GetValue(m_sys_setting.light_group_count, "light_group_count", 1, "")
+#undef D_GetValue
+
+            if(strVal == "anti_collision"){
+                val = "";
+                DBRes.GetField("value", val, Error);
+                log_info("init_setting: anti_collision:%s", val.c_str());
+                m_sys_setting.init_anti_coll_value(val);
+            }
+        }
+        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",
+                    m_sys_setting.rear_end_d,
+                    m_sys_setting.rear_end_t,
+					m_sys_setting.over_count_person,
+                    m_sys_setting.over_count_vehicle,
+                    m_sys_setting.over_time_person,
+                    m_sys_setting.over_time_vehicle,
+                    m_sys_setting.over_speed,
+                    m_sys_setting.light_group_count
+                    );
+	}
+
+    return true;
+}
+
+void ios_service::start_service_position(const int& port)
+{
+    m_ios_service = service_position_ptr(new service_position_ptr::element_type());
+    m_ios_service->set_port(port);
+    m_ios_service->start();
+}

+ 102 - 0
sys_setting.h

@@ -0,0 +1,102 @@
+#ifndef _YASL_SETTINS_H
+#define _YASL_SETTINS_H
+
+#include <time.h>
+#include <map>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string/classification.hpp>
+#include "common_tool.h"
+#include "service_position.h"
+
+// 系统设置,,读取DB.dat_setting
+struct  SSys_setting // system_limit_setting
+{
+	unsigned int over_count_person; // 井下人员超员
+	unsigned int over_count_vehicle; // 井下车辆超员
+	unsigned int over_time_person; // 井下人员超时
+	unsigned int over_time_vehicle; // 井下车辆超时
+	double over_speed; // 井下车辆超速
+
+	// 考勤偏移时间
+	int att_starttime_offset_staff;
+	int att_endtime_offset_staff;
+	int att_starttime_offset_vehicle;
+	int att_endtime_offset_vehicle; 
+	uint64_t att_person_thre_hour;
+	//车辆防追尾配置数据
+	double rear_end_d;
+	time_t rear_end_t;
+	double geofault_warn_dis;
+    std::string rav_disable;
+    int light_group_count;
+    // 人车防碰撞参数,三个档位
+    std::map<int, float> mp_anti_collision;
+
+    SSys_setting()
+    {
+        init();
+    }
+    bool check_rav(uint8_t type,uint32_t id)
+    {
+        bool f = false;
+        std::string cardid=tool_other::type_id_to_str(type,id);
+        if(rav_disable.find(cardid) != std::string::npos) 
+            f=true;
+        return f;
+    }
+    void init()
+    {
+        over_count_person = 1000;
+        over_count_vehicle = 100;
+        over_speed = 30;
+        over_time_person = 36000;
+        over_time_vehicle = 18000;
+        att_endtime_offset_staff = 600;
+        att_endtime_offset_vehicle = 600;
+        att_starttime_offset_staff = 900;
+        att_starttime_offset_vehicle = 600;
+        att_person_thre_hour = 0;
+        rear_end_d = 0;
+        rear_end_t = 0;
+        geofault_warn_dis=50; 
+        rav_disable = "";
+        light_group_count = 1;
+        mp_anti_collision.erase(mp_anti_collision.begin(), mp_anti_collision.end());
+    }
+
+    void init_anti_coll_value(const std::string& ctx)
+    {
+        std::string c = ctx;
+        std::vector<std::string> vt;
+        boost::split(vt, c, boost::is_any_of(","));
+
+        for(size_t i = 0;i < vt.size(); ++i)
+        {
+            mp_anti_collision.insert(std::make_pair(i, atof(vt[i].c_str())));
+        }
+    }
+
+    bool del_anti_coll_value()
+    {
+        mp_anti_collision.clear();
+        return mp_anti_collision.empty();
+    }
+};
+
+class CYaSetting
+{
+public:
+    /*
+    * 从数据库的dat_setting表初始化系统阈值,
+    * 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值
+    */
+    static SSys_setting m_sys_setting;
+    static bool Init_sys_setting();
+};
+
+struct ios_service{
+    static service_position_ptr m_ios_service;
+    static void start_service_position(const int& port);
+};
+
+#endif