Browse Source

优化公告牌显示

chensongchao 5 năm trước cách đây
mục cha
commit
6288b3fd60

+ 1 - 1
Makefile.am

@@ -22,7 +22,7 @@ SRC_MAIN= ant.cpp area.cpp base64.cpp bindmorecard.cpp mine_business.cpp card_ar
 		  landmark.cpp line_fit.cpp  message.cpp message_file.cpp mine.cpp \
 		  net-service.cpp point.cpp  special_area.cpp tdoa_sync.cpp visit.cpp \
 		  web-client.cpp worker.cpp event.cpp znet.cpp ya_setting.cpp area_business.cpp\
-		  forbid_staff_down_mine.cpp
+		  forbid_staff_down_mine.cpp bulletin_broad_show.cpp
 
 AM_SOURCES=$(SRC_MONKEYCAR) $(SRC_MODULE_SERVICE) $(SRC_MAIN) $(SRC_MAIN_EVENT)
 

+ 118 - 0
bulletin_broad_show.cpp

@@ -0,0 +1,118 @@
+//
+// Created by songchao.chen on 2019/6/26.
+//
+
+#include "bulletin_broad_show.h"
+#include "mine_business.h"
+#include <config_file.h>
+#include <boost/algorithm/string/split.hpp>
+#include <boost/algorithm/string.hpp>
+#include <fstream>
+#include <unistd.h>
+#include <sys/stat.h>
+#include "log.h"
+#include <tool_time.h>
+
+bulletin_broad_show::bulletin_broad_show()
+{
+
+}
+bulletin_broad_show* bulletin_broad_show::inst()
+{
+    static bulletin_broad_show mb;
+    return &mb;
+}
+
+void bulletin_broad_show::OnInit(config_file * config)
+{
+    if (config == nullptr)
+    {
+        return;
+    }
+    //公告牌显示设置
+    m_bulletin_board_time = config->get("bulletinboard.showtime",1*60);
+    std::string tmpSz = config->get("bulletinboard.show_filepath","../log/bulletin");
+    set_bulletin_board_path(tmpSz);
+    m_bulletin_board_file_name = config->get("bulletinboard.show_filename","bulletin.txt");
+}
+
+void bulletin_broad_show::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 += "/";
+    }
+}
+
+void bulletin_broad_show::run_bulletin_board()
+{
+    uint32_t t = tool_time::now_to_seconds();
+    if (m_lastshow_bulletin_time == 0)
+    {
+        m_lastshow_bulletin_time = t;
+        return;
+    }
+    if (t > m_lastshow_bulletin_time && t - m_lastshow_bulletin_time > m_bulletin_board_time )
+    {
+        //把当前文件写到文件中
+        m_lastshow_bulletin_time = t;
+        uint32_t num = mine_business::inst()->get_mine_display_staff_num();
+        std::string path = m_bulletin_board_path;
+        static bool g_bCreatePath = false;
+        if (!g_bCreatePath)
+        {
+            CreateDirectoryEx(path); //创建目录
+            g_bCreatePath = true;
+        }
+        path += "/" + m_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());
+    }
+}
+
+void bulletin_broad_show::set_bulletin_board_path(std::string & path)
+{
+    if (path.length() == 0)
+    {
+        return;
+    }
+    int count = 0;
+    for(int i = path.length() - 1 ; i > 0 ;i--)
+    {
+        if ( path[i] == '/')
+        {
+            count++;
+        }
+        else
+        {
+            break;
+        }
+    }
+    m_bulletin_board_path = path;
+    if (count > 0)
+    {
+        m_bulletin_board_path = path.substr(0,path.length() - count);
+    }
+}

+ 39 - 0
bulletin_broad_show.h

@@ -0,0 +1,39 @@
+//
+// Created by songchao.chen on 2019/6/26.
+// 公告牌显示
+//
+
+#ifndef WORKSPACE_BULLETIN_BROAD_SHOW_H
+#define WORKSPACE_BULLETIN_BROAD_SHOW_H
+
+#include <string>
+
+struct config_file;
+struct bulletin_broad_show
+{
+private:
+    bulletin_broad_show();
+public:
+    bulletin_broad_show(const bulletin_broad_show&)=delete;
+    bulletin_broad_show & operator=(const bulletin_broad_show&)=delete;
+    static bulletin_broad_show *inst();
+
+    void OnInit(config_file * config);
+    //公告牌显示
+    void run_bulletin_board();
+private:
+    void CreateDirectoryEx(const std::string & sPathName );
+    void set_bulletin_board_path(std::string & path);
+
+    //公告牌显示--当前井下人数: 100 人
+    uint32_t m_lastshow_bulletin_time = 0;
+    //公告牌显示-时间间隔
+    uint32_t m_bulletin_board_time = 0 ;
+    // 公告牌显示内容文件的目录
+    std::string m_bulletin_board_path = "";
+    // 公告牌显示内容文件名
+    std::string m_bulletin_board_file_name = "";
+};
+
+
+#endif //WORKSPACE_BULLETIN_BROAD_SHOW_H

+ 5 - 1
card_person.cpp

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

+ 2 - 5
main.cpp

@@ -22,6 +22,7 @@
 #include "ya_setting.h"
 #include "websocket/web_connect.h"
 #include "forbid_staff_down_mine.h"
+#include "bulletin_broad_show.h"
 
 config_file config;
 void handlereader(uint32_t readerid,bool duration,uint32_t t)
@@ -72,11 +73,7 @@ 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");
+        bulletin_broad_show::inst()->OnInit(&config);
 
         sit_list::instance()->load_from_db();
         card_list::instance()->init_card_from_db();

+ 34 - 2
main_test.h

@@ -74,13 +74,45 @@ struct test_Sa{
             printf("WSClient Send DataLen=%d count=%d \n",(int)text.length(),count++);
         }
     }
