1
0
Prechádzať zdrojové kódy

新增井下显示人数=公告牌上显示(写入文件)需要可配置时间,路径等

chensongchao 5 rokov pred
rodič
commit
46ceee63ab
6 zmenil súbory, kde vykonal 140 pridanie a 16 odobranie
  1. 1 3
      card_person.cpp
  2. 8 0
      main.cpp
  3. 93 8
      mine_business.cpp
  4. 12 5
      mine_business.h
  5. 19 0
      ya_setting.cpp
  6. 7 0
      ya_setting.h

+ 1 - 3
card_person.cpp

@@ -240,8 +240,6 @@ point person::getSmoothPoint(uint64_t& t)
 }
 void person::get_card(bool f)
 {
-    if(!m_mine_tool->m_is_attendance)
-		return;
-	mine_business::inst()->fetch_add(m_display);
+	mine_business::inst()->fetch_add(m_display,m_mine_tool->m_is_attendance);
 }
 

+ 8 - 0
main.cpp

@@ -72,6 +72,12 @@ struct Init_Setting
             log_warn("连接webServer[%s] 失败!",url.c_str());
         }
 		CYaSetting::Init_sys_setting();
+        //公告牌显示设置
+        CYaSetting::g_bulletin_board_time = config.get("bulletinboard.showtime",1*60);
+        std::string tmpSz = config.get("bulletinboard.show_filepath","../log/bulletin");
+        CYaSetting::set_bulletin_board_path(tmpSz);
+        CYaSetting::g_bulletin_board_file_name = config.get("bulletinboard.show_filename","bulletin.txt");
+
         sit_list::instance()->load_from_db();
         card_list::instance()->init_card_from_db();
         area_list::instance()->init_from_db();
@@ -182,6 +188,7 @@ int main(int argc ,char * argv[])
     log_init("../etc/log.ini");
     if(config.open("../etc/config.ini"))
         return -1;
+
     Init_Setting is;
     is.init();
 
@@ -194,6 +201,7 @@ int main(int argc ,char * argv[])
 
     log_info("service_handle::instance(&mh)->run(%d)",port);
     std_info("service_handle::instance(&mh)->run(%d)",port);
+
     service_handle::instance(&mh)->run(port);
     
     sDBConnPool.Close();

+ 93 - 8
mine_business.cpp

@@ -16,6 +16,12 @@
 #include "card.h"
 #include "area.h"
 #include "event.h"
+#include <fstream>
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string.hpp>
 
 #include <rapidjson/writer.h>
 #include <rapidjson/stringbuffer.h>
@@ -137,21 +143,39 @@ struct card_sensor_mgr
 struct staffer_num_business
 {
 	void record_staffer_num();
-	void fetch_add(bool f)
+
+	void fetch_add(bool bDisplay,bool bAttendance = true)
     {
-        if(f)
+        if(bDisplay && bAttendance) {
             m_staff_num++;
+        }
+        if (bDisplay){
+            m_staff_show_num++;
+        }
 		m_staff_num_real++;
-        
     }
 	staffer_num_business()
 	{
         reset();
 		m_record_staffer_timeval = 0;
 	}
-	private:
-	void reset(){m_staff_num=0;m_staff_num_real=0;}
-	std::atomic<uint32_t> m_staff_num,m_staff_num_real;
+    uint32_t get_staff_num() const { return m_staff_num;}
+    uint32_t get_staff_show_num() const { return m_staff_show_num;}
+    uint32_t get_staff_real_num() const { return m_staff_num_real;}
+
+private:
+	void reset(){
+	    m_staff_num=0;
+	    m_staff_num_real=0;
+        m_staff_show_num = 0;
+	}
+	// 井下考勤并且要显示的人数
+	std::atomic<uint32_t> m_staff_num;
+	// 井下总人数
+    std::atomic<uint32_t> m_staff_num_real;
+    // 井下显示人数
+    std::atomic<uint32_t> m_staff_show_num;
+    // 通知web最后时间
 	std::time_t m_record_staffer_timeval;
 };
 
@@ -255,14 +279,18 @@ mine_business* mine_business::inst()
 }
 void mine_business::run_business()
 {
+    //公告牌显示井下人数
+    show_bulletin_board();
+
     record_staffer_num();
     handle_reverse_alarm();
     handle_rear_end();
 }
-void mine_business::fetch_add(bool f)
+void mine_business::fetch_add(bool bDisplay,bool bAttendance/* = true*/)
 {
-    m_staffer_num_ptr->fetch_add(f);
+    m_staffer_num_ptr->fetch_add(bDisplay,bAttendance);
 }