+
+    static void test_geofault(void * p)
+    {
+        sleep(5);
+        std::shared_ptr<card_location_base> c = card_list::instance()->get_card_by_cid(1116);
+        if (c != nullptr)
+        {
+            double x = 2542.0;
+            double y = -180;
+            double a = 2;
+            point p(2542.0,y,0); //2542.0,-227.2,
+            c->set(p);
+            c->get_area_tool()->m_site = sit_list::instance()->get(245);
+
+            while (true)
+            {
+                y = y - a;
+                if (y < -222)
+                {
+                    a = -2;
+                }
+                else if (y >  -180)
+                {
+                    a = 2;
+                }
+                c->set(x,y,0);
+                p.set(x,y,0);
+                c->get_area_tool()->on_point(c,p);
+                sleep(1);
+            }
+        }
+    }
 };
 
 
 void test_createthread()
 {
-    for (int i = 1 ; i < 1 ; i++)
+    for (int i = 0 ; i < 1 ; i++)
     {
-        new  std::thread( std::bind( &test_Sa::Test_JsonDataSend, &i ) );
+        new  std::thread( std::bind( &test_Sa::test_geofault, &i ) );
     }
 }

+ 6 - 74
mine_business.cpp

@@ -16,12 +16,6 @@
 #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>
@@ -144,13 +138,10 @@ struct staffer_num_business
 {
 	void record_staffer_num();
 
-	void fetch_add(bool bDisplay,bool bAttendance = true)
+	void fetch_add(bool bDisplay)
     {
-        if(bDisplay && bAttendance) {
+        if(bDisplay) {
             m_staff_num++;
-        }
-        if (bDisplay){
-            m_staff_show_num++;
         }
 		m_staff_num_real++;
     }
@@ -160,21 +151,17 @@ struct staffer_num_business
 		m_record_staffer_timeval = 0;
 	}
     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;
 };
@@ -279,16 +266,13 @@ 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 bDisplay,bool bAttendance/* = true*/)
+void mine_business::fetch_add(bool bDisplay)
 {
-    m_staffer_num_ptr->fetch_add(bDisplay,bAttendance);
+    m_staffer_num_ptr->fetch_add(bDisplay);
 }
 
 void mine_business::record_staffer_num()
@@ -326,61 +310,9 @@ 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()
+uint32_t mine_business::get_mine_display_staff_num()
 {
-    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());
-    }
+    return m_staffer_num_ptr->get_staff_num();
 }
 ///////staffer_num_business
 /**********************************

+ 5 - 10
mine_business.h

@@ -13,10 +13,9 @@ struct mine_business
 	mine_business(const mine_business&)=delete;
 	mine_business & operator=(const mine_business&)=delete;
 	static mine_business *inst();
-	void run_business();;
-	//人员数量曲线功能
-	// bDisplay : 显示 bAttendance:考勤
-	void fetch_add(bool bDisplay,bool bAttendance/* = true*/);
+	void run_business();
+	//人员数量曲线功
+	void fetch_add(bool);
 	//天线反向功能
 	void load();
 	void make_reverse_condition(uint64_t type,uint32_t id,int32_t antid,uint32_t ct,uint64_t tof,uint32_t sid);
@@ -24,6 +23,8 @@ struct mine_business
 	void put(const std::shared_ptr<card_location_base>&);
 	void make_arg(uint64_t cid,const point &p,uint64_t t);
 	void clear_vehicle();
+
+	uint32_t get_mine_display_staff_num();
 private:
 	mine_business();
 	void handle_reverse_alarm();
@@ -32,11 +33,5 @@ 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

+ 1 - 1
module_service/module_meta_date_changed.cpp

@@ -76,7 +76,7 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
             int id = std::stoi(szParam);
             deal_call_edit_path(id, edit_type_id);
         }
-        else if(JSON_KEY_NAME_MAP == name)
+        else if(JSON_KEY_NAME_MAP == name || JSON_KEY_NAME_MAP_GIS == name)
         {
             int id = std::stoi(szParam);
             deal_call_edit_map(id, edit_type_id);

+ 2 - 1
websocket/constdef.h

@@ -51,7 +51,8 @@
 #define JSON_KEY_OP_TYPE_DELETE "DELETE"
 
 #define JSON_KEY_NAME "name"
-#define JSON_KEY_NAME_MAP "map_gis"
+#define JSON_KEY_NAME_MAP_GIS "map_gis"
+#define JSON_KEY_NAME_MAP "map"
 #define JSON_KEY_NAME_AREA "area"
 #define JSON_KEY_NAME_PATH "reader_path_tof_n"
 #define JSON_KEY_NAME_READER "reader"

+ 2 - 0
worker.cpp

@@ -17,6 +17,7 @@
 #include "area.h"
 #include "clock.h"
 #include "mine_business.h"
+#include "bulletin_broad_show.h"
 
 loop_thread::loop_thread ()
 {
@@ -104,6 +105,7 @@ struct timer_worker_thread: loop_thread
 			mine_business::inst()->clear_vehicle();
 		}
 		card_list::instance()->accept(clv);
+		bulletin_broad_show::inst()->run_bulletin_board();
 		mine_business::inst()->run_business();
 
 		log_info("timer_worker_thread use time:%ldus", clock.count_us());

+ 1 - 19
ya_setting.cpp

@@ -5,11 +5,7 @@
 #include <config_file.h>
 extern config_file config;
 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表初始化系统阈值,
 * 包括:井下人员阈值,井下车辆阈值,人员超时阈值,车辆超时阈值,车辆超速阈值
@@ -61,17 +57,3 @@ 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;
-}

+ 0 - 8
ya_setting.h

@@ -63,14 +63,6 @@ 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