+
 void mine_business::record_staffer_num()
 {
     m_staffer_num_ptr->record_staffer_num();
@@ -297,6 +325,63 @@ void mine_business::clear_vehicle()
 {
     m_rear_ended_ptr->clear();
 }
+
+void mine_business::CreateDirectoryEx(const std::string & sPathName )
+{
+    std::vector<std::string> vecSegTag;
+    boost::split(vecSegTag, sPathName, boost::is_any_of("/"));
+    if (vecSegTag.size() == 1)  //数据发生错误
+    {
+        return;
+    }
+    std::string curPath = "";
+    for  (int i = 0 ; i < (int)vecSegTag.size() ; i++)
+    {
+        curPath += vecSegTag[i];
+        if(vecSegTag[i].length() > 1 && vecSegTag[i][0] != '.' )
+        {
+            int a = access(curPath.c_str(), F_OK);
+            if(a == -1)
+            {
+                mkdir(curPath.c_str(),0755);
+            }
+        }
+        curPath += "/";
+    }
+}
+
+//公告牌显示--当前井下人数: 100 人
+void mine_business::show_bulletin_board()
+{
+    std::time_t t = time(NULL);
+    if (m_lastshow_bulletin_time == 0)
+    {
+        m_lastshow_bulletin_time = t;
+        return;
+    }
+    if (t > m_lastshow_bulletin_time && t - m_lastshow_bulletin_time > CYaSetting::g_bulletin_board_time )
+    {
+        //把当前文件写到文件中
+        m_lastshow_bulletin_time = t;
+        uint32_t num = m_staffer_num_ptr->get_staff_show_num();
+        std::string path = CYaSetting::g_bulletin_board_path;
+        static bool g_bCreatePath = false;
+        if (!g_bCreatePath)
+        {
+            CreateDirectoryEx(path); //创建目录
+            g_bCreatePath = true;
+        }
+        path += "/" + CYaSetting::g_bulletin_board_file_name;
+        std::ofstream  f1(path.c_str());//打开文件用于写,若文件不存在就创建它
+        if(!f1.is_open()) {
+            return;//打开文件失败则结束运行
+        }
+        std::string szText = "井下当前总人数: " + std::to_string(num) + "人";
+        f1<< szText << std::endl;
+        f1.close(); //关闭文件
+        log_info("show_bulletin_board : %s" ,szText.c_str());
+    }
+}
 ///////staffer_num_business
 /**********************************
 //每两分钟把人员数量入库。

+ 12 - 5
mine_business.h

@@ -13,13 +13,14 @@ struct mine_business
 	mine_business(const mine_business&)=delete;
 	mine_business & operator=(const mine_business&)=delete;
 	static mine_business *inst();
-	void run_business();
-//人员数量曲线功能
-	void fetch_add(bool);
-//天线反向功能
+	void run_business();;
+	//人员数量曲线功能
+	// bDisplay : 显示 bAttendance:考勤
+	void fetch_add(bool bDisplay,bool bAttendance/* = true*/);
+	//天线反向功能
 	void load();
 	void make_reverse_condition(uint64_t type,uint32_t id,int32_t antid,uint32_t ct,uint64_t tof,uint32_t sid);
-//车辆防追尾告警
+	//车辆防追尾告警
 	void put(const std::shared_ptr<card_location_base>&);
 	void make_arg(uint64_t cid,const point &p,uint64_t t);
 	void clear_vehicle();
@@ -31,5 +32,11 @@ private:
 	std::unique_ptr<staffer_num_business> m_staffer_num_ptr;
 	std::unique_ptr<reverse_alarm_business> m_reverse_alarm_ptr;
 	std::unique_ptr<rear_end_collision_prevented_business> m_rear_ended_ptr;
+
+public:
+    //公告牌显示--当前井下人数: 100 人
+    std::time_t m_lastshow_bulletin_time = 0;
+    void show_bulletin_board();
+    void CreateDirectoryEx(const std::string & sPathName  );
 };
 #endif

+ 19 - 0
ya_setting.cpp

@@ -3,6 +3,11 @@
 #include "log.h"
 
 SSys_setting CYaSetting::m_sys_setting;
+int CYaSetting::g_bulletin_board_time = 5 * 60;
+// 公告牌显示内容文件的目录
+std::string CYaSetting::g_bulletin_board_path;
+// 公告牌显示内容文件名
+std::string CYaSetting::g_bulletin_board_file_name;
 /*
 * 从数据库的dat_setting表初始化系统阈值,
 * 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值
@@ -50,3 +55,17 @@ bool CYaSetting::Init_sys_setting()
     return true;
 }
 
+void CYaSetting::set_bulletin_board_path(std::string & path)
+{
+	if (path.length() == 0)
+	{
+		return;
+	}
+	if ( path[path.length() - 1] == '/')
+	{
+		g_bulletin_board_path = path.substr(0,path.length() - 1);
+		set_bulletin_board_path(g_bulletin_board_path);
+		return;
+	}
+	g_bulletin_board_path = path;
+}

+ 7 - 0
ya_setting.h

@@ -55,6 +55,13 @@ public:
     static SSys_setting m_sys_setting;
     static bool Init_sys_setting();
 
+    //公告牌显示-时间间隔
+    static int g_bulletin_board_time;
+    // 公告牌显示内容文件的目录
+    static std::string g_bulletin_board_path;
+    // 公告牌显示内容文件名
+    static std::string g_bulletin_board_file_name;
+    static void set_bulletin_board_path(std::string & path);
 };
 
 #endif